MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / DoZoomInOutWindow

Function DoZoomInOutWindow

src/main_gui.cpp:93–140  ·  view source on GitHub ↗

* Zooms a viewport in a window in or out. * @param how Zooming direction. * @param w Window owning the viewport. * @return Returns \c true if zooming step could be done, \c false if further zooming is not possible. * @note No button handling or what so ever is done. */

Source from the content-addressed store, hash-verified

91 * @note No button handling or what so ever is done.
92 */
93bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
94{
95 assert(w != nullptr);
96
97 switch (how) {
98 case ZOOM_NONE:
99 /* On initialisation of the viewport we don't do anything. */
100 break;
101
102 case ZOOM_IN: {
103 ViewportData &vp = *w->viewport;
104 if (vp.zoom <= _settings_client.gui.zoom_min) return false;
105 --vp.zoom;
106 vp.virtual_width >>= 1;
107 vp.virtual_height >>= 1;
108
109 vp.scrollpos_x += vp.virtual_width >> 1;
110 vp.scrollpos_y += vp.virtual_height >> 1;
111 vp.dest_scrollpos_x = vp.scrollpos_x;
112 vp.dest_scrollpos_y = vp.scrollpos_y;
113 break;
114 }
115
116 case ZOOM_OUT: {
117 ViewportData &vp = *w->viewport;
118 if (vp.zoom >= _settings_client.gui.zoom_max) return false;
119 ++vp.zoom;
120
121 vp.scrollpos_x -= vp.virtual_width >> 1;
122 vp.scrollpos_y -= vp.virtual_height >> 1;
123 vp.dest_scrollpos_x = vp.scrollpos_x;
124 vp.dest_scrollpos_y = vp.scrollpos_y;
125
126 vp.virtual_width <<= 1;
127 vp.virtual_height <<= 1;
128 break;
129 }
130 }
131
132 if (w->viewport != nullptr) { // the viewport can be null when how == ZOOM_NONE
133 w->viewport->virtual_left = w->viewport->scrollpos_x;
134 w->viewport->virtual_top = w->viewport->scrollpos_y;
135 }
136
137 /* Update the windows that have zoom-buttons to perhaps disable their buttons */
138 w->InvalidateData();
139 return true;
140}
141
142void ZoomInOrOutToCursorWindow(bool in, Window *w)
143{

Callers 14

OnClickMethod · 0.85
ToolbarZoomInClickFunction · 0.85
ToolbarZoomOutClickFunction · 0.85
MainToolbarWindowMethod · 0.85
OnMouseWheelMethod · 0.85
OnMouseWheelMethod · 0.85
MaxZoomInOutFunction · 0.85
ConZoomToLevelFunction · 0.85
OnMouseWheelMethod · 0.85

Calls 1

InvalidateDataMethod · 0.45

Tested by

no test coverage detected