Hasty Badger
Small UI library (a branch of Turbo Badger)
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends Groups Pages
tb::TBSkin Class Reference

TBSkin contains a list of TBSkinElement. More...

#include <tb_skin.h>

Inheritance diagram for tb::TBSkin:
tb::TBRendererListener

Public Member Functions

void SetListener (TBSkinListener *listener)
 Set the listener for this skin. More...
 
TBSkinListenerGetListener () const
 
bool Load (const TBStr &skin_file, const TBStr &override_skin_file=TBStr())
 Load the skin file and the bitmaps it refers to. More...
 
bool Write (const TBStr &skin_file)
 Write the current skin to a file.
 
void UnloadBitmaps ()
 Unload all bitmaps used in this skin. More...
 
bool ReloadBitmaps ()
 Reload all bitmaps used in this skin. More...
 
const TBDimensionConverterGetDimensionConverter () const
 Get the dimension converter used for the current skin. More...
 
TBSkinElementGetSkinElement (const TBID &skin_id) const
 Get the skin element with the given id. More...
 
TBSkinElementGetSkinElementStrongOverride (const TBID &skin_id, SKIN_STATE state, TBSkinConditionContext &context) const
 Get the skin element with the given id and state. More...
 
TBColor GetDefaultTextColor () const
 Get the default text color for all skin elements.
 
void SetDefaultTextColor (TBColor color)
 Set the default text color for all skin elements.
 
float GetDefaultDisabledOpacity () const
 Get the default disabled opacity for all skin elements.
 
float GetDefaultPlaceholderOpacity () const
 Get the default placeholder opacity for all skin elements.
 
int GetDefaultSpacing () const
 Get the default layout spacing in pixels. More...
 
TBSkinElementPaintSkin (const TBRect &dst_rect, const TBID &skin_id, SKIN_STATE state, TBSkinConditionContext &context)
 Paint the skin at dst_rect. More...
 
TBSkinElementPaintSkin (const TBRect &dst_rect, TBSkinElement *element, SKIN_STATE state, TBSkinConditionContext &context)
 Paint the skin at dst_rect. More...
 
void PaintSkinOverlay (const TBRect &dst_rect, TBSkinElement *element, SKIN_STATE state, TBSkinConditionContext &context)
 Paint the overlay elements for the given skin element and state. More...
 
void PaintRect (const TBRect &dst_rect, const TBColor &color, int thickness)
 Paint a rectangle outline inside dst_rect with the given thickness and color. More...
 
void PaintRectFill (const TBRect &dst_rect, const TBColor &color)
 Paint a filled rectangle with the given color. More...
 
TBBitmapFragmentManagerGetFragmentManager ()
 Get the fragment manager. More...
 
virtual void OnContextLost ()
 Called when the context has been lost and all TBBitmaps need to be deleted. More...
 
virtual void OnContextRestored ()
 Called when the context has been restored again, and new TBBitmaps can be created again. More...
 

Friends

class TBSkinElement
 

Detailed Description

TBSkin contains a list of TBSkinElement.

Member Function Documentation

int tb::TBSkin::GetDefaultSpacing ( ) const
inline

Get the default layout spacing in pixels.

const TBDimensionConverter* tb::TBSkin::GetDimensionConverter ( ) const
inline

Get the dimension converter used for the current skin.

This dimension converter converts to px by the same factor as the skin (based on the skin DPI settings).

TBBitmapFragmentManager* tb::TBSkin::GetFragmentManager ( )
inline

Get the fragment manager.

TBSkinElement * tb::TBSkin::GetSkinElement ( const TBID skin_id) const

Get the skin element with the given id.

Returns nullptr if there's no match.

TBSkinElement * tb::TBSkin::GetSkinElementStrongOverride ( const TBID skin_id,
SKIN_STATE  state,
TBSkinConditionContext context 
) const

Get the skin element with the given id and state.

This is like calling GetSkinElement and also following any strong overrides that match the current state (if any). See details about strong overrides in PaintSkin. Returns nullptr if there's no match.

bool tb::TBSkin::Load ( const TBStr skin_file,
const TBStr override_skin_file = TBStr() 
)

Load the skin file and the bitmaps it refers to.

If override_skin_file is specified, it will also be loaded into this skin after loading skin_file. Elements using the same name will override any previosly read data for the same element. Known limitation: Clone can currently only clone elements in the same file!

Returns true on success, and all bitmaps referred to also loaded successfully.

void tb::TBSkin::OnContextLost ( )
virtual

Called when the context has been lost and all TBBitmaps need to be deleted.

NOTE: Only do cleanup here. It's not safe to do work on any bitmap since the context is already lost.

Implements tb::TBRendererListener.

void tb::TBSkin::OnContextRestored ( )
virtual

Called when the context has been restored again, and new TBBitmaps can be created again.

Implements tb::TBRendererListener.

void tb::TBSkin::PaintRect ( const TBRect dst_rect,
const TBColor color,
int  thickness 
)

Paint a rectangle outline inside dst_rect with the given thickness and color.

void tb::TBSkin::PaintRectFill ( const TBRect dst_rect,
const TBColor color 
)

Paint a filled rectangle with the given color.

TBSkinElement * tb::TBSkin::PaintSkin ( const TBRect dst_rect,
const TBID skin_id,
SKIN_STATE  state,
TBSkinConditionContext context 
)

Paint the skin at dst_rect.

Strong override elements: -Strong override elements are like override elements, but they don't only apply when painting. They also override padding and other things that might affect the layout of the widget having the skin set.

Override elements: -If there is a override element with the exact matching state, it will paint the override instead if the base skin. If no exact match was found, it will check for a partial match and paint that instead of the base skin.

Child elements: -It will paint all child elements that match the current state ("all" can be specified as state so it will always be painted). The elements are painted in the order they are specified in the skin.

Special elements: -There's some special generic skin elements used by TBWidget (see TBWidget::SetSkinBg)

Overlay elements: -Overlay elements are painted separately, from PaintSkinOverlay (when all sibling widgets has been painted). As with child elements, all overlay elements that match the current state will be painted in the order they are specified in the skin.

Return the skin element used (after following override elements), or nullptr if no skin element was found matching the skin_id.

TBSkinElement * tb::TBSkin::PaintSkin ( const TBRect dst_rect,
TBSkinElement element,
SKIN_STATE  state,
TBSkinConditionContext context 
)

Paint the skin at dst_rect.

Just like the PaintSkin above, but takes a specific skin element instead of looking it up from the id.

void tb::TBSkin::PaintSkinOverlay ( const TBRect dst_rect,
TBSkinElement element,
SKIN_STATE  state,
TBSkinConditionContext context 
)

Paint the overlay elements for the given skin element and state.

bool tb::TBSkin::ReloadBitmaps ( )

Reload all bitmaps used in this skin.

Calls UnloadBitmaps first to ensure no bitmaps are loaded before loading new ones.

void tb::TBSkin::SetListener ( TBSkinListener listener)
inline

Set the listener for this skin.

void tb::TBSkin::UnloadBitmaps ( )

Unload all bitmaps used in this skin.


The documentation for this class was generated from the following files: