User Interface Extension Library Usage Example 2.

The following example shows how to use UI Interface Extension Library to create previews with drawn shapes (rectangles, lines, etc).

demo2.gif (4509 bytes)

The BuildPreview creates the preview image depending on the following arguments:

  • Grid - equeals to 1 if grid must be drawn
  • H and V - specify the alignment. 0 = none, 1 = left (top), 2 = center, 3 = right (bottom)
  • RectX, RectY, RectW, RectH, EllX, EllY, EllW, EllH, TriX, TriY, TriW, TriH - coordinates of upper left corner and width and height of the rectangle, ellipse and triangle.
  • XX, YY, HH, WW - coordinates of upper left corner and width and height of the bounding rectangle of drawing area (outlined with light gray rectangle when grid is enabled).
SUB BuildPreview
DIM Tri&(4,2)
BeginImage 120,120,RGB(255,255,255) ' Create an empty image in memory
	IF Grid THEN ' Draw Grid
		ImageRectangle XX,YY,XX+WW-1,YY+HH-1,1,RGB(200,200,200)
		ImageLine XX,YY+HH\2,XX+WW-1,YY+HH\2,1,RGB(200,200,200)
		ImageLine XX+WW\2,YY,XX+WW\2,YY+HH-1,1,RGB(200,200,200)
	END IF
	rx&=RectX
	ry&=RectY
	ex&=EllX
	ey&=EllY
	tx&=TriX
	ty&=TriY
	SELECT CASE H ' Horizontal alignment
		CASE 1 ' Left
			rx=XX
			ex=XX
			tx=XX
		CASE 2 ' Center
			rx=XX+(WW-RectW)\2
			ex=XX+(WW-EllW)\2
			tx=XX+(WW-TriW)\2
		CASE 3 ' Right
			rx=XX+WW-RectW
			ex=XX+WW-EllW
			tx=XX+WW-TriW
	END SELECT
	SELECT CASE V ' Vertical alignment
		CASE 1 ' Top
			ry=YY
			ey=YY
			ty=YY
		CASE 2 ' Center
			ry=YY+(HH-RectH)\2
			ey=YY+(HH-EllH)\2
			ty=YY+(HH-TriH)\2
		CASE 3 ' Bottom
			ry=YY+HH-RectH
			ey=YY+HH-EllH
			ty=YY+HH-TriH
	END SELECT
	Tri(1,1)=tx
	Tri(1,2)=ty+TriH-1
	Tri(2,1)=tx+TriW\2
	Tri(2,2)=ty
	Tri(3,1)=tx+TriW-1
	Tri(3,2)=ty+TriH-1
	IF Filled=0 THEN ' Not filled shapes
		Tri(4,1)=Tri(1,1) ' 4th point to close unfilled triangle
		Tri(4,2)=Tri(1,2)
		ImageRectangle rx,ry,rx+RectW-1,ry+RectH-1,1,RGB(0,0,255)
		ImageEllipse ex,ey,ex+EllW-1,ey+EllH-1,1,RGB(255,0,0)
		ImagePolyline 4,Tri(1,1),1,RGB(0,200,0)
	ELSE ' Filled Shapes
		ImageFillRect rx,ry,rx+RectW-1,ry+RectH-1,RGB(0,0,255)
		ImageFillEllipse ex,ey,ex+EllW-1,ey+EllH-1,RGB(255,0,0)
		ImageFillPolyline 3,Tri(1,1),RGB(0,200,0)
	END IF
EndImage ImageFile$ ' Save the image to file and free memory
MainDialog.Preview.SetImage ImageFile
END SUB

[ <Previous page | Next Page> ]


[ Learning CorelSCRIPT | Oberon Home Page ]

Copyright 2000 by Alex Vakulenko. All rights reserved.
This page was last revised on 01/13/00.