00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "landscape.h"
00014 #include "window_gui.h"
00015 #include "viewport_func.h"
00016 #include "strings_func.h"
00017 #include "zoom_func.h"
00018 #include "window_func.h"
00019
00020 #include "table/strings.h"
00021 #include "table/sprites.h"
00022
00024 enum ExtraViewportWindowWidgets {
00025 EVW_CAPTION,
00026 EVW_VIEWPORT,
00027 EVW_ZOOMIN,
00028 EVW_ZOOMOUT,
00029 EVW_MAIN_TO_VIEW,
00030 EVW_VIEW_TO_MAIN,
00031 };
00032
00033
00034 static const NWidgetPart _nested_extra_view_port_widgets[] = {
00035 NWidget(NWID_HORIZONTAL),
00036 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00037 NWidget(WWT_CAPTION, COLOUR_GREY, EVW_CAPTION), SetDataTip(STR_EXTRA_VIEW_PORT_TITLE, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00038 NWidget(WWT_SHADEBOX, COLOUR_GREY),
00039 NWidget(WWT_STICKYBOX, COLOUR_GREY),
00040 EndContainer(),
00041 NWidget(WWT_PANEL, COLOUR_GREY),
00042 NWidget(NWID_VIEWPORT, INVALID_COLOUR, EVW_VIEWPORT), SetPadding(2, 2, 2, 2), SetResize(1, 1), SetFill(1, 1),
00043 EndContainer(),
00044 NWidget(NWID_HORIZONTAL),
00045 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, EVW_ZOOMIN), SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
00046 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, EVW_ZOOMOUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
00047 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
00048 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, EVW_MAIN_TO_VIEW), SetFill(1, 1), SetResize(1, 0),
00049 SetDataTip(STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW, STR_EXTRA_VIEW_MOVE_MAIN_TO_VIEW_TT),
00050 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, EVW_VIEW_TO_MAIN), SetFill(1, 1), SetResize(1, 0),
00051 SetDataTip(STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN, STR_EXTRA_VIEW_MOVE_VIEW_TO_MAIN_TT),
00052 EndContainer(),
00053 EndContainer(),
00054 NWidget(NWID_HORIZONTAL),
00055 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 0), EndContainer(),
00056 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
00057 EndContainer(),
00058 };
00059
00060 class ExtraViewportWindow : public Window {
00061 public:
00062 ExtraViewportWindow(const WindowDesc *desc, int window_number, TileIndex tile) : Window()
00063 {
00064 this->InitNested(desc, window_number);
00065
00066 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(EVW_VIEWPORT);
00067 nvp->InitializeViewport(this, 0, ZOOM_LVL_NORMAL);
00068 this->DisableWidget(EVW_ZOOMIN);
00069
00070 Point pt;
00071 if (tile == INVALID_TILE) {
00072
00073 const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
00074
00075
00076 pt.x = w->viewport->scrollpos_x + w->viewport->virtual_width / 2;
00077 pt.y = w->viewport->scrollpos_y + w->viewport->virtual_height / 2;
00078 } else {
00079 pt = RemapCoords(TileX(tile) * TILE_SIZE + TILE_SIZE / 2, TileY(tile) * TILE_SIZE + TILE_SIZE / 2, TileHeight(tile));
00080 }
00081
00082 this->viewport->scrollpos_x = pt.x - this->viewport->virtual_width / 2;
00083 this->viewport->scrollpos_y = pt.y - this->viewport->virtual_height / 2;
00084 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
00085 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
00086 }
00087
00088 virtual void SetStringParameters(int widget) const
00089 {
00090 switch (widget) {
00091 case EVW_CAPTION:
00092
00093 SetDParam(0, this->window_number + 1);
00094 break;
00095 }
00096 }
00097
00098 virtual void OnClick(Point pt, int widget, int click_count)
00099 {
00100 switch (widget) {
00101 case EVW_ZOOMIN: DoZoomInOutWindow(ZOOM_IN, this); break;
00102 case EVW_ZOOMOUT: DoZoomInOutWindow(ZOOM_OUT, this); break;
00103
00104 case EVW_MAIN_TO_VIEW: {
00105 Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
00106 int x = this->viewport->scrollpos_x;
00107 int y = this->viewport->scrollpos_y;
00108
00109
00110 w->viewport->dest_scrollpos_x = x - (w->viewport->virtual_width - this->viewport->virtual_width) / 2;
00111 w->viewport->dest_scrollpos_y = y - (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
00112 w->viewport->follow_vehicle = INVALID_VEHICLE;
00113 break;
00114 }
00115
00116 case EVW_VIEW_TO_MAIN: {
00117 const Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
00118 int x = w->viewport->scrollpos_x;
00119 int y = w->viewport->scrollpos_y;
00120
00121 this->viewport->dest_scrollpos_x = x + (w->viewport->virtual_width - this->viewport->virtual_width) / 2;
00122 this->viewport->dest_scrollpos_y = y + (w->viewport->virtual_height - this->viewport->virtual_height) / 2;
00123 break;
00124 }
00125 }
00126 }
00127
00128 virtual void OnResize()
00129 {
00130 if (this->viewport != NULL) {
00131 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(EVW_VIEWPORT);
00132 nvp->UpdateViewportCoordinates(this);
00133 }
00134 }
00135
00136 virtual void OnScroll(Point delta)
00137 {
00138 this->viewport->scrollpos_x += ScaleByZoom(delta.x, this->viewport->zoom);
00139 this->viewport->scrollpos_y += ScaleByZoom(delta.y, this->viewport->zoom);
00140 this->viewport->dest_scrollpos_x = this->viewport->scrollpos_x;
00141 this->viewport->dest_scrollpos_y = this->viewport->scrollpos_y;
00142 }
00143
00144 virtual void OnMouseWheel(int wheel)
00145 {
00146 ZoomInOrOutToCursorWindow(wheel < 0, this);
00147 }
00148
00149 virtual void OnInvalidateData(int data = 0)
00150 {
00151
00152 HandleZoomMessage(this, this->viewport, EVW_ZOOMIN, EVW_ZOOMOUT);
00153 }
00154 };
00155
00156 static const WindowDesc _extra_view_port_desc(
00157 WDP_AUTO, 300, 268,
00158 WC_EXTRA_VIEW_PORT, WC_NONE,
00159 WDF_UNCLICK_BUTTONS,
00160 _nested_extra_view_port_widgets, lengthof(_nested_extra_view_port_widgets)
00161 );
00162
00167 void ShowExtraViewPortWindow(TileIndex tile)
00168 {
00169 int i = 0;
00170
00171
00172 while (FindWindowById(WC_EXTRA_VIEW_PORT, i) != NULL) i++;
00173
00174 new ExtraViewportWindow(&_extra_view_port_desc, i, tile);
00175 }
00176
00182 void ShowExtraViewPortWindowForTileUnderCursor()
00183 {
00184
00185
00186 Point pt = GetTileBelowCursor();
00187 ShowExtraViewPortWindow(pt.x != -1 ? TileVirtXY(pt.x, pt.y) : INVALID_TILE);
00188 }