summaryrefslogtreecommitdiff
path: root/src/autoreplace_gui.cpp
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2010-07-26 13:08:48 +0000
committeralberth <alberth@openttd.org>2010-07-26 13:08:48 +0000
commit4203e641f8a507c017d10bf40f2c3882ce596da5 (patch)
tree883a2b182b8594de0b2048900956281c4efff861 /src/autoreplace_gui.cpp
parent97f85f7bfba286bf9a7c692b390eec8231cac9ae (diff)
downloadopenttd-4203e641f8a507c017d10bf40f2c3882ce596da5.tar.xz
(svn r20223) -Codechange: Replace scrolled row calculations by a call to GetScrolledRowFromWidget().
Diffstat (limited to 'src/autoreplace_gui.cpp')
-rw-r--r--src/autoreplace_gui.cpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index d4d1cb87f..963721beb 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -443,25 +443,27 @@ public:
case RVW_WIDGET_LEFT_MATRIX:
case RVW_WIDGET_RIGHT_MATRIX: {
- uint i = (pt.y - this->GetWidget<NWidgetBase>(RVW_WIDGET_LEFT_MATRIX)->pos_y) / this->resize.step_height;
- uint16 click_scroll_pos = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.GetPosition() : this->vscroll2.GetPosition();
- uint16 click_scroll_cap = widget == RVW_WIDGET_LEFT_MATRIX ? this->vscroll.GetCapacity() : this->vscroll2.GetCapacity();
- byte click_side = widget == RVW_WIDGET_LEFT_MATRIX ? 0 : 1;
- size_t engine_count = this->engines[click_side].Length();
-
- if (i < click_scroll_cap) {
- i += click_scroll_pos;
- EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
- if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
- this->sel_engine[click_side] = e;
- if (click_side == 0) {
- this->engines[1].ForceRebuild();
- this->reset_sel_engine = true;
- }
- this->SetDirty();
- }
- break;
+ uint i;
+ byte click_side;
+ if (widget == RVW_WIDGET_LEFT_MATRIX) {
+ i = this->vscroll.GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_LEFT_MATRIX);
+ click_side = 0;
+ } else {
+ i = this->vscroll2.GetScrolledRowFromWidget(pt.y, this, RVW_WIDGET_RIGHT_MATRIX);
+ click_side = 1;
}
+ size_t engine_count = this->engines[click_side].Length();
+
+ EngineID e = engine_count > i ? this->engines[click_side][i] : INVALID_ENGINE;
+ if (e == this->sel_engine[click_side]) break; // we clicked the one we already selected
+ this->sel_engine[click_side] = e;
+ if (click_side == 0) {
+ this->engines[1].ForceRebuild();
+ this->reset_sel_engine = true;
+ }
+ this->SetDirty();
+ break;
+ }
}
}