--- a/src/build_vehicle_gui.cpp Tue Feb 13 18:07:36 2007 +0000
+++ b/src/build_vehicle_gui.cpp Tue Feb 13 19:35:55 2007 +0000
@@ -919,7 +919,7 @@
break;
case WE_RESIZE:
- if (e->we.sizing.diff.x != 0) ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
+ if (e->we.sizing.diff.x != 0) w->ResizeButtons(BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
if (e->we.sizing.diff.y == 0) break;
w->vscroll.cap += e->we.sizing.diff.y / GetVehicleListHeight(bv->vehicle_type);
@@ -981,7 +981,7 @@
break;
}
SetupWindowStrings(w, type);
- ResizeButtons(w, BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
+ w->ResizeButtons(BUILD_VEHICLE_WIDGET_BUILD, BUILD_VEHICLE_WIDGET_RENAME);
w->resize.width = w->width;
w->resize.height = w->height;
--- a/src/depot_gui.cpp Tue Feb 13 18:07:36 2007 +0000
+++ b/src/depot_gui.cpp Tue Feb 13 19:35:55 2007 +0000
@@ -512,7 +512,7 @@
static void ResizeDepotButtons(Window *w)
{
- ResizeButtons(w, DEPOT_WIDGET_BUILD, DEPOT_WIDGET_LOCATION);
+ w->ResizeButtons(DEPOT_WIDGET_BUILD, DEPOT_WIDGET_LOCATION);
if (WP(w, depot_d).type == VEH_Train) {
/* Divide the size of DEPOT_WIDGET_SELL into two equally big buttons so DEPOT_WIDGET_SELL and DEPOT_WIDGET_SELL_CHAIN will get the same size.
--- a/src/train_gui.cpp Tue Feb 13 18:07:36 2007 +0000
+++ b/src/train_gui.cpp Tue Feb 13 19:35:55 2007 +0000
@@ -560,7 +560,7 @@
break;
case WE_RESIZE:
- if (e->we.sizing.diff.x != 0) ResizeButtons(w, 9, 12);
+ if (e->we.sizing.diff.x != 0) w->ResizeButtons(9, 12);
if (e->we.sizing.diff.y == 0) break;
w->vscroll.cap += e->we.sizing.diff.y / 14;
--- a/src/viewport.cpp Tue Feb 13 18:07:36 2007 +0000
+++ b/src/viewport.cpp Tue Feb 13 19:35:55 2007 +0000
@@ -2451,7 +2451,7 @@
if (_thd.place_mode != 0) {
_thd.place_mode = 0;
w = Window::FindById(_thd.window_class, _thd.window_number);
- if (w != NULL) CallWindowEventNP(w, WE_ABORT_PLACE_OBJ);
+ if (w != NULL) w->CallEventNP(WE_ABORT_PLACE_OBJ);
}
SetTileSelectSize(1, 1);
--- a/src/widget.cpp Tue Feb 13 18:07:36 2007 +0000
+++ b/src/widget.cpp Tue Feb 13 19:35:55 2007 +0000
@@ -39,13 +39,12 @@
* Handles the special scrolling buttons and other
* scrolling.
* Parameters:
- * w - Window.
* wi - Pointer to the scrollbar widget.
* x - The X coordinate of the mouse click.
* y - The Y coordinate of the mouse click.
*/
-void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y)
+void Window::ScrollbarClickHandler(const Widget *wi, int x, int y)
{
int mi, ma, pos;
Scrollbar *sb;
@@ -53,39 +52,39 @@
switch (wi->type) {
case WWT_SCROLLBAR: {
// vertical scroller
- w->flags4 &= ~WF_HSCROLL;
- w->flags4 &= ~WF_SCROLL2;
+ flags4 &= ~WF_HSCROLL;
+ flags4 &= ~WF_SCROLL2;
mi = wi->top;
ma = wi->bottom;
pos = y;
- sb = &w->vscroll;
+ sb = &vscroll;
break;
}
case WWT_SCROLL2BAR: {
// 2nd vertical scroller
- w->flags4 &= ~WF_HSCROLL;
- w->flags4 |= WF_SCROLL2;
+ flags4 &= ~WF_HSCROLL;
+ flags4 |= WF_SCROLL2;
mi = wi->top;
ma = wi->bottom;
pos = y;
- sb = &w->vscroll2;
+ sb = &vscroll2;
break;
}
case WWT_HSCROLLBAR: {
// horizontal scroller
- w->flags4 &= ~WF_SCROLL2;
- w->flags4 |= WF_HSCROLL;
+ flags4 &= ~WF_SCROLL2;
+ flags4 |= WF_HSCROLL;
mi = wi->left;
ma = wi->right;
pos = x;
- sb = &w->hscroll;
+ sb = &hscroll;
break;
}
default: return; //this should never happen
}
if (pos <= mi+9) {
// Pressing the upper button?
- w->flags4 |= WF_SCROLL_UP;
+ flags4 |= WF_SCROLL_UP;
if (_scroller_click_timeout == 0) {
_scroller_click_timeout = 6;
if (sb->pos != 0) sb->pos--;
@@ -93,7 +92,7 @@
_left_button_clicked = false;
} else if (pos >= ma-10) {
// Pressing the lower button?
- w->flags4 |= WF_SCROLL_DOWN;
+ flags4 |= WF_SCROLL_DOWN;
if (_scroller_click_timeout == 0) {
_scroller_click_timeout = 6;
@@ -115,13 +114,13 @@
} else {
_scrollbar_start_pos = pt.x - mi - 9;
_scrollbar_size = ma - mi - 23;
- w->flags4 |= WF_SCROLL_MIDDLE;
+ flags4 |= WF_SCROLL_MIDDLE;
_scrolling_scrollbar = true;
_cursorpos_drag_start = _cursor.pos;
}
}
- w->SetDirty();
+ this->SetDirty();
}
/** Returns the index for the widget located at the given position
@@ -727,27 +726,26 @@
/** Evenly distribute some widgets when resizing horizontally (often a button row)
* When only two arguments are given, the widgets are presumed to be on a line and only the ends are given
- * @param w widow to modify
* @param left The leftmost widget to resize
* @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT
*/
-void ResizeButtons(Window *w, byte left, byte right)
+void Window::ResizeButtons(byte first, byte last)
{
- int16 num_widgets = right - left + 1;
+ int16 num_widgets = last - first + 1;
if (num_widgets < 2) NOT_REACHED();
switch (num_widgets) {
- case 2: ResizeWidgets(w, left, right); break;
- case 3: ResizeWidgets(w, left, left + 1, right); break;
+ case 2: ResizeWidgets(this, first, last); break;
+ case 3: ResizeWidgets(this, first, first + 1, last); break;
default: {
/* Looks like we got more than 3 widgets to resize
* Now we will find the middle of the space desinated for the widgets
* and place half of the widgets on each side of it and call recursively.
* Eventually we will get down to blocks of 2-3 widgets and we got code to handle those cases */
- int16 offset = w->widget[left].left;
- int16 length = w->widget[right].right - offset;
- byte widget = ((num_widgets - 1)/ 2) + left; // rightmost widget of the left side
+ int16 offset = widget[first].left;
+ int16 length = widget[last].right - offset;
+ byte temp_widget = ((num_widgets - 1)/ 2) + first; // rightmost widget of the left side
/* Now we need to find the middle of the widgets.
* It will not always be the middle because if we got an uneven number of widgets,
@@ -762,11 +760,11 @@
int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset;
/* Set left and right on the widgets, that's next to our "middle" */
- w->widget[widget].right = middle;
- w->widget[widget + 1].left = w->widget[widget].right + 1;
+ widget[temp_widget].right = middle;
+ widget[temp_widget + 1].left = widget[temp_widget].right + 1;
/* Now resize the left and right of the middle */
- ResizeButtons(w, left, widget);
- ResizeButtons(w, widget + 1, right);
+ this->ResizeButtons(first, temp_widget);
+ this->ResizeButtons(temp_widget + 1, last);
}
}
}
--- a/src/window.cpp Tue Feb 13 18:07:36 2007 +0000
+++ b/src/window.cpp Tue Feb 13 19:35:55 2007 +0000
@@ -170,7 +170,7 @@
Window::s_list.Add(this);
SetDirty();
- CallWindowEventNP(this, WE_CREATE);
+ this->CallEventNP(WE_CREATE);
//return w;
}
@@ -206,7 +206,7 @@
ResetObjectToPlace();
}
- CallWindowEventNP(this, WE_DESTROY);
+ this->CallEventNP(WE_DESTROY);
if (viewport != NULL) DeleteWindowViewport(this);
SetDirty();
@@ -620,7 +620,7 @@
break;
}
} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
- ScrollbarClickHandler(this, wi, e.we.click.pt.x, e.we.click.pt.y);
+ this->ScrollbarClickHandler(wi, e.we.click.pt.x, e.we.click.pt.y);
}
if (desc_flags & WDF_STD_BTN) {
@@ -755,7 +755,7 @@
dp->pitch = _screen.pitch;
dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left;
dp->zoom = 0;
- CallWindowEventNP(w, WE_PAINT);
+ w->CallEventNP(WE_PAINT);
}
}
@@ -776,12 +776,12 @@
}
-void CallWindowEventNP(Window *w, int event)
+void Window::CallEventNP(int event)
{
WindowEvent e;
e.event = event;
- w->wndproc(w, &e);
+ wndproc(this, &e);
}
/** Find the z-value of a window. A window must already be open
@@ -1236,12 +1236,12 @@
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
w->SetDirty();
}
- CallWindowEventNP(w, WE_MOUSELOOP);
+ w->CallEventNP(WE_MOUSELOOP);
}
REVERSED_FOR_ALL_WINDOWS(w) {
if (w->autorepeat_timeout > 0 && (--w->autorepeat_timeout) == 0) {
- CallWindowEventNP(w, WE_TIMEOUT);
+ w->CallEventNP(WE_TIMEOUT);
if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons();
}
}
@@ -1818,7 +1818,7 @@
Window *w;
if (t >= 100) {
REVERSED_FOR_ALL_WINDOWS(w) {
- CallWindowEventNP(w, WE_4);
+ w->CallEventNP(WE_4);
}
t = 0;
}
@@ -1891,7 +1891,7 @@
void Window::InvalidateData()
{
- CallWindowEventNP(this, WE_INVALIDATE_DATA);
+ this->CallEventNP(WE_INVALIDATE_DATA);
this->SetDirty();
}
@@ -1915,7 +1915,7 @@
{
Window *w;
REVERSED_FOR_ALL_WINDOWS(w) {
- CallWindowEventNP(w, WE_TICK);
+ w->CallEventNP(WE_TICK);
}
}
--- a/src/window.h Tue Feb 13 18:07:36 2007 +0000
+++ b/src/window.h Tue Feb 13 19:35:55 2007 +0000
@@ -350,7 +350,8 @@
}
};
-struct Window : public CountedObject {
+class Window : public CountedObject {
+public:
static WindowList s_list;
WindowFlags flags4;
@@ -416,6 +417,8 @@
int GetMenuItemIndex(int x, int y) const;
void Resize(int x, int y);
+ void CallEventNP(int event);
+
void AssignWidget(const Widget *widget);
void InvalidateData();
@@ -428,6 +431,11 @@
int GetWidgetFromPos(int x, int y) const;
void DrawWidgets() const;
void ShowDropDownMenu(const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask);
+ void ResizeButtons(byte left, byte right);
+
+private:
+ void ScrollbarClickHandler(const Widget *wi, int x, int y);
+public:
//int32 AddRef()
//{
@@ -734,7 +742,7 @@
#define WIDGETS_END WWT_LAST, RESIZE_NONE, 0, 0, 0, 0, 0, 0, STR_NULL
/* window.c */
-void CallWindowEventNP(Window *w, int event);
+//void CallWindowEventNP(Window *w, int event);
void CallWindowTickEvent(void);
//void SetWindowDirty(const Window *w);
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam);
@@ -959,7 +967,6 @@
WSM_PRESIZE = 3,
};
-void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y);
/** Evenly distribute some widgets when resizing horizontally (often a button row)
* The widgets are presumed to be in a line and numberef from left to right (without gaps)
@@ -967,6 +974,6 @@
* @param left The leftmost widget to resize
* @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT
*/
-void ResizeButtons(Window *w, byte left, byte right);
+//void ResizeButtons(Window *w, byte left, byte right);
#endif /* WINDOW_H */