1 #include "WindowDecorator.h"
2 #include "scenegraph/Group.h"
3 #include "shapes/Rectangle.h"
6 using namespace awful::gui
;
8 BoringWindowDecorator::BoringWindowDecorator( Window
* pWindow_
, Pointer
< BoringTheme
> 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();
38 const Pointer
< scenegraph::Frame
>& pChildFrame
=
39 pContent
->getpFrame();
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();
54 m_pWindow
->setMinSize( min
);
56 math::Vector2f max
= m_pWindow
->getMaxSize();
61 m_pWindow
->setMaxSize( max
);
64 void BoringWindowDecorator::layout()
66 Pointer
< Widget
> pContent
= m_pWindow
->getContent();
70 const math::Rectf
& wrect( m_pWindow
->getRect() );
73 //r.width() = wrect.width();
75 r
.size() = wrect
.size();
76 m_pDragBar
->setRect( r
);
78 r
.left() = wrect
.width() - 10.f
;
79 r
.top() = wrect
.height() - 10.f
;
82 m_pSizeHandle
->setRect( r
);
86 r
.width() = wrect
.width() - 20.f
;
87 r
.height() = wrect
.height() - 20.f
;
88 pContent
->setRect( r
);
92 math::Matrix44f
& mtx
= m_pFrame
->getLocalToParent();
93 mtx
.right().x() = wrect
.width();
94 mtx
.up().y() = -wrect
.height();
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() )
126 rect
.size() = newsize
;
128 m_pWindow
->setRect( rect
);
129 m_pWindow
->reLayout();