1 /*
2 	GWEN
3 	Copyright (c) 2010 Facepunch Studios
4 	See license in Gwen.h
5 */
6 
7 #pragma once
8 #ifndef GWEN_CONTROLS_LAYOUT_SPLITTER_H
9 #define GWEN_CONTROLS_LAYOUT_SPLITTER_H
10 
11 #include "Gwen/Controls/Base.h"
12 
13 namespace Gwen
14 {
15 namespace Controls
16 {
17 namespace Layout
18 {
19 class GWEN_EXPORT Splitter : public Base
20 {
21 public:
22 	typedef Base BaseClass;
23 
Splitter(Base * pParent)24 	Splitter(Base* pParent) : BaseClass(pParent)
25 	{
26 		for (int i = 0; i < 2; i++)
27 			m_pPanel[i] = NULL;
28 	}
29 
SetPanel(int i,Base * pPanel)30 	void SetPanel(int i, Base* pPanel)
31 	{
32 		if (i < 0 || i > 1) return;
33 
34 		m_pPanel[i] = pPanel;
35 
36 		if (m_pPanel[i])
37 		{
38 			m_pPanel[i]->SetParent(this);
39 		}
40 	}
41 
GetPanel(int i)42 	Base* GetPanel(int i) const
43 	{
44 		if (i < 0 || i > 1) return NULL;
45 		return m_pPanel[i];
46 	}
47 
Layout(Skin::Base * skin)48 	void Layout(Skin::Base* skin)
49 	{
50 		LayoutVertical(skin);
51 	}
52 
53 private:
LayoutVertical(Skin::Base *)54 	void LayoutVertical(Skin::Base* /*skin*/)
55 	{
56 		int w = Width();
57 		int h = Height();
58 
59 		if (m_pPanel[0])
60 		{
61 			const Margin& m = m_pPanel[0]->GetMargin();
62 			m_pPanel[0]->SetBounds(m.left, m.top, w - m.left - m.right, (h * 0.5) - m.top - m.bottom);
63 		}
64 
65 		if (m_pPanel[1])
66 		{
67 			const Margin& m = m_pPanel[1]->GetMargin();
68 			m_pPanel[1]->SetBounds(m.left, m.top + (h * 0.5f), w - m.left - m.right, (h * 0.5f) - m.top - m.bottom);
69 		}
70 	}
71 
LayoutHorizontal(Skin::Base *)72 	void LayoutHorizontal(Skin::Base* /*skin*/)
73 	{
74 		// Todo.
75 	}
76 
77 	Base* m_pPanel[2];
78 };
79 }  // namespace Layout
80 }  // namespace Controls
81 }  // namespace Gwen
82 #endif
83