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

ui_slider.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_slider.cpp,v 1.1.1.1 2002/12/07 19:02:03 kolrabi Exp $ 
00026 
00027 /*
00028 
00029   $Log: ui_slider.cpp,v $
00030   Revision 1.1.1.1  2002/12/07 19:02:03  kolrabi
00031   initial release
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 }

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