1 //------------------------------------------------------------------------------
2 // emSplitter.h
3 //
4 // Copyright (C) 2005-2010,2014,2016 Oliver Hamann.
5 //
6 // Homepage: http://eaglemode.sourceforge.net/
7 //
8 // This program is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License version 3 as published by the
10 // Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License version 3
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20
21 #ifndef emSplitter_h
22 #define emSplitter_h
23
24 #ifndef emBorder_h
25 #include <emCore/emBorder.h>
26 #endif
27
28
29 //==============================================================================
30 //================================= emSplitter =================================
31 //==============================================================================
32
33 class emSplitter : public emBorder {
34
35 public:
36
37 // Class for a splitter panel. Such a panel can get two child panels
38 // which are laid out automatically, either horizontally or vertically,
39 // filling the whole content area. Between the two child panels is a
40 // grip which can be dragged by the user, for making one of the panels
41 // larger while the other gets smaller.
42
43 emSplitter(
44 ParentArg parent, const emString & name,
45 const emString & caption=emString(),
46 const emString & description=emString(),
47 const emImage & icon=emImage(),
48 bool vertical=false, double minPos=0.0, double maxPos=1.0,
49 double pos=0.5
50 );
51 // Constructor.
52 // Arguments:
53 // parent - Parent for this panel (emPanel or emView).
54 // name - The name for this panel.
55 // caption - The label's caption, or empty.
56 // description - The label's description, or empty.
57 // icon - The label's icon, or empty.
58 // vertical - See SetVertical.
59 // minPos - See SetMinMaxPos.
60 // maxPos - See SetMinMaxPos.
61 // pos - See SetPos.
62
63 virtual ~emSplitter();
64 // Destructor.
65
66 bool IsVertical() const;
67 void SetVertical(bool vertical=true);
68 // Whether the child panels are laid out left-right (false) or
69 // on top of each other (true).
70
71 double GetMinPos() const;
72 double GetMaxPos() const;
73 double GetPos() const;
74 void SetMinMaxPos(double minPos, double maxPos);
75 void SetPos(double pos);
76 // Get/set minimum, maximum and current position of the grip.
77 // The position ranges from 0.0 to 1.0 (0.0 = first child panel
78 // collapsed, 1.0 = second child panel collapsed).
79
80 const emSignal & GetPosSignal() const;
81 // This signal is signaled after each change of the grip
82 // position.
83
84 protected:
85
86 virtual void Input(emInputEvent & event, const emInputState & state,
87 double mx, double my);
88 virtual emCursor GetCursor() const;
89 virtual void PaintContent(
90 const emPainter & painter, double x, double y, double w,
91 double h, emColor canvasColor
92 ) const;
93 virtual void LayoutChildren();
94
95 private:
96
97 void CalcGripRect(
98 double contentX, double contentY, double contentW,
99 double contentH, double * pX, double * pY, double * pW,
100 double * pH
101 ) const;
102
103 bool Vertical;
104 double MinPos;
105 double MaxPos;
106 double Pos;
107 emSignal PosSignal;
108 bool Pressed;
109 double MousePosInGrip;
110 bool MouseInGrip;
111 };
112
IsVertical()113 inline bool emSplitter::IsVertical() const
114 {
115 return Vertical;
116 }
117
GetMinPos()118 inline double emSplitter::GetMinPos() const
119 {
120 return MinPos;
121 }
122
GetMaxPos()123 inline double emSplitter::GetMaxPos() const
124 {
125 return MaxPos;
126 }
127
GetPos()128 inline double emSplitter::GetPos() const
129 {
130 return Pos;
131 }
132
GetPosSignal()133 inline const emSignal & emSplitter::GetPosSignal() const
134 {
135 return PosSignal;
136 }
137
138
139 #endif
140