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

ThemeEngine.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 GUI_THEME_ENGINE_H
00024 #define GUI_THEME_ENGINE_H
00025 
00026 #include "common/scummsys.h"
00027 #include "common/fs.h"
00028 #include "common/hash-str.h"
00029 #include "common/hashmap.h"
00030 #include "common/list.h"
00031 #include "common/str.h"
00032 #include "common/rect.h"
00033 
00034 #include "graphics/surface.h"
00035 #include "graphics/transparent_surface.h"
00036 #include "graphics/font.h"
00037 #include "graphics/pixelformat.h"
00038 
00039 
00040 #define SCUMMVM_THEME_VERSION_STR "SCUMMVM_STX0.8.26"
00041 
00042 class OSystem;
00043 
00044 namespace Graphics {
00045 struct DrawStep;
00046 class VectorRenderer;
00047 }
00048 
00049 namespace GUI {
00050 
00051 struct WidgetDrawData;
00052 struct TextDrawData;
00053 struct TextColorData;
00054 class Dialog;
00055 class GuiObject;
00056 class ThemeEval;
00057 class ThemeParser;
00058 
00064 enum DrawData {
00065     kDDMainDialogBackground,
00066     kDDSpecialColorBackground,
00067     kDDPlainColorBackground,
00068     kDDTooltipBackground,
00069     kDDDefaultBackground,
00070     kDDTextSelectionBackground,
00071     kDDTextSelectionFocusBackground,
00072 
00073     kDDWidgetBackgroundDefault,
00074     kDDWidgetBackgroundSmall,
00075     kDDWidgetBackgroundEditText,
00076     kDDWidgetBackgroundSlider,
00077 
00078     kDDButtonIdle,
00079     kDDButtonHover,
00080     kDDButtonDisabled,
00081     kDDButtonPressed,
00082 
00083     kDDSliderFull,
00084     kDDSliderHover,
00085     kDDSliderDisabled,
00086 
00087     kDDCheckboxDefault,
00088     kDDCheckboxDisabled,
00089     kDDCheckboxSelected,
00090 
00091     kDDRadiobuttonDefault,
00092     kDDRadiobuttonDisabled,
00093     kDDRadiobuttonSelected,
00094 
00095     kDDTabActive,
00096     kDDTabInactive,
00097     kDDTabBackground,
00098 
00099     kDDScrollbarBase,
00100     kDDScrollbarButtonIdle,
00101     kDDScrollbarButtonHover,
00102     kDDScrollbarHandleIdle,
00103     kDDScrollbarHandleHover,
00104 
00105     kDDPopUpIdle,
00106     kDDPopUpHover,
00107     kDDPopUpDisabled,
00108 
00109     kDDCaret,
00110     kDDSeparator,
00111     kDrawDataMAX,
00112     kDDNone = -1
00113 };
00114 
00122 enum DrawLayer {
00123     kDrawLayerBackground,
00124     kDrawLayerForeground
00125 };
00126 
00127 // FIXME: TextData is really a bad name, not conveying what this enum is about.
00128 enum TextData {
00129     kTextDataNone = -1,
00130     kTextDataDefault = 0,
00131     kTextDataButton,
00132     kTextDataNormalFont,
00133     kTextDataTooltip,
00134     kTextDataMAX
00135 };
00136 
00137 enum TextColor {
00138     kTextColorNormal = 0,
00139     kTextColorNormalInverted,
00140     kTextColorNormalHover,
00141     kTextColorNormalDisabled,
00142     kTextColorAlternative,
00143     kTextColorAlternativeInverted,
00144     kTextColorAlternativeHover,
00145     kTextColorAlternativeDisabled,
00146     kTextColorButton,
00147     kTextColorButtonHover,
00148     kTextColorButtonDisabled,
00149     kTextColorMAX
00150 };
00151 
00152 class ThemeEngine {
00153 protected:
00154     typedef Common::HashMap<Common::String, Graphics::Surface *> ImagesMap;
00155     typedef Common::HashMap<Common::String, Graphics::TransparentSurface *> AImagesMap;
00156 
00157     friend class GUI::Dialog;
00158     friend class GUI::GuiObject;
00159 
00160 public:
00162     enum TextAlignVertical {
00163         kTextAlignVInvalid,
00164         kTextAlignVBottom,
00165         kTextAlignVCenter,
00166         kTextAlignVTop
00167     };
00168 
00170     enum WidgetBackground {
00171         kWidgetBackgroundNo,            
00172         kWidgetBackgroundPlain,         
00173         kWidgetBackgroundBorder,        
00174         kWidgetBackgroundBorderSmall,   
00175         kWidgetBackgroundEditText,      
00176         kWidgetBackgroundSlider         
00177     };
00178 
00180     enum DialogBackground {
00181         kDialogBackgroundMain,
00182         kDialogBackgroundSpecial,
00183         kDialogBackgroundPlain,
00184         kDialogBackgroundTooltip,
00185         kDialogBackgroundDefault,
00186         kDialogBackgroundNone
00187     };
00188 
00190     enum State {
00191         kStateDisabled,     
00192         kStateEnabled,      
00193         kStateHighlight,    
00194         kStatePressed       
00195     };
00196 
00197     typedef State WidgetStateInfo;
00198 
00200     enum TextInversionState {
00201         kTextInversionNone, 
00202         kTextInversion,     
00203         kTextInversionFocus 
00204     };
00205 
00206     enum ScrollbarState {
00207         kScrollbarStateNo,
00208         kScrollbarStateUp,
00209         kScrollbarStateDown,
00210         kScrollbarStateSlider,
00211         kScrollbarStateSinglePage
00212     };
00213 
00215     enum FontStyle {
00216         kFontStyleBold = 0,         
00217         kFontStyleNormal = 1,       
00218         kFontStyleItalic = 2,       
00219         kFontStyleFixedNormal = 3,  
00220         kFontStyleFixedBold = 4,    
00221         kFontStyleFixedItalic = 5,  
00222         kFontStyleTooltip = 6,      
00223         kFontStyleMax
00224     };
00225 
00227     enum FontColor {
00228         kFontColorNormal = 0,       
00229         kFontColorAlternate = 1,    
00230         kFontColorMax
00231     };
00232 
00234     enum ShadingStyle {
00235         kShadingNone,       
00236         kShadingDim,        
00237         kShadingLuminance   
00238     };
00239 
00241     enum AutoScaleMode {
00242         kAutoScaleNone = 0,     
00243         kAutoScaleStretch = 1,  
00244         kAutoScaleFit = 2,      
00245         kAutoScaleNinePatch = 3 
00246     };
00247 
00248     // Special image ids for images used in the GUI
00249     static const char *const kImageLogo;      
00250     static const char *const kImageLogoSmall; 
00251     static const char *const kImageSearch;    
00252     static const char *const kImageEraser;     
00253     static const char *const kImageDelButton; 
00254     static const char *const kImageList;      
00255     static const char *const kImageGrid;      
00256     static const char *const kImageStopButton; 
00257     static const char *const kImageEditButton; 
00258     static const char *const kImageSwitchModeButton; 
00259     static const char *const kImageFastReplayButton; 
00260     static const char *const kImageStopSmallButton; 
00261     static const char *const kImageEditSmallButton; 
00262     static const char *const kImageSwitchModeSmallButton; 
00263     static const char *const kImageFastReplaySmallButton; 
00264     static const char *const kImageDropboxLogo;      
00265     static const char *const kImageOneDriveLogo;      
00266     static const char *const kImageGoogleDriveLogo;      
00267     static const char *const kImageBoxLogo;      
00268 
00274     enum GraphicsMode {
00275         kGfxDisabled = 0,   
00276         kGfxStandard,  
00277         kGfxAntialias  
00278     };
00279 
00281     static const int kDirtyRectangleThreshold = 1;
00282 
00283     struct Renderer {
00284         const char *name;
00285         const char *shortname;
00286         const char *cfg;
00287         GraphicsMode mode;
00288     };
00289 
00290     static const Renderer _rendererModes[];
00291     static const uint _rendererModesSize;
00292 
00293     static const GraphicsMode _defaultRendererMode;
00294 
00295     static GraphicsMode findMode(const Common::String &cfg);
00296     static const char *findModeConfigName(GraphicsMode mode);
00297 
00299     ThemeEngine(Common::String id, GraphicsMode mode);
00300 
00302     ~ThemeEngine();
00303 
00304     bool init();
00305     void clearAll();
00306 
00307     void refresh();
00308     void enable();
00309 
00310     void showCursor();
00311     void hideCursor();
00312 
00313     void disable();
00314 
00315 
00319     const Graphics::PixelFormat getPixelFormat() const { return _overlayFormat; }
00320 
00326     void applyScreenShading(ShadingStyle shading);
00327 
00335     void drawToBackbuffer();
00336 
00342     void drawToScreen();
00343 
00348     void updateScreen();
00349 
00353     void copyBackBufferToScreen();
00354 
00355 
00358 
00359     TextData fontStyleToData(FontStyle font) const {
00360         if (font == kFontStyleNormal)
00361             return kTextDataNormalFont;
00362         if (font == kFontStyleTooltip)
00363             return kTextDataTooltip;
00364         return kTextDataDefault;
00365     }
00366 
00367     const Graphics::Font *getFont(FontStyle font = kFontStyleBold) const;
00368 
00369     int getFontHeight(FontStyle font = kFontStyleBold) const;
00370 
00371     int getStringWidth(const Common::String &str, FontStyle font = kFontStyleBold) const;
00372 
00373     int getCharWidth(byte c, FontStyle font = kFontStyleBold) const;
00374 
00375     int getKerningOffset(byte left, byte right, FontStyle font = kFontStyleBold) const;
00376 
00378 
00388     Common::Rect swapClipRect(const Common::Rect &newRect);
00389 
00392 
00393     void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background = kWidgetBackgroundPlain);
00394 
00395     void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled,
00396                     uint16 hints = 0);
00397 
00398     void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, bool themeTrans = false);
00399 
00400     void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled);
00401 
00402     void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked,
00403                       WidgetStateInfo state = kStateEnabled);
00404 
00405     void drawRadiobutton(const Common::Rect &r, const Common::String &str, bool checked,
00406                          WidgetStateInfo state = kStateEnabled);
00407 
00408     void drawTab(const Common::Rect &r, int tabHeight, const Common::Array<int> &tabWidths,
00409                  const Common::Array<Common::String> &tabs, int active);
00410 
00411     void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scrollState);
00412 
00413     void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax,
00414                          WidgetStateInfo state = kStateEnabled);
00415 
00416     void drawCaret(const Common::Rect &r, bool erase);
00417 
00418     void drawLineSeparator(const Common::Rect &r);
00419 
00420     void drawDialogBackground(const Common::Rect &r, DialogBackground type);
00421 
00422     void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled,
00423                   Graphics::TextAlign align = Graphics::kTextAlignCenter,
00424                   TextInversionState inverted = kTextInversionNone, int deltax = 0, bool useEllipsis = true,
00425                   FontStyle font = kFontStyleBold, FontColor color = kFontColorNormal, bool restore = true,
00426                   const Common::Rect &drawableTextArea = Common::Rect(0, 0, 0, 0));
00427 
00428     void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, FontColor color = kFontColorNormal);
00429 
00431 
00432 
00433 
00441     void addDirtyRect(Common::Rect r);
00442 
00443 
00453     DrawData parseDrawDataId(const Common::String &name) const;
00454 
00455     TextData getTextData(DrawData ddId) const;
00456     TextColor getTextColor(DrawData ddId) const;
00457 
00458 
00468     void addDrawStep(const Common::String &drawDataId, const Graphics::DrawStep &step);
00469 
00479     bool addDrawData(const Common::String &data, bool cached);
00480 
00481 
00491     bool addFont(TextData textId, const Common::String &file, const Common::String &scalableFile, const int pointsize);
00492 
00499     bool addTextColor(TextColor colorId, int r, int g, int b);
00500 
00501 
00508     bool addBitmap(const Common::String &filename);
00509 
00516     bool addAlphaBitmap(const Common::String &filename);
00517 
00522     bool addTextData(const Common::String &drawDataId, TextData textId, TextColor id, Graphics::TextAlign alignH, TextAlignVertical alignV);
00523 
00524 protected:
00531     bool ready() const {
00532         return _initOk && _themeOk;
00533     }
00534 
00536     void loadTheme(const Common::String &themeid);
00537 
00542     void setGraphicsMode(GraphicsMode mode);
00543 
00544 public:
00545     inline ThemeEval *getEvaluator() { return _themeEval; }
00546     inline Graphics::VectorRenderer *renderer() { return _vectorRenderer; }
00547 
00548     inline bool supportsImages() const { return true; }
00549     inline bool ownCursor() const { return _useCursor; }
00550 
00551     Graphics::Surface *getBitmap(const Common::String &name) {
00552         return _bitmaps.contains(name) ? _bitmaps[name] : 0;
00553     }
00554 
00555     Graphics::TransparentSurface *getAlphaBitmap(const Common::String &name) {
00556         return _abitmaps.contains(name) ? _abitmaps[name] : 0;
00557     }
00558 
00559     const Graphics::Surface *getImageSurface(const Common::String &name) const {
00560         return _bitmaps.contains(name) ? _bitmaps[name] : 0;
00561     }
00562 
00563     const Graphics::TransparentSurface *getAImageSurface(const Common::String &name) const {
00564         return _abitmaps.contains(name) ? _abitmaps[name] : 0;
00565     }
00566 
00575     bool createCursor(const Common::String &filename, int hotspotX, int hotspotY);
00576 
00583     void restoreBackground(Common::Rect r);
00584 
00585     const Common::String &getThemeName() const { return _themeName; }
00586     const Common::String &getThemeId() const { return _themeId; }
00587     int getGraphicsMode() const { return _graphicsMode; }
00588 
00589 protected:
00590 
00597     bool loadThemeXML(const Common::String &themeId);
00598 
00604     bool loadDefaultXML();
00605 
00610     void unloadTheme();
00611 
00612     const Graphics::Font *loadScalableFont(const Common::String &filename, const Common::String &charset, const int pointsize, Common::String &name);
00613     const Graphics::Font *loadFont(const Common::String &filename, Common::String &name);
00614     Common::String genCacheFilename(const Common::String &filename) const;
00615     const Graphics::Font *loadFont(const Common::String &filename, const Common::String &scalableFilename, const Common::String &charset, const int pointsize, const bool makeLocalizedFont);
00616 
00621     void updateDirtyScreen();
00622 
00631     void drawDD(DrawData type, const Common::Rect &r, uint32 dynamic = 0, bool forceRestore = false);
00632     void drawDDText(TextData type, TextColor color, const Common::Rect &r, const Common::String &text, bool restoreBg,
00633                     bool elipsis, Graphics::TextAlign alignH = Graphics::kTextAlignLeft,
00634                     TextAlignVertical alignV = kTextAlignVTop, int deltax = 0,
00635                     const Common::Rect &drawableTextArea = Common::Rect(0, 0, 0, 0));
00636     void drawBitmap(const Graphics::Surface *bitmap, const Common::Rect &clippingRect, bool alpha);
00637 
00641     void debugWidgetPosition(const char *name, const Common::Rect &r);
00642 
00643 public:
00644     struct ThemeDescriptor {
00645         Common::String name;
00646         Common::String id;
00647         Common::String filename;
00648     };
00649 
00653     static void listUsableThemes(Common::List<ThemeDescriptor> &list);
00654 private:
00655     static bool themeConfigUsable(const Common::FSNode &node, Common::String &themeName);
00656     static bool themeConfigUsable(const Common::ArchiveMember &member, Common::String &themeName);
00657     static bool themeConfigParseHeader(Common::String header, Common::String &themeName);
00658 
00659     static Common::String getThemeFile(const Common::String &id);
00660     static Common::String getThemeId(const Common::String &filename);
00661     static void listUsableThemes(const Common::FSNode &node, Common::List<ThemeDescriptor> &list, int depth = -1);
00662     static void listUsableThemes(Common::Archive &archive, Common::List<ThemeDescriptor> &list);
00663 
00664 protected:
00665     OSystem *_system; 
00668     Graphics::VectorRenderer *_vectorRenderer;
00669 
00671     GUI::ThemeParser *_parser;
00672 
00674     GUI::ThemeEval *_themeEval;
00675 
00677     Graphics::TransparentSurface _screen;
00678 
00680     Graphics::TransparentSurface _backBuffer;
00681 
00688     DrawLayer _layerToDraw;
00689 
00691     int _bytesPerPixel;
00692 
00694     GraphicsMode _graphicsMode;
00695 
00697     const Graphics::Font *_font;
00698 
00703     WidgetDrawData *_widgets[kDrawDataMAX];
00704 
00706     TextDrawData *_texts[kTextDataMAX];
00707 
00709     TextColorData *_textColors[kTextColorMAX];
00710 
00711     ImagesMap _bitmaps;
00712     AImagesMap _abitmaps;
00713     Graphics::PixelFormat _overlayFormat;
00714 #ifdef USE_RGB_COLOR
00715     Graphics::PixelFormat _cursorFormat;
00716 #endif
00717 
00719     Common::List<Common::Rect> _dirtyScreen;
00720 
00721     bool _initOk;  
00722     bool _themeOk; 
00723     bool _enabled; 
00724 
00725     Common::String _themeName; 
00726     Common::String _themeId;
00727     Common::String _themeFile;
00728     Common::Archive *_themeArchive;
00729     Common::SearchSet _themeFiles;
00730 
00731     bool _useCursor;
00732     int _cursorHotspotX, _cursorHotspotY;
00733     enum {
00734         MAX_CURS_COLORS = 255
00735     };
00736     byte *_cursor;
00737     uint _cursorWidth, _cursorHeight;
00738     byte _cursorPal[3 * MAX_CURS_COLORS];
00739     byte _cursorPalSize;
00740 
00741     Common::Rect _clip;
00742 };
00743 
00744 } // End of namespace GUI.
00745 
00746 #endif


Generated on Sat May 25 2019 05:00:55 for ResidualVM by doxygen 1.7.1
curved edge   curved edge