button.cpp

00001 /***************************************************************************
00002                           button.cpp  -  description
00003                              -------------------
00004     begin                : Wed Jan 28 2004
00005     copyright            : (C) 2004 by Dynacube Team
00006     email                : 
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018  #include "gui/components/button.h"
00019 
00020  void button::but_init(DW _id,DW _parent_id,DW _cnt_type,void *_cnt_ptr,DW _alias_id,DW _x,DW _y,DW _width,DW _height,DD _style,char *_label)
00021  {
00022     state = true; // Projecting out
00023     memcpy(label,_label,strlen(_label));
00024     comp_init(BUT_TYPE,_id,_parent_id,_cnt_type,_cnt_ptr,_alias_id,_x,_y,_width,_height,_style);
00025  }
00026 
00027  void button::paint()
00028   {
00029     window *win_ptr;
00030     frame *frm_ptr;
00031     DW _x,_y,_width,_height;
00032     DW i;
00033 
00034     COLOR color[] = {0xE5F1, 0xBC4D, 0xE637, 0xDE99, 0xCDE7, 0xB5DD, 0xAD57, 0xA537, 0x9D53, 0x9CD1, 0x9533, 0x94D9, 0x8557, 0x6C75};
00035 
00036     switch(cnt_type)
00037     {
00038       case WIND_TYPE :
00039                       win_ptr = (window *) cnt_ptr;
00040                       if(win_ptr->style & W_MAXIMIZE)
00041                        {
00042                          _x = BORDER_WIDTH;
00043                          _y = TITLE_HEIGHT + BORDER_HEIGHT + ((win_ptr->hasMenu) ? MENUBAR_HEIGHT : 0);
00044                          _width  = SCREEN_WIDTH;
00045                          _height = SCREEN_HEIGHT;
00046                        }
00047                       else
00048                        {
00049                          _x = win_ptr->x + BORDER_WIDTH;
00050                          _y = win_ptr->y + TITLE_HEIGHT + BORDER_HEIGHT + ((win_ptr->hasMenu) ? MENUBAR_HEIGHT : 0);
00051                          _width = win_ptr->width;
00052                          _height = win_ptr->height;
00053                        }
00054 
00055                       if((x + width < _width) && (y + height < _height))
00056                       {
00057                          fillrect(x+_x, y+_y, width, height,BUTTON_COLOR);//color[i]);
00058                          drawstring(x+_x+width/8,y+_y+height/4,label);
00059                          if(state)
00060                            emboss3D(x+_x, y+_y, width, height,0,_false,1);
00061                          else
00062                            emboss3D(x+_x, y+_y, width, height,0,_true,1);
00063                       }
00064                       break;
00065     }
00066   }
00067 
00068 
00069   void button::react()
00070   {
00071     window *win_ptr = (window *)cnt_ptr;
00072     DW i,j;
00073 
00074     if(state)
00075     {
00076       state = false;
00077       win_ptr->deactivate();
00078     }
00079     else
00080     {
00081       state = true;
00082       win_ptr->activate();            
00083     }
00084 
00085     restoreImage(mcurx,mcury);
00086     
00087     paint();
00088       
00089     if(mouse_inited)
00090     {
00091       getimage(mcurx,mcury,16,16, &mouseimg[0][0]);
00092 
00093       for(i = mcurx ; i < mcurx+16 ; i++)
00094       {
00095         for(j = mcury ; j < mcury+16 ; j++)
00096         {
00097           if(mouseptr[j-mcury][i-mcurx])
00098           {
00099             setPixel(i,j,0x0);
00100           }
00101         }
00102       }
00103     }
00104       
00105     mvBuf2Svga();      
00106   }
00107  
00108  

Generated on Thu Jul 27 23:52:25 2006 for Dynacube by  doxygen 1.4.7