diff options
author | alberth <alberth@openttd.org> | 2009-07-26 13:19:23 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2009-07-26 13:19:23 +0000 |
commit | 0081bb9a960473bd1e4f4891416f401d1f50e5b8 (patch) | |
tree | 2f40a3c3fff2eb9422c4640b6c74ed8bcdc2e8ca /src | |
parent | 75ccf9de3a4abc4a67a373959013a18321995d88 (diff) | |
download | openttd-0081bb9a960473bd1e4f4891416f401d1f50e5b8.tar.xz |
(svn r16961) -Codechange: Moving some methods up in the class hierarchy to avoid code duplication.
Diffstat (limited to 'src')
-rw-r--r-- | src/widget.cpp | 27 | ||||
-rw-r--r-- | src/widget_type.h | 6 |
2 files changed, 12 insertions, 21 deletions
diff --git a/src/widget.cpp b/src/widget.cpp index 7a3371c2b..4ece7f3a5 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -973,7 +973,7 @@ void NWidgetBase::Invalidate(const Window *w) const } /** - * @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 Window *w) const */ /** - * @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 *widgets, int length, bool left_moving, bo 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 space, uint max_space) 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::GetWidgetFromPos(int x, int y) 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 Window *w) const 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(Window *w, bool allow_next) 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. diff --git a/src/widget_type.h b/src/widget_type.h index 20c89e6e6..58c9c580b 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -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(); |