Mercurial > hg > openttd
changeset 9193:923deda0248a draft
(svn r13058) -Codechange: make a class of the ExtraViewportWindow.
author | glx <glx@openttd.org> |
---|---|
date | Mon, 12 May 2008 00:26:44 +0000 |
parents | 49fb4ed39805 |
children | 9fe1c3db5f06 |
files | src/smallmap_gui.cpp |
diffstat | 1 files changed, 103 insertions(+), 81 deletions(-) [+] |
line wrap: on
line diff
--- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -1103,88 +1103,129 @@ { WIDGETS_END}, }; -static void ExtraViewPortWndProc(Window *w, WindowEvent *e) +class ExtraViewportWindow : public Window { - switch (e->event) { - case WE_CREATE: // Disable zoom in button - /* New viewport start at (zero,zero) */ - InitializeWindowViewport(w, 3, 17, w->widget[4].right - w->widget[4].left - 1, w->widget[4].bottom - w->widget[4].top - 1, 0, ZOOM_LVL_VIEWPORT); + enum ExtraViewportWindowWidgets { + EVW_CLOSE, + EVW_CAPTION, + EVW_STICKY, + EVW_BACKGROUND, + EVW_VIEWPORT, + EVW_ZOOMIN, + EVW_ZOOMOUT, + EVW_MAIN_TO_VIEW, + EVW_VIEW_TO_MAIN, + EVW_SPACER1, + EVW_SPACER2, + EVW_RESIZE, + }; - w->DisableWidget(5); - break; +public: + ExtraViewportWindow(const WindowDesc *desc, void *data, int window_number) : Window(desc, data, window_number) + { + /* New viewport start at (zero,zero) */ + InitializeWindowViewport(this, 3, 17, this->widget[EVW_VIEWPORT].right - this->widget[EVW_VIEWPORT].left - 1, this->widget[EVW_VIEWPORT].bottom - this->widget[EVW_VIEWPORT].top - 1, 0, ZOOM_LVL_VIEWPORT); - case WE_PAINT: - /* set the number in the title bar */ - SetDParam(0, w->window_number + 1); - - DrawWindowWidgets(w); - DrawWindowViewport(w); - break; + this->DisableWidget(EVW_ZOOMIN); + this->FindWindowPlacementAndResize(desc); - case WE_CLICK: - switch (e->we.click.widget) { - case 5: DoZoomInOutWindow(ZOOM_IN, w); break; - case 6: DoZoomInOutWindow(ZOOM_OUT, w); break; + Point pt; + TileIndex tile = *(TileIndex*)data; + if (tile == INVALID_TILE) { + /* the main window with the main view */ + const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); - case 7: { // location button (move main view to same spot as this view) 'Paste Location' - Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); - int x = w->viewport->scrollpos_x; // Where is the main looking at - int y = w->viewport->scrollpos_y; + /* center on same place as main window (zoom is maximum, no adjustment needed) */ + pt.x = w->viewport->scrollpos_x + w->viewport->virtual_height / 2; + pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2; + } else { + pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile)); + } - /* set this view to same location. Based on the center, adjusting for zoom */ - w2->viewport->dest_scrollpos_x = x - (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; - w2->viewport->dest_scrollpos_y = y - (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; - } break; + this->viewport->scrollpos_x = pt.x - ((this->widget[EVW_VIEWPORT].right - this->widget[EVW_VIEWPORT].left) - 1) / 2; + this->viewport->scrollpos_y = pt.y - ((this->widget[EVW_VIEWPORT].bottom - this->widget[EVW_VIEWPORT].top) - 1) / 2; + this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x; + this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y; + + } - case 8: { // inverse location button (move this view to same spot as main view) 'Copy Location' - const Window *w2 = FindWindowById(WC_MAIN_WINDOW, 0); - int x = w2->viewport->scrollpos_x; - int y = w2->viewport->scrollpos_y; + virtual void OnPaint() + { + /* set the number in the title bar */ + SetDParam(0, this->window_number + 1); + + DrawWindowWidgets(this); + DrawWindowViewport(this); + } - w->viewport->dest_scrollpos_x = x + (w2->viewport->virtual_width - w->viewport->virtual_width) / 2; - w->viewport->dest_scrollpos_y = y + (w2->viewport->virtual_height - w->viewport->virtual_height) / 2; - } break; - } - break; + virtual void OnClick(Point pt, int widget) + { + switch (widget) { + case EVW_ZOOMIN: DoZoomInOutWindow(ZOOM_IN, this); break; + case EVW_ZOOMOUT: DoZoomInOutWindow(ZOOM_OUT, this); break; + + case EVW_MAIN_TO_VIEW: { // location button (move main view to same spot as this view) 'Paste Location' + Window *w = FindWindowById(WC_MAIN_WINDOW, 0); + int x = this->viewport->scrollpos_x; // Where is the main looking at + int y = this->viewport->scrollpos_y; - case WE_RESIZE: - w->viewport->width += e->we.sizing.diff.x; - w->viewport->height += e->we.sizing.diff.y; - w->viewport->virtual_width += e->we.sizing.diff.x; - w->viewport->virtual_height += e->we.sizing.diff.y; - break; + /* set this view to same location. Based on the center, adjusting for zoom */ + w->viewport->dest_scrollpos_x = x - (w->viewport->virtual_width - this->viewport->virtual_width) / 2; + w->viewport->dest_scrollpos_y = y - (w->viewport->virtual_height - this->viewport->virtual_height) / 2; + } break; - case WE_SCROLL: { - ViewPort *vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); + case EVW_VIEW_TO_MAIN: { // inverse location button (move this view to same spot as main view) 'Copy Location' + const Window *w = FindWindowById(WC_MAIN_WINDOW, 0); + int x = w->viewport->scrollpos_x; + int y = w->viewport->scrollpos_y; + + this->viewport->dest_scrollpos_x = x + (w->viewport->virtual_width - this->viewport->virtual_width) / 2; + this->viewport->dest_scrollpos_y = y + (w->viewport->virtual_height - this->viewport->virtual_height) / 2; + } break; + } + } - if (vp == NULL) { - _cursor.fix_at = false; - _scrolling_viewport = false; - } + virtual void OnResize(Point new_size, Point delta) + { + this->viewport->width += delta.x; + this->viewport->height += delta.y; + this->viewport->virtual_width += delta.x; + this->viewport->virtual_height += delta.y; + } - w->viewport->scrollpos_x += ScaleByZoom(e->we.scroll.delta.x, vp->zoom); - w->viewport->scrollpos_y += ScaleByZoom(e->we.scroll.delta.y, vp->zoom); - w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x; - w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y; - } break; + virtual void OnScroll(Point delta) + { + ViewPort *vp = IsPtInWindowViewport(this, _cursor.pos.x, _cursor.pos.y); + + if (vp == NULL) { + _cursor.fix_at = false; + _scrolling_viewport = false; + } - case WE_MOUSEWHEEL: - ZoomInOrOutToCursorWindow(e->we.wheel.wheel < 0, w); - break; + this->viewport->scrollpos_x += ScaleByZoom(delta.x, vp->zoom); + this->viewport->scrollpos_y += ScaleByZoom(delta.y, vp->zoom); + this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x; + this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y; + } - case WE_INVALIDATE_DATA: - /* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */ - HandleZoomMessage(w, w->viewport, 5, 6); - break; + virtual void OnMouseWheel(int wheel) + { + ZoomInOrOutToCursorWindow(wheel < 0, this); } -} + + virtual void OnInvalidateData(int data = 0) + { + /* Only handle zoom message if intended for us (msg ZOOM_IN/ZOOM_OUT) */ + HandleZoomMessage(this, this->viewport, EVW_ZOOMIN, EVW_ZOOMOUT); + } +}; static const WindowDesc _extra_view_port_desc = { WDP_AUTO, WDP_AUTO, 300, 68, 300, 268, WC_EXTRA_VIEW_PORT, WC_NONE, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, _extra_view_port_widgets, - ExtraViewPortWndProc + NULL }; void ShowExtraViewPortWindow(TileIndex tile) @@ -1194,26 +1235,7 @@ /* find next free window number for extra viewport */ while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++; - Window *w = AllocateWindowDescFront<Window>(&_extra_view_port_desc, i); - if (w != NULL) { - Point pt; - - if (tile == INVALID_TILE) { - /* the main window with the main view */ - const Window *v = FindWindowById(WC_MAIN_WINDOW, 0); - - /* center on same place as main window (zoom is maximum, no adjustment needed) */ - pt.x = v->viewport->scrollpos_x + v->viewport->virtual_height / 2; - pt.y = v->viewport->scrollpos_y + v->viewport->virtual_height / 2; - } else { - pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile)); - } - - w->viewport->scrollpos_x = pt.x - ((w->widget[4].right - w->widget[4].left) - 1) / 2; - w->viewport->scrollpos_y = pt.y - ((w->widget[4].bottom - w->widget[4].top) - 1) / 2; - w->viewport->dest_scrollpos_x = w->viewport->scrollpos_x; - w->viewport->dest_scrollpos_y = w->viewport->scrollpos_y; - } + AllocateWindowDescFront<ExtraViewportWindow>(&_extra_view_port_desc, i, &tile); } bool ScrollMainWindowTo(int x, int y, bool instant)