00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <stdlib.h>
00021 #include <stdio.h>
00022 #include "scrollbar.h"
00023 #include "globals.h"
00024 #include "fonts.h"
00025 glictScrollbar::glictScrollbar() {
00026
00027 this->containeroffsetx = 0;
00028 this->containeroffsety = 0;
00029
00030
00031 this->bgcolor.r = 0.75;
00032 this->bgcolor.g = 0.75;
00033 this->bgcolor.b = 0.75;
00034 this->bgcolor.a = 1.0;
00035 strcpy(this->objtype, "Scrollbar");
00036
00037 this->parent = NULL;
00038
00039 this->focusable = true;
00040
00041 this->SetHeight(100);
00042 this->SetWidth(10);
00043
00044 this->SetPos(0,0);
00045
00046 this->highlightdn = false;
00047 this->highlightup = false;
00048
00049 this->min = 0;
00050 this->max = 100;
00051 this->value = 0;
00052 this->step = 1;
00053
00054
00055 }
00056 glictScrollbar::~glictScrollbar() {
00057
00058 }
00059 void glictScrollbar::Paint() {
00060 if (!GetVisible()) return;
00061
00062
00063 glictColor col;
00064 if (!highlightup) {
00065 col = bgcolor;
00066 } else {
00067 col.r = this->bgcolor.r < .5 ? (float)this->bgcolor.r * 1.5 : (float)this->bgcolor.r / 1.5;
00068 col.g = this->bgcolor.g < .5 ? (float)this->bgcolor.g * 1.5 : (float)this->bgcolor.g / 1.5;
00069 col.b = this->bgcolor.b < .5 ? (float)this->bgcolor.b * 1.5 : (float)this->bgcolor.b / 1.5;
00070 col.a = this->bgcolor.a < .5 ? (float)this->bgcolor.a * 1.5 : (float)this->bgcolor.a / 1.5;
00071 }
00072 glictGlobals.PaintRect(this->x+glictGlobals.translation.x,this->x+this->width+glictGlobals.translation.x,
00073 this->y+glictGlobals.translation.y, this->y+this->width+glictGlobals.translation.y,
00074 col);
00075
00076
00077 if (!highlightdn) {
00078 col = bgcolor;
00079 } else {
00080 col.r = this->bgcolor.r < .5 ? (float)this->bgcolor.r * 1.5 : (float)this->bgcolor.r / 1.5;
00081 col.g = this->bgcolor.g < .5 ? (float)this->bgcolor.g * 1.5 : (float)this->bgcolor.g / 1.5;
00082 col.b = this->bgcolor.b < .5 ? (float)this->bgcolor.b * 1.5 : (float)this->bgcolor.b / 1.5;
00083 col.a = this->bgcolor.a < .5 ? (float)this->bgcolor.a * 1.5 : (float)this->bgcolor.a / 1.5;
00084 }
00085 glictGlobals.PaintRect(this->x+glictGlobals.translation.x,this->x+this->width+glictGlobals.translation.x,
00086 this->y+this->height-this->width+glictGlobals.translation.y,this->y+this->height+glictGlobals.translation.y,
00087 col);
00088
00089
00090 col.r = bgcolor.r * 0.7;
00091 col.g = bgcolor.g * 0.7;
00092 col.b = bgcolor.b * 0.7;
00093 col.a = bgcolor.a;
00094 glictGlobals.PaintRect(this->x+glictGlobals.translation.x, this->x+this->width+glictGlobals.translation.x,
00095 this->y+this->width+glictGlobals.translation.y,this->y+this->height-this->width+glictGlobals.translation.y, col);
00096
00097
00098
00099 col.r = bgcolor.r * 0.8;
00100 col.g = bgcolor.g * 0.8;
00101 col.b = bgcolor.b * 0.8;
00102 col.a = bgcolor.a;
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 glictGlobals.PaintRect(
00122 this->x+glictGlobals.translation.x,
00123 this->x + this->width +glictGlobals.translation.x,
00124
00125 this->y +glictGlobals.translation.y +
00126 this->width +
00127 ((float)(this->value-this->min) / (float)(this->max - this->min))
00128 * (float)(this->height - this->width*2 - this->width),
00129
00130 this->y +glictGlobals.translation.y +
00131 this->width +
00132 ((float)(this->value-this->min) / (float)(this->max - this->min))
00133 * (float)(this->height - this->width*2 - this->width)
00134 + this->width
00135
00136 ,col
00137 );
00138 this->CPaint();
00139
00140
00141 this->SetScissor();
00142
00143
00144 glictGlobals.SetColor(1., 1., 1., 1.);
00145
00146
00147
00148 glictFontRender("^","system",
00149 this->x + (this->width / 2 - glictFontSize("^", "system") / 2 +glictGlobals.translation.x) ,
00150 this->y - 9 + width / 2 + 9/2 +glictGlobals.translation.y);
00151
00152 glictFontRender("V","system",
00153 this->x + (this->width / 2 - glictFontSize("V", "system") / 2 +glictGlobals.translation.x) ,
00154 this->y + this->height - width / 2 - 9 / 2 +glictGlobals.translation.y);
00155
00156
00157 }
00158
00159 void glictScrollbar::SetBGColor(float r, float g, float b, float a) {
00160 this->bgcolor.r = r;
00161 this->bgcolor.g = g;
00162 this->bgcolor.b = b;
00163 this->bgcolor.a = a;
00164
00165 }
00166
00167 bool glictScrollbar::CastEvent(glictEvents evt, void* wparam, long lparam, void* returnvalue) {
00168
00169 if (!GetVisible()) return false;
00170 int oldx = this->x, oldy = this->y;
00171 if (evt == GLICT_MOUSECLICK || evt == GLICT_MOUSEDOWN || evt == GLICT_MOUSEUP) {
00172 if (((glictPos*)wparam)->x > this->clipleft &&
00173 ((glictPos*)wparam)->x < this->clipright &&
00174 ((glictPos*)wparam)->y > this->cliptop &&
00175 ((glictPos*)wparam)->y < this->clipbottom) {
00176
00177
00178
00179
00180 if (evt == GLICT_MOUSECLICK) {
00181 this->Focus(this);
00182 if (((glictPos*)wparam)->y - this->top < this->width) {
00183 if (this->value > this->min) this->value -= this->step;
00184 if (this->value < this->min) this->value = this->min;
00185 }
00186 if (((glictPos*)wparam)->y - this->top > this->height - this->width) {
00187 if (this->value < this->max) this->value += this->step;
00188 if (this->value > this->max) this->value = this->max;
00189 }
00190 }
00191 if (evt == GLICT_MOUSEDOWN) {
00192 if (((glictPos*)wparam)->y - this->top < this->width) {
00193 this->highlightup = true;
00194 }
00195 if (((glictPos*)wparam)->y - this->top > this->height - this->width) {
00196 this->highlightdn = true;
00197 }
00198 }
00199 if (evt == GLICT_MOUSEUP) {
00200 this->highlightdn = false;
00201 this->highlightup = false;
00202 }
00203
00204 }
00205 return DefaultCastEvent(evt, wparam, lparam, returnvalue);
00206 }
00207
00208 return false;
00209 }
00210
00211 void glictScrollbar::SetValue(int val) {
00212 this->value = val;
00213 }
00214 int glictScrollbar::GetValue() {
00215 return this->value;
00216 }
00217 void glictScrollbar::SetStep (unsigned int newstep) {
00218 this->step = newstep;
00219 }
00220 unsigned int glictScrollbar::GetStep() {
00221 return this->step;
00222 }
00223 void glictScrollbar::SetMin (int newmin) {
00224 this->min = newmin;
00225 }
00226 int glictScrollbar::GetMin() {
00227 return min;
00228 }
00229 void glictScrollbar::SetMax (int newmax) {
00230 this->max = newmax;
00231 }
00232 int glictScrollbar::GetMax() {
00233 return this->max;
00234 }
00235
00236
00237