GUIlib: Quick port to SDL 2.0

From 2880c090c04fede50bea7ab8bb383cf3572a9313 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 20 Jun 2022 10:30:02 -0700
Subject: [PATCH] Quick port to SDL 2.0

---
 GUI.cpp           |  10 +++--
 GUI.h             |   5 ++-
 GUI_C.cpp         |   4 +-
 GUI_C.h           |   2 +-
 GUI_area.cpp      |   4 +-
 GUI_area.h        |   2 +-
 GUI_button.cpp    |  13 +++---
 GUI_button.h      |   6 +--
 GUI_font.cpp      |  14 +++----
 GUI_font.h        |   6 +--
 GUI_loadimage.cpp |   2 +-
 GUI_menu.cpp      |   8 ++--
 GUI_menu.h        |  10 ++---
 GUI_output.cpp    |  31 ++++++++------
 GUI_output.h      |   4 +-
 GUI_termwin.cpp   |  55 +++++++++++++------------
 GUI_termwin.h     |  14 +++----
 GUI_widget.cpp    |  21 +++++++---
 GUI_widget.h      |  12 +++---
 Makefile.am       |   1 -
 Makefile.in       |   1 -
 aclocal.m4        | 100 ++++++++++++++++++++++++++++++++++++++++++++++
 configure         |  28 ++++++-------
 configure.ac      |  12 +++---
 hello.cpp         |  21 +++++-----
 hello_C.c         |  17 ++++----
 keyboard.cpp      |  43 ++++++--------------
 okay.c            |  11 ++---
 28 files changed, 272 insertions(+), 185 deletions(-)

diff --git a/GUI.cpp b/GUI.cpp
index cd68c5e..b8d8305 100644
--- a/GUI.cpp
+++ b/GUI.cpp
@@ -12,9 +12,10 @@
 #define WIDGET_ARRAYCHUNK	32
 
 
-GUI:: GUI(SDL_Surface *display)
+GUI:: GUI(SDL_Window *window)
 {
-	screen = display;
+	m_window = window;
+	screen = SDL_GetWindowSurface(window);
 	numwidgets = 0;
 	maxwidgets = 0;
 	widgets = NULL;
@@ -62,7 +63,7 @@ GUI:: AddWidget(GUI_Widget *widget)
 		++numwidgets;
 	}
 	widgets[i] = widget;
-	widget->SetDisplay(screen);
+	widget->SetDisplay(m_window);
 	return(0);
 }
 
@@ -76,7 +77,7 @@ GUI:: Display(void)
 			widgets[i]->Display();
 		}
 	}
-	SDL_UpdateRect(screen, 0, 0, 0, 0);
+	SDL_UpdateWindowSurface(m_window);
 }
 
 /* Function to handle a GUI status */
@@ -109,6 +110,7 @@ GUI:: HandleEvent(const SDL_Event *event)
 			break;
 
 		/* Keyboard and mouse events go to widgets */
+		case SDL_TEXTINPUT:
 		case SDL_KEYDOWN:
 		case SDL_KEYUP:
 		case SDL_MOUSEMOTION:
diff --git a/GUI.h b/GUI.h
index fdaad9d..a4a475d 100644
--- a/GUI.h
+++ b/GUI.h
@@ -15,7 +15,7 @@
 class GUI {
 
 public:
-	GUI(SDL_Surface *display);
+	GUI(SDL_Window *window);
 	~GUI();
 
 	/* Add a widget to the GUI.
@@ -48,6 +48,9 @@ class GUI {
 	void Run(GUI_IdleProc idle = NULL, int once = 0, int multitaskfriendly = 0);
 
 protected:
+	/* The display window */
+	SDL_Window *m_window;
+
 	/* The display surface */
 	SDL_Surface *screen;
 
diff --git a/GUI_C.cpp b/GUI_C.cpp
index 97f4c51..4b55218 100644
--- a/GUI_C.cpp
+++ b/GUI_C.cpp
@@ -10,9 +10,9 @@
 extern "C" {
 
 /* Create a GUI */
-CGUI *GUI_Create(SDL_Surface *screen)
+CGUI *GUI_Create(SDL_Window *window)
 {
-	return((CGUI *)new GUI(screen));
+	return((CGUI *)new GUI(window));
 }
 
 /* Create a generic widget */
diff --git a/GUI_C.h b/GUI_C.h
index f4b8b6a..5088b44 100644
--- a/GUI_C.h
+++ b/GUI_C.h
@@ -42,7 +42,7 @@ typedef void (*GUI_FreeProc)(widget_info *info);
 
 
 /* Create a GUI */
-extern CGUI *GUI_Create(SDL_Surface *screen);
+extern CGUI *GUI_Create(SDL_Window *window);
 
 /* Create a generic widget */
 extern CGUI_Widget *GUI_Widget_Create(void *data, int x, int y, int w, int h,
diff --git a/GUI_area.cpp b/GUI_area.cpp
index 4454331..afec7d0 100644
--- a/GUI_area.cpp
+++ b/GUI_area.cpp
@@ -36,9 +36,9 @@ GUI_Area:: GUI_Area(int x, int y, int w, int h, Uint8 r, Uint8 g, Uint8 b,
 
 /* Map the color to the display */
 void
-GUI_Area:: SetDisplay(SDL_Surface *display)
+GUI_Area:: SetDisplay(SDL_Window *window)
 {
-	GUI_Widget::SetDisplay(display);
+	GUI_Widget::SetDisplay(window);
 	color = SDL_MapRGB(screen->format, R, G, B);
 	if (useFrame)
 	  frameColor = SDL_MapRGB(screen->format, fR, fG, fB);
diff --git a/GUI_area.h b/GUI_area.h
index 8600bb1..5eccae4 100644
--- a/GUI_area.h
+++ b/GUI_area.h
@@ -23,7 +23,7 @@ class GUI_Area : public GUI_Widget {
 			Uint8 fr, Uint8 fg, Uint8 fb, int fthick, int aShape = AREA_ANGULAR);
 
 	/* Map the color to the display */
-	virtual void SetDisplay(SDL_Surface *display);
+	virtual void SetDisplay(SDL_Window *window);
 
 	/* Show the widget  */
 	virtual void Display(void);
diff --git a/GUI_button.cpp b/GUI_button.cpp
index 0d746ed..f7fc06c 100644
--- a/GUI_button.cpp
+++ b/GUI_button.cpp
@@ -68,7 +68,7 @@ GUI_Button:: GUI_Button(void *data, int x, int y, int w, int h,
 	checked=0;
 }
 
-GUI_Button::GUI_Button(void *data, int x, int y, int w, int h, char *text,
+GUI_Button::GUI_Button(void *data, int x, int y, int w, int h, const char *text,
 		       GUI_Font *font, int alignment, int is_checkbutton,
 		       GUI_ActiveProc activeproc, int flat)
  : GUI_Widget(data,x,y,w,h)
@@ -98,7 +98,7 @@ GUI_Button::GUI_Button(void *data, int x, int y, int w, int h, char *text,
   if (is_checkable &&(checkmarks==NULL))
   {
     checkmarks=GUI_LoadImage(checker_w,checker_h,checker_pal,checker_data);
-    SDL_SetColorKey(checkmarks,SDL_SRCCOLORKEY,0);
+    SDL_SetColorKey(checkmarks,SDL_TRUE,0);
   }
   ChangeTextButton(-1,-1,-1,-1,text,alignment);
 
@@ -122,7 +122,7 @@ GUI_Button::~GUI_Button()
 }
 
 /* Resize/reposition/change text */
-void GUI_Button::ChangeTextButton(int x, int y, int w, int h, char* text, int alignment)
+void GUI_Button::ChangeTextButton(int x, int y, int w, int h, const char* text, int alignment)
 {
   if (x>=0)
     area.x=x;
@@ -277,11 +277,12 @@ void GUI_Button::Enable(int flag)
 	Redraw();
 }
 
-SDL_Surface* GUI_Button::CreateTextButtonImage(int style, char *text, int alignment)
+SDL_Surface* GUI_Button::CreateTextButtonImage(int style, const char *_text, int alignment)
 {
   SDL_Rect fillrect;
   int th,tw,tx,ty;
-  SDL_Surface *img=SDL_AllocSurface(SDL_SWSURFACE,area.w,area.h,
+  char *text;
+  SDL_Surface *img=SDL_CreateRGBSurface(SDL_SWSURFACE,area.w,area.h,
 				    16,31 << 11,63 << 5,31,0);
   Uint32 color1=SDL_MapRGB(img->format,BL_R,BL_G,BL_B);
   Uint32 color2=SDL_MapRGB(img->format,BS_R,BS_G,BS_B);
@@ -290,6 +291,7 @@ SDL_Surface* GUI_Button::CreateTextButtonImage(int style, char *text, int alignm
 
   if (img==NULL) return NULL;
 
+  text=SDL_strdup(_text);
   buttonFont->SetColoring(0,0,0);
   buttonFont->SetTransparency(1);
   buttonFont->TextExtent(text,&tw,&th);
@@ -360,5 +362,6 @@ SDL_Surface* GUI_Button::CreateTextButtonImage(int style, char *text, int alignm
     buttonFont->TextOut(img,tx,ty,text);
     break;
   }
+  SDL_free(text);
   return img;
 }
diff --git a/GUI_button.h b/GUI_button.h
index dcdf540..1f13def 100644
--- a/GUI_button.h
+++ b/GUI_button.h
@@ -52,14 +52,14 @@ class GUI_Button : public GUI_Widget {
 	/* Passed the button data, position, width, height, a caption, a font,
 	   an alignment (one of the constants above), if it should be a checkbutton (1/0),
 	   the callback and a flag if it should be 2D (1) or 3D (0) */
-	GUI_Button(void *data, int x, int y, int w, int h, char* text,
+	GUI_Button(void *data, int x, int y, int w, int h, const char* text,
 		   GUI_Font *font, int alignment, int is_checkbutton,
 		   GUI_ActiveProc activeproc = NULL, int flat = 0);
 
 	~GUI_Button();
 
 	/* change features of a text button (if one of the dimensions is negativ, it's ignored) */
-	virtual void ChangeTextButton(int x, int y, int w, int h, char* text, int alignment);
+	virtual void ChangeTextButton(int x, int y, int w, int h, const char* text, int alignment);
 
 	/* Show the widget  */
 	virtual void Display(void);
@@ -83,7 +83,7 @@ class GUI_Button : public GUI_Widget {
 
 protected:
 	/* yields an appropriate image */
-	virtual SDL_Surface* CreateTextButtonImage(int style, char *text, int alignment);
+	virtual SDL_Surface* CreateTextButtonImage(int style, const char *text, int alignment);
 
 	/* The button font */
 	GUI_Font *buttonFont;
diff --git a/GUI_font.cpp b/GUI_font.cpp
index 9944c65..b587608 100644
--- a/GUI_font.cpp
+++ b/GUI_font.cpp
@@ -17,7 +17,7 @@ GUI_Font::GUI_Font()
 }
 
 /* open named BMP file */
-GUI_Font::GUI_Font(char *name)
+GUI_Font::GUI_Font(const char *name)
 {
   fontStore=SDL_LoadBMP(name);
   if (fontStore!=NULL)
@@ -68,21 +68,19 @@ GUI_Font::~GUI_Font()
 /* determine drawing style */
 void GUI_Font::SetTransparency(int on)
 {
-  if (transparent=on)  // single "=" is correct
-    SDL_SetColorKey(fontStore,SDL_SRCCOLORKEY,0);
-  else
-    SDL_SetColorKey(fontStore,0,0);
+  transparent=on;
+  SDL_SetColorKey(fontStore,on,0);
 }
 
 /* determine foreground and background color values RGB*/
 void GUI_Font::SetColoring(Uint8 fr, Uint8 fg, Uint8 fb, Uint8 br, Uint8 bg, Uint8 bb)
 {
   SDL_Color colors[3]={{br,bg,bb,0},{fr,fg,fb,0}};
-  SDL_SetColors(fontStore,colors,0,2);
+  SDL_SetPaletteColors(fontStore->format->palette,colors,0,2);
 }
 
 /* put the text onto the given surface using the preset mode and colors */
-void GUI_Font::TextOut(SDL_Surface* context,int x, int y, char* text)
+void GUI_Font::TextOut(SDL_Surface* context,int x, int y, const char* text)
 {
   int i;
   Uint8 ch;
@@ -94,7 +92,7 @@ void GUI_Font::TextOut(SDL_Surface* context,int x, int y, char* text)
   dst.w = charw;
   dst.h = charh-1;
   i=0;
-  while (ch=text[i])  // single "=" is correct!
+  while ((ch=text[i]) != 0)
   {
     src.x = (ch%16)*charw;
     src.y = (ch/16)*charh;
diff --git a/GUI_font.h b/GUI_font.h
index 0904ab4..ae3a8e8 100644
--- a/GUI_font.h
+++ b/GUI_font.h
@@ -13,7 +13,7 @@ class GUI_Font
   GUI_Font();
 
   /* open named BMP file */
-  GUI_Font(char *name);
+  GUI_Font(const char *name);
 
   /* use given YxY surface */
   GUI_Font(SDL_Surface *bitmap);
@@ -38,11 +38,11 @@ class GUI_Font
     {return charw;}
 
   /* yields pixel width and height of a string when printed with this font */
-  inline virtual void TextExtent(char *text, int *w, int *h)
+  inline virtual void TextExtent(const char *text, int *w, int *h)
     {*w=strlen(text)*charw; *h=charh-1;}
 
   /* put the text onto the given surface using the preset mode and colors */
-  virtual void TextOut(SDL_Surface *context, int x, int y, char* text);
+  virtual void TextOut(SDL_Surface *context, int x, int y, const char* text);
 
 protected:
   /* the font source surface */
diff --git a/GUI_loadimage.cpp b/GUI_loadimage.cpp
index 4be2861..e5e1338 100644
--- a/GUI_loadimage.cpp
+++ b/GUI_loadimage.cpp
@@ -13,7 +13,7 @@ SDL_Surface *GUI_LoadImage(int w, int h, Uint8 *pal, Uint8 *data)
 {
 	SDL_Surface *image;
 
-	image = SDL_AllocSurface(SDL_SWSURFACE, w, h, 8, 0, 0, 0, 0);
+	image = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 8, 0, 0, 0, 0);
 	if ( image ) {
 		for ( int row=0; row<h; ++row ) {
 			memcpy((Uint8 *)image->pixels + row * image->pitch,
diff --git a/GUI_menu.cpp b/GUI_menu.cpp
index acda901..4ea2e35 100644
--- a/GUI_menu.cpp
+++ b/GUI_menu.cpp
@@ -20,7 +20,7 @@ static GUI_status Default_MenuActiveProc(int caller_id, int is_checked, void *un
 
 
 GUI_Submenu::GUI_Submenu(GUI_Menu *Aparent, int Asubmenuid, int x, int y,
-			 char *Atext, GUI_Font *Afont, int is_checkmenu)
+			 const char *Atext, GUI_Font *Afont, int is_checkmenu)
   : GUI_Button(NULL,x,y,(strlen(Atext)+is_checkmenu*2)*Afont->CharWidth()+(MENU_OVERSIZE << 1),
 	       Afont->CharHeight()+MENU_OVERSIZE,Atext,Afont,
 	       BUTTON_TEXTALIGN_LEFT,is_checkmenu,NULL,1)
@@ -138,7 +138,7 @@ void GUI_Submenu::SetItemsClickState(int button, int value)
 //////////////////////////////////////////////////////////////////////////////////////
 
 GUI_Menuitem::GUI_Menuitem(GUI_Menu *Aparent,int Asubmenuid, int Aid,
-			   int x, int y, char *Atext, GUI_Font *Afont,
+			   int x, int y, const char *Atext, GUI_Font *Afont,
 			   GUI_MenuActiveProc activeproc, int is_checkmenu)
   : GUI_Submenu(Aparent,Asubmenuid,x,y,Atext,Afont,is_checkmenu)
 {
@@ -178,7 +178,7 @@ GUI_Menu::~GUI_Menu()
 // future: free dynamic items array
 }
 
-void GUI_Menu::AddSubmenu(int Asubmenuid, char *Atext)
+void GUI_Menu::AddSubmenu(int Asubmenuid, const char *Atext)
 {
   int newpos=0;
 
@@ -192,7 +192,7 @@ void GUI_Menu::AddSubmenu(int Asubmenuid, char *Atext)
   }
 }
 
-void GUI_Menu::AddMenuitem(int Asubmenuid, int Aid, char *Atext,
+void GUI_Menu::AddMenuitem(int Asubmenuid, int Aid, const char *Atext,
 	       GUI_MenuActiveProc Aactiveproc, int is_checkmenu)
 {
   GUI_Submenu *temp=NULL;
diff --git a/GUI_menu.h b/GUI_menu.h
index 320d364..07d57a2 100644
--- a/GUI_menu.h
+++ b/GUI_menu.h
@@ -31,7 +31,7 @@ class GUI_Submenu : public GUI_Button
 
  public:
 
-  GUI_Submenu(GUI_Menu *Aparent, int Asubmenuid, int x, int y, char *Atext,
+  GUI_Submenu(GUI_Menu *Aparent, int Asubmenuid, int x, int y, const char *Atext,
 	      GUI_Font *Afont, int is_checkmenu);
 
   virtual ~GUI_Submenu();
@@ -49,7 +49,7 @@ class GUI_Submenu : public GUI_Button
     {return numitems;}
   inline virtual int GetLength()
     {return strlen(Text);}
-  inline virtual char* GetText()
+  inline virtual const char* GetText()
     {return Text;}
 
   virtual void SetItemsClickState(int button, int value);
@@ -72,7 +72,7 @@ class GUI_Menuitem : public GUI_Submenu
 
  public:
   GUI_Menuitem(GUI_Menu *Aparent, int Asubmenuid, int Aid, int x, int y,
-	       char *Atext, GUI_Font *Afont,
+	       const char *Atext, GUI_Font *Afont,
 	       GUI_MenuActiveProc Aactiveproc, int is_checkmenu = 0);
 
   inline virtual int GetId()
@@ -96,10 +96,10 @@ class GUI_Menu : public GUI_Area
   ~GUI_Menu();
 
   /* add a toplevel menu with an id and the caption */
-  virtual void AddSubmenu(int Aid, char *Atext);
+  virtual void AddSubmenu(int Aid, const char *Atext);
   /* add an item below the given submenu with an idm a caption, a callback and
      a flag if it shall be a checkable menu item */
-  virtual void AddMenuitem(int Asubmenuid, int Aid, char *Atext,
+  virtual void AddMenuitem(int Asubmenuid, int Aid, const char *Atext,
 	       GUI_MenuActiveProc activeproc, int is_checkmenu = 0);
 
   /* the menu items call this to keep track of each other - not very nice, I know*/
diff --git a/GUI_output.cpp b/GUI_output.cpp
index 7a21a83..ac07bff 100644
--- a/GUI_output.cpp
+++ b/GUI_output.cpp
@@ -31,6 +31,7 @@ extern "C" {
 /* The (really C++) structure holding information for popup text output */
 struct GUI_Output {
 	int visible;
+	SDL_Window *m_window;
 	SDL_Surface *screen;
 	GUI_TermWin *window;
 	GUI_Area *frame_inner;
@@ -43,15 +44,17 @@ struct GUI_Output {
    image (with an extra pixel row under each row of characters), or NULL to
    use a default internal 8x8-pixel font.
  */
-GUI_Output *GUI_CreateOutput(SDL_Surface *screen,
+GUI_Output *GUI_CreateOutput(SDL_Window *window,
 				int width, int height, SDL_Surface *font)
 {
+	SDL_Surface *screen = SDL_GetWindowSurface(window);
 	GUI_Output *output;
 	int w, h, x, y;
 
 	/* Create a new output window */
 	output = new GUI_Output;
 	output->visible = 0;
+	output->m_window = window;
 	output->screen = screen;
 	if ( font == NULL ) {
 		font = GUI_DefaultFont();
@@ -73,7 +76,7 @@ GUI_Output *GUI_CreateOutput(SDL_Surface *screen,
 	output->frame_outer = new GUI_Area(x, y, w, h, 0, 0, 0);
 
 	/* Allocate a save buffer for the area behind it */
-	output->behind = SDL_AllocSurface(SDL_SWSURFACE, w, h,
+	output->behind = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h,
 				screen->format->BitsPerPixel,
 				screen->format->Rmask,
 				screen->format->Gmask,
@@ -114,9 +117,9 @@ void GUI_ClearOutput(GUI_Output *output)
 void GUI_ShowOutput(GUI_Output *output, int wait)
 {
 	/* Display the text output window */
-	output->frame_outer->SetDisplay(output->screen);
-	output->frame_inner->SetDisplay(output->screen);
-	output->window->SetDisplay(output->screen);
+	output->frame_outer->SetDisplay(output->m_window);
+	output->frame_inner->SetDisplay(output->m_window);
+	output->window->SetDisplay(output->m_window);
 	if ( output->behind ) {
 		SDL_Rect src;
 
@@ -129,15 +132,15 @@ void GUI_ShowOutput(GUI_Output *output, int wait)
 	output->frame_outer->Display();
 	output->frame_inner->Display();
 	output->window->Display();
-	SDL_UpdateRect(output->screen, 0, 0, 0, 0);
+	SDL_UpdateWindowSurface(output->m_window);
 	output->visible = 1;
 
 	/* Pump the event queue, waiting for key and mouse press events */
 	if ( wait ) {
 		SDL_Event event;
 
-		while ( ! SDL_PeepEvents(&event, 1, SDL_GETEVENT,
-				(SDL_KEYDOWNMASK|SDL_MOUSEBUTTONDOWNMASK)) ) {
+		while ( ! SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_KEYDOWN, SDL_KEYDOWN) &&
+		        ! SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_MOUSEBUTTONDOWN, SDL_MOUSEBUTTONDOWN) ) {
 			SDL_Delay(20);
 			SDL_PumpEvents();
 		}
@@ -155,7 +158,7 @@ void GUI_HideOutput(GUI_Output *output)
 		dst.w = output->frame_outer->W();
 		dst.h = output->frame_outer->H();
 		SDL_BlitSurface(output->behind, NULL, output->screen, &dst);
-		SDL_UpdateRects(output->screen, 1, &dst);
+		SDL_UpdateWindowSurfaceRects(output->m_window, &dst, 1);
 	}
 	output->visible = 0;
 }
@@ -194,7 +197,7 @@ void GUI_DeleteOutput(GUI_Output *output)
 
    Returns the index of the button pressed, which is style dependent:
 */
-int GUI_MessageBox(SDL_Surface *screen,
+int GUI_MessageBox(SDL_Window *window,
 			const char *title, const char *text, Uint32 style)
 {
 	int status;
@@ -205,6 +208,7 @@ int GUI_MessageBox(SDL_Surface *screen,
 	GUI_Button *button;
 	int w, h, x, y;
 	unsigned int i;
+	SDL_Surface *screen;
 	SDL_Surface *font;
 	SDL_Surface *images[2];
 	SDL_Surface *background;
@@ -215,8 +219,9 @@ int GUI_MessageBox(SDL_Surface *screen,
 	status = -1;
 
 	/* Create the GUI holder */
-	gui = new GUI(screen);
+	gui = new GUI(window);
 	font = GUI_DefaultFont();
+	screen = SDL_GetWindowSurface(window);
 
 	/* Create the GUI elements */
 	w = gui_w;
@@ -230,7 +235,7 @@ int GUI_MessageBox(SDL_Surface *screen,
 	srcrect.w = w;
 	srcrect.h = h;
 	dstrect = srcrect;
-	background = SDL_AllocSurface(SDL_SWSURFACE, w, h, 
+	background = SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 
 				screen->format->BitsPerPixel,
 				screen->format->Rmask,
 				screen->format->Gmask,
@@ -361,7 +366,7 @@ int GUI_MessageBox(SDL_Surface *screen,
 		}
 	}
 	SDL_BlitSurface(background, NULL, screen, &dstrect);
-	SDL_UpdateRects(screen, 1, &dstrect);
+	SDL_UpdateWindowSurfaceRects(window, &dstrect, 1);
 	return(status);
 }
 
diff --git a/GUI_output.h b/GUI_output.h
index 9803c9e..50f932e 100644
--- a/GUI_output.h
+++ b/GUI_output.h
@@ -28,7 +28,7 @@ typedef struct GUI_Output GUI_Output;
    use a default internal 8x8-pixel font.
    When shown, the output window will display to the 'screen' surface.
  */
-extern GUI_Output *GUI_CreateOutput(SDL_Surface *screen,
+extern GUI_Output *GUI_CreateOutput(SDL_Window *window,
 				int width, int height, SDL_Surface *font);
 
 /* Add output to an output window.  If the window is visible, the output
@@ -68,7 +68,7 @@ extern void GUI_DeleteOutput(GUI_Output *output);
 #define GUI_MBOKCANCEL	0x0002	/* A "Cancel" button on the left - return 0
 				   An "OK" button on the right - return 1 */
 /* */
-extern int GUI_MessageBox(SDL_Surface *screen,
+extern int GUI_MessageBox(SDL_Window *window,
 			const char *title, const char *text, Uint32 style);
 
 #ifdef __cplusplus
diff --git a/GUI_termwin.cpp b/GUI_termwin.cpp
index 51995fd..f7d79d7 100644
--- a/GUI_termwin.cpp
+++ b/GUI_termwin.cpp
@@ -14,7 +14,7 @@
 #define KEYREPEAT_TIME	100		/* Repeat every 100 ms */
 
 GUI_TermWin:: GUI_TermWin(int x, int y, int w, int h, SDL_Surface *Font,
-				void (*KeyProc)(SDLKey key, Uint16 unicode), int scrollback)
+				void (*KeyProc)(SDL_Keycode key, Uint16 unicode), int scrollback)
  : GUI_Scrollable(NULL, x, y, w, h)
 {
 	/* The font surface should be a 16x16 character pixmap */
@@ -38,19 +38,11 @@ GUI_TermWin:: GUI_TermWin(int x, int y, int w, int h, SDL_Surface *Font,
 
 	/* Set the user-defined keyboard handler */
 	keyproc = KeyProc;
-	repeat_key = SDLK_UNKNOWN;
-	repeat_unicode = 0;
-
-	/* Set key event translation on */
-	translated = SDL_EnableUNICODE(1);
 }
 
 GUI_TermWin:: ~GUI_TermWin()
 {
 	delete[] vscreen;
-
-	/* Reset key event translation */
-	SDL_EnableUNICODE(translated);
 }
 
 void
@@ -106,25 +98,40 @@ GUI_TermWin:: Range(int &first, int &last)
 }
 
 GUI_status
-GUI_TermWin:: KeyDown(SDL_keysym key)
+GUI_TermWin:: TextInput(const char *text)
+{
+	GUI_status status;
+
+	status = GUI_PASS;
+	if ( keyproc ) {
+		Uint16 *text16 = SDL_iconv_utf8_ucs2(text);
+		if (text16) {
+			for (int i = 0; text16[i]; ++i) {
+				keyproc(0, text16[i]);
+			}
+			SDL_free(text16);
+		}
+		status = GUI_YUM;
+	}
+	return(status);
+}
+
+GUI_status
+GUI_TermWin:: KeyDown(SDL_Keysym key)
 {
 	GUI_status status;
 
 	status = GUI_PASS;
 	if ( keyproc ) {
-		keyproc(key.sym, key.unicode);
-		repeat_key = key.sym;
-		repeat_unicode = key.unicode;
-		repeat_next = SDL_GetTicks()+5*KEYREPEAT_TIME;
+		keyproc(key.sym, 0);
 		status = GUI_YUM;
 	}
 	return(status);
 }
 
 GUI_status
-GUI_TermWin:: KeyUp(SDL_keysym key)
+GUI_TermWin:: KeyUp(SDL_Keysym key)
 {
-	repeat_key = SDLK_UNKNOWN;
 	return(GUI_PASS);
 }
 
@@ -233,14 +240,6 @@ GUI_TermWin:: Idle(void)
 
 	status = GUI_PASS;
 
-	/* Perform any necessary key repeat */
-	if ( repeat_key && keyproc ) {
-		if ( repeat_next <= SDL_GetTicks() ) {
-			keyproc(repeat_key, repeat_unicode);
-			repeat_next = SDL_GetTicks()+KEYREPEAT_TIME;
-		}
-	}
-
 	/* Check to see if display contents have changed */
 	if ( changed ) {
 		status = GUI_REDRAW;
@@ -256,12 +255,12 @@ void GUI_TermWin::SetColoring(Uint8 fr,Uint8 fg,Uint8 fb, int bg_opaque,
 	SDL_Color colors[3]={{br,bg,bb,0},{fr,fg,fb,0}};
 	if (bg_opaque)
 	{
-	  SDL_SetColors(font,colors,0,2);
-	  SDL_SetColorKey(font,0,0);
+	  SDL_SetPaletteColors(font->format->palette,colors,0,2);
+	  SDL_SetColorKey(font,SDL_FALSE,0);
 	}
 	else
 	{
-	  SDL_SetColors(font,&colors[1],1,1);
-	  SDL_SetColorKey(font,SDL_SRCCOLORKEY,0);
+	  SDL_SetPaletteColors(font->format->palette,&colors[1],1,1);
+	  SDL_SetColorKey(font,SDL_TRUE,0);
 	}
 }
diff --git a/GUI_termwin.h b/GUI_termwin.h
index 6429145..a350267 100644
--- a/GUI_termwin.h
+++ b/GUI_termwin.h
@@ -16,7 +16,7 @@ class GUI_TermWin : public GUI_Scrollable {
 public:
 	/* The font surface should be a 16x16 character pixmap */
 	GUI_TermWin(int x, int y, int w, int h, SDL_Surface *font = NULL,
-			void (*KeyProc)(SDLKey key, Uint16 unicode) = NULL, int scrollback = 0);
+			void (*KeyProc)(SDL_Keycode key, Uint16 unicode) = NULL, int scrollback = 0);
 	~GUI_TermWin();
 
 	/* Show the text window */
@@ -29,8 +29,9 @@ class GUI_TermWin : public GUI_Scrollable {
 	virtual void Range(int &first, int &last);
 
 	/* Handle keyboard input */
-	virtual GUI_status KeyDown(SDL_keysym key);
-	virtual GUI_status KeyUp(SDL_keysym key);
+	virtual GUI_status TextInput(const char *text);
+	virtual GUI_status KeyDown(SDL_Keysym key);
+	virtual GUI_status KeyUp(SDL_Keysym key);
 
 	/* Function to add text to the visible buffer */
 	virtual void AddText(const char *text, int len);
@@ -67,12 +68,7 @@ class GUI_TermWin : public GUI_Scrollable {
 	int translated;	/* Whether or not UNICODE translation was enabled */
 
 	/* The keyboard handling function */
-	void (*keyproc)(SDLKey key, Uint16 unicode);
-
-	/* The last key that was pressed, along with key repeat time */
-	SDLKey repeat_key;
-	Uint16 repeat_unicode;
-	Uint32 repeat_next;
+	void (*keyproc)(SDL_Keycode key, Uint16 unicode);
 
 	/* Flag -- whether or not we need to redisplay ourselves */
 	int changed;
diff --git a/GUI_widget.cpp b/GUI_widget.cpp
index 447ea20..2da9f4a 100644
--- a/GUI_widget.cpp
+++ b/GUI_widget.cpp
@@ -18,6 +18,7 @@ void
 GUI_Widget:: Init(void *data, int x, int y, int w, int h)
 {
 	widget_data = data;
+	m_window = NULL;
 	screen = NULL;
 	SetRect(x, y, w, h);
 	Show();
@@ -126,9 +127,10 @@ GUI_Widget:: HitRect(int x, int y, SDL_Rect &rect)
 
 /* Set the display surface for this widget */
 void
-GUI_Widget:: SetDisplay(SDL_Surface *display)
+GUI_Widget:: SetDisplay(SDL_Window *window)
 {
-	screen = display;
+	m_window = window;
+	screen = SDL_GetWindowSurface(window);
 }
 
 /* Show the widget.
@@ -149,7 +151,7 @@ void GUI_Widget::Redraw(void)
   if (status==WIDGET_VISIBLE)
   {
     Display();
-    SDL_UpdateRects(screen,1,&area);
+    SDL_UpdateWindowSurfaceRects(m_window,&area,1);
   }
 }
 
@@ -166,12 +168,17 @@ GUI_Widget:: Idle(void)
    These are called by the default HandleEvent function.
 */
 GUI_status
-GUI_Widget:: KeyDown(SDL_keysym key)
+GUI_Widget:: TextInput(const char *text)
 {
 	return(GUI_PASS);
 }
 GUI_status
-GUI_Widget:: KeyUp(SDL_keysym key)
+GUI_Widget:: KeyDown(SDL_Keysym key)
+{
+	return(GUI_PASS);
+}
+GUI_status
+GUI_Widget:: KeyUp(SDL_Keysym key)
 {
 	return(GUI_PASS);
 }
@@ -198,6 +205,10 @@ GUI_status
 GUI_Widget:: HandleEvent(const SDL_Event *event)
 {
 	switch (event->type) {
+		case SDL_TEXTINPUT: {
+			return(TextInput(event->text.text));
+		}
+		break;
 		case SDL_KEYDOWN: {
 			return(KeyDown(event->key.keysym));
 		}
diff --git a/GUI_widget.h b/GUI_widget.h
index 61fa04f..8c5b427 100644
--- a/GUI_widget.h
+++ b/GUI_widget.h
@@ -54,7 +54,7 @@ class GUI_Widget {
 	virtual int HitRect(int x, int y, SDL_Rect &rect);
 
 	/* Set the display surface for this widget */
-	virtual void SetDisplay(SDL_Surface *display);
+	virtual void SetDisplay(SDL_Window *window);
 
 	/* Show the widget.
 	   If the surface needs to be locked, it will be locked
@@ -73,8 +73,9 @@ class GUI_Widget {
 	   or not the event should be passed on to other widgets.
 	   These are called by the default HandleEvent function.
 	*/
-	virtual GUI_status KeyDown(SDL_keysym key);
-	virtual GUI_status KeyUp(SDL_keysym key);
+	virtual GUI_status TextInput(const char *text);
+	virtual GUI_status KeyDown(SDL_Keysym key);
+	virtual GUI_status KeyUp(SDL_Keysym key);
 	virtual GUI_status MouseDown(int x, int y, int button);
 	virtual GUI_status MouseUp(int x, int y, int button);
 	virtual GUI_status MouseMotion(int x, int y, Uint8 state);
@@ -85,7 +86,7 @@ class GUI_Widget {
 	virtual GUI_status HandleEvent(const SDL_Event *event);
 
 	/* Returns NULL if everything is okay, or an error message if not */
-	char *Error(void) {
+	const char *Error(void) {
 		return(error);
 	}
 
@@ -106,6 +107,7 @@ class GUI_Widget {
 	void *widget_data;
 
 	/* The display surface for the widget */
+	SDL_Window *m_window;
 	SDL_Surface *screen;
 
 	/* The area covered by the widget */
@@ -115,7 +117,7 @@ class GUI_Widget {
 	int status;
 
 	/* Useful for getting error feedback */
-	void SetError(char *fmt, ...) {
+	void SetError(const char *fmt, ...) {
 		va_list ap;
 
 		va_start(ap, fmt);
diff --git a/Makefile.am b/Makefile.am
index e40bba3..ee70702 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -51,7 +51,6 @@ libGUI_la_LDFLAGS = 		\
 EXTRA_DIST =			\
 	CHANGES			\
 	autogen.sh		\
-	MPWmake.sea.hqx		\
 	hello.bmp		\
 	hello2.bmp		\
 	scroll_dn.bmp		\
diff --git a/Makefile.in b/Makefile.in
index cdeb768..3acf26b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -471,7 +471,6 @@ libGUI_la_LDFLAGS = \
 EXTRA_DIST = \
 	CHANGES			\
 	autogen.sh		\
-	MPWmake.sea.hqx		\
 	hello.bmp		\
 	hello2.bmp		\
 	scroll_dn.bmp		\
diff --git a/aclocal.m4 b/aclocal.m4
index 6406b8a..1f6e176 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -20,6 +20,106 @@ You have another version of autoconf.  It may work, but is not guaranteed to.
 If you have problems, you may need to regenerate the build system entirely.
 To do so, use the procedure documented by the package, typically 'autoreconf'.])])
 
+# lt~obsolete.m4 -- aclocal satisfying obsolete definitions.    -*-Autoconf-*-
+#
+#   Copyright (C) 2004-2005, 2007, 2009, 2011-2015 Free Software
+#   Foundation, Inc.
+#   Written by Scott James Remnant, 2004.
+#
+# This file is free software; the Free Software Foundation gives
+# unlimited permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+
+# serial 5 lt~obsolete.m4
+
+# These exist entirely to fool aclocal when bootstrapping libtool.
+#
+# In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN),
+# which have later been changed to m4_define as they aren't part of the
+# exported API, or moved to Autoconf or Automake where they belong.
+#
+# The trouble is, aclocal is a bit thick.  It'll see the old AC_DEFUN
+# in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
+# using a macro with the same name in our local m4/libtool.m4 it'll
+# pull the old libtool.m4 in (it doesn't see our shiny new m4_define
+# and doesn't know about Autoconf macros at all.)
+#
+# So we provide this file, which has a silly filename so it's always
+# included after everything else.  This provides aclocal with the
+# AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
+# because those macros already exist, or will be overwritten later.
+# We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6.
+#
+# Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
+# Yes, that means every name once taken will need to remain here until
+# we give up compatibility with versions before 1.7, at which point
+# we need to keep only those names which we still refer to.
+
+# This is to help aclocal find these macros, as it can't see m4_define.
+AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
+
+m4_ifndef([AC_LIBTOOL_LINKER_OPTION],	[AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
+m4_ifndef([AC_PROG_EGREP],		[AC_DEFUN([AC_PROG_EGREP])])
+m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH],	[AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
+m4_ifndef([_LT_AC_SHELL_INIT],		[AC_DEFUN([_LT_AC_SHELL_INIT])])
+m4_ifndef([_LT_AC_SYS_LIBPATH_AIX],	[AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
+m4_ifndef([_LT_PROG_LTMAIN],		[AC_DEFUN([_LT_PROG_LTMAIN])])
+m4_ifndef([_LT_AC_TAGVAR],		[AC_DEFUN([_LT_AC_TAGVAR])])
+m4_ifndef([AC_LTDL_ENABLE_INSTALL],	[AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
+m4_ifndef([AC_LTDL_PREOPEN],		[AC_DEFUN([AC_LTDL_PREOPEN])])
+m4_ifndef([_LT_AC_SYS_COMPILER],	[AC_DEFUN([_LT_AC_SYS_COMPILER])])
+m4_ifndef([_LT_AC_LOCK],		[AC_DEFUN([_LT_AC_LOCK])])
+m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE],	[AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
+m4_ifndef([_LT_AC_TRY_DLOPEN_SELF],	[AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
+m4_ifndef([AC_LIBTOOL_PROG_CC_C_O],	[AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
+m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
+m4_ifndef([AC_LIBTOOL_OBJDIR],		[AC_DEFUN([AC_LIBTOOL_OBJDIR])])
+m4_ifndef([AC_LTDL_OBJDIR],		[AC_DEFUN([AC_LTDL_OBJDIR])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
+m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP],	[AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
+m4_ifndef([AC_PATH_MAGIC],		[AC_DEFUN([AC_PATH_MAGIC])])
+m4_ifndef([AC_PROG_LD_GNU],		[AC_DEFUN([AC_PROG_LD_GNU])])
+m4_ifndef([AC_PROG_LD_RELOAD_FLAG],	[AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
+m4_ifndef([AC_DEPLIBS_CHECK_METHOD],	[AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
+m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
+m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
+m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS],	[AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
+m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP],	[AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
+m4_ifndef([LT_AC_PROG_EGREP],		[AC_DEFUN([LT_AC_PROG_EGREP])])
+m4_ifndef([LT_AC_PROG_SED],		[AC_DEFUN([LT_AC_PROG_SED])])
+m4_ifndef([_LT_CC_BASENAME],		[AC_DEFUN([_LT_CC_BASENAME])])
+m4_ifndef([_LT_COMPILER_BOILERPLATE],	[AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
+m4_ifndef([_LT_LINKER_BOILERPLATE],	[AC_DEFUN([_LT_LINKER_BOILERPLATE])])
+m4_ifndef([_AC_PROG_LIBTOOL],		[AC_DEFUN([_AC_PROG_LIBTOOL])])
+m4_ifndef([AC_LIBTOOL_SETUP],		[AC_DEFUN([AC_LIBTOOL_SET

(Patch may be truncated, please check the link at the top of this post.)