ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

ThemeLayout.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef THEME_LAYOUT_H
00024 #define THEME_LAYOUT_H
00025 
00026 #include "common/array.h"
00027 #include "common/rect.h"
00028 #include "graphics/font.h"
00029 
00030 #ifdef LAYOUT_DEBUG_DIALOG
00031 namespace Graphics {
00032 struct Surface;
00033 }
00034 #endif
00035 
00036 namespace GUI {
00037 
00038 class Widget;
00039 
00040 class ThemeLayout {
00041     friend class ThemeLayoutMain;
00042     friend class ThemeLayoutStacked;
00043     friend class ThemeLayoutSpacing;
00044     friend class ThemeLayoutWidget;
00045 public:
00046     enum LayoutType {
00047         kLayoutMain,
00048         kLayoutVertical,
00049         kLayoutHorizontal,
00050         kLayoutWidget,
00051         kLayoutTabWidget,
00052         kLayoutSpace
00053     };
00054 
00056     enum ItemAlign {
00057         kItemAlignStart,   
00058         kItemAlignCenter,  
00059         kItemAlignEnd,     
00060         kItemAlignStretch  
00061     };
00062 
00063     ThemeLayout(ThemeLayout *p) :
00064         _parent(p), _x(0), _y(0), _w(-1), _h(-1),
00065         _defaultW(-1), _defaultH(-1),
00066         _textHAlign(Graphics::kTextAlignInvalid) {}
00067 
00068     virtual ~ThemeLayout() {
00069         for (uint i = 0; i < _children.size(); ++i)
00070             delete _children[i];
00071     }
00072 
00073     virtual void reflowLayout(Widget *widgetChain) = 0;
00074     virtual void resetLayout();
00075 
00076     void addChild(ThemeLayout *child) { _children.push_back(child); }
00077 
00078     void setPadding(int8 left, int8 right, int8 top, int8 bottom) {
00079         _padding.left = left;
00080         _padding.right = right;
00081         _padding.top = top;
00082         _padding.bottom = bottom;
00083     }
00084 
00085 protected:
00086     int16 getWidth() { return _w; }
00087     int16 getHeight() { return _h; }
00088 
00089     void offsetX(int newX) {
00090         _x += newX;
00091         for (uint i = 0; i < _children.size(); ++i)
00092             _children[i]->offsetX(newX);
00093     }
00094 
00095     void offsetY(int newY) {
00096         _y += newY;
00097         for (uint i = 0; i < _children.size(); ++i)
00098             _children[i]->offsetY(newY);
00099     }
00100 
00101     void setWidth(int16 width) { _w = width; }
00102     void setHeight(int16 height) { _h = height; }
00103     void setTextHAlign(Graphics::TextAlign align) { _textHAlign = align; }
00104 
00110     virtual bool isBound(Widget *widgetChain) const { return true; }
00111 
00112     virtual LayoutType getLayoutType() const = 0;
00113 
00114     virtual ThemeLayout *makeClone(ThemeLayout *newParent) = 0;
00115 
00116 public:
00117     virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h);
00118 
00119     virtual Graphics::TextAlign getWidgetTextHAlign(const Common::String &name);
00120 
00121     void importLayout(ThemeLayout *layout);
00122 
00123     Graphics::TextAlign getTextHAlign() { return _textHAlign; }
00124 
00125 #ifdef LAYOUT_DEBUG_DIALOG
00126     void debugDraw(Graphics::Surface *screen, const Graphics::Font *font);
00127 
00128     virtual const char *getName() const = 0;
00129 #endif
00130 
00131 protected:
00132     ThemeLayout *_parent;
00133     int16 _x, _y, _w, _h;
00134     Common::Rect _padding;
00135     Common::Array<ThemeLayout *> _children;
00136     int16 _defaultW, _defaultH;
00137     Graphics::TextAlign _textHAlign;
00138 };
00139 
00140 class ThemeLayoutMain : public ThemeLayout {
00141 public:
00142     ThemeLayoutMain(const Common::String &name, const Common::String &overlays, int16 width, int16 height, int inset) :
00143             ThemeLayout(nullptr),
00144             _name(name),
00145             _overlays(overlays),
00146             _inset(inset) {
00147         _w = _defaultW = width;
00148         _h = _defaultH = height;
00149         _x = _defaultX = -1;
00150         _y = _defaultY = -1;
00151     }
00152     void reflowLayout(Widget *widgetChain) override;
00153 
00154     void resetLayout() override {
00155         ThemeLayout::resetLayout();
00156         _x = _defaultX;
00157         _y = _defaultY;
00158     }
00159 
00160     const char *getName() const { return _name.c_str(); }
00161 
00162 protected:
00163     LayoutType getLayoutType() const override { return kLayoutMain; }
00164     ThemeLayout *makeClone(ThemeLayout *newParent) override { assert(!"Do not copy Main Layouts!"); return nullptr; }
00165 
00166     int16 _defaultX;
00167     int16 _defaultY;
00168 
00169     Common::String _name;
00170     Common::String _overlays;
00171     int _inset;
00172 };
00173 
00174 class ThemeLayoutStacked : public ThemeLayout {
00175 public:
00176     ThemeLayoutStacked(ThemeLayout *p, LayoutType type, int spacing, ItemAlign itemAlign) :
00177         ThemeLayout(p), _type(type), _itemAlign(itemAlign) {
00178         assert((type == kLayoutVertical) || (type == kLayoutHorizontal));
00179         _spacing = spacing;
00180     }
00181 
00182     void reflowLayout(Widget *widgetChain) override {
00183         if (_type == kLayoutVertical)
00184             reflowLayoutVertical(widgetChain);
00185         else
00186             reflowLayoutHorizontal(widgetChain);
00187     }
00188 
00189     void reflowLayoutHorizontal(Widget *widgetChain);
00190     void reflowLayoutVertical(Widget *widgetChain);
00191 
00192 #ifdef LAYOUT_DEBUG_DIALOG
00193     const char *getName() const {
00194         return (_type == kLayoutVertical)
00195             ? "Vertical Layout" : "Horizontal Layout";
00196     }
00197 #endif
00198 
00199 protected:
00200     int16 getParentWidth();
00201     int16 getParentHeight();
00202 
00203     LayoutType getLayoutType() const override { return _type; }
00204 
00205     ThemeLayout *makeClone(ThemeLayout *newParent) override {
00206         ThemeLayoutStacked *n = new ThemeLayoutStacked(*this);
00207         n->_parent = newParent;
00208 
00209         for (uint i = 0; i < n->_children.size(); ++i)
00210             n->_children[i] = n->_children[i]->makeClone(n);
00211 
00212         return n;
00213     }
00214 
00215     const LayoutType _type;
00216     ItemAlign _itemAlign;
00217     int8 _spacing;
00218 };
00219 
00220 class ThemeLayoutWidget : public ThemeLayout {
00221 public:
00222     ThemeLayoutWidget(ThemeLayout *p, const Common::String &name, int16 w, int16 h, Graphics::TextAlign align) : ThemeLayout(p), _name(name) {
00223         _w = _defaultW = w;
00224         _h = _defaultH = h;
00225 
00226         setTextHAlign(align);
00227     }
00228 
00229     bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override;
00230     Graphics::TextAlign getWidgetTextHAlign(const Common::String &name) override;
00231 
00232     void reflowLayout(Widget *widgetChain) override;
00233 
00234     virtual const char *getName() const { return _name.c_str(); }
00235 
00236 protected:
00237     LayoutType getLayoutType() const override { return kLayoutWidget; }
00238 
00239     bool isBound(Widget *widgetChain) const override;
00240     Widget *getWidget(Widget *widgetChain) const;
00241 
00242     ThemeLayout *makeClone(ThemeLayout *newParent) override {
00243         ThemeLayout *n = new ThemeLayoutWidget(*this);
00244         n->_parent = newParent;
00245         return n;
00246     }
00247 
00248     Common::String _name;
00249 };
00250 
00251 class ThemeLayoutTabWidget : public ThemeLayoutWidget {
00252     int _tabHeight;
00253 
00254 public:
00255     ThemeLayoutTabWidget(ThemeLayout *p, const Common::String &name, int16 w, int16 h, Graphics::TextAlign align, int tabHeight):
00256         ThemeLayoutWidget(p, name, w, h, align) {
00257         _tabHeight = tabHeight;
00258     }
00259 
00260     void reflowLayout(Widget *widgetChain) override {
00261         for (uint i = 0; i < _children.size(); ++i) {
00262             _children[i]->reflowLayout(widgetChain);
00263         }
00264     }
00265 
00266     bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override {
00267         if (ThemeLayoutWidget::getWidgetData(name, x, y, w, h)) {
00268             h -= _tabHeight;
00269             return true;
00270         }
00271 
00272         return false;
00273     }
00274 
00275 protected:
00276     LayoutType getLayoutType() const override { return kLayoutTabWidget; }
00277 
00278     ThemeLayout *makeClone(ThemeLayout *newParent) override {
00279         ThemeLayoutTabWidget *n = new ThemeLayoutTabWidget(*this);
00280         n->_parent = newParent;
00281         return n;
00282     }
00283 };
00284 
00285 class ThemeLayoutSpacing : public ThemeLayout {
00286 public:
00287     ThemeLayoutSpacing(ThemeLayout *p, int size) : ThemeLayout(p) {
00288         if (p->getLayoutType() == kLayoutHorizontal) {
00289             _w = _defaultW = size;
00290             _h = _defaultH = 1;
00291         } else if (p->getLayoutType() == kLayoutVertical) {
00292             _w = _defaultW = 1;
00293             _h = _defaultH = size;
00294         }
00295     }
00296 
00297     bool getWidgetData(const Common::String &name, int16 &x, int16 &y, int16 &w, int16 &h) override { return false; }
00298     void reflowLayout(Widget *widgetChain) override {}
00299 #ifdef LAYOUT_DEBUG_DIALOG
00300     const char *getName() const { return "SPACE"; }
00301 #endif
00302 
00303 protected:
00304     LayoutType getLayoutType() const override { return kLayoutSpace; }
00305 
00306     ThemeLayout *makeClone(ThemeLayout *newParent) override {
00307         ThemeLayout *n = new ThemeLayoutSpacing(*this);
00308         n->_parent = newParent;
00309         return n;
00310     }
00311 };
00312 
00313 }
00314 
00315 #endif


Generated on Sat May 30 2020 05:01:06 for ResidualVM by doxygen 1.7.1
curved edge   curved edge