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 { "div1Fill", AG_PANE_DIV1FILL }, 36 { "forceDiv1Fill", AG_PANE_FORCE_DIV1FILL }, 37 { "frame", AG_PANE_FRAME }, 38 { "div", AG_PANE_DIV }, 39 { "forceDiv", AG_PANE_FORCE_DIV }, 40 { "unmovable", AG_PANE_UNMOVABLE }, 41 { NULL, 0 } 42 }; 43 44 MODULE = Agar::Pane PACKAGE = Agar::Pane PREFIX = AG_ 45 PROTOTYPES: ENABLE 46 VERSIONCHECK: DISABLE 47 48 Agar::Pane 49 newHoriz(package, parent, ...) 50 const char * package 51 Agar::Widget parent 52 PREINIT: 53 Uint flags = 0, wflags = 0; 54 CODE: 55 if ((items == 3 && SvTYPE(SvRV(ST(2))) != SVt_PVHV) || items > 3) { 56 Perl_croak(aTHX_ "Usage: Agar::Pane->newHoriz(parent,[{opts}])"); 57 } 58 if (items == 3) { 59 AP_MapHashToFlags(SvRV(ST(2)), flagNames, &flags); 60 AP_MapHashToFlags(SvRV(ST(2)), AP_WidgetFlagNames, &wflags); 61 } 62 RETVAL = AG_PaneNewHoriz(parent, flags); 63 AGWIDGET(RETVAL)->flags |= wflags; 64 OUTPUT: 65 RETVAL 66 67 Agar::Pane 68 newVert(package, parent, ...) 69 const char * package 70 Agar::Widget parent 71 PREINIT: 72 Uint flags = 0, wflags = 0; 73 CODE: 74 if ((items == 3 && SvTYPE(SvRV(ST(2))) != SVt_PVHV) || items > 3) { 75 Perl_croak(aTHX_ "Usage: Agar::Pane->newVert(parent,[{opts}])"); 76 } 77 if (items == 3) { 78 AP_MapHashToFlags(SvRV(ST(2)), flagNames, &flags); 79 AP_MapHashToFlags(SvRV(ST(2)), AP_WidgetFlagNames, &wflags); 80 } 81 RETVAL = AG_PaneNewVert(parent, flags); 82 AGWIDGET(RETVAL)->flags |= wflags; 83 OUTPUT: 84 RETVAL 85 86 void 87 setDividerWidth(self, pixels) 88 Agar::Pane self 89 int pixels 90 CODE: 91 AG_PaneSetDividerWidth(self, pixels); 92 93 void 94 setDivisionMin(self, pixels) 95 Agar::Pane self 96 int pixels 97 CODE: 98 AG_PaneSetDivisionMin(self, 0, pixels, pixels); 99 AG_PaneSetDivisionMin(self, 1, pixels, pixels); 100 101 Agar::Box 102 leftPane(self) 103 Agar::Pane self 104 CODE: 105 RETVAL = self->div[0]; 106 OUTPUT: 107 RETVAL 108 109 Agar::Box 110 rightPane(self) 111 Agar::Pane self 112 CODE: 113 RETVAL = self->div[1]; 114 OUTPUT: 115 RETVAL 116 117 Agar::Box 118 topPane(self) 119 Agar::Pane self 120 CODE: 121 RETVAL = self->div[0]; 122 OUTPUT: 123 RETVAL 124 125 Agar::Box 126 bottomPane(self) 127 Agar::Pane self 128 CODE: 129 RETVAL = self->div[1]; 130 OUTPUT: 131 RETVAL 132 133 void 134 moveDivider(self, x) 135 Agar::Pane self 136 int x 137 CODE: 138 AG_PaneMoveDivider(self, x); 139 140 void 141 moveDividerPct(self, pct) 142 Agar::Pane self 143 int pct 144 CODE: 145 AG_PaneMoveDividerPct(self, pct); 146 147 148 void 149 setFlag(self, name) 150 Agar::Pane self 151 const char * name 152 CODE: 153 if (AP_SetNamedFlag(name, flagNames, &(self->flags))) { 154 AP_SetNamedFlag(name, AP_WidgetFlagNames, &(AGWIDGET(self)->flags)); 155 } 156 157 void 158 unsetFlag(self, name) 159 Agar::Pane self 160 const char * name 161 CODE: 162 if (AP_UnsetNamedFlag(name, flagNames, &(self->flags))) { 163 AP_UnsetNamedFlag(name, AP_WidgetFlagNames, &(AGWIDGET(self)->flags)); 164 } 165 166 Uint 167 getFlag(self, name) 168 Agar::Pane self 169 const char * name 170 CODE: 171 if (AP_GetNamedFlag(name, flagNames, self->flags, &RETVAL)) { 172 if (AP_GetNamedFlag(name, AP_WidgetFlagNames, AGWIDGET(self)->flags, 173 &RETVAL)) { XSRETURN_UNDEF; } 174 } 175 OUTPUT: 176 RETVAL 177 178