Changeset - r15552:db706a5de04a
[Not reviewed]
master
0 2 0
alberth - 14 years ago 2010-07-26 13:03:40
alberth@openttd.org
(svn r20222) -Add: Add functions to compute the row in a scrolled widget.
2 files changed with 20 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/window.cpp
Show inline comments
 
@@ -77,36 +77,52 @@ WindowDesc::WindowDesc(WindowPosition de
 
{
 
}
 

	
 
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.
 
 * @param line_height Height of a single row. A negative value means using the vertical resize step of the widget.
 
 * @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 (line_height < 0) line_height = wid->resize_y;
 
	if (clickpos < (int)wid->pos_y + padding) return INT_MAX;
 
	return (clickpos - (int)wid->pos_y - padding) / line_height;
 
}
 

	
 
/**
 
 * Compute the row of a scrolled widget that a user clicked in.
 
 * @param clickpos    Vertical position of the mouse click (without taking scrolling into account).
 
 * @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. Default value is \c 0.
 
 * @param line_height Height of a single row. A negative value means using the vertical resize step of the widget.
 
 * @return Row number clicked at. If clicked at a wrong position, #INT_MAX is returned.
 
 */
 
int Scrollbar::GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding, int line_height) const
 
{
 
	uint pos = w->GetRowFromWidget(clickpos, widget, padding, line_height);
 
	if (pos != INT_MAX) pos += this->GetPosition();
 
	return (pos >= this->GetCount()) ? INT_MAX : pos;
 
}
 

	
 
/**
 
 * 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.
 
 * @param padding Padding to subtract from the size.
 
 * @note Updates the position if needed.
 
 */
 
void Scrollbar::SetCapacityFromWidget(Window *w, int widget, int padding)
 
{
 
	NWidgetBase *nwid = w->GetWidget<NWidgetBase>(widget);
 
	if (this->is_vertical) {
 
		this->SetCapacity(((int)nwid->current_y - padding) / (int)nwid->resize_y);
 
	} else {
src/window_gui.h
Show inline comments
 
@@ -296,24 +296,26 @@ public:
 
	 * @param position the position to scroll towards.
 
	 */
 
	void ScrollTowards(int position)
 
	{
 
		if (position < this->GetPosition()) {
 
			/* scroll up to the item */
 
			this->SetPosition(position);
 
		} else if (position >= this->GetPosition() + this->GetCapacity()) {
 
			/* scroll down so that the item is at the bottom */
 
			this->SetPosition(position - this->GetCapacity() + 1);
 
		}
 
	}
 

	
 
	int GetScrolledRowFromWidget(int clickpos, const Window * const w, int widget, int padding = 0, int line_height = -1) const;
 
};
 

	
 
/**
 
 * Data structure for resizing a window
 
 */
 
struct ResizeInfo {
 
	uint step_width;  ///< Step-size of width resize changes
 
	uint step_height; ///< Step-size of height resize changes
 
};
 

	
 
/** State of a sort direction button. */
 
enum SortButtonState {
 
@@ -519,25 +521,25 @@ public:
 
	 * @return status of the widget ie: lowered = true, raised= false
 
	 */
 
	inline bool IsWidgetLowered(byte widget_index) const
 
	{
 
		assert(widget_index < this->nested_array_size);
 
		return this->GetWidget<NWidgetCore>(widget_index)->IsLowered();
 
	}
 

	
 
	void UnfocusFocusedWidget();
 
	bool SetFocusedWidget(byte widget_index);
 

	
 
	void HandleButtonClick(byte widget);
 
	int GetRowFromWidget(int clickpos, int widget, int padding, int line_height) const;
 
	int GetRowFromWidget(int clickpos, int widget, int padding, int line_height = -1) const;
 

	
 
	void RaiseButtons(bool autoraise = false);
 
	void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets, ...);
 
	void CDECL SetWidgetsLoweredState(bool lowered_stat, int widgets, ...);
 
	void SetWidgetDirty(byte widget_index) const;
 

	
 
	void DrawWidgets() const;
 
	void DrawViewport() const;
 
	void DrawSortButtonState(int widget, SortButtonState state) const;
 

	
 
	void DeleteChildWindows(WindowClass wc = WC_INVALID) const;
 

	
0 comments (0 inline, 0 general)