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.27"
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     kTextDataConsole,
00135     kTextDataMAX
00136 };
00137 
00138 enum TextColor {
00139     kTextColorNormal = 0,
00140     kTextColorNormalInverted,
00141     kTextColorNormalHover,
00142     kTextColorNormalDisabled,
00143     kTextColorAlternative,
00144     kTextColorAlternativeInverted,
00145     kTextColorAlternativeHover,
00146     kTextColorAlternativeDisabled,
00147     kTextColorButton,
00148     kTextColorButtonHover,
00149     kTextColorButtonDisabled,
00150     kTextColorMAX
00151 };
00152 
00153 class ThemeEngine {
00154 protected:
00155     typedef Common::HashMap<Common::String, Graphics::Surface *> ImagesMap;
00156     typedef Common::HashMap<Common::String, Graphics::TransparentSurface *> AImagesMap;
00157 
00158     friend class GUI::Dialog;
00159     friend class GUI::GuiObject;
00160 
00161 public:
00163     enum TextAlignVertical {
00164         kTextAlignVInvalid,
00165         kTextAlignVBottom,
00166         kTextAlignVCenter,
00167         kTextAlignVTop
00168     };
00169 
00171     enum WidgetBackground {
00172         kWidgetBackgroundNo,            
00173         kWidgetBackgroundPlain,         
00174         kWidgetBackgroundBorder,        
00175         kWidgetBackgroundBorderSmall,   
00176         kWidgetBackgroundEditText,      
00177         kWidgetBackgroundSlider         
00178     };
00179 
00181     enum DialogBackground {
00182         kDialogBackgroundMain,
00183         kDialogBackgroundSpecial,
00184         kDialogBackgroundPlain,
00185         kDialogBackgroundTooltip,
00186         kDialogBackgroundDefault,
00187         kDialogBackgroundNone
00188     };
00189 
00191     enum State {
00192         kStateDisabled,     
00193         kStateEnabled,      
00194         kStateHighlight,    
00195         kStatePressed       
00196     };
00197 
00198     typedef State WidgetStateInfo;
00199 
00201     enum TextInversionState {
00202         kTextInversionNone, 
00203         kTextInversion,     
00204         kTextInversionFocus 
00205     };
00206 
00207     enum ScrollbarState {
00208         kScrollbarStateNo,
00209         kScrollbarStateUp,
00210         kScrollbarStateDown,
00211         kScrollbarStateSlider,
00212         kScrollbarStateSinglePage
00213     };
00214 
00216     enum FontStyle {
00217         kFontStyleBold = 0,         
00218         kFontStyleNormal = 1,       
00219         kFontStyleItalic = 2,       
00220         kFontStyleFixedNormal = 3,  
00221         kFontStyleFixedBold = 4,    
00222         kFontStyleFixedItalic = 5,  
00223         kFontStyleTooltip = 6,      
00224         kFontStyleConsole = 7,      
00225         kFontStyleMax
00226     };
00227 
00229     enum FontColor {
00230         kFontColorNormal = 0,       
00231         kFontColorAlternate = 1,    
00232         kFontColorMax
00233     };
00234 
00236     enum ShadingStyle {
00237         kShadingNone,       
00238         kShadingDim,        
00239         kShadingLuminance   
00240     };
00241 
00243     enum AutoScaleMode {
00244         kAutoScaleNone = 0,     
00245         kAutoScaleStretch = 1,  
00246         kAutoScaleFit = 2,      
00247         kAutoScaleNinePatch = 3 
00248     };
00249 
00250     // Special image ids for images used in the GUI
00251     static const char *const kImageLogo;      
00252     static const char *const kImageLogoSmall; 
00253     static const char *const kImageSearch;    
00254     static const char *const kImageEraser;     
00255     static const char *const kImageDelButton; 
00256     static const char *const kImageList;      
00257     static const char *const kImageGrid;      
00258     static const char *const kImageStopButton; 
00259     static const char *const kImageEditButton; 
00260     static const char *const kImageSwitchModeButton; 
00261     static const char *const kImageFastReplayButton; 
00262     static const char *const kImageStopSmallButton; 
00263     static const char *const kImageEditSmallButton; 
00264     static const char *const kImageSwitchModeSmallButton; 
00265     static const char *const kImageFastReplaySmallButton; 
00266     static const char *const kImageDropboxLogo;      
00267     static const char *const kImageOneDriveLogo;      
00268     static const char *const kImageGoogleDriveLogo;      
00269     static const char *const kImageBoxLogo;      
00270 
00276     enum GraphicsMode {
00277         kGfxDisabled = 0,   
00278         kGfxStandard,  
00279         kGfxAntialias  
00280     };
00281 
00283     static const int kDirtyRectangleThreshold = 1;
00284 
00285     struct Renderer {
00286         const char *name;
00287         const char *shortname;
00288         const char *cfg;
00289         GraphicsMode mode;
00290     };
00291 
00292     static const Renderer _rendererModes[];
00293     static const uint _rendererModesSize;
00294 
00295     static const GraphicsMode _defaultRendererMode;
00296 
00297     static GraphicsMode findMode(const Common::String &cfg);
00298     static const char *findModeConfigName(GraphicsMode mode);
00299 
00301     ThemeEngine(Common::String id, GraphicsMode mode);
00302 
00304     ~ThemeEngine();
00305 
00306     bool init();
00307     void clearAll();
00308 
00309     void refresh();
00310     void enable();
00311 
00312     void showCursor();
00313     void hideCursor();
00314 
00315     void disable();
00316 
00317 
00321     const Graphics::PixelFormat getPixelFormat() const { return _overlayFormat; }
00322 
00328     void applyScreenShading(ShadingStyle shading);
00329 
00337     void drawToBackbuffer();
00338 
00344     void drawToScreen();
00345 
00350     void updateScreen();
00351 
00355     void copyBackBufferToScreen();
00356 
00357 
00360 
00361     TextData fontStyleToData(FontStyle font) const {
00362         if (font == kFontStyleNormal)
00363             return kTextDataNormalFont;
00364         if (font == kFontStyleTooltip)
00365             return kTextDataTooltip;
00366         if (font == kFontStyleConsole)
00367             return kTextDataConsole;
00368         return kTextDataDefault;
00369     }
00370 
00371     const Graphics::Font *getFont(FontStyle font = kFontStyleBold) const;
00372 
00373     int getFontHeight(FontStyle font = kFontStyleBold) const;
00374 
00375     int getStringWidth(const Common::String &str, FontStyle font = kFontStyleBold) const;
00376 
00377     int getCharWidth(byte c, FontStyle font = kFontStyleBold) const;
00378 
00379     int getKerningOffset(byte left, byte right, FontStyle font = kFontStyleBold) const;
00380 
00382 
00392     Common::Rect swapClipRect(const Common::Rect &newRect);
00393 
00396 
00397     void drawWidgetBackground(const Common::Rect &r, uint16 hints, WidgetBackground background = kWidgetBackgroundPlain);
00398 
00399     void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled,
00400                     uint16 hints = 0);
00401 
00402     void drawSurface(const Common::Rect &r, const Graphics::Surface &surface, bool themeTrans = false);
00403 
00404     void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled);
00405 
00406     void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked,
00407                       WidgetStateInfo state = kStateEnabled);
00408 
00409     void drawRadiobutton(const Common::Rect &r, const Common::String &str, bool checked,
00410                          WidgetStateInfo state = kStateEnabled);
00411 
00412     void drawTab(const Common::Rect &r, int tabHeight, const Common::Array<int> &tabWidths,
00413                  const Common::Array<Common::String> &tabs, int active);
00414 
00415     void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scrollState);
00416 
00417     void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax,
00418                          WidgetStateInfo state = kStateEnabled);
00419 
00420     void drawCaret(const Common::Rect &r, bool erase);
00421 
00422     void drawLineSeparator(const Common::Rect &r);
00423 
00424     void drawDialogBackground(const Common::Rect &r, DialogBackground type);
00425 
00426     void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled,
00427                   Graphics::TextAlign align = Graphics::kTextAlignCenter,
00428                   TextInversionState inverted = kTextInversionNone, int deltax = 0, bool useEllipsis = true,
00429                   FontStyle font = kFontStyleBold, FontColor color = kFontColorNormal, bool restore = true,
00430                   const Common::Rect &drawableTextArea = Common::Rect(0, 0, 0, 0));
00431 
00432     void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, FontColor color = kFontColorNormal);
00433 
00435 
00436 
00437 
00445     void addDirtyRect(Common::Rect r);
00446 
00447 
00457     DrawData parseDrawDataId(const Common::String &name) const;
00458 
00459     TextData getTextData(DrawData ddId) const;
00460     TextColor getTextColor(DrawData ddId) const;
00461 
00462 
00472     void addDrawStep(const Common::String &drawDataId, const Graphics::DrawStep &step);
00473 
00483     bool addDrawData(const Common::String &data, bool cached);
00484 
00485 
00495     bool addFont(TextData textId, const Common::String &file, const Common::String &scalableFile, const int pointsize);
00496 
00503     bool addTextColor(TextColor colorId, int r, int g, int b);
00504 
00505 
00512     bool addBitmap(const Common::String &filename);
00513 
00520     bool addAlphaBitmap(const Common::String &filename);
00521 
00526     bool addTextData(const Common::String &drawDataId, TextData textId, TextColor id, Graphics::TextAlign alignH, TextAlignVertical alignV);
00527 
00528 protected:
00535     bool ready() const {
00536         return _initOk && _themeOk;
00537     }
00538 
00540     void loadTheme(const Common::String &themeid);
00541 
00546     void setGraphicsMode(GraphicsMode mode);
00547 
00548 public:
00549     inline ThemeEval *getEvaluator() { return _themeEval; }
00550     inline Graphics::VectorRenderer *renderer() { return _vectorRenderer; }
00551 
00552     inline bool supportsImages() const { return true; }
00553     inline bool ownCursor() const { return _useCursor; }
00554 
00555     Graphics::Surface *getBitmap(const Common::String &name) {
00556         return _bitmaps.contains(name) ? _bitmaps[name] : 0;
00557     }
00558 
00559     Graphics::TransparentSurface *getAlphaBitmap(const Common::String &name) {
00560         return _abitmaps.contains(name) ? _abitmaps[name] : 0;
00561     }
00562 
00563     const Graphics::Surface *getImageSurface(const Common::String &name) const {
00564         return _bitmaps.contains(name) ? _bitmaps[name] : 0;
00565     }
00566 
00567     const Graphics::TransparentSurface *getAImageSurface(const Common::String &name) const {
00568         return _abitmaps.contains(name) ? _abitmaps[name] : 0;
00569     }
00570 
00579     bool createCursor(const Common::String &filename, int hotspotX, int hotspotY);
00580 
00587     void restoreBackground(Common::Rect r);
00588 
00589     const Common::String &getThemeName() const { return _themeName; }
00590     const Common::String &getThemeId() const { return _themeId; }
00591     int getGraphicsMode() const { return _graphicsMode; }
00592 
00593 protected:
00594 
00601     bool loadThemeXML(const Common::String &themeId);
00602 
00608     bool loadDefaultXML();
00609 
00614     void unloadTheme();
00615 
00616     const Graphics::Font *loadScalableFont(const Common::String &filename, const Common::String &charset, const int pointsize, Common::String &name);
00617     const Graphics::Font *loadFont(const Common::String &filename, Common::String &name);
00618     Common::String genCacheFilename(const Common::String &filename) const;
00619     const Graphics::Font *loadFont(const Common::String &filename, const Common::String &scalableFilename, const Common::String &charset, const int pointsize, const bool makeLocalizedFont);
00620 
00625     void updateDirtyScreen();
00626 
00635     void drawDD(DrawData type, const Common::Rect &r, uint32 dynamic = 0, bool forceRestore = false);
00636     void drawDDText(TextData type, TextColor color, const Common::Rect &r, const Common::String &text, bool restoreBg,
00637                     bool elipsis, Graphics::TextAlign alignH = Graphics::kTextAlignLeft,
00638                     TextAlignVertical alignV = kTextAlignVTop, int deltax = 0,
00639                     const Common::Rect &drawableTextArea = Common::Rect(0, 0, 0, 0));
00640     void drawBitmap(const Graphics::Surface *bitmap, const Common::Rect &clippingRect, bool alpha);
00641 
00645     void debugWidgetPosition(const char *name, const Common::Rect &r);
00646 
00647 public:
00648     struct ThemeDescriptor {
00649         Common::String name;
00650         Common::String id;
00651         Common::String filename;
00652     };
00653 
00657     static void listUsableThemes(Common::List<ThemeDescriptor> &list);
00658 private:
00659     static bool themeConfigUsable(const Common::FSNode &node, Common::String &themeName);
00660     static bool themeConfigUsable(const Common::ArchiveMember &member, Common::String &themeName);
00661     static bool themeConfigParseHeader(Common::String header, Common::String &themeName);
00662 
00663     static Common::String getThemeFile(const Common::String &id);
00664     static Common::String getThemeId(const Common::String &filename);
00665     static void listUsableThemes(const Common::FSNode &node, Common::List<ThemeDescriptor> &list, int depth = -1);
00666     static void listUsableThemes(Common::Archive &archive, Common::List<ThemeDescriptor> &list);
00667 
00668 protected:
00669     OSystem *_system; 
00672     Graphics::VectorRenderer *_vectorRenderer;
00673 
00675     GUI::ThemeParser *_parser;
00676 
00678     GUI::ThemeEval *_themeEval;
00679 
00681     Graphics::TransparentSurface _screen;
00682 
00684     Graphics::TransparentSurface _backBuffer;
00685 
00692     DrawLayer _layerToDraw;
00693 
00695     int _bytesPerPixel;
00696 
00698     GraphicsMode _graphicsMode;
00699 
00701     const Graphics::Font *_font;
00702 
00707     WidgetDrawData *_widgets[kDrawDataMAX];
00708 
00710     TextDrawData *_texts[kTextDataMAX];
00711 
00713     TextColorData *_textColors[kTextColorMAX];
00714 
00715     ImagesMap _bitmaps;
00716     AImagesMap _abitmaps;
00717     Graphics::PixelFormat _overlayFormat;
00718 #ifdef USE_RGB_COLOR
00719     Graphics::PixelFormat _cursorFormat;
00720 #endif
00721 
00723     Common::List<Common::Rect> _dirtyScreen;
00724 
00725     bool _initOk;  
00726     bool _themeOk; 
00727     bool _enabled; 
00728 
00729     Common::String _themeName; 
00730     Common::String _themeId;
00731     Common::String _themeFile;
00732     Common::Archive *_themeArchive;
00733     Common::SearchSet _themeFiles;
00734 
00735     bool _useCursor;
00736     int _cursorHotspotX, _cursorHotspotY;
00737     enum {
00738         MAX_CURS_COLORS = 255
00739     };
00740     byte *_cursor;
00741     uint _cursorWidth, _cursorHeight;
00742     byte _cursorPal[3 * MAX_CURS_COLORS];
00743     byte _cursorPalSize;
00744 
00745     Common::Rect _clip;
00746 };
00747 
00748 } // End of namespace GUI.
00749 
00750 #endif


Generated on Sat Sep 14 2019 05:01:32 for ResidualVM by doxygen 1.7.1
curved edge   curved edge