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.36"
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     kDDDropDownButtonIdle,
00084     kDDDropDownButtonHoverLeft,
00085     kDDDropDownButtonHoverRight,
00086     kDDDropDownButtonDisabled,
00087     kDDDropDownButtonPressedLeft,
00088     kDDDropDownButtonPressedRight,
00089 
00090     kDDSliderFull,
00091     kDDSliderHover,
00092     kDDSliderDisabled,
00093 
00094     kDDCheckboxDefault,
00095     kDDCheckboxDisabled,
00096     kDDCheckboxSelected,
00097     kDDCheckboxDisabledSelected,
00098 
00099     kDDRadiobuttonDefault,
00100     kDDRadiobuttonDisabled,
00101     kDDRadiobuttonSelected,
00102 
00103     kDDTabActive,
00104     kDDTabInactive,
00105     kDDTabBackground,
00106 
00107     kDDScrollbarBase,
00108     kDDScrollbarButtonIdle,
00109     kDDScrollbarButtonHover,
00110     kDDScrollbarHandleIdle,
00111     kDDScrollbarHandleHover,
00112 
00113     kDDPopUpIdle,
00114     kDDPopUpHover,
00115     kDDPopUpDisabled,
00116 
00117     kDDCaret,
00118     kDDSeparator,
00119     kDrawDataMAX,
00120     kDDNone = -1
00121 };
00122 
00130 enum DrawLayer {
00131     kDrawLayerBackground,
00132     kDrawLayerForeground
00133 };
00134 
00135 // FIXME: TextData is really a bad name, not conveying what this enum is about.
00136 enum TextData {
00137     kTextDataNone = -1,
00138     kTextDataDefault = 0,
00139     kTextDataButton,
00140     kTextDataNormalFont,
00141     kTextDataTooltip,
00142     kTextDataConsole,
00143     kTextDataMAX
00144 };
00145 
00146 enum TextColor {
00147     kTextColorNormal = 0,
00148     kTextColorNormalInverted,
00149     kTextColorNormalHover,
00150     kTextColorNormalDisabled,
00151     kTextColorAlternative,
00152     kTextColorAlternativeInverted,
00153     kTextColorAlternativeHover,
00154     kTextColorAlternativeDisabled,
00155     kTextColorButton,
00156     kTextColorButtonHover,
00157     kTextColorButtonDisabled,
00158     kTextColorMAX
00159 };
00160 
00161 class ThemeEngine {
00162 protected:
00163     typedef Common::HashMap<Common::String, Graphics::Surface *> ImagesMap;
00164     typedef Common::HashMap<Common::String, Graphics::TransparentSurface *> AImagesMap;
00165 
00166     friend class GUI::Dialog;
00167     friend class GUI::GuiObject;
00168 
00169 public:
00171     enum TextAlignVertical {
00172         kTextAlignVInvalid,
00173         kTextAlignVBottom,
00174         kTextAlignVCenter,
00175         kTextAlignVTop
00176     };
00177 
00179     enum WidgetBackground {
00180         kWidgetBackgroundNo,            
00181         kWidgetBackgroundPlain,         
00182         kWidgetBackgroundBorder,        
00183         kWidgetBackgroundBorderSmall,   
00184         kWidgetBackgroundEditText,      
00185         kWidgetBackgroundSlider         
00186     };
00187 
00189     enum DialogBackground {
00190         kDialogBackgroundMain,
00191         kDialogBackgroundSpecial,
00192         kDialogBackgroundPlain,
00193         kDialogBackgroundTooltip,
00194         kDialogBackgroundDefault,
00195         kDialogBackgroundNone
00196     };
00197 
00199     enum State {
00200         kStateDisabled,     
00201         kStateEnabled,      
00202         kStateHighlight,    
00203         kStatePressed       
00204     };
00205 
00206     typedef State WidgetStateInfo;
00207 
00209     enum TextInversionState {
00210         kTextInversionNone, 
00211         kTextInversion,     
00212         kTextInversionFocus 
00213     };
00214 
00215     enum ScrollbarState {
00216         kScrollbarStateNo,
00217         kScrollbarStateUp,
00218         kScrollbarStateDown,
00219         kScrollbarStateSlider,
00220         kScrollbarStateSinglePage
00221     };
00222 
00224     enum FontStyle {
00225         kFontStyleBold = 0,         
00226         kFontStyleNormal = 1,       
00227         kFontStyleItalic = 2,       
00228         kFontStyleFixedNormal = 3,  
00229         kFontStyleFixedBold = 4,    
00230         kFontStyleFixedItalic = 5,  
00231         kFontStyleTooltip = 6,      
00232         kFontStyleConsole = 7,      
00233         kFontStyleMax
00234     };
00235 
00237     enum FontColor {
00238         kFontColorNormal = 0,       
00239         kFontColorAlternate = 1,    
00240         kFontColorMax
00241     };
00242 
00244     enum ShadingStyle {
00245         kShadingNone,       
00246         kShadingDim,        
00247         kShadingLuminance   
00248     };
00249 
00251     enum AutoScaleMode {
00252         kAutoScaleNone = 0,     
00253         kAutoScaleStretch = 1,  
00254         kAutoScaleFit = 2,      
00255         kAutoScaleNinePatch = 3 
00256     };
00257 
00258     // Special image ids for images used in the GUI
00259     static const char *const kImageLogo;      
00260     static const char *const kImageLogoSmall; 
00261     static const char *const kImageSearch;    
00262     static const char *const kImageEraser;     
00263     static const char *const kImageDelButton; 
00264     static const char *const kImageList;      
00265     static const char *const kImageGrid;      
00266     static const char *const kImageStopButton; 
00267     static const char *const kImageEditButton; 
00268     static const char *const kImageSwitchModeButton; 
00269     static const char *const kImageFastReplayButton; 
00270     static const char *const kImageStopSmallButton; 
00271     static const char *const kImageEditSmallButton; 
00272     static const char *const kImageSwitchModeSmallButton; 
00273     static const char *const kImageFastReplaySmallButton; 
00274 
00280     enum GraphicsMode {
00281         kGfxDisabled = 0,   
00282         kGfxStandard,  
00283         kGfxAntialias  
00284     };
00285 
00287     static const int kDirtyRectangleThreshold = 1;
00288 
00289     struct Renderer {
00290         const char *name;
00291         const char *shortname;
00292         const char *cfg;
00293         GraphicsMode mode;
00294     };
00295 
00296     static const Renderer _rendererModes[];
00297     static const uint _rendererModesSize;
00298 
00299     static const GraphicsMode _defaultRendererMode;
00300 
00301     static GraphicsMode findMode(const Common::String &cfg);
00302     static const char *findModeConfigName(GraphicsMode mode);
00303 
00305     ThemeEngine(Common::String id, GraphicsMode mode);
00306 
00308     ~ThemeEngine();
00309 
00310     bool init();
00311     void clearAll();
00312 
00313     void refresh();
00314     void enable();
00315 
00316     void showCursor();
00317     void hideCursor();
00318 
00319     void disable();
00320 
00321 
00325     const Graphics::PixelFormat getPixelFormat() const { return _overlayFormat; }
00326 
00332     void applyScreenShading(ShadingStyle shading);
00333 
00341     void drawToBackbuffer();
00342 
00348     void drawToScreen();
00349 
00354     void updateScreen();
00355 
00359     void copyBackBufferToScreen();
00360 
00361 
00364 
00365     TextData fontStyleToData(FontStyle font) const {
00366         if (font == kFontStyleNormal)
00367             return kTextDataNormalFont;
00368         if (font == kFontStyleTooltip)
00369             return kTextDataTooltip;
00370         if (font == kFontStyleConsole)
00371             return kTextDataConsole;
00372         return kTextDataDefault;
00373     }
00374 
00375     const Graphics::Font *getFont(FontStyle font = kFontStyleBold) const;
00376 
00377     int getFontHeight(FontStyle font = kFontStyleBold) const;
00378 
00379     int getStringWidth(const Common::String &str, FontStyle font = kFontStyleBold) const;
00380 
00381     int getCharWidth(byte c, FontStyle font = kFontStyleBold) const;
00382 
00383     int getKerningOffset(byte left, byte right, FontStyle font = kFontStyleBold) const;
00384 
00386 
00396     Common::Rect swapClipRect(const Common::Rect &newRect);
00397 
00401     void disableClipRect();
00402 
00405 
00406     void drawWidgetBackground(const Common::Rect &r, WidgetBackground background);
00407 
00408     void drawButton(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled,
00409                     uint16 hints = 0);
00410 
00411     void drawDropDownButton(const Common::Rect &r, uint32 dropdownWidth, const Common::String &str,
00412                             WidgetStateInfo buttonState, bool inButton, bool inDropdown);
00413 
00414     void drawSurface(const Common::Point &p, const Graphics::Surface &surface, bool themeTrans = false);
00415 
00416     void drawSlider(const Common::Rect &r, int width, WidgetStateInfo state = kStateEnabled);
00417 
00418     void drawCheckbox(const Common::Rect &r, const Common::String &str, bool checked,
00419                       WidgetStateInfo state = kStateEnabled);
00420 
00421     void drawRadiobutton(const Common::Rect &r, const Common::String &str, bool checked,
00422                          WidgetStateInfo state = kStateEnabled);
00423 
00424     void drawTab(const Common::Rect &r, int tabHeight, const Common::Array<int> &tabWidths,
00425                  const Common::Array<Common::String> &tabs, int active);
00426 
00427     void drawScrollbar(const Common::Rect &r, int sliderY, int sliderHeight, ScrollbarState scrollState);
00428 
00429     void drawPopUpWidget(const Common::Rect &r, const Common::String &sel, int deltax,
00430                          WidgetStateInfo state = kStateEnabled);
00431 
00432     void drawCaret(const Common::Rect &r, bool erase);
00433 
00434     void drawLineSeparator(const Common::Rect &r);
00435 
00436     void drawDialogBackground(const Common::Rect &r, DialogBackground type);
00437 
00438     void drawText(const Common::Rect &r, const Common::String &str, WidgetStateInfo state = kStateEnabled,
00439                   Graphics::TextAlign align = Graphics::kTextAlignCenter,
00440                   TextInversionState inverted = kTextInversionNone, int deltax = 0, bool useEllipsis = true,
00441                   FontStyle font = kFontStyleBold, FontColor color = kFontColorNormal, bool restore = true,
00442                   const Common::Rect &drawableTextArea = Common::Rect(0, 0, 0, 0));
00443 
00444     void drawChar(const Common::Rect &r, byte ch, const Graphics::Font *font, FontColor color = kFontColorNormal);
00445 
00447 
00448 
00449 
00457     void addDirtyRect(Common::Rect r);
00458 
00459 
00469     DrawData parseDrawDataId(const Common::String &name) const;
00470 
00471     TextData getTextData(DrawData ddId) const;
00472     TextColor getTextColor(DrawData ddId) const;
00473 
00474 
00484     void addDrawStep(const Common::String &drawDataId, const Graphics::DrawStep &step);
00485 
00495     bool addDrawData(const Common::String &data, bool cached);
00496 
00497 
00507     bool addFont(TextData textId, const Common::String &file, const Common::String &scalableFile, const int pointsize);
00508 
00515     bool addTextColor(TextColor colorId, int r, int g, int b);
00516 
00517 
00524     bool addBitmap(const Common::String &filename);
00525 
00532     bool addAlphaBitmap(const Common::String &filename);
00533 
00538     bool addTextData(const Common::String &drawDataId, TextData textId, TextColor id, Graphics::TextAlign alignH, TextAlignVertical alignV);
00539 
00540 protected:
00547     bool ready() const {
00548         return _initOk && _themeOk;
00549     }
00550 
00552     void loadTheme(const Common::String &themeid);
00553 
00558     void setGraphicsMode(GraphicsMode mode);
00559 
00560 public:
00561     inline ThemeEval *getEvaluator() { return _themeEval; }
00562     inline Graphics::VectorRenderer *renderer() { return _vectorRenderer; }
00563 
00564     inline bool supportsImages() const { return true; }
00565     inline bool ownCursor() const { return _useCursor; }
00566 
00567     Graphics::Surface *getBitmap(const Common::String &name) {
00568         return _bitmaps.contains(name) ? _bitmaps[name] : 0;
00569     }
00570 
00571     Graphics::TransparentSurface *getAlphaBitmap(const Common::String &name) {
00572         return _abitmaps.contains(name) ? _abitmaps[name] : 0;
00573     }
00574 
00575     const Graphics::Surface *getImageSurface(const Common::String &name) const {
00576         return _bitmaps.contains(name) ? _bitmaps[name] : 0;
00577     }
00578 
00579     const Graphics::TransparentSurface *getAImageSurface(const Common::String &name) const {
00580         return _abitmaps.contains(name) ? _abitmaps[name] : 0;
00581     }
00582 
00591     bool createCursor(const Common::String &filename, int hotspotX, int hotspotY);
00592 
00599     void restoreBackground(Common::Rect r);
00600 
00601     const Common::String &getThemeName() const { return _themeName; }
00602     const Common::String &getThemeId() const { return _themeId; }
00603     int getGraphicsMode() const { return _graphicsMode; }
00604 
00605 protected:
00606 
00613     bool loadThemeXML(const Common::String &themeId);
00614 
00620     bool loadDefaultXML();
00621 
00626     void unloadTheme();
00627 
00628     const Graphics::Font *loadScalableFont(const Common::String &filename, const Common::String &charset, const int pointsize, Common::String &name);
00629     const Graphics::Font *loadFont(const Common::String &filename, Common::String &name);
00630     Common::String genCacheFilename(const Common::String &filename) const;
00631     const Graphics::Font *loadFont(const Common::String &filename, const Common::String &scalableFilename, const Common::String &charset, const int pointsize, const bool makeLocalizedFont);
00632 
00637     void updateDirtyScreen();
00638 
00647     void drawDD(DrawData type, const Common::Rect &r, uint32 dynamic = 0, bool forceRestore = false);
00648     void drawDDText(TextData type, TextColor color, const Common::Rect &r, const Common::String &text, bool restoreBg,
00649                     bool elipsis, Graphics::TextAlign alignH = Graphics::kTextAlignLeft,
00650                     TextAlignVertical alignV = kTextAlignVTop, int deltax = 0,
00651                     const Common::Rect &drawableTextArea = Common::Rect(0, 0, 0, 0));
00652 
00656     void debugWidgetPosition(const char *name, const Common::Rect &r);
00657 
00658 public:
00659     struct ThemeDescriptor {
00660         Common::String name;
00661         Common::String id;
00662         Common::String filename;
00663     };
00664 
00668     static void listUsableThemes(Common::List<ThemeDescriptor> &list);
00669 private:
00670     static bool themeConfigUsable(const Common::FSNode &node, Common::String &themeName);
00671     static bool themeConfigUsable(const Common::ArchiveMember &member, Common::String &themeName);
00672     static bool themeConfigParseHeader(Common::String header, Common::String &themeName);
00673 
00674     static Common::String getThemeFile(const Common::String &id);
00675     static Common::String getThemeId(const Common::String &filename);
00676     static void listUsableThemes(const Common::FSNode &node, Common::List<ThemeDescriptor> &list, int depth = -1);
00677     static void listUsableThemes(Common::Archive &archive, Common::List<ThemeDescriptor> &list);
00678 
00679 protected:
00680     OSystem *_system; 
00683     Graphics::VectorRenderer *_vectorRenderer;
00684 
00686     GUI::ThemeParser *_parser;
00687 
00689     GUI::ThemeEval *_themeEval;
00690 
00692     Graphics::TransparentSurface _screen;
00693 
00695     Graphics::TransparentSurface _backBuffer;
00696 
00703     DrawLayer _layerToDraw;
00704 
00706     int _bytesPerPixel;
00707 
00709     GraphicsMode _graphicsMode;
00710 
00712     const Graphics::Font *_font;
00713 
00718     WidgetDrawData *_widgets[kDrawDataMAX];
00719 
00721     TextDrawData *_texts[kTextDataMAX];
00722 
00724     TextColorData *_textColors[kTextColorMAX];
00725 
00726     ImagesMap _bitmaps;
00727     AImagesMap _abitmaps;
00728     Graphics::PixelFormat _overlayFormat;
00729 #ifdef USE_RGB_COLOR
00730     Graphics::PixelFormat _cursorFormat;
00731 #endif
00732 
00734     Common::List<Common::Rect> _dirtyScreen;
00735 
00736     bool _initOk;  
00737     bool _themeOk; 
00738     bool _enabled; 
00739 
00740     Common::String _themeName; 
00741     Common::String _themeId;
00742     Common::String _themeFile;
00743     Common::Archive *_themeArchive;
00744     Common::SearchSet _themeFiles;
00745 
00746     bool _useCursor;
00747     int _cursorHotspotX, _cursorHotspotY;
00748     enum {
00749         MAX_CURS_COLORS = 255
00750     };
00751     byte *_cursor;
00752     uint _cursorWidth, _cursorHeight;
00753     byte _cursorPal[3 * MAX_CURS_COLORS];
00754     byte _cursorPalSize;
00755 
00756     Common::Rect _clip;
00757 };
00758 
00759 } // End of namespace GUI.
00760 
00761 #endif


Generated on Sat May 23 2020 05:00:44 for ResidualVM by doxygen 1.7.1
curved edge   curved edge