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

Method SetNewScroll

src/smallmap_gui.cpp:843–871  ·  view source on GitHub ↗

* Set new #scroll_x, #scroll_y, and #subscroll values after limiting them such that the center * of the smallmap always contains a part of the map. * @param sx Proposed new #scroll_x * @param sy Proposed new #scroll_y * @param sub Proposed new #subscroll */

Source from the content-addressed store, hash-verified

841 * @param sub Proposed new #subscroll
842 */
843 void SetNewScroll(int sx, int sy, int sub)
844 {
845 const NWidgetBase *wi = this->GetWidget<NWidgetBase>(WID_SM_MAP);
846 Point hv = InverseRemapCoords(wi->current_x * ZOOM_BASE * TILE_SIZE / 2, wi->current_y * ZOOM_BASE * TILE_SIZE / 2);
847 hv.x *= this->zoom;
848 hv.y *= this->zoom;
849
850 if (sx < -hv.x) {
851 sx = -hv.x;
852 sub = 0;
853 }
854 if (sx > (int)(Map::MaxX() * TILE_SIZE) - hv.x) {
855 sx = Map::MaxX() * TILE_SIZE - hv.x;
856 sub = 0;
857 }
858 if (sy < -hv.y) {
859 sy = -hv.y;
860 sub = 0;
861 }
862 if (sy > (int)(Map::MaxY() * TILE_SIZE) - hv.y) {
863 sy = Map::MaxY() * TILE_SIZE - hv.y;
864 sub = 0;
865 }
866
867 this->scroll_x = sx;
868 this->scroll_y = sy;
869 this->subscroll = sub;
870 if (this->map_type == SMT_LINKSTATS) this->overlay->SetDirty();
871 }
872
873 /**
874 * Adds map indicators to the smallmap.

Callers 3

SetZoomLevelMethod · 0.95
OnScrollMethod · 0.95

Calls 3

InverseRemapCoordsFunction · 0.85
SetDirtyMethod · 0.45

Tested by

no test coverage detected