19ecf9d1cSIngo Weinhold/*
29ecf9d1cSIngo Weinhold * Copyright 2006, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
39ecf9d1cSIngo Weinhold * All rights reserved. Distributed under the terms of the MIT License.
49ecf9d1cSIngo Weinhold */
59ecf9d1cSIngo Weinhold
69ecf9d1cSIngo Weinhold#include "OneElementLayouter.h"
79ecf9d1cSIngo Weinhold
89ecf9d1cSIngo Weinhold#include <Size.h>
99ecf9d1cSIngo Weinhold
109ecf9d1cSIngo Weinhold
119ecf9d1cSIngo Weinholdclass OneElementLayouter::MyLayoutInfo : public LayoutInfo {
129ecf9d1cSIngo Weinholdpublic:
139ecf9d1cSIngo Weinhold	float	fSize;
149ecf9d1cSIngo Weinhold
159ecf9d1cSIngo Weinhold	MyLayoutInfo()
169ecf9d1cSIngo Weinhold		: fSize(0)
179ecf9d1cSIngo Weinhold	{
189ecf9d1cSIngo Weinhold	}
199ecf9d1cSIngo Weinhold
209ecf9d1cSIngo Weinhold	virtual float ElementLocation(int32 element)
219ecf9d1cSIngo Weinhold	{
229ecf9d1cSIngo Weinhold		return 0;
239ecf9d1cSIngo Weinhold	}
249ecf9d1cSIngo Weinhold
259ecf9d1cSIngo Weinhold	virtual float ElementSize(int32 element)
269ecf9d1cSIngo Weinhold	{
279ecf9d1cSIngo Weinhold		return fSize;
289ecf9d1cSIngo Weinhold	}
299ecf9d1cSIngo Weinhold};
309ecf9d1cSIngo Weinhold
319ecf9d1cSIngo Weinhold
329ecf9d1cSIngo Weinhold// constructor
339ecf9d1cSIngo WeinholdOneElementLayouter::OneElementLayouter()
349ecf9d1cSIngo Weinhold	: fMin(-1),
359ecf9d1cSIngo Weinhold	  fMax(B_SIZE_UNLIMITED),
369ecf9d1cSIngo Weinhold	  fPreferred(-1)
379ecf9d1cSIngo Weinhold{
389ecf9d1cSIngo Weinhold}
399ecf9d1cSIngo Weinhold
409ecf9d1cSIngo Weinhold// destructor
419ecf9d1cSIngo WeinholdOneElementLayouter::~OneElementLayouter()
429ecf9d1cSIngo Weinhold{
439ecf9d1cSIngo Weinhold}
449ecf9d1cSIngo Weinhold
459ecf9d1cSIngo Weinhold// AddConstraints
469ecf9d1cSIngo Weinholdvoid
479ecf9d1cSIngo WeinholdOneElementLayouter::AddConstraints(int32 element, int32 length,
489ecf9d1cSIngo Weinhold	float min, float max, float preferred)
499ecf9d1cSIngo Weinhold{
509ecf9d1cSIngo Weinhold	fMin = max_c(fMin, min);
519ecf9d1cSIngo Weinhold	fMax = min_c(fMax, max);
529ecf9d1cSIngo Weinhold	fMax = max_c(fMax, fMin);
539ecf9d1cSIngo Weinhold	fPreferred = max_c(fPreferred, preferred);
549ecf9d1cSIngo Weinhold	fPreferred = max_c(fPreferred, fMin);
559ecf9d1cSIngo Weinhold	fPreferred = min_c(fPreferred, fMax);
569ecf9d1cSIngo Weinhold}
579ecf9d1cSIngo Weinhold
589ecf9d1cSIngo Weinhold// SetWeight
599ecf9d1cSIngo Weinholdvoid
609ecf9d1cSIngo WeinholdOneElementLayouter::SetWeight(int32 element, float weight)
619ecf9d1cSIngo Weinhold{
629ecf9d1cSIngo Weinhold	// not needed
639ecf9d1cSIngo Weinhold}
649ecf9d1cSIngo Weinhold
659ecf9d1cSIngo Weinhold// MinSize
669ecf9d1cSIngo Weinholdfloat
679ecf9d1cSIngo WeinholdOneElementLayouter::MinSize()
689ecf9d1cSIngo Weinhold{
699ecf9d1cSIngo Weinhold	return fMin;
709ecf9d1cSIngo Weinhold}
719ecf9d1cSIngo Weinhold
729ecf9d1cSIngo Weinhold// MaxSize
739ecf9d1cSIngo Weinholdfloat
749ecf9d1cSIngo WeinholdOneElementLayouter::MaxSize()
759ecf9d1cSIngo Weinhold{
769ecf9d1cSIngo Weinhold	return fMax;
779ecf9d1cSIngo Weinhold}
789ecf9d1cSIngo Weinhold
799ecf9d1cSIngo Weinhold// PreferredSize
809ecf9d1cSIngo Weinholdfloat
819ecf9d1cSIngo WeinholdOneElementLayouter::PreferredSize()
829ecf9d1cSIngo Weinhold{
839ecf9d1cSIngo Weinhold	return fPreferred;
849ecf9d1cSIngo Weinhold}
859ecf9d1cSIngo Weinhold
869ecf9d1cSIngo Weinhold// CreateLayoutInfo
879ecf9d1cSIngo WeinholdLayoutInfo*
889ecf9d1cSIngo WeinholdOneElementLayouter::CreateLayoutInfo()
899ecf9d1cSIngo Weinhold{
909ecf9d1cSIngo Weinhold	return new MyLayoutInfo;
919ecf9d1cSIngo Weinhold}
929ecf9d1cSIngo Weinhold
939ecf9d1cSIngo Weinhold// Layout
949ecf9d1cSIngo Weinholdvoid
959ecf9d1cSIngo WeinholdOneElementLayouter::Layout(LayoutInfo* layoutInfo, float size)
969ecf9d1cSIngo Weinhold{
979ecf9d1cSIngo Weinhold	((MyLayoutInfo*)layoutInfo)->fSize = max_c(size, fMin);
989ecf9d1cSIngo Weinhold}
999ecf9d1cSIngo Weinhold
1009ecf9d1cSIngo Weinhold// CloneLayouter
1019ecf9d1cSIngo WeinholdLayouter*
1029ecf9d1cSIngo WeinholdOneElementLayouter::CloneLayouter()
1039ecf9d1cSIngo Weinhold{
1049ecf9d1cSIngo Weinhold	OneElementLayouter* layouter = new OneElementLayouter;
1059ecf9d1cSIngo Weinhold	layouter->fMin = fMin;
1069ecf9d1cSIngo Weinhold	layouter->fMax = fMax;
1079ecf9d1cSIngo Weinhold	layouter->fPreferred = fPreferred;
1089ecf9d1cSIngo Weinhold
1099ecf9d1cSIngo Weinhold	return layouter;
1109ecf9d1cSIngo Weinhold}
111