changeset 9316:ce6d01689a1d draft

(svn r13184) -Codechange: make a window class of the signs list.
author rubidium <rubidium@openttd.org>
date Mon, 19 May 2008 09:45:24 +0000
parents 7458510a7cad
children c399bf075b2f
files src/signs_gui.cpp
diffstat 1 files changed, 49 insertions(+), 45 deletions(-) [+]
line wrap: on
line diff
--- a/src/signs_gui.cpp
+++ b/src/signs_gui.cpp
@@ -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();
+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
 
-			SetVScrollCount(w, _num_sign_sort);
-
-			SetDParam(0, w->vscroll.count);
-			w->DrawWidgets();
+		this->FindWindowPlacementAndResize(desc);
+	}
 
-			/* No signs? */
-			int y = 16; // offset from top of widget
-			if (w->vscroll.count == 0) {
-				DrawString(2, y, STR_304A_NONE, TC_FROMSTRING);
-				return;
-			}
+	virtual void OnPaint()
+	{
+		if (_sign_sort_dirty) GlobalSortSignList();
+
+		SetVScrollCount(this, _num_sign_sort);
 
-			/* 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];
+		SetDParam(0, this->vscroll.count);
+		this->DrawWidgets();
 
-				if (si->owner != OWNER_NONE) DrawPlayerIcon(si->owner, 4, y + 1);
+		/* No signs? */
+		int y = 16; // offset from top of widget
+		if (this->vscroll.count == 0) {
+			DrawString(2, y, STR_304A_NONE, TC_FROMSTRING);
+			return;
+		}
 
-				SetDParam(0, si->index);
-				DrawString(22, y, STR_SIGN_NAME, TC_YELLOW);
-				y += 10;
-			}
-		} break;
+		/* 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);
 
-		case WE_CLICK:
-			if (e->we.click.widget == 3) {
-				uint32 id_v = (e->we.click.pt.y - 15) / 10;
+			SetDParam(0, si->index);
+			DrawString(22, y, STR_SIGN_NAME, TC_YELLOW);
+			y += 10;
+		}
+	}
 
-				if (id_v >= w->vscroll.cap) return;
-				id_v += w->vscroll.pos;
-				if (id_v >= w->vscroll.count) return;
+	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));
-			}
-			break;
+			const Sign *si = _sign_sort[id_v];
+			ScrollMainWindowToTile(TileVirtXY(si->x, si->y));
+		}
+	}
 
-		case WE_RESIZE:
-			w->vscroll.cap += e->we.sizing.diff.y / 10;
-			break;
+	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,13 @@
 	WC_SIGN_LIST, WC_NONE,
 	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
 	_sign_list_widget,
-	SignListWndProc
+	NULL
 };
 
 
 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)