Minor cleanup here and there.
[fail.git] / gui / BoringTheme / WindowDecorator.cpp
blobefa01f66d5b2978650c630205e82f59f77e36452
1 #include "WindowDecorator.h"
2 #include "scenegraph/Group.h"
3 #include "shapes/Rectangle.h"
5 using namespace awful;
6 using namespace awful::gui;
8 BoringWindowDecorator::BoringWindowDecorator( Window* pWindow_, Pointer< BoringTheme > pTheme_ ) :
9 m_pWindow( pWindow_ ),
10 m_pTheme( pTheme_ )
12 m_pDragBar = new Draggable( this );
13 m_pDragBar->m_Dragging.connect( this, &BoringWindowDecorator::dragging );
15 m_pSizeHandle = new Draggable( this );
16 m_pSizeHandle->m_Dragging.connect( this, &BoringWindowDecorator::sizing );
19 void BoringWindowDecorator::buildSceneGraph( Pointer< scenegraph::Frame >& o_pFrame,
20 Pointer< scenegraph::Renderable >& o_pRenderable )
22 // The root window frame
23 o_pFrame = new scenegraph::Frame();
25 // The decoration frame
26 m_pFrame = new scenegraph::Frame();
27 m_pFrame->setpParent( o_pFrame );
29 Pointer< scenegraph::Group > pGroup = new scenegraph::Group( o_pFrame );
30 o_pRenderable = pGroup.raw();
32 pGroup->add( new shapes::Rectangle( m_pTheme->m_pWindowMat, m_pFrame ) );
34 Pointer< Widget > pContent = m_pWindow->getContent();
35 if( !pContent )
36 return;
38 const Pointer< scenegraph::Frame >& pChildFrame =
39 pContent->getpFrame();
40 if( pChildFrame )
41 pChildFrame->setpParent( o_pFrame );
43 const Pointer< scenegraph::Renderable >& pChildRenderable =
44 pContent->getpRenderable();
45 if( pChildRenderable )
46 pGroup->add( pChildRenderable );
49 void BoringWindowDecorator::calcMinMax()
51 math::Vector2f min = m_pWindow->getMinSize();
52 min.x() += 20.f;
53 min.y() += 20.f;
54 m_pWindow->setMinSize( min );
56 math::Vector2f max = m_pWindow->getMaxSize();
57 if( max.x() > 0.f )
58 max.x() += 20.f;
59 if( max.y() > 0.f )
60 max.y() += 20.f;
61 m_pWindow->setMaxSize( max );
64 void BoringWindowDecorator::layout()
66 Pointer< Widget > pContent = m_pWindow->getContent();
67 if( !pContent )
68 return;
70 const math::Rectf& wrect( m_pWindow->getRect() );
71 math::Rectf r;
73 //r.width() = wrect.width();
74 //r.height() = 10.f;
75 r.size() = wrect.size();
76 m_pDragBar->setRect( r );
78 r.left() = wrect.width() - 10.f;
79 r.top() = wrect.height() - 10.f;
80 r.width() = 10.f;
81 r.height() = 10.f;
82 m_pSizeHandle->setRect( r );
84 r.left() = 10.f;
85 r.top() = 10.f;
86 r.width() = wrect.width() - 20.f;
87 r.height() = wrect.height() - 20.f;
88 pContent->setRect( r );
90 pContent->layout();
92 math::Matrix44f& mtx = m_pFrame->getLocalToParent();
93 mtx.right().x() = wrect.width();
94 mtx.up().y() = -wrect.height();
95 m_pFrame->dirty();
98 void BoringWindowDecorator::dragging( math::Vector2f pos, math::Vector2f )
100 m_pWindow->setAbsPos( pos );
103 void BoringWindowDecorator::sizing( math::Vector2f pos, math::Vector2f )
105 math::Vector2f newsize = pos - m_pWindow->getAbsPos();
106 newsize += math::Vector2f( 10.f, 10.f );
108 const math::Vector2f& minsize = m_pWindow->getMinSize();
110 if( newsize.x() < minsize.x() )
111 newsize.x() = minsize.x();
112 if( newsize.y() < minsize.y() )
113 newsize.y() = minsize.y();
115 const math::Vector2f& maxsize = m_pWindow->getMaxSize();
116 if( maxsize.x() && maxsize.x() < newsize.x() )
117 newsize.x() = maxsize.x();
118 if( maxsize.y() && maxsize.y() < newsize.y() )
119 newsize.y() = maxsize.y();
121 math::Rectf rect( m_pWindow->getRect() );
123 if( newsize == rect.size() )
124 return;
126 rect.size() = newsize;
128 m_pWindow->setRect( rect );
129 m_pWindow->reLayout();