Title: CGLIB - Constraint-based Graphics Library
1CGLIB - Constraint-based Graphics Library
- Features
- Use constraints to specify the layouts of objects
- Use action rules to specify interactions
- Implementation
- Implemented in B-Prolog, Java, and C
- Applications
- Drawing editors, interactive user interfaces,
document authoring, animation, information
visualization, intelligent agents, and games.
2An Illustrative Example
go- cgButton(B), (1)
Btext Hello World!, (2) handleButtonClick(
B), (3) cgShow(B). (4) handleButtonClick(B
), (5) actionPerformed(B) (6) gt
(7) halt. (8)
3Objects
- cgButton(X)
- Create a button X
- cgButton(X1,,Xn)
- Create a list of buttons
4Attributes of Objects
B is a button
y
Bwindow Bx By Bwidth Bheight Btext
Bcolor Bfont
BrightX BbottomY BcenterX BcenterY BleftTopPo
int BleftBottomPoint BrightTopPoint BrightBotto
mPoint Bcenter
x
height
width
5Constraints
- Arithmetic constraints
- O1x O1width//2 O2x
- O1centerX O2x
- Positioning constraints
- cgLeft(O1,O2)
- Same property constraints
- cgSame(O1,O2,size)
- cgSame(O1,O2,width,100)
6Constraints (Cont.)
cgGrid(_, S1,_, S2,S3,S4,
_,S5,_)
cgGrid(Bc,Bdiv,Bmul,Bsub, B7,B8, B9,
Badd, B4,B5, B6, Badd, B1,B2, B3,
Beq, B0,B0, Bdot,Beq,1,1),
7Constraints (Cont.)
cgTable(Larc,Arc,Button,Lbutton,
Lcheckbox, Checkbox, Choice, Lchoice,
Lcircle,Circle,Image,Limage,
Llabel,Label,Line,Lline,
Llist,List,Oval,Loval,
Lrrectangle,Rrectangle,Rectangle,Lrectangle,
Lpolygon,Polygon,Square,Lsquare,
Lstar,Star,TextArea,Ltextarea,
Ltextfield,TextField,TextBox,Ltextbox,
Ltriangle,Triangle,_,_,20,20),
8Constraints (Cont.)
Tnode(C0,node(C1,node(C3,
node(C4,)), node(C2,node(C5,),
node(C6,))), cgTree(T,top_down,10,10,centered)
.
9Event Handling
Agent ConditionSeq Event gt ActionSeq
handleButtonClick(B),actionPerformed(B) gt
handleMousePress(O),mousePressed(O,E)
gt Ex X, Ey Y, write(mouse_pressed
_at(X,Y)),nl. handleKeyType(O),keyTyped(O,E)
gt Echar Char, write(Char).
10Other Primitives in CGLIB
- Packing and showing objects
- cgPack(O) cgShow(O)
- Altering and moving objects
- Oattr Value
- cgScale(O,F) cgResize(O,W,H)
- cgMove(O,X,Y)
- Animation
- cgSleep(Time)
- Generating Java applets
- cgStartRecord(FileName) cgStopRecord
11Demo of CGLIB
12Related Work
- Postscript Latex
- Every detail must be specified
- Java Tcl/Tk
- Layout managers are helpful for certain layouts
- Functional programming
- New data types and functions for events, time,
and behaviors - Constraints Constraint programming
- Sketchpad, ThinkLab, Amulet, SubArctic
13Further Work
- Extension of the set of base objects
- Application-specific objects
- 3D objects
- Constructs for users to define their own objects
- Non-linear and soft constraints
- Improving the performance
- Constraint solving
- Graphics rendering
14Papers
- N.F. Zhou CGLIB - A Constraint-based Graphics
Library, Software - Practice and Experience, Vol.
33, No.13, pp.1199-1216, 2003. - N.F. Zhou Authoring Graphics-rich and
Interactive Documents in CGLIB - A
Constraint-based Graphics Library, Proceedings of
the ACM Symposium on Document Engineering,
pp.28-38, November, 2001.