2009-12-07 Rolf Bjarne Kvinge <RKvinge@novell.com>
[moon.git] / src / size.h
blob65da45929d7edacae74e08cccda1573962362fa4
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * size.h
5 * Copyright 2008 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #ifndef __MOON_SIZE_H__
12 #define __MOON_SIZE_H__
14 #include <math.h>
15 #include <glib.h>
16 #include "eventargs.h"
17 #include "thickness.h"
19 /* @IncludeInKinds */
20 struct Size {
21 double width, height;
23 Size () : width(0), height(0) {}
25 Size (int zero) : width(0), height(0) {}
27 Size (double w, double h)
29 this->width = w;
30 this->height = h;
33 bool IsEmpty () const
35 return (isinf (width) == -1 && isinf (height) == -1);
38 Size Max (double w, double h) const
40 return Size (width < w ? w : width, height < h ? h : height);
43 Size Max (const Size &s) const
45 return Max (s.width, s.height);
48 Size Min (double w, double h) const
50 return Size (width > w ? w : width, height > h ? h : height);
53 Size Min (const Size &s) const
55 return Min (s.width, s.height);
58 Size GrowBy (const double w, const double h) const
60 const double hh = isinf (height) ? height : height + h;
61 const double ww = isinf (width) ? width : width + w;
63 return Size (ww > 0 ? ww : 0, hh > 0 ? hh : 0);
66 Size GrowBy (const Thickness &t)
68 return GrowBy (t.left + t.right, t.top + t.bottom);
71 bool operator == (const Size &size)
73 return fabs (size.width-width) < DBL_EPSILON && fabs (size.height-height) < DBL_EPSILON;
76 bool operator != (const Size &size)
78 return !(*this == size);
82 // FromStr
83 // Parses @s and return a new size in @size. Returns true if
84 // this was successful, false otherwise.
86 static bool FromStr (const char *s, Size *size);
89 /* @Namespace=None */
90 class SizeChangedEventArgs : public RoutedEventArgs {
91 Size prev_size;
92 Size new_size;
94 public:
95 /* @GenerateCBinding,GeneratePInvoke */
96 SizeChangedEventArgs ();
98 SizeChangedEventArgs (Size prev_size, Size new_size);
100 Size GetPrevSize () { return prev_size; }
101 Size GetNewSize () { return new_size; }
104 G_BEGIN_DECLS
106 /* @GeneratePInvoke */
107 void size_changed_event_args_get_prev_size (SizeChangedEventArgs *args, /* @MarshalAs=Size,IsRef */ Size *prev_size);
108 /* @GeneratePInvoke */
109 void size_changed_event_args_get_new_size (SizeChangedEventArgs *args, /* @MarshalAs=Size,IsRef */ Size *new_size);
111 G_END_DECLS
113 #endif /* __MOON_POINT_H__ */