(svn r20221) -Codechange: Move unscrolled row calculation into a function.

pull/155/head
alberth 14 years ago
parent f48fca6bfc
commit 71aac2192f

@ -401,7 +401,7 @@ struct MusicTrackSelectionWindow : public Window {
{
switch (widget) {
case MTSW_LIST_LEFT: { // add to playlist
int y = (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y) / FONT_HEIGHT_SMALL;
int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL);
if (msf.playlist < 4) return;
if (!IsInsideMM(y, 0, BaseMusic::GetUsedSet()->num_available)) return;
@ -425,7 +425,7 @@ struct MusicTrackSelectionWindow : public Window {
} break;
case MTSW_LIST_RIGHT: { // remove from playlist
int y = (pt.y - this->GetWidget<NWidgetBase>(widget)->pos_y) / FONT_HEIGHT_SMALL;
int y = this->GetRowFromWidget(pt.y, widget, 0, FONT_HEIGHT_SMALL);
if (msf.playlist < 4) return;
if (!IsInsideMM(y, 0, NUM_SONGS_PLAYLIST)) return;

@ -259,8 +259,7 @@ public:
{
switch (widget) {
case TWA_COMMAND_LIST: {
int y = (pt.y - this->GetWidget<NWidgetBase>(TWA_COMMAND_LIST)->pos_y - 1) / FONT_HEIGHT_NORMAL;
int y = this->GetRowFromWidget(pt.y, TWA_COMMAND_LIST, 1, FONT_HEIGHT_NORMAL);
if (!IsInsideMM(y, 0, 5)) return;
y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_company, this->town), y + this->vscroll.GetPosition() - 1);

@ -81,6 +81,22 @@ WindowDesc::~WindowDesc()
{
}
/**
* Compute the row of a widget that a user clicked in.
* @param clickpos Vertical position of the mouse click.
* @param widget Widget number of the widget clicked in.
* @param padding Amount of empty space between the widget edge and the top of the first row.
* @param line_height Height of a single row.
* @return Row number clicked at. If clicked at a wrong position, #INT_MAX is returned.
* @note The widget does not know where a list printed at the widget ends, so below a list is not a wrong position.
*/
int Window::GetRowFromWidget(int clickpos, int widget, int padding, int line_height) const
{
const NWidgetBase *wid = this->GetWidget<NWidgetBase>(widget);
if (clickpos < (int)wid->pos_y + padding) return INT_MAX;
return (clickpos - (int)wid->pos_y - padding) / line_height;
}
/**
* Set capacity of visible elements from the size and resize properties of a widget.
* @param w Window.

@ -528,6 +528,7 @@ public:
bool SetFocusedWidget(byte widget_index);
void HandleButtonClick(byte widget);
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height) const;
void RaiseButtons(bool autoraise = false);
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);

Loading…
Cancel
Save