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
00040 #include "omicron/internal.h"
00041 #include "omicron/render.h"
00042 #include "omicron/image.h"
00043 #include "omicron/gui.h"
00044
00045 uislider_c::uislider_c()
00046 {
00047 classname = "slider";
00048 min = 0;
00049 max = 100;
00050 pos = 0;
00051 }
00052
00053 uislider_c::~uislider_c()
00054 {
00055 AssertThis;
00056
00057 }
00058
00059 void uislider_c::paint()
00060 {
00061 AssertThis;
00062
00063 uiobject_c::paint();
00064
00065 float posfrac = (pos-min)/(max-min);
00066 slong i;
00067 animation_c *pic = gv.gui->get_image(UII_SLIDER);
00068
00069 if (width<32)
00070 resize(32, height);
00071 if (height<32)
00072 resize(width, 32);
00073
00074 if (width>height)
00075 {
00076 ushort imgw = pic->get_width();
00077 ushort imgh = pic->get_height();
00078 ushort ypos = (height-imgh)/2;
00079
00080 for (i=0; i<1+width/imgw; i++)
00081 img->blt(pic->set_frame(1), 0, 0, i*imgw, ypos, imgw, imgh);
00082
00083 img->blt(pic->set_frame(0), 0, 0, 0, ypos, imgw, imgh);
00084 img->blt(pic->set_frame(2), 0, 0, width-imgw, ypos, imgw, imgh);
00085
00086 float xpos = posfrac*(width-32);
00087
00088 img->blt_blend(pic->set_frame(6), 0, 0, 8+(sshort)xpos, ypos, imgw, imgh, BT_BLEND);
00089 }
00090 else
00091 {
00092 ushort imgw = pic->get_width();
00093 ushort imgh = pic->get_height();
00094 ushort xpos = (width-imgw)/2;
00095
00096 for (i=0; i<1+height/imgh; i++)
00097 img->blt(pic->set_frame(4), 0, 0, xpos, i*imgh, imgw, imgh);
00098
00099 img->blt(pic->set_frame(3), 0, 0, xpos, 0, imgw, imgh);
00100 img->blt(pic->set_frame(5), 0, 0, xpos, height-imgh, imgw, imgh);
00101
00102 float ypos = posfrac*(height-32);
00103
00104 img->blt_blend(pic->set_frame(7), 0, 0, xpos, 8+(sshort)ypos, imgw, imgh, BT_BLEND);
00105 }
00106 }
00107
00108 void uislider_c::set_text(const char *txt)
00109 {
00110 AssertThis;
00111
00112 sscanf(txt, "%f %f %f", &min, &max, &pos);
00113 set_needs_refresh();
00114 }
00115
00116 void uislider_c::event(uievent_s *eve)
00117 {
00118 AssertThis;
00119
00120 switch(eve->event)
00121 {
00122 case UIE_MOUSEDOWN:
00123 case UIE_MOUSEUP:
00124 case UIE_MOUSEMOVE:
00125 if (gv.gui->get_focus() == this && gv.mouse_b & 1)
00126 {
00127 float x, p;
00128
00129 if (width>height)
00130 {
00131 x = eve->x-16.0f;
00132 p = x/((float)width-32.0f);
00133 }
00134 else
00135 {
00136 x = eve->y-16.0f;
00137 p = x/((float)height-32.0f);
00138 }
00139
00140 p *= max-min;
00141 p += min;
00142
00143 if (p<min) p = min;
00144 if (p>max) p = max;
00145
00146 set_pos(p);
00147 }
00148 break;
00149 }
00150 uiobject_c::event(eve);
00151 }