mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-25 22:01:33 +00:00
[qwaq] Implement device management for input-app
Currently shows only the axes (along with dev "path" and name), but it has done a good job of pushing dev of other bits of code :)
This commit is contained in:
parent
1a5cce4374
commit
4057500acc
12 changed files with 288 additions and 24 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
19
ruamoko/qwaq/device/axisdata.h
Normal file
19
ruamoko/qwaq/device/axisdata.h
Normal file
|
@ -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 <TableViewDataSource>
|
||||
{
|
||||
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
|
58
ruamoko/qwaq/device/axisdata.r
Normal file
58
ruamoko/qwaq/device/axisdata.r
Normal file
|
@ -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
|
18
ruamoko/qwaq/device/axisview.h
Normal file
18
ruamoko/qwaq/device/axisview.h
Normal file
|
@ -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
|
42
ruamoko/qwaq/device/axisview.r
Normal file
42
ruamoko/qwaq/device/axisview.r
Normal file
|
@ -0,0 +1,42 @@
|
|||
#include <string.h>
|
||||
#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
|
26
ruamoko/qwaq/device/device.h
Normal file
26
ruamoko/qwaq/device/device.h
Normal file
|
@ -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
|
77
ruamoko/qwaq/device/device.r
Normal file
77
ruamoko/qwaq/device/device.r
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include <string.h>
|
||||
#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
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "ruamoko/qwaq/debugger/views/defview.h"
|
||||
|
||||
@interface NameView : DefView
|
||||
@interface NameView : View
|
||||
{
|
||||
string name;
|
||||
}
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include <string.h>
|
||||
#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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue