pbsw-code.net : pbsw-InteractiveGraphics

pbsw-InteractiveGraphics

A framework for creating and manipulating interactive graphical objects

Allows for the creation of objects with different "shapes" (lines, rectangles, ovals, arc/wedges, polygons...)

Modifications to objects (such as moving and resizing) are done interactively.

The 3 main classes that make up the framework are:

pbsw_IG_Canvas : where the objects are drawn, and where control of them begins.

pbsw_IG_Object : the first level representation of an object that is contained by the canvas - Subclasses of this would usually add non-visual properties that are shared among all Objects, regardless of their "shape". Each Object encapsulates an instance of a subclass of pbsw_IG_ShapeCore to handle its visual representation and interactivity.

pbsw_IG_ShapeCore : this class and its subclasses control the visual representation of the object, and determine how they are manipulated


Requirements:

Usage Notes:



Classes
Modules



Class: pbsw_IG_Canvas Superclass: Canvas Interfaces: None
This Canvas subclass is the first place where user interaction is handled (and passed off as appropriate),
and where all of the drawing ends up.

You can subclass pbsw_IG_Canvas to add to, or modify its behavior.


Methods
AddObject(theObject as pbsw_IG_Object) [Public]
Adds theObject to the Canvas
(This is normally only called by the Canvas and its subclasses/instances)
CountObjects() as integer [Public]
returns the number of objects (pbsw_IG_Object) contained in the Canvas
CountSelectedObjects() as integer [Public]
returns the number of currently selected objects (pbsw_IG_Object)
DeleteSelectedObjects() [Public]
deletes the selected objects from the Canvas
DoResize() [Public]
update the Canvas after it is resized (this must be called any time the Canvas is resized)
GetAsPicture() as Picture [Public]
return the Canvas (and its objects) as a picture
GetMouseOverObject() as pbsw_IG_Object [Public]
return the object that the mouse is currently over
GetMouseOverObjectNum() as integer [Public]
return the number of the object the mouse is currently over
GetObject(index as integer) as pbsw_IG_Object [Public]
return the object numbered: index
GetSelectedObject(index as integer) as pbsw_IG_Object [Public]
return the selected object numbered: index
GetTool() as integer [Public]
return the current tool number
HasSelection() as Boolean [Public]
returns true if there is at least one object selected
IsObjectSelected(theObject as pbsw_IG_Object) as boolean [Public]
returns true if "theObject" is selected
MoveSelectedObjects(dX as integer, dY as integer) [Public]
moves the selected objects dX pixels horizontally and dY pixels vertically
MoveSelectedObjectsBackward() [Public]
moves the selected objects backward in the visible "stacking order"
MoveSelectedObjectsForward() [Public]
moves the selected objects forward in the visible "stacking order"
MoveSelectedObjectsToBack() [Public]
moves the selected objects to the back of the visible "stacking order"
MoveSelectedObjectsToFront() [Public]
moves the selected objects to the front of the visible "stacking order"
pbsw_IG_Canvas() [Public]
Default constructor
NOTE: If you subclass pbsw_IG_Canvas, and include a constructor, you MUST call the default constructor FIRST
RestoreGraphicsState(g as graphics) [Public]
restores the graphics state of the Canvas to the last stored state
SaveGraphicsState(g as graphics) [Public]
saves the graphics state for later restoration
SelectAllObjects() [Public]
makes all of the Canvas' objects selected
SetDoubleBuffering(doDoubleBuffer as boolean) [Public]
if "doDoubleBuffer" is true, turns on double buffering, otherwise, turns it off
SetGridSize(theSize as integer) [Public]
sets the size (in pixels) of the drawn grid
SetGridVisible(isVisible as boolean) [Public]
sets the visibility of the drawn grid
SetObjectBorder(theBorder as double) [Public]
sets the border opacity of all selected objects to "theBorder"
"theBorder" should be between 0 (transparent) and 100 (opaque)
SetObjectBorderColor(theColor as Color) [Public]
sets the border color of all selected objects to "theColor"
SetObjectBorderWidth(theWidth as double) [Public]
sets the width of all objects borders to "theWidth"
SetObjectFill(theFill as double) [Public]
sets the fill opacity of all selected objects to "theFill"
"theFill" should be between 0 (transparent) and 100 (opaque)
SetObjectFillColor(theColor as Color) [Public]
sets the fill color of all selected objects to "theColor"
SetTool(theTool as integer) [Public]
tells the Canvas that "theTool" is the current tool in use

New Events
InfoChanged(theInfoNum as integer, theInfoText as string)
This event fires to let instances know that some defined "info" (piece of information) has changed
"theInfoNum" is a unique identifier for the info
"theInfoText" is the new value (or other description) of the info

This event is useful for updating some form of display (at runtime) of some property of the canvas or its objects
Open()
(this new event is created to allow instances access to the open event)


Class: pbsw_IG_HitTester Superclass: None Interfaces: None
This class handles the hit testing for the pbsw_IG_Canvas class.
It figures out which object the mouse hits (or is over) and which object handle has been hit.

You do not normally interact with this class.



Class: pbsw_IG_Object Superclass: None Interfaces: None
This is the class that directly represents the objects on the pbsw_IG_Canvas.
The physical / visual representation of the object is separated out in the pbsw_IG_ShapeCore class
Most of the methods of this class are simply pass-through methods to the pbsw_IG_ShapeCore class.

You would subclass this class to create a new "top-level" object, independent of the visual representation.
Instances of this "top-level" class may have different visual representations, but similar non-visual properties and methods.

If you want to create a new visual representation, you would subclass pbsw_IG_ShapeCore (or one of its subclasses)


Methods
CountHandles() as integer [Public]
returns the number of handles the object has
(passthrough to pbsw_IG_ShapeCore)
DoMouseDown(X as integer, Y as integer, theHandleHit as integer) [Public]
tells the object to deal with a mouse down event at X,Y on the handle numbered "theHandleHit"
(passthrough to pbsw_IG_ShapeCore)
DoMouseDrag(X as integer, Y as integer) [Public]
tells the object to deal with a mouse drag event at X,Y
(passthrough to pbsw_IG_ShapeCore)
DoMouseMove(X as integer, Y as integer) [Public]
tells the object to deal with a mouse move event at X,Y
(passthrough to pbsw_IG_ShapeCore)
DoMouseUp(X as integer, Y as integer) [Public]
tells the object to deal with a mouse up event at X,Y
(passthrough to pbsw_IG_ShapeCore)
Draw(g as graphics) [Public]
tells the object to draw itself into "g"
(passthrough to pbsw_IG_ShapeCore)
Draw(g as graphics, dX as integer, dY as integer) [Public]
tells the object to draw itself into "g", offset hroizonally by dX and vertically by dY
(passthrough to pbsw_IG_ShapeCore)
DrawHandle(g as graphics, index as integer, multipleHighlights as Boolean) [Public]
draw the handle numbered "index" into "g"
if multiple objects currently need to be highlighted, set multipleHighlights to true
(passthrough to pbsw_IG_ShapeCore)
DrawHandles(g as Graphics, multipleHighlights as Boolean) [Public]
draw all handles into "g"
if multiple objects currently need to be highlighted, set multipleHighlights to true
(passthrough to pbsw_IG_ShapeCore)
DrawHighlight(g as Graphics, theColor as Color, multipleHighlights as Boolean) [Public]
draw the object highlight into "g" with color "theColor"
if multiple objects currently need to be highlighted, set multipleHighlights to true
(passthrough to pbsw_IG_ShapeCore)
DrawToHitTest(g as graphics) [Public]
draw hit test information into "g"
(passthrough to pbsw_IG_ShapeCore)
GetBorder() as double [Public]
return the object's border opacity (0-100%)
(passthrough to pbsw_IG_ShapeCore)
GetBorderColor() as Color [Public]
return the object's border color
(passthrough to pbsw_IG_ShapeCore)
GetBorderWidth() as double [Public]
return the object's border width
(passthrough to pbsw_IG_ShapeCore)
GetFill() as double [Public]
return the object's fill opacity (0-100%)
(passthrough to pbsw_IG_ShapeCore)
GetFillColor() as Color [Public]
return the object's fill color
(passthrough to pbsw_IG_ShapeCore)
GetHandleSize() as integer [Public]
return the size of the handles (in pixels)
(passthrough to pbsw_IG_ShapeCore)
GetShape() as pbsw_IG_ShapeCore [Public]
Returns the shape (pbsw_IG_ShapeCore subclass) associated with this object
NOTE: be careful interacting directly with the "inner shapes" - this is not normally done
GetSID() as integer [Public]
returns the special ID of the object (this is for internal tracking and should not normally be used)
GetState() as integer [Public]
return the current state of the object
(passthrough to pbsw_IG_ShapeCore)
GetType() as integer [Public]
returns the type of the encapsulated pbsw_IG_ShapeCore
this method must be overriden if you add your own subclasses of pbsw_IG_ShapeCore
iH() as integer [Public]
return the visual height of the object
(passthrough to pbsw_IG_ShapeCore)
IsEnclosedBy(L as integer, T as integer, R as integer, B as integer) as boolean [Public]
returns true if the shape is enclosed by the rectangle with:
left edge: "L" , top edge: "T", right edge: "R", and bottom edge: "B"
(passthrough to pbsw_IG_ShapeCore)
iW() as integer [Public]
return the visual width of the object
(passthrough to pbsw_IG_ShapeCore)
iX() as integer [Public]
return the horizontal position of the upper left corner of the object (visually)
(passthrough to pbsw_IG_ShapeCore)
iY() as integer [Public]
return the vertical position of the upper left corner of the object (visually)
(passthrough to pbsw_IG_ShapeCore)
Move(dX as integer, dY as integer) [Public]
move the object dX pixels horizontally and dY pixels vertically
(passthrough to pbsw_IG_ShapeCore)
pbsw_IG_Object(theShape as pbsw_IG_ShapeCore) [Public]
constructor : creates the new object with an existing pbsw_IG_ShapeCore (theShape)
pbsw_IG_Object(theType as integer, X as integer, Y as integer) [Public]
constructor: creates a new object of type "theType"
at horizontal position "X" and vertical position "Y"
this constructor needs to be overriden if you are using your own pbsw_IG_ShapeCore subclasses
RestoreDrawState() [Public]
restores the drawing state of the object to the last saved state (if there is one)
(passthrough to pbsw_IG_ShapeCore)
SaveDrawState() [Public]
saves the current drawing state of the object
(passthrough to pbsw_IG_ShapeCore)
SetBorder(theBorder as double) [Public]
set the object's border opacity to "theBorder" (0-100%)
(passthrough to pbsw_IG_ShapeCore)
SetBorderColor(theColor as Color) [Public]
sets the objects border color to "theColor"
(passthrough to pbsw_IG_ShapeCore)
SetBorderWidth(theWidth as double) [Public]
sets the width of the object's border to "theWidth"
(passthrough to pbsw_IG_ShapeCore)
SetFill(theFill as double) [Public]
sets the object's fill opacity to "theFill" (0-100%)
(passthrough to pbsw_IG_ShapeCore)
SetFillColor(theColor as Color) [Public]
sets the object's fill color to "theColor"
(passthrough to pbsw_IG_ShapeCore)
SetHandleSize(theSize as integer) [Public]
sets the size of the objects handles to "theSize"
(passthrough to pbsw_IG_ShapeCore)
SetShape(theShape as pbsw_IG_ShapeCore) [Public]
Sets the shape (pbsw_IG_ShapeCore subclass) associated with this object to : theShape
NOTE: be careful interacting directly with the "inner shapes" - this is not normally done
SetSID(theSID as integer) [Public]
sets the special ID of the object (this is for internal tracking and should not normally be used)
SetState(theState as integer) [Public]
sets the current state of the object to "theState"
(passthrough to pbsw_IG_ShapeCore)


Class: pbsw_IG_ShapeCore Superclass: None Interfaces: None
This is the abstract base class for visual representation of the object to be drawn and manipulated in the canvas.
Each pbsw_IG_Object has a pbsw_IG_ShapeCore to define its visual representation.

You subclass pbsw_IG_ShapeCore (or one of its subclasses) to create a new way to view or manipulate an object.


Methods
CountHandles() as integer [Public]
returns the number of handles the object has
DoMouseDown(X as integer, Y as integer, theHandleHit as integer) [Public]
tells the object to deal with a mouse down event at X,Y on the handle numbered "theHandleHit"
DoMouseDrag(X as integer, Y as integer) [Public]
tells the object to deal with a mouse drag event at X,Y
DoMouseMove(X as integer, Y as integer) [Public]
tells the object to deal with a mouse move event at X,Y
DoMouseUp(X as integer, Y as integer) [Public]
tells the object to deal with a mouse up event at X,Y
Draw(g as graphics) [Public]
tells the object to draw itself into "g"
Draw(g as graphics, dX as integer, dY as integer) [Public]
tells the object to draw itself into "g", offset hroizonally by dX and vertically by dY
DrawHandle(g as graphics, index as integer, multipleHighlights as Boolean) [Public]
draw the handle numbered "index" into "g"
if multiple objects currently need to be highlighted, set multipleHighlights to true
DrawHandles(g as Graphics, multipleHighlights as Boolean) [Public]
draw all handles into "g"
if multiple objects currently need to be highlighted, set multipleHighlights to true
DrawHighlight(g as Graphics, theColor as Color, multipleHighlights as Boolean) [Public]
draw the object highlight into "g" with color "theColor"
if multiple objects currently need to be highlighted, set multipleHighlights to true
DrawToHitTest(g as graphics) [Public]
draw hit test information into "g"
GetBorder() as double [Public]
return the object's border opacity (0-100%)
GetBorderColor() as Color [Public]
return the object's border color
GetBorderWidth() as double [Public]
return the object's border width
GetFill() as double [Public]
return the object's fill opacity (0-100%)
GetFillColor() as Color [Public]
return the object's fill color
GetHandleSize() as integer [Public]
return the size of the handles (in pixels)
GetObjectAsPicture() as Picture [Public]
returns a picture with the object drawn into it
GetState() as integer [Public]
return the current state of the object
iH() as integer [Public]
return the visual height of the object
IsEnclosedBy(L as integer, T as integer, R as integer, B as integer) as boolean [Public]
returns true if the shape is enclosed by the rectangle with:
left edge: "L" , top edge: "T", right edge: "R", and bottom edge: "B"
iW() as integer [Public]
return the visual width of the object
iX() as integer [Public]
return the horizontal position of the upper left corner of the object (visually)
iY() as integer [Public]
return the vertical position of the upper left corner of the object (visually)
Move(dX as integer, dY as integer) [Public]
move the object dX pixels horizontally and dY pixels vertically
pbsw_IG_ShapeCore(X as integer, Y as integer) [Public]
constructor: creates the shape with center at point X,Y
(pbsw_IG_ShapeCore is an abstract class, you should not be creating instances of it directly)
RestoreDrawState() [Public]
restores the drawing state of the object to the last saved state (if there is one)
SaveDrawState() [Public]
saves the current drawing state of the object
SetBorder(theBorder as double) [Public]
set the object's border opacity to "theBorder" (0-100%)
SetBorderColor(theColor as Color) [Public]
sets the objects border color to "theColor"
SetBorderWidth(theWidth as double) [Public]
sets the width of the object's border to "theWidth"
SetFill(theFill as double) [Public]
sets the object's fill opacity to "theFill" (0-100%)
SetFillColor(theColor as Color) [Public]
sets the object's fill color to "theColor"
SetHandleSize(theSize as integer) [Public]
sets the size of the objects handles to "theSize"
SetState(theState as integer) [Public]
sets the current state of the object to "theState"


Class: pbsw_IG_O2DShape Superclass: pbsw_IG_ShapeCore Interfaces: None
This is an abstract subclass of pbsw_IG_ShapeCore based on Object2D


Methods
GetObject() as Object2D [Public]
Returns the Object2D shape associated with this shape
NOTE: be careful interacting directly with the "inner shapes" - this is not normally done
pbsw_IG_O2DShape(X as integer, Y as integer) [Public]
constructor: creates an Object2D shape with center at point X,Y
(pbsw_IG_O2DShape is an abstract class, you should not be creating instances of it directly)
SetObject(theObject as Object2D) [Public]
Sets the Object2D shape associated with this shape to : theObject
NOTE: be careful interacting directly with the "inner shapes" - this is not normally done


Class: pbsw_IG_RectShape Superclass: pbsw_IG_O2DShape Interfaces: None
This is a subclass of pbsw_IG_ShapeCore based on a RectShape.


Methods
pbsw_IG_RectShape(X as integer, Y as integer) [Public]
constructor: creates a RectShape with center at point X,Y
pbsw_IG_RectShape(theShape as RectShape) [Public]
constructor: creates the shape from: theShape
if theShape is nil, it will create a default shape at X,Y with width/height = 0


Class: pbsw_IG_OvalShape Superclass: pbsw_IG_RectShape Interfaces: None
This is a subclass of pbsw_IG_ShapeCore based on an OvalShape.


Methods
pbsw_IG_OvalShape(X as integer, Y as integer) [Public]
constructor: creates tan OvalShape with center at point X,Y
pbsw_IG_OvalShape(theShape as OvalShape) [Public]
constructor: creates the shape from: theShape
if theShape is nil, it will create a default shape at X,Y with width/height = 0


Class: pbsw_IG_ArcShape Superclass: pbsw_IG_OvalShape Interfaces: None
This is a subclass of pbsw_IG_ShapeCore based on an ArcShape.


Methods
pbsw_IG_ArcShape(X as integer, Y as integer) [Public]
constructor: creates an ArcShape with center at point X,Y
pbsw_IG_ArcShape(theShape as ArcShape) [Public]
constructor: creates the shape from: theShape
if theShape is nil, it will create a default shape at X,Y with width/height = 0


Class: pbsw_IG_CurveShape Superclass: pbsw_IG_O2DShape Interfaces: None
This is an abstract subclass of pbsw_IG_ShapeCore based on a CurveShape.
(you do not use this class directly... yet)


Methods
pbsw_IG_CurveShape(X as integer, Y as integer) [Public]
constructor: creates a CurveShape starting at point X,Y
(pbsw_IG_CurveShape is an abstract class, you should not be creating instances of it directly)


Class: pbsw_IG_LineShape Superclass: pbsw_IG_CurveShape Interfaces: None
This is a subclass of pbsw_IG_ShapeCore based on a CurveShape - that is a straight line.


Methods
pbsw_IG_LineShape(X as integer, Y as integer) [Public]
constructor: creates a line shape starting at point X,Y


Class: pbsw_IG_FigureShape Superclass: pbsw_IG_O2DShape Interfaces: None
This is an abstract subclass of pbsw_IG_ShapeCore based on a FigureShape.
(you do not use this class directly... yet)


Methods
pbsw_IG_FigureShape(X as integer, Y as integer) [Public]
constructor: creates a FigureShape with a starting point of X,Y
(pbsw_IG_FigureShape is an abstract class, you should not be creating instances of it directly)


Class: pbsw_IG_PolygonShape Superclass: pbsw_IG_FigureShape Interfaces: None
This is a subclass of pbsw_IG_ShapeCore based on a FigureShape with straight lines as sides.



Methods
pbsw_IG_PolygonShape(X as integer, Y as integer) [Public]
constructor: creates a polygon shape with a starting point of X,Y



Module: pbsw_IG_Tools
Tool numbers
The values of these constants can be modified to suit your needs.


Constants
NameTypeValueScopeDescription
igToolArc Integer 4 Global
igToolArrow Integer 0 Global
igToolLine Integer 1 Global
igToolOval Integer 3 Global
igToolPolygon Integer 5 Global
igToolSquare Integer 2 Global


Module: pbsw_IG_Types
Shape types
(values <= 0 are reserved for the original base classes, and should not be used in your own versions or subclasses)


Constants
NameTypeValueScopeDescription
igTypeArc Integer -3 Global
igTypeLine Integer -4 Global
igTypeOval Integer -2 Global
igTypePolygon Integer -5 Global
igTypeRect Integer -1 Global
igTypeUnknown Integer 0 Global


Module: pbsw_IG_CanvasStates
Canvas states
(values <= 0 are reserved for the original base classes, and should not be used in your own versions or subclasses)


Constants
NameTypeValueScopeDescription
igCSDraggingObject Integer -101 Global
igCSDrawingArc Integer -3 Global
igCSDrawingLine Integer -4 Global
igCSDrawingOval Integer -2 Global
igCSDrawingPolygon Integer -5 Global
igCSDrawingRect Integer -1 Global
igCSNormal Integer 0 Global
igCSSelectionRect Integer -102 Global


Module: pbsw_IG_ObjectStates
Object states
(values <= 0 are reserved for the original base classes, and should not be used in your own versions or subclasses)


Constants
NameTypeValueScopeDescription
igOSCreation Integer -1 Global
igOSNormal Integer 0 Global


Module: pbsw_IG_InfoNums
The values used to indentify some "info" from pbsw_IG_Canvas's InfoChanged event
(values <= 0 are reserved for the original base classes, and should not be used in your own versions or subclasses)



Constants
NameTypeValueScopeDescription
igInfoCanvasState Integer -1 Global
igInfoLastMouseUp Integer -8 Global
igInfoMouseOverObjectDimensions Integer -3 Global
igInfoMouseOverObjectNum Integer -2 Global
igInfoSelectionRectDim1 Integer -5 Global
igInfoSelectionRectDim2 Integer -6 Global


pbsw-code.net : pbsw-InteractiveGraphics