mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-19 07:20:50 +00:00
[qwaq] Add a button class
It may or may not work just yet, but I think it's the right direction.
This commit is contained in:
parent
6a18b1dd55
commit
bd3884f6fa
3 changed files with 120 additions and 0 deletions
|
@ -25,6 +25,7 @@ SUFFIXES=.o .r
|
|||
|
||||
qwaq_app_dat_src= \
|
||||
qwaq-app.r \
|
||||
qwaq-button.r \
|
||||
qwaq-draw.r \
|
||||
qwaq-garray.r \
|
||||
qwaq-group.r \
|
||||
|
|
28
ruamoko/qwaq/qwaq-button.h
Normal file
28
ruamoko/qwaq/qwaq-button.h
Normal file
|
@ -0,0 +1,28 @@
|
|||
#ifndef __qwaq_button_h
|
||||
#define __qwaq_button_h
|
||||
|
||||
#include "qwaq-draw.h"
|
||||
#include "qwaq-view.h"
|
||||
|
||||
@class ListenerGroup;
|
||||
|
||||
@interface Button : View
|
||||
{
|
||||
DrawBuffer *icon[2];
|
||||
int pressed;
|
||||
ListenerGroup *onPress;
|
||||
ListenerGroup *onRelease;
|
||||
ListenerGroup *onClick;
|
||||
ListenerGroup *onDrag;
|
||||
ListenerGroup *onAuto;
|
||||
}
|
||||
-initWithPos: (Point) pos releasedIcon: (DrawBuffer *) released
|
||||
pressedIcon: (DrawBuffer *) pressed;
|
||||
-(ListenerGroup *) onPress;
|
||||
-(ListenerGroup *) onRelease;
|
||||
-(ListenerGroup *) onClick;
|
||||
-(ListenerGroup *) onDrag;
|
||||
-(ListenerGroup *) onAuto;
|
||||
@end
|
||||
|
||||
#endif//__qwaq_button_h
|
91
ruamoko/qwaq/qwaq-button.r
Normal file
91
ruamoko/qwaq/qwaq-button.r
Normal file
|
@ -0,0 +1,91 @@
|
|||
#include "qwaq-button.h"
|
||||
#include "qwaq-listener.h"
|
||||
|
||||
@implementation Button
|
||||
-initWithPos: (Point) pos releasedIcon: (DrawBuffer *) released
|
||||
pressedIcon: (DrawBuffer *) pressed
|
||||
{
|
||||
Extent size = mergeExtents ([released size], [pressed size]);
|
||||
|
||||
if (!(self = [super initWithRect: {pos, size}])) {
|
||||
return nil;
|
||||
}
|
||||
icon[0] = released;
|
||||
icon[1] = pressed;
|
||||
onPress = [[ListenerGroup alloc] init];
|
||||
onRelease = [[ListenerGroup alloc] init];
|
||||
onClick = [[ListenerGroup alloc] init];
|
||||
onDrag = [[ListenerGroup alloc] init];
|
||||
onAuto = [[ListenerGroup alloc] init];
|
||||
return self;
|
||||
}
|
||||
|
||||
-draw
|
||||
{
|
||||
[textContext blitFromBuffer: icon[pressed]
|
||||
to: pos
|
||||
from: [icon[pressed] rect]];
|
||||
return self;
|
||||
}
|
||||
|
||||
-handleEvent: (qwaq_event_t *) event
|
||||
{
|
||||
ListenerGroup *action = nil;
|
||||
|
||||
if (event.what & qe_mouse) {
|
||||
switch ((qwaq_mouse_event) (event.what & qe_mouse)) {
|
||||
case qe_mousedown:
|
||||
pressed = 1;
|
||||
[self redraw];
|
||||
action = onPress;
|
||||
break;
|
||||
case qe_mouseup:
|
||||
pressed = 0;
|
||||
[self redraw];
|
||||
action = onRelease;
|
||||
break;
|
||||
case qe_mouseclick:
|
||||
action = onClick;
|
||||
break;
|
||||
case qe_mousemove:
|
||||
if (pressed) {
|
||||
action = onDrag;
|
||||
}
|
||||
break;
|
||||
case qe_mouseauto:
|
||||
action = onAuto;
|
||||
break;
|
||||
}
|
||||
if (action) {
|
||||
[action respond: self];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(ListenerGroup *) onPress
|
||||
{
|
||||
return onPress;
|
||||
}
|
||||
|
||||
-(ListenerGroup *) onRelease
|
||||
{
|
||||
return onRelease;
|
||||
}
|
||||
|
||||
-(ListenerGroup *) onClick
|
||||
{
|
||||
return onClick;
|
||||
}
|
||||
|
||||
-(ListenerGroup *) onDrag
|
||||
{
|
||||
return onDrag;
|
||||
}
|
||||
|
||||
-(ListenerGroup *) onAuto
|
||||
{
|
||||
return onAuto;
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in a new issue