2020-03-04 13:09:40 +00:00
|
|
|
int fence;
|
2020-02-29 15:40:55 +00:00
|
|
|
#include <AutoreleasePool.h>
|
|
|
|
|
2020-02-29 05:48:18 +00:00
|
|
|
#include "color.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
#include "qwaq-app.h"
|
2020-03-19 09:41:53 +00:00
|
|
|
#include "qwaq-button.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
#include "qwaq-curses.h"
|
2020-03-19 02:32:44 +00:00
|
|
|
#include "qwaq-group.h"
|
2020-03-19 09:41:53 +00:00
|
|
|
#include "qwaq-listener.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
#include "qwaq-window.h"
|
2020-03-01 09:25:02 +00:00
|
|
|
#include "qwaq-screen.h"
|
|
|
|
#include "qwaq-view.h"
|
2020-02-29 15:40:55 +00:00
|
|
|
|
|
|
|
static AutoreleasePool *autorelease_pool;
|
|
|
|
static void
|
|
|
|
arp_start (void)
|
|
|
|
{
|
|
|
|
autorelease_pool = [[AutoreleasePool alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arp_end (void)
|
|
|
|
{
|
|
|
|
[autorelease_pool release];
|
|
|
|
autorelease_pool = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@implementation QwaqApplication
|
|
|
|
+app
|
|
|
|
{
|
|
|
|
return [[[self alloc] init] autorelease];
|
|
|
|
}
|
|
|
|
|
|
|
|
-init
|
|
|
|
{
|
|
|
|
if (!(self = [super init])) {
|
|
|
|
return nil;
|
|
|
|
}
|
2020-03-05 15:32:09 +00:00
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
initialize ();
|
|
|
|
init_pair (1, COLOR_WHITE, COLOR_BLUE);
|
|
|
|
init_pair (2, COLOR_WHITE, COLOR_BLACK);
|
2020-03-19 09:41:53 +00:00
|
|
|
init_pair (3, COLOR_WHITE, COLOR_GREEN);
|
|
|
|
init_pair (4, COLOR_YELLOW, COLOR_RED);
|
2020-03-05 15:32:09 +00:00
|
|
|
|
2020-03-19 09:41:53 +00:00
|
|
|
screen = [TextContext screen];
|
2020-03-19 07:27:30 +00:00
|
|
|
objects = [[Group alloc] initWithContext: screen owner: nil];
|
2020-03-14 10:45:07 +00:00
|
|
|
|
|
|
|
[screen bkgd: COLOR_PAIR (1)];
|
|
|
|
Rect r = { nil, [screen size] };
|
2020-03-05 06:44:53 +00:00
|
|
|
r.offset.x = r.extent.width / 4;
|
|
|
|
r.offset.y = r.extent.height / 4;
|
|
|
|
r.extent.width /= 2;
|
|
|
|
r.extent.height /= 2;
|
2020-03-19 09:41:53 +00:00
|
|
|
Window *w;
|
|
|
|
[objects insert: w = [[Window windowWithRect: r] setBackground: COLOR_PAIR (2)]];
|
|
|
|
DrawBuffer *released = [DrawBuffer buffer: {12, 1}];
|
|
|
|
DrawBuffer *pressed = [DrawBuffer buffer: {12, 1}];
|
|
|
|
Button *b = [[Button alloc] initWithPos: {3, 4} releasedIcon: released
|
|
|
|
pressedIcon: pressed];
|
|
|
|
[w addView: b];
|
|
|
|
[released bkgd: COLOR_PAIR(3)];
|
|
|
|
[released clear];
|
|
|
|
[released mvaddstr: {2, 0}, "press me"];
|
|
|
|
[pressed bkgd: COLOR_PAIR(4)];
|
|
|
|
[pressed clear];
|
|
|
|
[pressed mvaddstr: {1, 0}, "release me"];
|
|
|
|
[[b onPress] addListener: self message: @selector (buttonPressed:)];
|
|
|
|
[[b onRelease] addListener: self message: @selector (buttonReleased:)];
|
|
|
|
[[b onClick] addListener: self message: @selector (buttonClick:)];
|
|
|
|
[[b onDrag] addListener: self message: @selector (buttonDrag:)];
|
|
|
|
[[b onAuto] addListener: self message: @selector (buttonAuto:)];
|
2020-02-29 15:40:55 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-19 09:41:53 +00:00
|
|
|
-(void) buttonPressed: (id) sender
|
|
|
|
{
|
|
|
|
[screen mvaddstr: {2, 0}, " pressed"];
|
|
|
|
[screen refresh];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) buttonReleased: (id) sender
|
|
|
|
{
|
|
|
|
[screen mvaddstr: {2, 0}, "released"];
|
|
|
|
[screen refresh];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) buttonClick: (id) sender
|
|
|
|
{
|
|
|
|
[screen mvaddstr: {2, 0}, "clicked "];
|
|
|
|
[screen refresh];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) buttonDrag: (id) sender
|
|
|
|
{
|
|
|
|
[screen mvaddstr: {2, 0}, "dragged "];
|
|
|
|
Rect rect = [sender rect];
|
|
|
|
[screen mvprintf: {15, 0}, "%d %d", rect.offset.x, rect.offset.y];
|
|
|
|
[screen refresh];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) buttonAuto: (id) sender
|
|
|
|
{
|
|
|
|
[screen mvprintf: {2, 1}, "%d", autocount++];
|
|
|
|
[screen refresh];
|
|
|
|
}
|
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
-run
|
|
|
|
{
|
2020-03-05 15:32:09 +00:00
|
|
|
[self draw];
|
2020-02-29 15:40:55 +00:00
|
|
|
do {
|
|
|
|
arp_start ();
|
|
|
|
|
|
|
|
get_event (&event);
|
2020-03-04 13:09:40 +00:00
|
|
|
if (event.what != qe_none) {
|
2020-02-29 15:40:55 +00:00
|
|
|
[self handleEvent: &event];
|
|
|
|
}
|
2020-02-27 12:01:09 +00:00
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
arp_end ();
|
|
|
|
} while (!endState);
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-03-12 17:43:01 +00:00
|
|
|
-draw
|
|
|
|
{
|
2020-03-14 10:45:07 +00:00
|
|
|
[objects draw];
|
2020-03-12 17:43:01 +00:00
|
|
|
[TextContext refresh];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
-handleEvent: (qwaq_event_t *) event
|
|
|
|
{
|
2020-03-14 10:45:07 +00:00
|
|
|
[objects handleEvent: event];
|
2020-03-04 13:09:40 +00:00
|
|
|
if (event.what == qe_key && event.key == '\x18') {
|
|
|
|
event.what = qe_command;
|
2020-03-04 10:10:09 +00:00
|
|
|
event.message.command = qc_exit;
|
2020-02-29 15:40:55 +00:00
|
|
|
}
|
2020-03-04 13:09:40 +00:00
|
|
|
if (event.what == qe_command
|
2020-03-04 10:10:09 +00:00
|
|
|
&& (event.message.command == qc_exit
|
|
|
|
|| event.message.command == qc_error)) {
|
|
|
|
endState = event.message.command;
|
2020-02-29 15:40:55 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
int main (int argc, string *argv)
|
|
|
|
{
|
2020-03-04 13:09:40 +00:00
|
|
|
fence = 0;
|
|
|
|
//while (!fence) {}
|
|
|
|
|
2020-02-29 15:40:55 +00:00
|
|
|
id app = [[QwaqApplication app] retain];
|
|
|
|
|
|
|
|
[app run];
|
|
|
|
[app release];
|
|
|
|
qwaq_event_t event;
|
|
|
|
get_event (&event); // XXX need a "wait for queue idle"
|
|
|
|
return 0;
|
|
|
|
}
|