Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals   Related Pages  

ui_checkbutton.cpp

Go to the documentation of this file.
00001 // OMICRON ENGINE HEADER FILE
00002 //
00003 // --------------------------------------------------------------------------
00004 // Copyright (C) 2001-2002 by Bjoern Paetzel <kolrabi@gmx.de>
00005 //
00006 // This file is part of the Omicron Engine.
00007 //
00008 // The Omicron Engine is free software; you can redistribute it and/or modify
00009 // it under the terms of the  GNU General Public License  as published by the
00010 // Free Software Foundation;  either version  2  of the License,  or (at your
00011 // option) any later version.
00012 //
00013 // The Omicron Engine  is distributed in the hope that it will be useful, but
00014 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015 // or  FITNESS FOR A PARTICULAR PURPOSE.  See the  GNU General Public License
00016 // for more details.
00017 //
00018 // You should have  received a copy of the  GNU General Public License  along
00019 // with The Omicron Engine;  if not,  write to the  Free Software Foundation,
00020 // Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
00021 //
00022 // --------------------------------------------------------------------------
00023 // Last modified:       $Date: 2002/12/07 19:02:03 $
00024 // By           :       $Author: kolrabi $
00025 // $Id: ui_checkbutton.cpp,v 1.1.1.1 2002/12/07 19:02:03 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: ui_checkbutton.cpp,v $
00030   Revision 1.1.1.1  2002/12/07 19:02:03  kolrabi
00031   initial release
00032 
00033 
00034 */
00035 
00041 #include            "omicron/internal.h" 
00042 #include            "omicron/render.h"
00043 #include            "omicron/gui.h" 
00044 #include            "omicron/image.h"
00045 #include            "omicron/list.h"
00046 
00047 uicheckbutton_c::uicheckbutton_c()
00048 {
00049     classname   = "checkbutton";
00050 
00051     radio   = false;
00052     checked = false;
00053 
00054     fnt         = gv.gui->get_font(UIF_FONT8);
00055 
00056     bgcolor     = gv.gui->get_color(UIC_WINDOW);
00057 }
00058 
00059 uicheckbutton_c::~uicheckbutton_c()
00060 {
00061     AssertThis;
00062 
00063 }
00064 
00065 void uicheckbutton_c::paint()
00066 {
00067     AssertThis;
00068 
00069     if (styleflags&UI_CHECK_BUTTON)
00070     {
00071         // first update
00072         if (hilite)
00073             bgcolor = gv.gui->get_color(UIC_HIGHLIGHT);
00074         else
00075             bgcolor = gv.gui->get_color(UIC_FACE);
00076 
00077         if (pressed||checked)
00078         {
00079             styleflags |= UI_BORDER_SUNKEN;
00080             styleflags &= ~UI_BORDER_RAISED;
00081         }
00082         else
00083         {
00084             styleflags &= ~UI_BORDER_SUNKEN;
00085             styleflags |= UI_BORDER_RAISED;
00086         }
00087 
00088         // then paint
00089         uiobject_c::paint();
00090 
00091         if (this == gv.gui->get_focus())
00092             img->rectangle(2,2, width-4, height-4, gv.gui->get_color(UIC_FOCUS));
00093 
00094         if (fnt && text)
00095         {
00096             sshort ofs = (pressed||checked)?1:0;
00097 
00098             sshort  w = gv.renderer->get_string_pixelwidth(text, fnt);
00099             color_t c;
00100 
00101             if (disabled)
00102             {
00103                 c = gv.gui->get_color(UIC_LIGHT);
00104                 img->draw_string((width-w)/2+ofs,(height-fnt->height)/2+ofs,text,fnt, c);
00105 
00106                 c = gv.gui->get_color(UIC_SHADOW);
00107                 img->draw_string((width-w)/2+ofs-1,(height-fnt->height)/2+ofs-1,text,fnt, c);
00108             }
00109             else
00110             {
00111                 c = gv.gui->get_color(UIC_TEXT);
00112                 img->draw_string((width-w)/2+ofs,(height-fnt->height)/2+ofs,text,fnt, c);
00113             }
00114         }
00115     }
00116     else
00117     {
00118         animation_c *pic = gv.gui->get_image(UII_CHECKBOX);
00119 
00120         sshort ycenter = height/2;
00121         ushort  f = (pressed?0:1)|(checked?0:2)|(hilite?4:0);
00122         ushort imgh = pic->get_height();
00123         ushort imgw = pic->get_width();
00124     
00125         img->blt(pic->set_frame(f), 0,0, 0, ycenter-imgh/2, imgw, imgh);
00126 
00127         if (fnt && text)
00128         {
00129             color_t c;
00130 
00131             if (disabled)
00132             {
00133                 c = gv.gui->get_color(UIC_DISABLED);
00134                 img->draw_string(imgw,(height-fnt->height)/2,text,fnt, c);
00135             }
00136             else
00137             {
00138                 c = gv.gui->get_color(UIC_TEXT);
00139                 img->draw_string(imgw,(height-fnt->height)/2,text,fnt, c);
00140             }
00141         }
00142     }
00143 }
00144  
00145 void uicheckbutton_c::event(uievent_s *eve)
00146 { 
00147     AssertThis;
00148 
00149     AssertReturn1(eve);
00150 
00151     switch(eve->event) 
00152     { 
00153         case UIE_MOUSECLICK:
00154             {
00155                 uievent_s eve2  = *eve;
00156                 eve2.event      = UIE_COMMAND;
00157                 gv.iface->gui_callback(&eve2);
00158 
00159                 if (radio)
00160                 {
00161                     set_checked(true);
00162 
00163                     if (parent)
00164                     {
00165                         uiobject_c *obj = (uiobject_c *)parent->get_children()->get_first();
00166 
00167                         while(obj)
00168                         {
00169                             if (obj != this && !strcmpi(obj->get_classname(), "checkbutton"))
00170                             {
00171                                 if (((uicheckbutton_c*)obj)->radio)
00172                                     ((uicheckbutton_c*)obj)->set_checked(false);
00173                             }
00174                             obj = (uiobject_c *)parent->get_children()->get_next();
00175                         }
00176                     }
00177                 }
00178                 else
00179                     set_checked(!checked);
00180             }
00181             break;
00182     }
00183 
00184     uibutton_c::event(eve);
00185 }

Generated on Wed Dec 18 15:48:48 2002 for omicron engine by doxygen1.2.18