00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #if !defined(_XRB_WIDGETSKIN_HPP_)
00012 #define _XRB_WIDGETSKIN_HPP_
00013
00014 #include "xrb.hpp"
00015
00016 #include "xrb_font.hpp"
00017 #include "xrb_gltexture.hpp"
00018 #include "xrb_resourcelibrary.hpp"
00019 #include "xrb_screencoord.hpp"
00020
00021 namespace Xrb
00022 {
00023
00024 class Screen;
00025 class WidgetBackground;
00026
00031 class WidgetSkin
00032 {
00033 public:
00034
00038 enum WidgetBackgroundType
00039 {
00040 MODAL_WIDGET_BACKGROUND = 0,
00041 BUTTON_BACKGROUND,
00042 BUTTON_MOUSEOVER_BACKGROUND,
00043 BUTTON_PRESSED_BACKGROUND,
00044 LINE_EDIT_BACKGROUND,
00045 CHECK_BOX_BACKGROUND,
00046 RADIO_BUTTON_BACKGROUND,
00047 TOOLBAR_BUTTON_BACKGROUND,
00048 TOOLBAR_BUTTON_MOUSEOVER_BACKGROUND,
00049 TOOLBAR_BUTTON_CHECKED_BACKGROUND,
00050 TOOLBAR_BUTTON_PRESSED_BACKGROUND,
00051
00052 WIDGET_BACKGROUND_TYPE_COUNT
00053 };
00054
00058 enum FontType
00059 {
00060 DEFAULT_FONT = 0,
00061
00062 FONT_TYPE_COUNT
00063 };
00064
00068 enum TextureType
00069 {
00070 CHECK_BOX_CHECK_TEXTURE = 0,
00071 RADIO_BUTTON_CHECK_TEXTURE,
00072
00073 TEXTURE_TYPE_COUNT
00074 };
00075
00079 enum MarginsType
00080 {
00081 DEFAULT_FRAME_MARGINS = 0,
00082 DEFAULT_CONTENT_MARGINS,
00083 LAYOUT_FRAME_MARGINS,
00084 LAYOUT_SPACING_MARGINS,
00085
00086 MARGINS_TYPE_COUNT
00087 };
00088
00094 WidgetSkin (Screen const *screen);
00099 ~WidgetSkin ();
00100
00104 WidgetSkin *CreateClone () const;
00105
00110 Float RatioFromScreenCoord (ScreenCoord screen_coord) const;
00115 ScreenCoord ScreenCoordFromRatio (Float ratio) const;
00121 FloatVector2 RatiosFromScreenCoords (
00122 ScreenCoordVector2 const &screen_coords) const;
00128 ScreenCoordVector2 ScreenCoordsFromRatios (
00129 FloatVector2 const &ratios) const;
00130
00135 inline WidgetBackground const *GetWidgetBackground (
00136 WidgetBackgroundType const widget_background_type) const
00137 {
00138 ASSERT1(widget_background_type < WIDGET_BACKGROUND_TYPE_COUNT);
00139 return m_widget_background[widget_background_type];
00140 }
00144 inline Resource<Font> const &GetFont (FontType const font_type) const
00145 {
00146 ASSERT1(font_type < FONT_TYPE_COUNT);
00147 return m_font_specification[font_type].m_font;
00148 }
00153 inline Resource<GLTexture> const &GetTexture (
00154 TextureType const texture_type) const
00155 {
00156 ASSERT1(texture_type < TEXTURE_TYPE_COUNT);
00157 return m_texture[texture_type];
00158 }
00163 inline ScreenCoordVector2 const &Margins (MarginsType const margins_type) const
00164 {
00165 ASSERT1(margins_type < MARGINS_TYPE_COUNT);
00166 return m_margins_specification[margins_type].m_margins;
00167 }
00168
00174 void SetWidgetBackground (
00175 WidgetBackgroundType widget_background_type,
00176 WidgetBackground const *widget_background);
00181 void SetFont (
00182 FontType font_type,
00183 Resource<Font> const &font);
00189 void SetFontFacePath (
00190 FontType font_type,
00191 std::string const &font_face_path);
00198 void SetFontHeightRatio (
00199 FontType font_type,
00200 Float font_height_ratio);
00206 void SetFontHeight (
00207 FontType font_type,
00208 ScreenCoord font_height);
00213 void SetTexture (
00214 TextureType texture_type,
00215 Resource<GLTexture> const &texture);
00220 void SetTexturePath (
00221 TextureType texture_type,
00222 std::string const &texture_path);
00228 void SetMarginRatios (
00229 MarginsType margins_type,
00230 FloatVector2 const &margin_ratios);
00235 void SetMargins (
00236 MarginsType margins_type,
00237 ScreenCoordVector2 const &margins);
00238
00239
00240
00241 protected:
00242
00246 inline WidgetSkin () { }
00247
00248 private:
00249
00250 void UpdateFontHeight (FontType font_type);
00251 void UpdateMargins (MarginsType margins_type);
00252
00253 struct FontSpecification
00254 {
00255 Resource<Font> m_font;
00256 Float m_font_height_ratio;
00257 ScreenCoord m_font_height;
00258
00259 inline FontSpecification ()
00260 {
00261 m_font_height_ratio = 0.0f;
00262 m_font_height = 0;
00263 }
00264 };
00265
00266 struct MarginsSpecification
00267 {
00268 FloatVector2 m_margin_ratios;
00269 ScreenCoordVector2 m_margins;
00270
00271 inline MarginsSpecification ()
00272 {
00273 m_margin_ratios = FloatVector2::ms_zero;
00274 m_margins = ScreenCoordVector2::ms_zero;
00275 }
00276 };
00277
00278
00279 Screen const *m_screen;
00280
00281 WidgetBackground const *m_widget_background[WIDGET_BACKGROUND_TYPE_COUNT];
00282 FontSpecification m_font_specification[FONT_TYPE_COUNT];
00283 Resource<GLTexture> m_texture[TEXTURE_TYPE_COUNT];
00284 MarginsSpecification m_margins_specification[MARGINS_TYPE_COUNT];
00285 };
00286
00287 }
00288
00289 #endif // !defined(_XRB_WIDGETSKIN_HPP_)