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 ThemeLayout {
00039     friend class ThemeLayoutMain;
00040     friend class ThemeLayoutStacked;
00041     friend class ThemeLayoutSpacing;
00042     friend class ThemeLayoutWidget;
00043 public:
00044     enum LayoutType {
00045         kLayoutMain,
00046         kLayoutVertical,
00047         kLayoutHorizontal,
00048         kLayoutWidget,
00049         kLayoutTabWidget
00050     };
00051 
00052     ThemeLayout(ThemeLayout *p) :
00053         _parent(p), _x(0), _y(0), _w(-1), _h(-1),
00054         _centered(false), _defaultW(-1), _defaultH(-1),
00055         _textHAlign(Graphics::kTextAlignInvalid) {}
00056 
00057     virtual ~ThemeLayout() {
00058         for (uint i = 0; i < _children.size(); ++i)
00059             delete _children[i];
00060     }
00061 
00062     virtual void reflowLayout() = 0;
00063 
00064     virtual void resetLayout() { _x = 0; _y = 0; _w = _defaultW; _h = _defaultH; }
00065 
00066     void addChild(ThemeLayout *child) { _children.push_back(child); }
00067 
00068     void setPadding(int8 left, int8 right, int8 top, int8 bottom) {
00069         _padding.left = left;
00070         _padding.right = right;
00071         _padding.top = top;
00072         _padding.bottom = bottom;
00073     }
00074 
00075 protected:
00076     int16 getWidth() { return _w; }
00077     int16 getHeight() { return _h; }
00078 
00079     void offsetX(int newX) {
00080         _x += newX;
00081         for (uint i = 0; i < _children.size(); ++i)
00082             _children[i]->offsetX(newX);
00083     }
00084 
00085     void offsetY(int newY) {
00086         _y += newY;
00087         for (uint i = 0; i < _children.size(); ++i)
00088             _children[i]->offsetY(newY);
00089     }
00090 
00091     void setWidth(int16 width) { _w = width; }
00092     void setHeight(int16 height) { _h = height; }
00093     void setTextHAlign(Graphics::TextAlign align) { _textHAlign = align; }
00094 
00095     virtual LayoutType getLayoutType() = 0;
00096 
00097     virtual ThemeLayout *makeClone(ThemeLayout *newParent) = 0;
00098 
00099 public:
00100     virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
00101 
00102     virtual Graphics::TextAlign getWidgetTextHAlign(const Common::String &name);
00103 
00104     void importLayout(ThemeLayout *layout);
00105 
00106     Graphics::TextAlign getTextHAlign() { return _textHAlign; }
00107 
00108 #ifdef LAYOUT_DEBUG_DIALOG
00109     void debugDraw(Graphics::Surface *screen, const Graphics::Font *font);
00110 
00111     virtual const char *getName() const = 0;
00112 #endif
00113 
00114 protected:
00115     ThemeLayout *_parent;
00116     int16 _x, _y, _w, _h;
00117     Common::Rect _padding;
00118     Common::Array<ThemeLayout *> _children;
00119     bool _centered;
00120     int16 _defaultW, _defaultH;
00121     Graphics::TextAlign _textHAlign;
00122 };
00123 
00124 class ThemeLayoutMain : public ThemeLayout {
00125 public:
00126     ThemeLayoutMain(int16 x, int16 y, int16 w, int16 h) : ThemeLayout(0) {
00127         _w = _defaultW = w;
00128         _h = _defaultH = h;
00129         _x = _defaultX = x;
00130         _y = _defaultY = y;
00131     }
00132     void reflowLayout();
00133 
00134     void resetLayout() {
00135         ThemeLayout::resetLayout();
00136         _x = _defaultX;
00137         _y = _defaultY;
00138     }
00139 
00140 #ifdef LAYOUT_DEBUG_DIALOG
00141     const char *getName() const { return "Global Layout"; }
00142 #endif
00143 
00144 protected:
00145     LayoutType getLayoutType() { return kLayoutMain; }
00146     ThemeLayout *makeClone(ThemeLayout *newParent) { assert(!"Do not copy Main Layouts!"); return 0; }
00147 
00148     int16 _defaultX;
00149     int16 _defaultY;
00150 };
00151 
00152 class ThemeLayoutStacked : public ThemeLayout {
00153 public:
00154     ThemeLayoutStacked(ThemeLayout *p, LayoutType type, int spacing, bool center) :
00155         ThemeLayout(p), _type(type) {
00156         assert((type == kLayoutVertical) || (type == kLayoutHorizontal));
00157         _spacing = spacing;
00158         _centered = center;
00159     }
00160 
00161     void reflowLayout() {
00162         if (_type == kLayoutVertical)
00163             reflowLayoutVertical();
00164         else
00165             reflowLayoutHorizontal();
00166     }
00167     void reflowLayoutHorizontal();
00168     void reflowLayoutVertical();
00169 
00170 #ifdef LAYOUT_DEBUG_DIALOG
00171     const char *getName() const {
00172         return (_type == kLayoutVertical)
00173             ? "Vertical Layout" : "Horizontal Layout";
00174     }
00175 #endif
00176 
00177 protected:
00178     int16 getParentWidth();
00179     int16 getParentHeight();
00180 
00181     LayoutType getLayoutType() { return _type; }
00182 
00183     ThemeLayout *makeClone(ThemeLayout *newParent) {
00184         ThemeLayoutStacked *n = new ThemeLayoutStacked(*this);
00185         n->_parent = newParent;
00186 
00187         for (uint i = 0; i < n->_children.size(); ++i)
00188             n->_children[i] = n->_children[i]->makeClone(n);
00189 
00190         return n;
00191     }
00192 
00193     const LayoutType _type;
00194     int8 _spacing;
00195 };
00196 
00197 class ThemeLayoutWidget : public ThemeLayout {
00198 public:
00199     ThemeLayoutWidget(ThemeLayout *p, const Common::String &name, int16 w, int16 h, Graphics::TextAlign align) : ThemeLayout(p), _name(name) {
00200         _w = _defaultW = w;
00201         _h = _defaultH = h;
00202 
00203         setTextHAlign(align);
00204     }
00205 
00206     bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h);
00207     Graphics::TextAlign getWidgetTextHAlign(const Common::String &name);
00208 
00209     void reflowLayout() {}
00210 
00211 #ifdef LAYOUT_DEBUG_DIALOG
00212     virtual const char *getName() const { return _name.c_str(); }
00213 #endif
00214 
00215 protected:
00216     LayoutType getLayoutType() { return kLayoutWidget; }
00217 
00218     ThemeLayout *makeClone(ThemeLayout *newParent) {
00219         ThemeLayout *n = new ThemeLayoutWidget(*this);
00220         n->_parent = newParent;
00221         return n;
00222     }
00223 
00224     Common::String _name;
00225 };
00226 
00227 class ThemeLayoutTabWidget : public ThemeLayoutWidget {
00228     int _tabHeight;
00229 
00230 public:
00231     ThemeLayoutTabWidget(ThemeLayout *p, const Common::String &name, int16 w, int16 h, Graphics::TextAlign align, int tabHeight):
00232         ThemeLayoutWidget(p, name, w, h, align) {
00233         _tabHeight = tabHeight;
00234     }
00235 
00236     void reflowLayout() {
00237         for (uint i = 0; i < _children.size(); ++i) {
00238             _children[i]->resetLayout();
00239             _children[i]->reflowLayout();
00240         }
00241     }
00242 
00243     virtual bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) {
00244         if (ThemeLayoutWidget::getWidgetData(name, x, y, w, h)) {
00245             h -= _tabHeight;
00246             return true;
00247         }
00248 
00249         return false;
00250     }
00251 
00252 protected:
00253     LayoutType getLayoutType() { return kLayoutTabWidget; }
00254 
00255     ThemeLayout *makeClone(ThemeLayout *newParent) {
00256         ThemeLayoutTabWidget *n = new ThemeLayoutTabWidget(*this);
00257         n->_parent = newParent;
00258         return n;
00259     }
00260 };
00261 
00262 class ThemeLayoutSpacing : public ThemeLayout {
00263 public:
00264     ThemeLayoutSpacing(ThemeLayout *p, int size) : ThemeLayout(p) {
00265         if (p->getLayoutType() == kLayoutHorizontal) {
00266             _w = _defaultW = size;
00267             _h = _defaultH = 1;
00268         } else if (p->getLayoutType() == kLayoutVertical) {
00269             _w = _defaultW = 1;
00270             _h = _defaultH = size;
00271         }
00272     }
00273 
00274     bool getWidgetData(const Common::String &name, int16 &x, int16 &y, uint16 &w, uint16 &h) { return false; }
00275     void reflowLayout() {}
00276 #ifdef LAYOUT_DEBUG_DIALOG
00277     const char *getName() const { return "SPACE"; }
00278 #endif
00279 
00280 protected:
00281     LayoutType getLayoutType() { return kLayoutWidget; }
00282 
00283     ThemeLayout *makeClone(ThemeLayout *newParent) {
00284         ThemeLayout *n = new ThemeLayoutSpacing(*this);
00285         n->_parent = newParent;
00286         return n;
00287     }
00288 };
00289 
00290 }
00291 
00292 #endif


Generated on Sat Feb 16 2019 05:01:09 for ResidualVM by doxygen 1.7.1
curved edge   curved edge