Changeset - r15551:b196633d2a08
[Not reviewed]
master
0 4 0
alberth - 14 years ago 2010-07-26 13:02:28
alberth@openttd.org
(svn r20221) -Codechange: Move unscrolled row calculation into a function.
4 files changed with 20 insertions and 4 deletions:
0 comments (0 inline, 0 general)
src/music_gui.cpp
Show inline comments
 
@@ -401,7 +401,7 @@ struct MusicTrackSelectionWindow : publi
 
	{
 
		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 : publi
 
			} 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;
src/town_gui.cpp
Show inline comments
 
@@ -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);
src/window.cpp
Show inline comments
 
@@ -82,6 +82,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.
 
 * @param widget  Widget with size and resize properties.
src/window_gui.h
Show inline comments
 
@@ -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, ...);
0 comments (0 inline, 0 general)