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


Generated on Sat Feb 22 2020 05:00:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge