1 #include "ButtonDecorator.h"
2 #include "scenegraph/VertexBuffer.h"
3 #include "scenegraph/IndexBuffer16.h"
4 #include "scenegraph/Geometry.h"
5 #include "scenegraph/Material.h"
6 #include "scenegraph/Drawable.h"
7 #include "scenegraph/Group.h"
10 using namespace awful
;
11 using namespace awful::gui
;
13 BoringButtonDecorator::BoringButtonDecorator( Button
* pButton_
, Pointer
< BoringTheme
> pTheme_
) :
14 m_pButton( pButton_
),
21 void BoringButtonDecorator::buildSceneGraph( Pointer
< scenegraph::Frame
>& o_pFrame
,
22 Pointer
< scenegraph::Renderable
>& o_pRenderable
)
24 o_pFrame
= new scenegraph::Frame
;
25 Pointer
< scenegraph::Group
> pGroup
= new scenegraph::Group( o_pFrame
);
27 m_pRectFrame
= new scenegraph::Frame
;
28 m_pRectFrame
->setpParent( o_pFrame
);
30 m_pRectangle
= new shapes::Rectangle( m_pTheme
->m_pIdleButtonMat
, m_pRectFrame
);
31 pGroup
->add( m_pRectangle
.raw() );
33 m_pTextFrame
= new scenegraph::Frame
;
34 m_pTextFrame
->setpParent( o_pFrame
);
36 m_pText
= new scenegraph::Text
37 ( m_pTheme
->m_pFont
, m_pTextFrame
, m_pTheme
->m_pTextMat
);
38 pGroup
->add( m_pText
.raw() );
40 o_pRenderable
= pGroup
.raw();
43 void BoringButtonDecorator::calcMinMax()
45 math::Vector2f minmax
;
46 minmax
.x() = m_pTheme
->m_pFont
->getTextWidth( m_pButton
->getLabel() ) + 12.f
;
47 minmax
.y() = m_pTheme
->m_pFont
->getHeight() + 12.f
;
48 m_pButton
->setMinSize( minmax
);
51 m_pButton
->setMaxSize( minmax
);
54 void BoringButtonDecorator::layout()
56 const math::Rectf
& rect( m_pButton
->getRect() );
58 math::Matrix44f
& mtx
= m_pRectFrame
->getLocalToParent();
59 mtx
.right().x() = rect
.width();
60 mtx
.up().y() = -rect
.height();
61 m_pRectFrame
->dirty();
63 const std::string
& label
= m_pButton
->getLabel();
64 m_pText
->setTextString( label
);
66 math::Matrix44f
& tmtx
= m_pTextFrame
->getLocalToParent();
67 tmtx
.position().x() = ( rect
.width() - m_pTheme
->m_pFont
->getTextWidth( label
) ) / 2.f
;
69 // Round up position to an integer, to avoid the text to get blurry if it falls half-way between
71 // A bit hackish to do this here, but this is yeat something else to do
72 // when reimplementing text rendering (maybe just disabling filtering could be enough, or
73 // maybe a special vertex shader will be needed to do this rounding)
74 tmtx
.position().x() = std::floor( tmtx
.position().x() + 0.5f
);
76 tmtx
.position().y() = -( rect
.height() - m_pTheme
->m_pFont
->getHeight() ) / 2.f
;
77 tmtx
.position().z() = 1.f
/ 32768.f
;
80 void BoringButtonDecorator::updateState()
82 switch( m_pButton
->getState() )
85 m_pRectangle
->setpMaterial( m_pTheme
->m_pIdleButtonMat
);
88 case Button::s_Hilighted
:
89 m_pRectangle
->setpMaterial( m_pTheme
->m_pHilightButtonMat
);
92 case Button::s_Pressed
:
93 m_pRectangle
->setpMaterial( m_pTheme
->m_pPressedButtonMat
);