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
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
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
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 }