00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include <SDL.h>
00024
#include "guitypedefs.h"
00025
#include "guicolors.h"
00026
#ifdef _WIN32
00027
#pragma warning(push)
00028
00029
#include <yvals.h>
00030
00031
#pragma warning(disable: 4251)
00032
#pragma warning(disable: 4786) // identifier was truncated to 'number' characters in the debug information
00033
00034
00035
00036
00037
00038
#include <sge.h>
00039
00040
#pragma warning(pop)
00041
#else
00042
#include <sge.h>
00043
#endif
00044
00045
#include "SDL_prim.h"
00046
00047
#include "TTFont.h"
00048
#include "SDLControl.h"
00049
#include "Surface.h"
00050
#include "Static.h"
00051
#include "Button.h"
00052
#include "HotButton.h"
00053
#include "ScrollBarV.h"
00054
00055
00056
namespace gui
00057 {
00058
00059
00060 ScrollBarV::ScrollBarV(
Surface *s,
coord_t x,coord_t y,coord_t w,coord_t h,
SurfaceHelper *sh)
00061 :
Surface(s,x,y,w,h,sh)
00062 ,m_up(this, w -
SBSIZE, 0,
BUTTONSTYLE_SBUP)
00063 ,m_down(this, w -
SBSIZE, h -
SBSIZE,
BUTTONSTYLE_SBDOWN)
00064 ,m_pos(0)
00065 ,m_max(100)
00066 ,m_step(1)
00067 {
00068 SetBgColor(128,128,0);
00069 SetFgColor(255,255,128);
00070 SetFrameWidth(0);
00071 SetFrameColor(0,255,128);
00072
00073 AddChild(&
m_up);
00074 AddChild(&
m_down);
00075 }
00076
00077
00078 ScrollBarV::ScrollBarV(
Surface *s,
SurfaceHelper *sh)
00079 :
Surface(s,s -> GetClientRectPtr() -> w -
SBSIZE,0,
00080
SBSIZE,
00081 s -> GetClientRectPtr() -> h -
SBSIZE,
00082 sh)
00083 ,m_up(this, GetW() -
SBSIZE, 0,
BUTTONSTYLE_SBUP)
00084 ,m_down(this, GetW() -
SBSIZE, GetH() -
SBSIZE,
BUTTONSTYLE_SBDOWN)
00085 ,m_pos(0)
00086 ,m_max(100)
00087 ,m_step(1)
00088 {
00089 SetBgColor(128,128,0);
00090 SetFgColor(255,255,128);
00091 SetFrameWidth(0);
00092 SetFrameColor(0,255,128);
00093
00094 AddChild(&
m_up);
00095 AddChild(&
m_down);
00096 }
00097
00098
00099 ScrollBarV::~ScrollBarV()
00100 {
00101 }
00102
00103
00104 void ScrollBarV::SetPos(
long l)
00105 {
00106
m_pos = l;
00107 SetDirty(
true);
00108 }
00109
00110
00111 void ScrollBarV::SetMax(
long l,
long step)
00112 {
00113
m_max = l;
00114
m_step = step;
00115 }
00116
00117
00118 long ScrollBarV::GetPos()
00119 {
00120
return m_pos;
00121 }
00122
00123
00124 void ScrollBarV::OnEvent(
surface_event_t *pstEvent)
00125 {
00126
if (pstEvent -> type ==
GUI_EVENT_BUTTON)
00127 {
00128
if (pstEvent -> local_id ==
m_down.
GetLocalID())
00129 {
00130
if (
m_pos +
m_step <
m_max)
00131 {
00132
m_pos +=
m_step;
00133 SetDirty(
true);
00134 }
00135 }
00136
else
00137
if (pstEvent -> local_id ==
m_up.
GetLocalID())
00138 {
00139
if (
m_pos -
m_step >= 0)
00140 {
00141
m_pos -= m_step;
00142 SetDirty(
true);
00143 }
00144 }
00145 }
00146 }
00147
00148
00149 void ScrollBarV::Draw()
00150 {
00151 SDL_Rect a =
GetClientRect();
00152
long range = a.h - 2 *
SBSIZE -
SBSIZE / 2;
00153
long y;
00154
long h;
00155
00156 SDL_FillRect(m_screen, &a,
GetBgColor());
00157
00158 y = (
m_pos * range) /
m_max +
SBSIZE;
00159 h = (
m_step * range) /
m_max;
00160
if (h <
SBSIZE / 2)
00161 {
00162 h =
SBSIZE / 2;
00163 }
00164 a.y = y;
00165 a.h = h;
00166 SDL_FillRect(m_screen, &a,
GetFgColor());
00167 a.x++;
00168 a.y++;
00169 a.w -= 2;
00170 a.h -= 2;
00171 SDL_FillRect(m_screen, &a,
GetBgColor());
00172 }
00173
00174
00175 }
00176
00177