1*9ecf9d1cSIngo Weinhold /*
2*9ecf9d1cSIngo Weinhold * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3*9ecf9d1cSIngo Weinhold * All rights reserved. Distributed under the terms of the MIT License.
4*9ecf9d1cSIngo Weinhold */
5*9ecf9d1cSIngo Weinhold
6*9ecf9d1cSIngo Weinhold #include "OneElementLayouter.h"
7*9ecf9d1cSIngo Weinhold
8*9ecf9d1cSIngo Weinhold #include <Size.h>
9*9ecf9d1cSIngo Weinhold
10*9ecf9d1cSIngo Weinhold
11*9ecf9d1cSIngo Weinhold class OneElementLayouter::MyLayoutInfo : public LayoutInfo {
12*9ecf9d1cSIngo Weinhold public:
13*9ecf9d1cSIngo Weinhold float fSize;
14*9ecf9d1cSIngo Weinhold
MyLayoutInfo()15*9ecf9d1cSIngo Weinhold MyLayoutInfo()
16*9ecf9d1cSIngo Weinhold : fSize(0)
17*9ecf9d1cSIngo Weinhold {
18*9ecf9d1cSIngo Weinhold }
19*9ecf9d1cSIngo Weinhold
ElementLocation(int32 element)20*9ecf9d1cSIngo Weinhold virtual float ElementLocation(int32 element)
21*9ecf9d1cSIngo Weinhold {
22*9ecf9d1cSIngo Weinhold return 0;
23*9ecf9d1cSIngo Weinhold }
24*9ecf9d1cSIngo Weinhold
ElementSize(int32 element)25*9ecf9d1cSIngo Weinhold virtual float ElementSize(int32 element)
26*9ecf9d1cSIngo Weinhold {
27*9ecf9d1cSIngo Weinhold return fSize;
28*9ecf9d1cSIngo Weinhold }
29*9ecf9d1cSIngo Weinhold };
30*9ecf9d1cSIngo Weinhold
31*9ecf9d1cSIngo Weinhold
32*9ecf9d1cSIngo Weinhold // constructor
OneElementLayouter()33*9ecf9d1cSIngo Weinhold OneElementLayouter::OneElementLayouter()
34*9ecf9d1cSIngo Weinhold : fMin(-1),
35*9ecf9d1cSIngo Weinhold fMax(B_SIZE_UNLIMITED),
36*9ecf9d1cSIngo Weinhold fPreferred(-1)
37*9ecf9d1cSIngo Weinhold {
38*9ecf9d1cSIngo Weinhold }
39*9ecf9d1cSIngo Weinhold
40*9ecf9d1cSIngo Weinhold // destructor
~OneElementLayouter()41*9ecf9d1cSIngo Weinhold OneElementLayouter::~OneElementLayouter()
42*9ecf9d1cSIngo Weinhold {
43*9ecf9d1cSIngo Weinhold }
44*9ecf9d1cSIngo Weinhold
45*9ecf9d1cSIngo Weinhold // AddConstraints
46*9ecf9d1cSIngo Weinhold void
AddConstraints(int32 element,int32 length,float min,float max,float preferred)47*9ecf9d1cSIngo Weinhold OneElementLayouter::AddConstraints(int32 element, int32 length,
48*9ecf9d1cSIngo Weinhold float min, float max, float preferred)
49*9ecf9d1cSIngo Weinhold {
50*9ecf9d1cSIngo Weinhold fMin = max_c(fMin, min);
51*9ecf9d1cSIngo Weinhold fMax = min_c(fMax, max);
52*9ecf9d1cSIngo Weinhold fMax = max_c(fMax, fMin);
53*9ecf9d1cSIngo Weinhold fPreferred = max_c(fPreferred, preferred);
54*9ecf9d1cSIngo Weinhold fPreferred = max_c(fPreferred, fMin);
55*9ecf9d1cSIngo Weinhold fPreferred = min_c(fPreferred, fMax);
56*9ecf9d1cSIngo Weinhold }
57*9ecf9d1cSIngo Weinhold
58*9ecf9d1cSIngo Weinhold // SetWeight
59*9ecf9d1cSIngo Weinhold void
SetWeight(int32 element,float weight)60*9ecf9d1cSIngo Weinhold OneElementLayouter::SetWeight(int32 element, float weight)
61*9ecf9d1cSIngo Weinhold {
62*9ecf9d1cSIngo Weinhold // not needed
63*9ecf9d1cSIngo Weinhold }
64*9ecf9d1cSIngo Weinhold
65*9ecf9d1cSIngo Weinhold // MinSize
66*9ecf9d1cSIngo Weinhold float
MinSize()67*9ecf9d1cSIngo Weinhold OneElementLayouter::MinSize()
68*9ecf9d1cSIngo Weinhold {
69*9ecf9d1cSIngo Weinhold return fMin;
70*9ecf9d1cSIngo Weinhold }
71*9ecf9d1cSIngo Weinhold
72*9ecf9d1cSIngo Weinhold // MaxSize
73*9ecf9d1cSIngo Weinhold float
MaxSize()74*9ecf9d1cSIngo Weinhold OneElementLayouter::MaxSize()
75*9ecf9d1cSIngo Weinhold {
76*9ecf9d1cSIngo Weinhold return fMax;
77*9ecf9d1cSIngo Weinhold }
78*9ecf9d1cSIngo Weinhold
79*9ecf9d1cSIngo Weinhold // PreferredSize
80*9ecf9d1cSIngo Weinhold float
PreferredSize()81*9ecf9d1cSIngo Weinhold OneElementLayouter::PreferredSize()
82*9ecf9d1cSIngo Weinhold {
83*9ecf9d1cSIngo Weinhold return fPreferred;
84*9ecf9d1cSIngo Weinhold }
85*9ecf9d1cSIngo Weinhold
86*9ecf9d1cSIngo Weinhold // CreateLayoutInfo
87*9ecf9d1cSIngo Weinhold LayoutInfo*
CreateLayoutInfo()88*9ecf9d1cSIngo Weinhold OneElementLayouter::CreateLayoutInfo()
89*9ecf9d1cSIngo Weinhold {
90*9ecf9d1cSIngo Weinhold return new MyLayoutInfo;
91*9ecf9d1cSIngo Weinhold }
92*9ecf9d1cSIngo Weinhold
93*9ecf9d1cSIngo Weinhold // Layout
94*9ecf9d1cSIngo Weinhold void
Layout(LayoutInfo * layoutInfo,float size)95*9ecf9d1cSIngo Weinhold OneElementLayouter::Layout(LayoutInfo* layoutInfo, float size)
96*9ecf9d1cSIngo Weinhold {
97*9ecf9d1cSIngo Weinhold ((MyLayoutInfo*)layoutInfo)->fSize = max_c(size, fMin);
98*9ecf9d1cSIngo Weinhold }
99*9ecf9d1cSIngo Weinhold
100*9ecf9d1cSIngo Weinhold // CloneLayouter
101*9ecf9d1cSIngo Weinhold Layouter*
CloneLayouter()102*9ecf9d1cSIngo Weinhold OneElementLayouter::CloneLayouter()
103*9ecf9d1cSIngo Weinhold {
104*9ecf9d1cSIngo Weinhold OneElementLayouter* layouter = new OneElementLayouter;
105*9ecf9d1cSIngo Weinhold layouter->fMin = fMin;
106*9ecf9d1cSIngo Weinhold layouter->fMax = fMax;
107*9ecf9d1cSIngo Weinhold layouter->fPreferred = fPreferred;
108*9ecf9d1cSIngo Weinhold
109*9ecf9d1cSIngo Weinhold return layouter;
110*9ecf9d1cSIngo Weinhold }
111