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

ui_button.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_button.cpp,v 1.1.1.1 2002/12/07 19:02:03 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: ui_button.cpp,v $
00030   Revision 1.1.1.1  2002/12/07 19:02:03  kolrabi
00031   initial release
00032 
00033 
00034 */
00035 
00042 #include            "omicron/internal.h" 
00043 #include            "omicron/render.h"
00044 #include            "omicron/gui.h" 
00045 #include            "omicron/image.h"
00046 
00048 uibutton_c::uibutton_c()
00049 {
00050     classname   = "button";
00051 
00052     hilite      = false;
00053     pressed     = false;
00054 
00055     fnt         = gv.gui->get_font(UIF_FONT8);
00056 
00057     bgcolor     = gv.gui->get_color(UIC_FACE);
00058 }
00059 
00060 uibutton_c::~uibutton_c()
00061 {
00062     AssertThis;
00063 
00064 }
00065 
00066 void uibutton_c::paint()
00067 {
00068     AssertThis;
00069 
00070     // first update
00071 
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)
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?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  
00117 void uibutton_c::event(uievent_s *eve)
00118 {
00119     AssertThis;
00120 
00121     AssertReturn1(eve);
00122 
00123     switch(eve->event) 
00124     { 
00125         case UIE_MOUSEOVER: 
00126             if ((this == gv.gui->get_focus()) && (gv.mouse_b&1)) 
00127                 pressed = true;
00128  
00129             /*if (!disabled) */hilite = true;
00130             set_needs_refresh();
00131             break; 
00132  
00133         case UIE_MOUSEOUT: 
00134             hilite  = false;
00135             pressed = false;
00136             set_needs_refresh();
00137             break; 
00138  
00139         case UIE_MOUSEDOWN: 
00140             if (!disabled) pressed = true;
00141             set_needs_refresh();
00142             break; 
00143  
00144         case UIE_MOUSEUP: 
00145             pressed = false;
00146             set_needs_refresh();
00147             break; 
00148 
00149         case UIE_GETFOCUS:
00150         case UIE_LOSTFOCUS:
00151             set_needs_refresh();
00152             break;
00153 
00154         case UIE_MOUSECLICK:
00155             {
00156                 uievent_s eve2 = *eve;
00157                 eve2.event = UIE_COMMAND;
00158                 gv.iface->gui_callback(&eve2);
00159             }
00160             break;
00161     }
00162 
00163     uiobject_c::event(eve);
00164 }

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