src/signs_gui.cpp
branchnoai
changeset 10645 8cbdb511a674
parent 10513 33cb70ff2f5d
child 10955 56b381e5253f
--- a/src/signs_gui.cpp	Mon May 19 14:14:33 2008 +0000
+++ b/src/signs_gui.cpp	Mon May 19 15:13:58 2008 +0000
@@ -66,54 +66,63 @@
 	DEBUG(misc, 3, "Resorting global signs list");
 }
 
-static void SignListWndProc(Window *w, WindowEvent *e)
-{
-	switch (e->event) {
-		case WE_PAINT: {
-			if (_sign_sort_dirty) GlobalSortSignList();
-
-			SetVScrollCount(w, _num_sign_sort);
-
-			SetDParam(0, w->vscroll.count);
-			DrawWindowWidgets(w);
-
-			/* No signs? */
-			int y = 16; // offset from top of widget
-			if (w->vscroll.count == 0) {
-				DrawString(2, y, STR_304A_NONE, TC_FROMSTRING);
-				return;
-			}
-
-			/* Start drawing the signs */
-			for (uint16 i = w->vscroll.pos; i < w->vscroll.cap + w->vscroll.pos && i < w->vscroll.count; i++) {
-				const Sign *si = _sign_sort[i];
-
-				if (si->owner != OWNER_NONE) DrawPlayerIcon(si->owner, 4, y + 1);
+struct SignListWindow : Window {
+	SignListWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
+	{
+		this->vscroll.cap = 12;
+		this->resize.step_height = 10;
+		this->resize.height = this->height - 10 * 7; // minimum if 5 in the list
 
-				SetDParam(0, si->index);
-				DrawString(22, y, STR_SIGN_NAME, TC_YELLOW);
-				y += 10;
-			}
-		} break;
-
-		case WE_CLICK:
-			if (e->we.click.widget == 3) {
-				uint32 id_v = (e->we.click.pt.y - 15) / 10;
+		this->FindWindowPlacementAndResize(desc);
+	}
 
-				if (id_v >= w->vscroll.cap) return;
-				id_v += w->vscroll.pos;
-				if (id_v >= w->vscroll.count) return;
+	virtual void OnPaint()
+	{
+		if (_sign_sort_dirty) GlobalSortSignList();
 
-				const Sign *si = _sign_sort[id_v];
-				ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
-			}
-			break;
+		SetVScrollCount(this, _num_sign_sort);
 
-		case WE_RESIZE:
-			w->vscroll.cap += e->we.sizing.diff.y / 10;
-			break;
+		SetDParam(0, this->vscroll.count);
+		this->DrawWidgets();
+
+		/* No signs? */
+		int y = 16; // offset from top of widget
+		if (this->vscroll.count == 0) {
+			DrawString(2, y, STR_304A_NONE, TC_FROMSTRING);
+			return;
+		}
+
+		/* Start drawing the signs */
+		for (uint16 i = this->vscroll.pos; i < this->vscroll.cap + this->vscroll.pos && i < this->vscroll.count; i++) {
+			const Sign *si = _sign_sort[i];
+
+			if (si->owner != OWNER_NONE) DrawPlayerIcon(si->owner, 4, y + 1);
+
+			SetDParam(0, si->index);
+			DrawString(22, y, STR_SIGN_NAME, TC_YELLOW);
+			y += 10;
+		}
 	}
-}
+
+	virtual void OnClick(Point pt, int widget)
+	{
+		if (widget == 3) {
+			uint32 id_v = (pt.y - 15) / 10;
+
+			if (id_v >= this->vscroll.cap) return;
+			id_v += this->vscroll.pos;
+			if (id_v >= this->vscroll.count) return;
+
+			const Sign *si = _sign_sort[id_v];
+			ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
+		}
+	}
+
+	virtual void OnResize(Point new_size, Point delta)
+	{
+		this->vscroll.cap += delta.y / 10;
+	}
+};
 
 static const Widget _sign_list_widget[] = {
 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,              STR_018B_CLOSE_WINDOW},
@@ -130,18 +139,12 @@
 	WC_SIGN_LIST, WC_NONE,
 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
 	_sign_list_widget,
-	SignListWndProc
 };
 
 
 void ShowSignList()
 {
-	Window *w = AllocateWindowDescFront<Window>(&_sign_list_desc, 0);
-	if (w != NULL) {
-		w->vscroll.cap = 12;
-		w->resize.step_height = 10;
-		w->resize.height = w->height - 10 * 7; // minimum if 5 in the list
-	}
+	AllocateWindowDescFront<SignListWindow>(&_sign_list_desc, 0);
 }
 
 static void RenameSign(SignID index, const char *text)
@@ -170,6 +173,7 @@
 		this->LowerWidget(QUERY_EDIT_SIGN_WIDGET_TEXT);
 
 		UpdateSignEditWindow(si);
+		this->FindWindowPlacementAndResize(desc);
 	}
 
 	~SignWindow()
@@ -197,7 +201,7 @@
 	virtual void OnPaint()
 	{
 		SetDParam(0, this->caption);
-		DrawWindowWidgets(this);
+		this->DrawWidgets();
 		this->DrawEditBox(QUERY_EDIT_SIGN_WIDGET_TEXT);
 	}
 
@@ -255,10 +259,10 @@
 		}
 	}
 
-	virtual bool OnKeyPress(uint16 key, uint16 keycode)
+	virtual EventState OnKeyPress(uint16 key, uint16 keycode)
 	{
-		bool cont = true;
-		switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, cont)) {
+		EventState state = ES_NOT_HANDLED;
+		switch (this->HandleEditBoxKey(QUERY_EDIT_SIGN_WIDGET_TEXT, key, keycode, state)) {
 			case 1: // Enter pressed, confirms change
 				RenameSign(this->cur_sign, this->text.buf);
 				/* FALL THROUGH */
@@ -267,7 +271,7 @@
 				delete this;
 				break;
 		}
-		return cont;
+		return state;
 	}
 
 	virtual void OnMouseLoop()
@@ -295,7 +299,6 @@
 	WC_QUERY_STRING, WC_NONE,
 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
 	_query_sign_edit_widgets,
-	NULL
 };
 
 void ShowRenameSignWindow(const Sign *si)