00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <stdlib.h>
00033
00034 #include "gadgets/gadget_Space.h"
00035 #include "debug.h"
00036 #include "classes.h"
00037 #include "Bases.h"
00038 #include "Module.h"
00039 #include "Common.h"
00040 #include "Window.h"
00041
00042
00043
00044 struct _space
00045 {
00046 Gadget_t gadget;
00047 int width;
00048 int height;
00049 u32 color;
00050 };
00051
00052
00053 static bases_Modules_t *api;
00054 VERSION("Space.gadget",1,0,"Gergely Gati","g.gati@freemail.hu");
00055
00056
00057 static gadget_Binding_t binding[]=
00058 {
00059 {"width",TAG_SPC_WIDTH,GADGET_INT,NULL},
00060 {"height",TAG_SPC_HEIGHT,GADGET_INT,NULL},
00061 {"color",TAG_SPC_COLOR,GADGET_INT,NULL},
00062 GADGET_BINDING_DONE
00063 };
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 static void space_get_extent(Gadget_t *this, Extent_t *min, Extent_t *max)
00074 {
00075 debug_Begin();
00076
00077 if(((space *)this)->width<0)
00078 {
00079 min->width=0;
00080 max->width=GADGET_MAXIMUM_SIZE;
00081 }
00082 else
00083 {
00084 min->width=((space *)this)->width;
00085 max->width=((space *)this)->width;
00086 }
00087 if(((space *)this)->height<0)
00088 {
00089 min->height=0;
00090 max->height=GADGET_MAXIMUM_SIZE;
00091 }
00092 else
00093 {
00094 min->height=((space *)this)->height;
00095 max->height=((space *)this)->height;
00096 }
00097
00098 debug_End();
00099 }
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 static void space_layout(Gadget_t *this, Rect_t *rect)
00111 {
00112 debug_Begin();
00113
00114 api->glw_Call(GLW_SETCOLOR,TAG_GLW_WINDOW,this->window->handle, TAG_GLW_RGB,((space *)this)->color,TAG_DONE);
00115 api->glw_Call(GLW_DRAWFILLEDRECT,TAG_GLW_WINDOW,this->window->handle,TAG_GLW_LEFT,rect->left,TAG_GLW_TOP,rect->top,TAG_GLW_WIDTH,rect->width,TAG_GLW_HEIGHT,rect->height,TAG_DONE);
00116
00117 debug_End();
00118 }
00119
00120
00121 #if 0
00122 static int space_input_event_handler(Gadget_t *gad, struct glw_Event *event)
00123 {
00124 return(0);
00125 }
00126 #endif
00127
00128
00129 int space_init_gadget(Gadget_t *this, tag *taglist)
00130 {
00131 debug_Begin();
00132
00133 ((space *)this)->width=(int)tag_GetTagData(taglist,TAG_SPC_WIDTH,(u32)-1);
00134 ((space *)this)->height=(int)tag_GetTagData(taglist,TAG_SPC_HEIGHT,(u32)-1);
00135 ((space *)this)->color=(int)tag_GetTagData(taglist,TAG_SPC_COLOR,(u32)~0);
00136
00137 debug_End();
00138
00139 return(0);
00140 }
00141
00142
00143 static int space_gadget_event_handler(Gadget_t *this, int event, tag *taglist)
00144 {
00145 int ret=-1;
00146
00147 debug_Begin();
00148
00149 if(this!=NULL&&event>=0)
00150 {
00151 switch(event)
00152 {
00153 case GADEV_INIT_GADGET:
00154 {
00155 ret=space_init_gadget(this,taglist);
00156 break;
00157 }
00158 case GADEV_DELETE_GADGET:
00159 {
00160 ret=0;
00161 break;
00162 }
00163 case GADEV_GET_EXTENT:
00164 {
00165 Extent_t *min,*max,n,x;
00166 min=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMIN,(u32)&n);
00167 max=(Extent_t *)tag_GetTagData(taglist,TAG_GAD_EXTMAX,(u32)&x);
00168 space_get_extent(this,min,max);
00169 ret=0;
00170 break;
00171 }
00172 case GADEV_LAYOUT:
00173 case GADEV_DAMAGE:
00174 {
00175 Rect_t *rect,r;
00176 rect=(Rect_t *)tag_GetTagData(taglist,TAG_GAD_RECT,(u32)&r);
00177 space_layout(this,rect);
00178 ret=0;
00179 break;
00180 }
00181 }
00182 }
00183
00184 debug_End();
00185
00186 return(ret);
00187 }
00188
00189
00190
00191
00192
00193
00194 static void init_space_class(u32 module)
00195 {
00196 api->gadget_Call(GADGET_REGISTER_CLASS,
00197 TAG_GADGET_CLASS_ID,CLASS_SPACE_ID,
00198 TAG_GADGET_NAME,CLASS_SPACE_NAME,
00199 TAG_GADGET_BINDING,binding,
00200 TAG_GADGET_COLOR_NAMES,NULL,
00201 TAG_GADGET_CUSTOM_NAMES,NULL,
00202 TAG_GADGET_STATE_MASK,GADSTF_NORMAL,
00203 TAG_GADGET_MODULE,module,
00204 TAG_GADGET_GADGET_SIZE,sizeof(space),
00205 TAG_GADGET_METHODS,NULL,
00206 TAG_GADGET_INPUT_EVENT_HANDLER,NULL,
00207 TAG_GADGET_EVENT_HANDLER,NULL,
00208 TAG_GADGET_GADGET_EVENT_HANDLER,space_gadget_event_handler,
00209 TAG_DONE);
00210 }
00211
00212
00213 EXPORT int module_Init(u32 module, bases_Modules_t *bases)
00214 {
00215 api=bases;
00216 init_space_class(module); return(0);
00217 }