1 /*
2  * Copyright (c) 2009 Mat Sutcliffe (oktal@gmx.co.uk)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23  * USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #include "EXTERN.h"
27 #include "perl.h"
28 #include "XSUB.h"
29 
30 #include <agar/core.h>
31 #include <agar/gui.h>
32 #include "perl_agar.h"
33 
34 static const AP_FlagNames flagNames[] = {
35 	{ "fillBG",		AG_FIXED_FILLBG },
36 	{ "box",		AG_FIXED_BOX },
37 	{ "frame",		AG_FIXED_FRAME },
38 	{ "noUpdate",		AG_FIXED_NO_UPDATE },
39 	{ NULL,			0 }
40 };
41 
42 MODULE = Agar::Fixed	PACKAGE = Agar::Fixed	PREFIX = AG_
43 PROTOTYPES: ENABLE
44 VERSIONCHECK: DISABLE
45 
46 Agar::Fixed
47 new(package, parent, ...)
48 	const char * package
49 	Agar::Widget parent
50 PREINIT:
51 	Uint flags = 0, wflags = 0;
52 CODE:
53 	if ((items == 3 && SvTYPE(SvRV(ST(2))) != SVt_PVHV) || items > 3) {
54 		Perl_croak(aTHX_ "Usage: Agar::Fixed->new(parent,[{opts}])");
55 	}
56 	if (items == 3) {
57 		AP_MapHashToFlags(SvRV(ST(2)), flagNames, &flags);
58 		AP_MapHashToFlags(SvRV(ST(2)), AP_WidgetFlagNames, &wflags);
59 	}
60 	RETVAL = AG_FixedNew(parent, flags);
61 	AGWIDGET(RETVAL)->flags |= wflags;
62 OUTPUT:
63 	RETVAL
64 
65 void
66 size(self, child, w, h)
67 	Agar::Fixed self
68 	Agar::Widget child
69 	int w
70 	int h
71 CODE:
72 	AG_FixedSize(self, child, w, h);
73 
74 void
75 move(self, child, x, y)
76 	Agar::Fixed self
77 	Agar::Widget child
78 	int x
79 	int y
80 CODE:
81 	AG_FixedMove(self, child, x, y);
82 
83 void
84 setFlag(self, name)
85 	Agar::Fixed self
86 	const char * name
87 CODE:
88 	if (AP_SetNamedFlag(name, flagNames, &(self->flags))) {
89 		AP_SetNamedFlag(name, AP_WidgetFlagNames, &(AGWIDGET(self)->flags));
90 	}
91 
92 void
93 unsetFlag(self, name)
94 	Agar::Fixed self
95 	const char * name
96 CODE:
97 	if (AP_UnsetNamedFlag(name, flagNames, &(self->flags))) {
98 		AP_UnsetNamedFlag(name, AP_WidgetFlagNames, &(AGWIDGET(self)->flags));
99 	}
100 
101 Uint
102 getFlag(self, name)
103 	Agar::Fixed self
104 	const char * name
105 CODE:
106 	if (AP_GetNamedFlag(name, flagNames, self->flags, &RETVAL)) {
107 		if (AP_GetNamedFlag(name, AP_WidgetFlagNames, AGWIDGET(self)->flags,
108 			&RETVAL)) { XSRETURN_UNDEF; }
109 	}
110 OUTPUT:
111 	RETVAL
112 
113