Changeset - r12514:dae232b962a6
[Not reviewed]
master
0 2 0
alberth - 15 years ago 2009-07-26 13:19:23
alberth@openttd.org
(svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
2 files changed with 12 insertions and 21 deletions:
0 comments (0 inline, 0 general)
src/widget.cpp
Show inline comments
 
@@ -973,7 +973,7 @@ void NWidgetBase::Invalidate(const Windo
 
}
 

	
 
/**
 
 * @fn NWidgetCore *GetWidgetFromPos(int x, int y)
 
 * @fn NWidgetCore *NWidgetBase::GetWidgetFromPos(int x, int y)
 
 * Retrieve a widget by its position.
 
 * @param x Horizontal position relative to the left edge of the window.
 
 * @param y Vertical position relative to the top edge of the window.
 
@@ -981,11 +981,14 @@ void NWidgetBase::Invalidate(const Windo
 
 */
 

	
 
/**
 
 * @fn NWidgetBase *GetWidgetOfType(WidgetType tp)
 
 * Retrieve a widget by its type.
 
 * @param tp Widget type to search for.
 
 * @return Returns the first widget of the specified type, or \c NULL if no widget can be found.
 
 */
 
NWidgetBase *NWidgetBase::GetWidgetOfType(WidgetType tp)
 
{
 
	return (this->type == tp) ? this : NULL;
 
}
 

	
 
/**
 
 * Constructor for resizable nested widgets.
 
@@ -1109,6 +1112,11 @@ void NWidgetCore::StoreWidgets(Widget *w
 
	w->tooltips = this->tool_tip;
 
}
 

	
 
NWidgetCore *NWidgetCore::GetWidgetFromPos(int x, int y)
 
{
 
	return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : NULL;
 
}
 

	
 
/**
 
 * @fn Scrollbar *NWidgetCore::FindScrollbar(Window *w, bool allow_next = true)
 
 * Find the scrollbar of the widget through the Window::nested_array.
 
@@ -1200,7 +1208,6 @@ static inline uint ComputeOffset(uint sp
 
	return (max_space - space) / 2;
 
}
 

	
 

	
 
/**
 
 * Widgets stacked on top of each other.
 
 * @param tp Kind of stacking, must be either #NWID_SELECTION or #NWID_LAYERED.
 
@@ -1615,11 +1622,6 @@ NWidgetCore *NWidgetSpacer::GetWidgetFro
 
	return NULL;
 
}
 

	
 
NWidgetBase *NWidgetSpacer::GetWidgetOfType(WidgetType tp)
 
{
 
	return (this->type == tp) ? this : NULL;
 
}
 

	
 
/**
 
 * Constructor parent nested widgets.
 
 * @param tp     Type of parent widget.
 
@@ -2152,10 +2154,6 @@ void NWidgetLeaf::Invalidate(const Windo
 
	NWidgetBase::Invalidate(w);
 
}
 

	
 
NWidgetCore *NWidgetLeaf::GetWidgetFromPos(int x, int y)
 
{
 
	return (IsInsideBS(x, this->pos_x, this->current_x) && IsInsideBS(y, this->pos_y, this->current_y)) ? this : NULL;
 
}
 

	
 
Scrollbar *NWidgetLeaf::FindScrollbar(Window *w, bool allow_next)
 
{
 
@@ -2169,11 +2167,6 @@ Scrollbar *NWidgetLeaf::FindScrollbar(Wi
 
	return NULL;
 
}
 

	
 
NWidgetBase *NWidgetLeaf::GetWidgetOfType(WidgetType tp)
 
{
 
	return (this->type == tp) ? this : NULL;
 
}
 

	
 
/**
 
 * Intialize nested widget tree and convert to widget array.
 
 * @param nwid Nested widget tree.
src/widget_type.h
Show inline comments
 
@@ -182,7 +182,7 @@ public:
 
	virtual void StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl) = 0;
 

	
 
	virtual NWidgetCore *GetWidgetFromPos(int x, int y) = 0;
 
	virtual NWidgetBase *GetWidgetOfType(WidgetType tp) = 0;
 
	virtual NWidgetBase *GetWidgetOfType(WidgetType tp);
 

	
 
	/**
 
	 * Set additional space (padding) around the widget.
 
@@ -295,6 +295,7 @@ public:
 
	inline bool IsDisabled();
 

	
 
	void StoreWidgets(Widget *widgets, int length, bool left_moving, bool top_moving, bool rtl);
 
	/* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
 

	
 
	virtual Scrollbar *FindScrollbar(Window *w, bool allow_next = true) = 0;
 

	
 
@@ -444,7 +445,6 @@ public:
 
	/* virtual */ void Draw(const Window *w);
 
	/* virtual */ void Invalidate(const Window *w) const;
 
	/* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
 
	/* virtual */ NWidgetBase *GetWidgetOfType(WidgetType tp);
 
};
 

	
 
/** Nested widget with a child.
 
@@ -480,8 +480,6 @@ public:
 
	/* virtual */ void SetupSmallestSize(Window *w, bool init_array);
 
	/* virtual */ void Draw(const Window *w);
 
	/* virtual */ void Invalidate(const Window *w) const;
 
	/* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y);
 
	/* virtual */ NWidgetBase *GetWidgetOfType(WidgetType tp);
 
	/* virtual */ Scrollbar *FindScrollbar(Window *w, bool allow_next = true);
 

	
 
	static void InvalidateDimensionCache();
0 comments (0 inline, 0 general)