MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / initViewport

Function initViewport

src/OpenLoco/src/Ui/Windows/IndustryWindow.cpp:232–292  ·  view source on GitHub ↗

0x00456C36

Source from the content-addressed store, hash-verified

230
231 // 0x00456C36
232 static void initViewport(Window& self)
233 {
234 if (self.currentTab != Common::widx::tab_industry - Common::widx::tab_industry)
235 {
236 return;
237 }
238
239 self.callPrepareDraw();
240
241 // Figure out the industry's position on the map.
242 auto industry = IndustryManager::get(IndustryId(self.number));
243 int16_t tileZ = World::TileManager::getHeight({ industry->x, industry->y }).landHeight;
244
245 // Compute views.
246 SavedView view = {
247 industry->x,
248 industry->y,
249 ZoomLevel::quarter,
250 static_cast<int8_t>(self.viewports[0]->getRotation()),
251 tileZ,
252 };
253 // view.flags |= (1 << 14);
254
255 ViewportFlags flags = ViewportFlags::none;
256 if (self.viewports[0] != nullptr)
257 {
258 if (self.savedView == view)
259 {
260 return;
261 }
262
263 flags = self.viewports[0]->flags;
264 self.viewportRemove(0);
265 }
266 else
267 {
268 if (Config::get().gridlinesOnLandscape)
269 {
270 flags |= ViewportFlags::gridlines_on_landscape;
271 }
272 }
273
274 self.savedView = view;
275
276 if (self.viewports[0] == nullptr)
277 {
278 auto widget = &self.widgets[widx::viewport];
279 auto tile = World::Pos3({ industry->x, industry->y, tileZ });
280 auto origin = Ui::Point(widget->left + self.x + 1, widget->top + self.y + 1);
281 auto size = Ui::Size(widget->width() - 2, widget->height() - 2);
282 ViewportManager::create(&self, 0, origin, size, self.savedView.zoomLevel, tile);
283 self.invalidate();
284 self.flags |= WindowFlags::viewportNoScrolling;
285 }
286
287 if (self.viewports[0] != nullptr)
288 {
289 self.viewports[0]->flags = flags;

Callers 2

onResizeFunction · 0.70
openFunction · 0.70

Calls 11

IndustryIdEnum · 0.85
getHeightFunction · 0.85
SizeClass · 0.85
callPrepareDrawMethod · 0.80
viewportRemoveMethod · 0.80
createFunction · 0.70
getFunction · 0.50
getRotationMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45
invalidateMethod · 0.45

Tested by

no test coverage detected