1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright 2008 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
11 #ifndef __MOON_SIZE_H__
12 #define __MOON_SIZE_H__
16 #include "eventargs.h"
17 #include "thickness.h"
23 Size () : width(0), height(0) {}
25 Size (int zero
) : width(0), height(0) {}
27 Size (double w
, double h
)
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
);
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
);
90 class SizeChangedEventArgs
: public RoutedEventArgs
{
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
; }
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
);
113 #endif /* __MOON_POINT_H__ */