Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

gadget_Space.c

Go to the documentation of this file.
00001 /*
00002  *    gui - [gega user interface] the flexible solution for user interface problems
00003  *    Copyright (C) 2002  Gergely Gati
00004  *
00005  *    This program is free software; you can redistribute it and/or modify
00006  *    it under the terms of the GNU General Public License as published by
00007  *    the Free Software Foundation; version 2 of the License.
00008  *
00009  *    This program is distributed in the hope that it will be useful,
00010  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *    GNU General Public License for more details.
00013  *
00014  *    You should have received a copy of the GNU General Public License
00015  *    along with this program; if not, write to the Free Software
00016  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017  *
00018  *    Gergely Gati
00019  *      email:           g.gati@freemail.hu
00020  *      AIM screenname:  GatiGergely
00021  *      ICQ number:      93131690
00022  *
00023  */
00024 /*
00025  *  space.c
00026  *
00027  *  Author            : Gergely Gáti
00028  *  Date              :
00029  *  Description       :
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  *  This function is always called after the Gadget_t has been created and
00069  *  attached to the Gadget_t tree, but before the call to space_layout(). It may be
00070  *  called more than once. It must fill in the Gadget_t's minimum and maximum
00071  *  sizes into the supplied extent structures.
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  *  This function is called always after space_get_extent() has been called at
00104  *  least once. It receives a position and an extent which determine the
00105  *  position and the size of the Gadget_t on the screen. This extent is always
00106  *  between the minimum and maximum sizes which were returned by
00107  *  space_get_extent() of the same gadget. After this call the Gadget_t is made
00108  *  visible.
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  *  This function is called once before the creation of any Gadget_t of this
00192  *  class. Gadgets can be created only after this function has been called.
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 }

Generated on Tue Jan 7 12:11:20 2003 for THEGUI by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002