Class
BoxController
In: rbSnack/tkSnackUtil.rb
Parent: Object

The BoxController allows the attachment of one or more box controls to a canvas. Each box can be selected and moved by the mouse. Each box may have either or both a vertical and horizontal line attached to them. Thus the box controls can be used to define one or more regions on the associated canvas. After specifiying the worldFrame, we can determine the coordinates (and hence the associated regions) of the box controls by invoking getXfor and getYfor upon the indices of the boxes of interest.

Methods

addBox, addConstraint, autoBoxPlacement, getXfor, getYfor, new, placeBoxWorldX, placeBoxWorldY, refresh, screenX2World, screenY2World, worldX2Screen, worldY2Screen,
Attributes

 [RW]  :onMove

onMove is a proc which if set will be executed everytime a box is moved.

 [RW]  :onRefresh

onRefresh is a proc which if set will be executed for each box whenever refresh is called

 [RW]  :worldFrame

worldFrame is an array of length 4 consisting of x0 , y0, x1, y1 representing the world region to be displayed. For example, if the horizontal axis is to represent the first formant, and the verical the second formant we might be interested in values where the first formant is between 200 and 900, and the second is between 800 and 2500. In this case, our world frame would be

 [200, 900, 800, 2500]
Public Class methods
new(canvas) src

Constructs a BoxController. Takes one argument, canvas, which is the TkCanvas on which the boxes are to reside. Binding of mouse clicks is done here.

Public Instance methods
addBox(x, y, color=') src

Adds a new box to the controller. Arguments are

x
The x screen coordinate of the new box
y
The y screen coordinate of the new box
color
The color of the new box
vert
A boolean, true if a vertical line is to be attached to the box, false othewise
horz
A boolean, true if a horizontal line is to be attached to the box, false othewise
autoBoxPlacement() src

A way of automatically creating a reasonable set of x,y coordinates for the boxes on the canvas

addConstraint( &block ) src

Takes a block and adds it as a constraint on the placement of the boxes. For example

 { y[0]<x[0] ; x[0]>50 ;  x[0]<100; x[1]>x[0] }

Constrains the y coord of the first box to be less that the x coord of the first box. Furthermore, the first box is confined to be between x=0 and x=100. Finally the second box must be to the right of the first box

refresh(anew=false) src

Draws all the boxes and associated lines on the canvas associated with this control

placeBoxWorldX(boxId, wx) src

Places the given box (identified by it's number boxId) on the screen at the position corresponding to the horizontal world coordinate wx.

placeBoxWorldY(boxId, wy) src

Places the given box (identified by it's number boxId) on the screen at the position corresponding to the verticalworld coordinate wy.

screenX2World(x) src

Given the horizontal viewport coordinate (horizontal screen coordinate relative to the associated canvas) returns the horizontal world frame coordinate. For this to make any sense you must minimally have specifiedthe horizontal portion of the world frame. This is accomplished by

worldFrame  =  [x0,y0,x1,y1]

Where x0, x1 represents the horizontal range of the world frame

screenY2World(y) src

Given the vertical viewport coordinate ( vertical screen coordinate relative to the associated canvas) returns the vertical world frame coordinate. For this to make any sense you must have specified at the minimum the vertical portion of the world frame. This is accomplished by

worldFrame  =  [x0,y0,x1,y1]

Where y0, y1 represents the vertical range of the world frame

worldX2Screen(x) src

Given a horizontal world frame coordinate returns the horizontal viewport coordinate (horizontal screen coordinate relative to the associated canvas). For this to make any sense you minimally must have specified the horizontal portion of the world frame. This is accomplished by

worldFrame  =  [x0,y0,x1,y1]

Where x0, x1 represents the horizontal range of the world frame.

worldY2Screen(y) src

Given a vertical world frame coordinate returns the vertical viewport coordinate (vertical screen coordinate relative to the associated canvas). For this to make any sense you must minimally have specified vertical portion of the world frame. This is accomplished by

worldFrame  =  [x0,y0,x1,y1]

Where y0, y1 represents the horizontal range of the view port

getXfor( *indxs ) src

Given the index a specified box, returns the x-value of that box(the x-coordinate relative to the world frame) If presented more that one box index, will return an array of corresponding x-values

Of course one needs to set the horizontal worldFrame prior to usage.

getYfor( *indxs ) src

Given the index a specified box, returns the y-value of that box(the y-coordinate relative to the world frame) If presented more that one box index, will return an array of corresponding x-values

Of course one needs to set the vertical worldFrame prior to usage.