8
#define output core->output()
10
static void putChar(unsigned char character,int x,int y,int red,int blue)
12
unsigned short *ptr = ((unsigned short *)output) + x + y*core->outWidth;
13
unsigned short put = (blue<<8)+red;
15
for(i=0;i<8;i++,ptr += core->outWidth-8)
16
for(j=0;j<8;j++,ptr++)
17
if (font[character*8+i] & (128>>j))
21
void Interface::putString(char *string,int x,int y,int red,int blue)
23
if (x < 0 || y < 0 || y >= core->outHeight-8)
25
for(;*string && x <= core->outWidth-8;string++,x+=8)
26
putChar((unsigned char)(*string),x,y,red,blue);
29
void UIObject::changed()
33
struct Button : public UIObject
40
Button(int _am,int _vm,double _x,double _y,
41
double _size,int _icon,char _key = 0,
42
bool _passive = false, bool _bright = false)
44
activeMask = _am; visibleMask = _vm;
45
x = _x; y = _y; width = height = _size;
46
icon = _icon; hotKey = _key; passive = _passive; bright = _bright;
49
int go(bool mouseDown,bool mouseClick,bool mouseOver,
50
double _x, double _y, double scale, char &_hotKey, int &action)
55
core->polygonEngine.icon(
57
(bright ? 0x0202 : 0x0100),
58
x*scale,y*scale,width*scale,height*scale);
60
if (mouseOver && !passive)
61
core->polygonEngine.icon(
64
(x-IconWidths[icon]*width/2)*scale,
65
(y-height/2)*scale,width*scale*2,height*scale*2);
67
if (mouseOver && mouseClick && !passive)
70
if (mouseOver && !passive && hotKey)
76
void handleKey(char key, int &action)
78
if (key == hotKey && !passive)
83
struct SliderBar : public UIObject
86
char leftKey, rightKey;
88
typedef void (Core::*Callback)(double v);
91
SliderBar(int _am,int _vm,double _x,double _y,
92
double _width,double _height, double *_value,
93
Callback _callback, char _leftKey, char _rightKey)
95
activeMask = _am; visibleMask = _vm;
96
x = _x; y = _y; width = _width; height = _height;
97
value = _value; callback = _callback;
98
leftKey = _leftKey; rightKey = _rightKey;
101
int go(bool mouseDown,bool mouseClick,bool mouseOver,
102
double _x, double _y, double scale, char &_hotKey, int &action)
107
core->polygonEngine.icon(
110
x*scale,y*scale,width*scale,height*scale);
111
core->polygonEngine.icon(
114
(x+*value*width-IconWidths[Slider]*height/2)*scale,
115
y*scale,height*scale,height*scale);
119
double newValue = (_x)/(width);
120
if (newValue < 0.0) newValue = 0.0;
121
if (newValue > 1.0) newValue = 1.0;
123
core->polygonEngine.icon(
126
(x+newValue*width-IconWidths[Selector]*height/2)*scale,
127
y*scale,height*scale,height*scale);
134
(core->*callback)(*value);
139
_hotKey = (newValue < *value ? leftKey : rightKey);
144
void handleKey(char key, int &action)
147
if (key == leftKey || key == rightKey)
151
if (*value == 0.0) return;
153
if (*value < 0.0) *value = 0.0;
157
if (*value == 1.0) return;
159
if (*value > 1.0) *value = 1.0;
163
(core->*callback)(*value);
171
struct PopperUpper : public UIObject
175
PopperUpper(int _am,int _vm,double _x,double _y,
176
double _width,double _height, int _maskAdd)
178
activeMask = _am; visibleMask = _vm;
179
x = _x; y = _y; width = _width; height = _height;
183
int go(bool mouseDown,bool mouseClick, bool mouseOver,
184
double _x, double _y, double scale, char &_hotKey, int &action)
193
core->polygonEngine.icon(
196
x*scale,y*scale,width*scale,height*scale);
198
return mouseOver ? maskAdd : 0;
201
void handleKey(char key, int &action)
208
void Interface::setupPalette()
210
#define BOUND(x) ((x) > 255 ? 255 : (x))
211
#define PEAKIFY(x) int(BOUND((x) - (x)*(255-(x))/255/2))
212
#define MAX(x,y) ((x) > (y) ? (x) : (y))
214
unsigned char palette[768];
216
double scale, fgRed, fgGreen, fgBlue, bgRed, bgGreen, bgBlue;
217
fgRed = core->fgRedSlider;
218
fgGreen = core->fgGreenSlider;
219
fgBlue = 1.0 - MAX(core->fgRedSlider,core->fgGreenSlider);
220
scale = MAX(MAX(fgRed,fgGreen),fgBlue);
225
bgRed = core->bgRedSlider;
226
bgGreen = core->bgGreenSlider;
227
bgBlue = 1.0 - MAX(core->bgRedSlider, core->bgGreenSlider);
228
scale = MAX(MAX(bgRed, bgGreen), bgBlue);
235
int f = i&15, b = i/16;
236
palette[i*3+0] = PEAKIFY(b*bgRed*16+f*fgRed*16);
237
palette[i*3+1] = PEAKIFY(b*bgGreen*16+f*fgGreen*16);
238
palette[i*3+2] = PEAKIFY(b*bgBlue*16+f*fgBlue*16);
240
core->screen->setPalette(palette);
262
// TODO Lay things out with parents and a stack, like QT
263
Interface::Interface()
265
static const float IconSize=0.2;
266
static const float SliderSize=0.125;
269
KConfig config("noatun/synaescope", false, false, "data");
270
core->fadeMode=(SymbolID)config.readNumEntry("mode", (int)Stars);
271
core->pointsAreDiamonds=config.readBoolEntry("diamonds", false);
272
core->brightnessTwiddler=config.readDoubleNumEntry("brightness", .4);
273
core->starSize=config.readDoubleNumEntry("starsize", .1);
274
core->fgRedSlider=config.readDoubleNumEntry("FGRed", 0.0);
275
core->fgGreenSlider=config.readDoubleNumEntry("FGgreen", 1.0);
276
core->bgRedSlider=config.readDoubleNumEntry("BGRed", 0.0);
277
core->bgGreenSlider=config.readDoubleNumEntry("BGGreen", 0.0);
280
uiObjects.setAutoDelete(true);
284
//addUI(new Button(ALL,0.025,0.525,IconSize, 0, 'x'));
285
// addUI(new PopperUpper(ALL,ALL,0,0,0.25,0.25, BUTTONBAR));
286
// addUI(stateButton = new Button(ALL,ALL,0.05,0.025,IconSize, 0, 0, true, false));
288
addUI(new PopperUpper(ALL,BUTTONBAR,x=0.25,y=0,1.375,0.25, BUTTONBAR));
289
// x += 0.1; y += 0.025;
291
// addUI(new PopperUpper(PLAYING|PAUSED|STOPPED, ALL,0,0.25,0.25,0.25, TRACKBAR));
292
// addUI(new PopperUpper(PLAYING|PAUSED|STOPPED, TRACKBAR,x=0.25,y=0.25,1.0,0.625, TRACKBAR));
293
// x += 0.1; y += 0.1;
295
addUI(new PopperUpper(ALL,ALL,0,0.0,0.25,0.25, DIALBAR));
296
addUI(new Button(ALL,ALL,0.075,0.05,IconSize, Bulb, 0, true, false));
298
addUI(new PopperUpper(ALL,DIALBAR,x=0.25,y=0.0,1.25,1.0, DIALBAR));
299
x += 0.05; y += 0.025;
301
addUI(starsButton = new Button(ALL,DIALBAR,x,y,IconSize, Stars, 'd'));
302
addUI(waveButton = new Button(ALL,DIALBAR,x+IconSize,y,IconSize, Wave, 'f'));
303
addUI(flameButton = new Button(ALL,DIALBAR,x+IconSize*2.5,y,IconSize, Flame, 'g'));
305
addUI(starButton = new Button(ALL,DIALBAR,x+IconSize*3.5,y,IconSize, Star, 'h'));
306
addUI(diamondButton = new Button(ALL,DIALBAR,x+IconSize*4.5,y,IconSize, Diamond, 'j'));
310
addUI(new Button(ALL,DIALBAR,x,y-0.05,IconSize, Bulb, 0, true));
311
addUI(new SliderBar(ALL,DIALBAR,
312
x+IconSize,y, 0.75, SliderSize, &core->brightnessTwiddler, /*&Core::setBrightness,*/0, 'z', 'x'));
314
addUI(new Button(ALL,DIALBAR,x,y+SliderSize*1,IconSize, Size, 'x', true));
315
addUI(new SliderBar(ALL,DIALBAR,
316
x+IconSize,y+SliderSize, 0.75, SliderSize, &core->starSize, &Core::setStarSize, 'c','v'));
318
addUI(new Button(ALL,DIALBAR,x+0.5,y+SliderSize*2-0.025,IconSize, FgColor, 0, true));
319
addUI(new SliderBar(ALL,DIALBAR,
320
x,y+SliderSize*2, 0.45, SliderSize, &(core->fgRedSlider), &Core::setupPalette, 'b','n'));
321
addUI(new SliderBar(ALL,DIALBAR,
322
x+0.5+SliderSize,y+SliderSize*2, 0.45, SliderSize, &core->fgGreenSlider, &Core::setupPalette, 'm',','));
324
addUI(new Button(ALL,DIALBAR,x+0.5,y+SliderSize*3,IconSize, BgColor, 0, true));
325
addUI(new SliderBar(ALL,DIALBAR,
326
x,y+SliderSize*3, 0.45, SliderSize, &core->bgRedSlider, &Core::setupPalette, 'B','N'));
327
addUI(new SliderBar(ALL,DIALBAR,
328
x+0.5+SliderSize,y+SliderSize*3, 0.45, SliderSize, &core->bgGreenSlider, &Core::setupPalette, 'M','<'));
330
x += 0.1;// y += 0.0625;
331
//static double value = 0.5;
332
//addUI(new SliderBar(ALL,0,0.75,1.0,0.25,&value));
334
//addUI(new Button(BUTTONBAR,x,y,IconSize, 1, 'x'));
335
//addUI(new Button(BUTTONBAR,x += IconSize,y,IconSize, 2, 'x'));
336
//addUI(new Button(BUTTONBAR,x += IconSize,y,IconSize, 3, 'x'));
350
Interface::~Interface()
352
KConfig config("noatun/synaescope", false, false, "data");
353
config.writeEntry("mode",core->fadeMode);
354
config.writeEntry("diamonds", core->pointsAreDiamonds);
355
config.writeEntry("brightness", core->brightnessTwiddler);
356
config.writeEntry("starsize", core->starSize);
357
config.writeEntry("FGRed", core->fgRedSlider);
358
config.writeEntry("FGgreen", core->fgGreenSlider);
359
config.writeEntry("BGRed", core->bgRedSlider);
360
config.writeEntry("BGGreen", core->bgGreenSlider);
363
void Interface::addUI(UIObject *obj)
365
uiObjects.append(obj);
368
void Interface::syncToState()
370
starsButton->bright = (core->fadeMode == Stars);
371
flameButton->bright = (core->fadeMode == Flame);
372
waveButton->bright = (core->fadeMode == Wave);
374
starButton->bright = !core->pointsAreDiamonds;
375
diamondButton->bright = core->pointsAreDiamonds;
380
void Interface::changeState(int transitionSymbol)
382
if (transitionSymbol < 0)
388
switch(transitionSymbol)
391
starsButton->bright = false;
392
flameButton->bright = true;
393
waveButton->bright = false;
394
core->fadeMode = Flame;
395
core->setStarSize(core->starSize);
398
starsButton->bright = false;
399
flameButton->bright = false;
400
waveButton->bright = true;
401
core->fadeMode = Wave;
402
core->setStarSize(core->starSize);
405
starsButton->bright = true;
406
flameButton->bright = false;
407
waveButton->bright = false;
408
core->fadeMode = Stars;
409
core->setStarSize(core->starSize);
413
core->pointsAreDiamonds = false;
414
starButton->bright = true;
415
diamondButton->bright = false;
418
core->pointsAreDiamonds = true;
419
starButton->bright = false;
420
diamondButton->bright = true;
431
int newVisibleMask = ALL;
433
int action = NotASymbol;
434
int oldButtons = mouseButtons;
436
core->screen->sizeUpdate();
437
if (!core->screen->inputUpdate(mouseX,mouseY,mouseButtons,keyHit))
440
bool mouseClick = (mouseButtons && !oldButtons);
442
if ((mouseX != lastX || mouseY != lastY) &&
443
lastX > 0 && lastY > 0 &&
444
lastX < core->outWidth && lastY < core->outHeight)
447
int activeMask = ALL;
454
(core->outWidth*0.625 < core->outHeight ? core->outWidth*0.625 : core->outHeight);
455
double scaledX = mouseX / scale;
456
double scaledY = mouseY / scale;
460
core->polygonEngine.clear();
462
// stateButton->icon = core->state;
465
for (UIObject *i=uiObjects.first(); i!=0; i = uiObjects.next())
467
if ((i->visibleMask & visibleMask) && (i->activeMask & activeMask))
468
newVisibleMask |= i->go(mouseButtons,mouseClick,
471
scaledX < i->x+i->width &&
472
scaledY < i->y+i->height),
480
visibleMask = newVisibleMask;
481
if (visibleMask != 1)
484
core->polygonEngine.icon(Icons[Pointer],0x0303,mouseX,mouseY,50,50);
486
core->polygonEngine.apply(core->outputBmp.data);
490
putString(hint,mouseX+6,mouseY+7,0,0);
494
for(UIObject *i=uiObjects.first(); i!=0; i = uiObjects.next())
495
if (i->activeMask & activeMask)
496
i->handleKey(keyHit,action);