diff --git a/ruamoko/qwaq/Makemodule.am b/ruamoko/qwaq/Makemodule.am index 79a16aef0..43c306003 100644 --- a/ruamoko/qwaq/Makemodule.am +++ b/ruamoko/qwaq/Makemodule.am @@ -57,6 +57,10 @@ qwaq_app_dat_src= \ ruamoko/qwaq/editor/status.r qwaq_input_app_dat_src= \ + ruamoko/qwaq/device/axisdata.r \ + ruamoko/qwaq/device/axisview.r \ + ruamoko/qwaq/device/nameview.r \ + ruamoko/qwaq/device/device.r \ ruamoko/qwaq/qwaq-input.r \ ruamoko/qwaq/input-app.r diff --git a/ruamoko/qwaq/builtins/input.c b/ruamoko/qwaq/builtins/input.c index 5c7b5bfb5..3affcdcc7 100644 --- a/ruamoko/qwaq/builtins/input.c +++ b/ruamoko/qwaq/builtins/input.c @@ -625,7 +625,6 @@ bi_get_device_info (progs_t *pr) qwaq_input_resources_t *res = PR_Resources_Find (pr, "input"); int devid = P_INT (pr, 0); - Sys_Printf ("qwaq_get_device_info: %d\n", devid); int command[] = { qwaq_cmd_get_device_info, 0, devid, diff --git a/ruamoko/qwaq/device/axisdata.h b/ruamoko/qwaq/device/axisdata.h new file mode 100644 index 000000000..c743bad3d --- /dev/null +++ b/ruamoko/qwaq/device/axisdata.h @@ -0,0 +1,19 @@ +#ifndef __qwaq_device_axisdata_h +#define __qwaq_device_axisdata_h + +#include "ruamoko/qwaq/qwaq-input.h" +#include "ruamoko/qwaq/ui/tableview.h" + +@class AxisView; + +@interface AxisData : Object +{ + int numaxes; + in_axisinfo_t *axes; + AxisView **axis_views; +} ++withDevice:(qwaq_devinfo_t *)device; +-updateAxis:(int)axis value:(int)value; +@end + +#endif//__qwaq_device_axisdata_h diff --git a/ruamoko/qwaq/device/axisdata.r b/ruamoko/qwaq/device/axisdata.r new file mode 100644 index 000000000..5fa92c270 --- /dev/null +++ b/ruamoko/qwaq/device/axisdata.r @@ -0,0 +1,58 @@ +#include "ruamoko/qwaq/device/axisdata.h" +#include "ruamoko/qwaq/device/axisview.h" + +@implementation AxisData + +-initWithDevice:(qwaq_devinfo_t *)device +{ + if (!(self = [super init])) { + return nil; + } + numaxes = device.numaxes; + axes = device.axes; + axis_views = obj_malloc (numaxes); + for (int i = 0; i < numaxes; i++) { + axis_views[i] = [[AxisView withAxis:&axes[i]] retain]; + } + return self; +} + ++withDevice:(qwaq_devinfo_t *)device +{ + return [[[self alloc] initWithDevice:device] autorelease]; +} + +-(void)dalloc +{ +} + +-updateAxis:(int)axis value:(int)value +{ + axes[axis].value = value; + return self; +} + +-(ListenerGroup *)onRowCountChanged +{ + return nil; +} + +-(int)numberOfRows:(TableView *)tableview +{ + return numaxes; +} + +-(View *)tableView:(TableView *)tableview + forColumn:(TableViewColumn *)column + row:(int)row +{ + View *view = nil; + + if (row >= 0 && row < numaxes) { + AxisView *av = axis_views[row]; + view = [av viewAtRow:0 forColumn:column]; + } + return view; +} + +@end diff --git a/ruamoko/qwaq/device/axisview.h b/ruamoko/qwaq/device/axisview.h new file mode 100644 index 000000000..4ea867b9d --- /dev/null +++ b/ruamoko/qwaq/device/axisview.h @@ -0,0 +1,18 @@ +#ifndef __qwaq_device_axisview_h +#define __qwaq_device_axisview_h + +#include "ruamoko/qwaq/qwaq-input.h" +#include "ruamoko/qwaq/ui/view.h" + +@class TableViewColumn; + +@interface AxisView : View +{ + in_axisinfo_t *axis; +} ++withAxis:(in_axisinfo_t *)axis; +-(int)rows; +-(View *)viewAtRow:(int)row forColumn:(TableViewColumn *)column; +@end + +#endif//__qwaq_device_axisview_h diff --git a/ruamoko/qwaq/device/axisview.r b/ruamoko/qwaq/device/axisview.r new file mode 100644 index 000000000..621af66b1 --- /dev/null +++ b/ruamoko/qwaq/device/axisview.r @@ -0,0 +1,42 @@ +#include +#include "ruamoko/qwaq/ui/tableview.h" +#include "ruamoko/qwaq/device/axisview.h" +#include "ruamoko/qwaq/device/nameview.h" + +@implementation AxisView + +-initWithAxis:(in_axisinfo_t *)axis +{ + if (!(self = [super init])) { + return nil; + } + self.axis = axis; + return self; +} + ++withAxis:(in_axisinfo_t *)axis +{ + return [[[self alloc] initWithAxis:axis] retain]; +} + +-draw +{ + [super draw]; + [self mvprintf:{0, 0}, "%*.*d", xlen, xlen, axis.value]; + return self; +} + +-(int)rows +{ + return 1; +} + +-(View *)viewAtRow:(int)row forColumn:(TableViewColumn *)column +{ + if ([column name] == "axis") { + return [NameView withName:sprintf("%d", axis.axis)]; + } + return self; +} + +@end diff --git a/ruamoko/qwaq/device/device.h b/ruamoko/qwaq/device/device.h new file mode 100644 index 000000000..df287b4ce --- /dev/null +++ b/ruamoko/qwaq/device/device.h @@ -0,0 +1,26 @@ +#ifndef __qwaq_device_device_h +#define __qwaq_device_device_h + +#include "ruamoko/qwaq/qwaq-input.h" + +@class Window; +@class TableView; +@class AxisData; + +@interface Device : Object +{ + int devid; + qwaq_devinfo_t *device; + + Window *window; + TableView *axis_view; + AxisData *axis_data; +} ++withDevice:(qwaq_devinfo_t *)device id:(int)devid; +-updateAxis:(int)axis value:(int)value; +-updateButton:(int)button state:(int)state; +-(int)devid; +-redraw; +@end + +#endif//__qwaq_device_device_h diff --git a/ruamoko/qwaq/device/device.r b/ruamoko/qwaq/device/device.r new file mode 100644 index 000000000..9ae04c628 --- /dev/null +++ b/ruamoko/qwaq/device/device.r @@ -0,0 +1,77 @@ +#include +#include "ruamoko/qwaq/input-app.h" +#include "ruamoko/qwaq/ui/scrollbar.h" +#include "ruamoko/qwaq/ui/stringview.h" +#include "ruamoko/qwaq/ui/tableview.h" +#include "ruamoko/qwaq/ui/window.h" +#include "ruamoko/qwaq/device/axisdata.h" +#include "ruamoko/qwaq/device/device.h" + +@implementation Device + +-initWithDevice:(qwaq_devinfo_t *)device id:(int)devid +{ + if (!(self = [super init])) { + return nil; + } + self.device = device; + self.devid = devid; + + window = [Window withRect:{{0, 0}, {40, 10}}]; + [window setBackground: color_palette[064]]; + [window setTitle: device.id]; + + [window insert:[StringView withRect:{{1, 1}, {38, 1}} string:device.name]]; + axis_data = [[AxisData withDevice:device] retain]; + axis_view = [TableView withRect:{{1, 2}, {38, 7}}]; + [axis_view addColumn:[TableViewColumn named:"axis" width:3]]; + [axis_view addColumn:[TableViewColumn named:"value" width:6]]; + ScrollBar *sb = [ScrollBar vertical:7 at:{39, 2}]; + [axis_view setVerticalScrollBar:sb]; + [axis_view setDataSource:axis_data]; + [window insertSelected: axis_view]; + [window insert: sb]; + [application addView: window]; + + return self; +} + ++withDevice:(qwaq_devinfo_t *)device id:(int)devid +{ + return [[[self alloc] initWithDevice:device id:devid] autorelease]; +} + +-(void)dealloc +{ + obj_free (device.axes); + obj_free (device.buttons); + str_free (device.name); + str_free (device.id); + obj_free (device); + + [application removeView:window]; +} + +-updateAxis:(int)axis value:(int)value +{ + [axis_data updateAxis:axis value:value]; + return self; +} + +-updateButton:(int)button state:(int)state +{ + return self; +} + +-(int)devid +{ + return devid; +} + +-redraw +{ + [axis_view redraw]; + return self; +} + +@end diff --git a/ruamoko/qwaq/device/nameview.h b/ruamoko/qwaq/device/nameview.h index ee5622062..8ba0a8df8 100644 --- a/ruamoko/qwaq/device/nameview.h +++ b/ruamoko/qwaq/device/nameview.h @@ -3,7 +3,7 @@ #include "ruamoko/qwaq/debugger/views/defview.h" -@interface NameView : DefView +@interface NameView : View { string name; } diff --git a/ruamoko/qwaq/device/nameview.r b/ruamoko/qwaq/device/nameview.r index 6393acfd2..5568870e6 100644 --- a/ruamoko/qwaq/device/nameview.r +++ b/ruamoko/qwaq/device/nameview.r @@ -1,11 +1,11 @@ #include -#include "ruamoko/qwaq/debugger/views/nameview.h" +#include "ruamoko/qwaq/device/nameview.h" @implementation NameView -initWithName:(string)name { - if (!(self = [super initWithDef:def type:nil])) { + if (!(self = [super init])) { return nil; } self.name = name; diff --git a/ruamoko/qwaq/input-app.h b/ruamoko/qwaq/input-app.h index 1fd908bb2..7947b13bb 100644 --- a/ruamoko/qwaq/input-app.h +++ b/ruamoko/qwaq/input-app.h @@ -23,10 +23,13 @@ extern int color_palette[64]; TextContext *screen; Extent screenSize; int autocount; + + Array *devices; } -(Extent)size; -(TextContext *)screen; -addView:(View *)view; +-removeView:(View *)view; -run; @end diff --git a/ruamoko/qwaq/input-app.r b/ruamoko/qwaq/input-app.r index fe8243ee4..550a91f70 100644 --- a/ruamoko/qwaq/input-app.r +++ b/ruamoko/qwaq/input-app.r @@ -8,6 +8,7 @@ int fence; #include "ruamoko/qwaq/ui/curses.h" #include "ruamoko/qwaq/ui/group.h" #include "ruamoko/qwaq/ui/view.h" +#include "ruamoko/qwaq/device/device.h" #include "ruamoko/qwaq/qwaq-input.h" #include "ruamoko/qwaq/input-app.h" @@ -58,6 +59,8 @@ arp_end (void) [screen clear]; wrefresh (stdscr);//FIXME + devices = [[Array array] retain]; + send_connected_devices (); return self; @@ -105,33 +108,41 @@ arp_end (void) { int devid = event.message.int_val; qwaq_devinfo_t *dev = get_device_info (devid); - [screen printf:"dev add: %d %s %s\n", devid, dev.id, dev.name]; - [screen printf:" : %d %d\n", dev.numaxes, dev.numbuttons]; - for (int i = 0; i < dev.numaxes; i++) { - [screen printf:" : %d %d %d\n", dev.axes[i].value, - dev.axes[i].min, dev.axes[i].max]; - } - [screen refresh]; - obj_free (dev.axes); - obj_free (dev.buttons); - str_free (dev.name); - str_free (dev.id); - obj_free (dev); + Device *device = [Device withDevice:dev id:devid]; + [devices addObject:device]; } break; case qe_dev_rem: - [screen printf:"dev rem: %d\n", event.message.int_val]; - [screen refresh]; + for (int i = [devices count]; i-- > 0; ) { + Device *device = [devices objectAtIndex:i]; + if ([device devid] == event.message.ivector_val[0]) { + [devices removeObjectAtIndex:i]; + break; + } + } break; case qe_axis: - [screen printf:"axis: %d %d %d\n", event.message.ivector_val[0], - event.message.ivector_val[1], event.message.ivector_val[2]]; - [screen refresh]; + for (int i = [devices count]; i-- > 0; ) { + Device *device = [devices objectAtIndex:i]; + if ([device devid] == event.message.ivector_val[0]) { + [device updateAxis:event.message.ivector_val[1] + value:event.message.ivector_val[2]]; + [device redraw]; + break; + } + } break; case qe_button: - [screen printf:"button: %d %d %d\n", event.message.ivector_val[0], - event.message.ivector_val[1], event.message.ivector_val[2]]; - [screen refresh]; + for (int i = [devices count]; i-- > 0; ) { + Device *device = [devices objectAtIndex:i]; + if ([device devid] == event.message.ivector_val[0]) { + [device updateButton:event.message.ivector_val[1] + state:event.message.ivector_val[2]]; + [device redraw]; + break; + } + } + break; } if (event.what != qe_none) { [objects handleEvent: event]; @@ -162,6 +173,13 @@ arp_end (void) [screen refresh]; return self; } + +-removeView:(View *)view +{ + [objects remove: view]; + [screen refresh]; + return self; +} @end InputApplication *application;