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

Function getPart

src/OpenLoco/src/Ui/ScrollView.cpp:167–290  ·  view source on GitHub ↗

0x004C8EF0 Note: Original function returns a scrollAreaOffset not an index

Source from the content-addressed store, hash-verified

165 // 0x004C8EF0
166 // Note: Original function returns a scrollAreaOffset not an index
167 GetPartResult getPart(Ui::Window& window, Ui::Widget* widget, int16_t x, int16_t y)
168 {
169 GetPartResult res{ { x, y }, ScrollPart::none, 0 };
170
171 for (auto& widget2 : window.widgets)
172 {
173 if (widget == &widget2)
174 {
175 break;
176 }
177 if (widget2.type == WidgetType::scrollview)
178 {
179 res.index++;
180 }
181 }
182
183 res.index = std::min<size_t>(res.index, Window::kMaxScrollAreas - 1);
184
185 const auto& scroll = window.scrollAreas[res.index];
186 auto right = widget->right + window.x;
187 auto left = widget->left + window.x;
188 auto top = widget->top + window.y;
189 auto bottom = widget->bottom + window.y;
190
191 const bool needsHScroll = scroll.contentWidth > widget->width();
192 const bool needsVScroll = scroll.contentHeight > widget->height();
193
194 if (needsHScroll && scroll.hasFlags(ScrollFlags::hscrollbarVisible) && y >= (bottom - kScrollbarSize))
195 {
196 if (x < left + kScrollbarSize)
197 {
198 res.area = ScrollPart::hscrollbarButtonLeft;
199 return res;
200 }
201
202 // If vertical is also visible then there is a deadzone in the corner
203 if (scroll.hasFlags(ScrollFlags::vscrollbarVisible))
204 {
205 right -= kScrollbarSize;
206 }
207
208 // Within deadzone
209 if (x >= right)
210 {
211 res.area = ScrollPart::none;
212 return res;
213 }
214
215 if (x >= right - kThumbSize)
216 {
217 res.area = ScrollPart::hscrollbarButtonRight;
218 return res;
219 }
220
221 if (x < scroll.hThumbLeft + left)
222 {
223 res.area = ScrollPart::hscrollbarTrackLeft;
224 return res;

Callers 6

scrollLeftBeginFunction · 0.85
scrollModalRightFunction · 0.85
scrollLeftContinueFunction · 0.85
getCarFromScrollViewPosFunction · 0.85
stateNormalHoverFunction · 0.85
processMouseOverFunction · 0.85

Calls 3

widthMethod · 0.45
heightMethod · 0.45
hasFlagsMethod · 0.45

Tested by

no test coverage detected