Skip to content

Commit 048e14a

Browse files
committed
Merge remote-tracking branch 'remotes/fenyo1/MaxClickExtend'
Conflicts: src/Interface/TextList.cpp
2 parents 3d461dd + 49d51c7 commit 048e14a

5 files changed

Lines changed: 66 additions & 32 deletions

File tree

src/Basescape/CraftSoldiersState.cpp

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,18 +166,26 @@ void CraftSoldiersState::populateList()
166166
*/
167167
void CraftSoldiersState::lstItemsLeftArrowClick(Action *action)
168168
{
169-
if (action->getDetails()->button.button != SDL_BUTTON_LEFT)
169+
if (SDL_BUTTON_LEFT == action->getDetails()->button.button
170+
|| SDL_BUTTON_RIGHT == action->getDetails()->button.button)
170171
{
171-
return;
172-
}
173-
int row = _lstSoldiers->getSelectedRow();
174-
if (row > 0 )
175-
{
176-
Soldier *s = _base->getSoldiers()->at(row);
177-
_base->getSoldiers()->at(row) = _base->getSoldiers()->at(row-1);
178-
_base->getSoldiers()->at(row-1) = s;
172+
int row = _lstSoldiers->getSelectedRow();
173+
if (row > 0 )
174+
{
175+
Soldier *s = _base->getSoldiers()->at(row);
176+
if (SDL_BUTTON_LEFT == action->getDetails()->button.button)
177+
{
178+
_base->getSoldiers()->at(row) = _base->getSoldiers()->at(row-1);
179+
_base->getSoldiers()->at(row-1) = s;
180+
}
181+
else
182+
{
183+
_base->getSoldiers()->erase(_base->getSoldiers()->begin()+row);
184+
_base->getSoldiers()->insert(_base->getSoldiers()->begin(),s);
185+
}
186+
}
187+
populateList();
179188
}
180-
populateList();
181189
}
182190

183191
/**
@@ -186,18 +194,26 @@ void CraftSoldiersState::lstItemsLeftArrowClick(Action *action)
186194
*/
187195
void CraftSoldiersState::lstItemsRightArrowClick(Action *action)
188196
{
189-
if (action->getDetails()->button.button != SDL_BUTTON_LEFT)
197+
if (SDL_BUTTON_LEFT == action->getDetails()->button.button
198+
|| SDL_BUTTON_RIGHT == action->getDetails()->button.button)
190199
{
191-
return;
192-
}
193-
unsigned int row = _lstSoldiers->getSelectedRow();
194-
if (row < _base->getSoldiers()->size() - 1 )
195-
{
196-
Soldier *s = _base->getSoldiers()->at(row);
197-
_base->getSoldiers()->at(row) = _base->getSoldiers()->at(row+1);
198-
_base->getSoldiers()->at(row+1) = s;
200+
unsigned int row = _lstSoldiers->getSelectedRow();
201+
if (row < _base->getSoldiers()->size() - 1 )
202+
{
203+
Soldier *s = _base->getSoldiers()->at(row);
204+
if (SDL_BUTTON_LEFT == action->getDetails()->button.button)
205+
{
206+
_base->getSoldiers()->at(row) = _base->getSoldiers()->at(row+1);
207+
_base->getSoldiers()->at(row+1) = s;
208+
}
209+
else
210+
{
211+
_base->getSoldiers()->erase(_base->getSoldiers()->begin()+row);
212+
_base->getSoldiers()->insert(_base->getSoldiers()->end(),s);
213+
}
214+
}
215+
populateList();
199216
}
200-
populateList();
201217
}
202218

203219
/**

src/Interface/ArrowButton.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,11 +296,11 @@ void ArrowButton::scroll()
296296
{
297297
if (_shape == ARROW_BIG_UP)
298298
{
299-
_list->scrollUp();
299+
_list->scrollUp(false);
300300
}
301301
else if (_shape == ARROW_BIG_DOWN)
302302
{
303-
_list->scrollDown();
303+
_list->scrollDown(false);
304304
}
305305
}
306306

@@ -332,4 +332,18 @@ void ArrowButton::mouseRelease(Action *action, State *state)
332332
}
333333
}
334334

335+
/*
336+
* Scrolls the associated list to top or bottom.
337+
* @param action Pointer to an action.
338+
* @param state State that the action handlers belong to.
339+
*/
340+
void ArrowButton::mouseClick(Action *action, State *state)
341+
{
342+
ImageButton::mouseClick(action, state);
343+
if (0 != _list && SDL_BUTTON_RIGHT == action->getDetails()->button.button) {
344+
if (_shape == ARROW_BIG_UP) _list->scrollUp(true);
345+
else if (_shape == ARROW_BIG_DOWN) _list->scrollDown(true);
346+
}
347+
}
348+
335349
}

src/Interface/ArrowButton.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class ArrowButton : public ImageButton
5959
void mousePress(Action *action, State *state);
6060
/// Special handling for mouse releases.
6161
void mouseRelease(Action *action, State *state);
62+
/// Special handling for mouse clicks.
63+
void mouseClick(Action *action, State *state);
6264
};
6365

6466
}

src/Interface/TextList.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,30 +604,32 @@ void TextList::clearList()
604604
}
605605

606606
/**
607-
* Scrolls the text in the list up by one row.
607+
* Scrolls the text in the list up by one row or to the top.
608+
* @param toMax If true then scrolls to the top of the list. false => one row up
608609
*/
609-
void TextList::scrollUp()
610+
void TextList::scrollUp(bool toMax)
610611
{
611612
if (!_scrolling)
612613
return;
613614
if (_texts.size() > _visibleRows && _scroll > 0)
614615
{
615-
_scroll--;
616+
if (toMax) _scroll=0; else _scroll--;
616617
_redraw = true;
617618
}
618619
updateArrows();
619620
}
620621

621622
/**
622-
* Scrolls the text in the list down by one row.
623+
* Scrolls the text in the list down by one row or to the bottom.
624+
* @param toMax If true then scrolls to the bottom of the list. false => one row down
623625
*/
624-
void TextList::scrollDown()
626+
void TextList::scrollDown(bool toMax)
625627
{
626628
if (!_scrolling)
627629
return;
628630
if (_texts.size() > _visibleRows && _scroll < _texts.size() - _visibleRows)
629631
{
630-
_scroll++;
632+
if (toMax) _scroll=_texts.size()-_visibleRows; else _scroll++;
631633
_redraw = true;
632634
}
633635
updateArrows();
@@ -743,11 +745,11 @@ void TextList::mousePress(Action *action, State *state)
743745
{
744746
if (action->getDetails()->button.button == SDL_BUTTON_WHEELUP)
745747
{
746-
scrollUp();
748+
scrollUp(false);
747749
}
748750
else if (action->getDetails()->button.button == SDL_BUTTON_WHEELDOWN)
749751
{
750-
scrollDown();
752+
scrollDown(false);
751753
}
752754
if (_selectable)
753755
{

src/Interface/TextList.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ class TextList : public InteractiveSurface
135135
/// Clears the list.
136136
void clearList();
137137
/// Scrolls the list up.
138-
void scrollUp();
138+
void scrollUp(bool toMax);
139139
/// Scrolls the list down.
140-
void scrollDown();
140+
void scrollDown(bool toMax);
141141
/// Sets the list scrolling.
142142
void setScrolling(bool scrolling);
143143
/// Draws the text onto the text list.

0 commit comments

Comments
 (0)