diff --git a/scripts/javascript/lib/widgetlibrary/osc_controller_interface.js b/scripts/javascript/lib/widgetlibrary/osc_controller_interface.js new file mode 100644 index 00000000..de6659ab --- /dev/null +++ b/scripts/javascript/lib/widgetlibrary/osc_controller_interface.js @@ -0,0 +1,149 @@ +// OSC controller interface +// buZz, Puik. started aug. 2009 + +// ment to do : +// - widgets +// - editing of interface? +// - send OSC events on widget change + +// startup with: +// # freej -cFj osc_controller_interface.js + +// eee fullscreen res ;) +W = 800; +H = 480; + +include('widget_class.js'); + +set_resolution(W,H); + +MAX_WIDGETS = 10; // unused atm + +widgets = new Array(); + +mousestate = 0; +plzredraw = 1; + +geo = new GeometryLayer(); +geo.set_blit("ADD"); +geo.set_fps(); +geo.activate(true); +geo.color(255,255,255,255); +add_layer(geo); + +kbd = new KeyboardController(); +kbd.activate(true); +kbd.pressed_esc = function() { quit(); } +register_controller( kbd ); + +ms = new MouseController(); +ms.activate(true); +ms.grab(true); +ms.button = function(b, s, x, y) { + var i; + // (button, state, x, y) +// echo("mousestate "+mousestate+" b"+b+" s"+s+" x"+x+" y"+y); + this.grab(s); + + + switch (mousestate) { + // mousestate 0 = nothing + // mousestate 1 = click + // mousestate 2 = nothing + just clicked earlier (needs a timer) + // mousestate 3 = double click + // mousestate 4 = drag (not working right) + case 0: + if ((s == 1) && (b == 1)) { + // left mousebutton pressed + mousestate = 1; + + // do widget click change? + for (i=0; i0) { + lay.color(192,192,192,255); + } else { + lay.color(255,255,255,255); + } + + // bottomleft and topright corners + lay.line(this.x+this.w,this.y,this.x+this.w-2,this.y+2); + lay.line(this.x,this.y+this.h,this.x+2,this.y+this.h-2); + + // right and bottom lines + lay.line(this.x+this.w-2,this.y+2,this.x+this.w-2,this.y+this.h-2); + lay.line(this.x+2,this.y+this.h-2,this.x+this.w-2,this.y+this.h-2); + lay.line(this.x+this.w-1,this.y+1,this.x+this.w-1,this.y+this.h-1); + lay.line(this.x+1,this.y+this.h-1,this.x+this.w-1,this.y+this.h-1); + + // bottomright corner + lay.line(0,0,0,255); + lay.line(this.x+this.w,this.y+this.h,this.x+this.w-2,this.y+this.h-2); + + // middle + lay.color(160,160,160,255); + lay.rectangle_fill(this.x+3,this.y+3,this.x+this.w-3,this.y+this.h-3); + + // delivery! one ugly button! + + break; + case 2: + // toggle + lay.color(255,255,255,255); + lay.rectangle(this.x,this.y,this.x+this.h,this.y+this.w); + if (this.data > 0) { + // draw cross + lay.color(255,255,255,255); + } else { + lay.color(0,0,0,255); + } + // commented lines are for a 'cross' style checkbox, i like the square one better .. + +// lay.line(this.x+2,this.y+2,this.x+this.h-2,this.y+this.w-2); +// lay.line(this.x+this.h-2,this.y+2,this.x+2,this.y+this.w-2); + lay.rectangle_fill(this.x+2,this.y+2,this.x+this.h-2,this.y+this.w-2); + + break; + case 0: + default: + // do nothing + } + + return; +} + +Widget.prototype.intersects = function(x,y) { + // is x,y within this widget? + + if ((x>this.x) && (x<(this.x+this.h) && (y>this.y) && (y<(this.y+this.w) ) ) ) + return true; + return false; + +} + +Widget.prototype.change = function(b,mousestate) { + + switch(this.type) { + case 1: + this.data = 1; + echo ("BANG @ "+this.name); + break; + case 2: + if (this.data>0) { this.data = 0; } else { this.data = 1; } + echo ("TOGGLE newdata: "+this.data+" @ "+this.name); + break; + case 0: + default: + // do nothing + } + +}