More scripts: Dialog
Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# DRAWDLG.SML
# Sample script for Building Dialogs in SML.
# Creates and opens a dialog window
# and uses a drawing area.
clear();
# Define global class variables used in procedures.
class XmForm win1; # parent widget for dialog window.
class XmDrawingArea da; # drawing area widget.
class GC gc; # graphics context for drawing area.
# Procedure for redraw of drawing area when exposed.
proc OnRedraw() {
local numeric radius1, radius2;
local numeric x, y;
# A graphics context (GC) is a structure that holds relevant
# information such as color, line width, and font for
# drawing text or graphics in a window. A GC must be
# created and activated before drawing, and the GC must be
# created AFTER the dialog window has actually opened.
if (!gc) gc = CreateGCForDrawingArea(da);
ActivateGC(gc);
# Draw background white rectangle from lower left corner of
# drawing area and with same height and width as drawing area.
SetColorName("white"); # color name from reference file RGB.text.
FillRect(0,0,da.width,da.height);
# Draw filled red circle centered on center of drawing area.
radius1 = SetMin(da.width,da.height) / 2;
x = da.width / 2; y = da.height / 2;
SetColorRGB(255,0,0); # RGB values for red color
FillCircle(x,y,radius1);
# Draw yellow circle centered on center of drawing area.
radius2 = radius1 / 2;
SetColorRGB(255,255,0); # RGB valuse for yellow color
SetLineWidth(4); # Set line width in screen pixels.
DrawCircle(x,y,radius2);
SetColorRGB(0,0,0);
DrawTextSetHeightPixels(15);
DrawTextSetFont("duck.of");
DrawTextSimple("Drawing Area",17,da.height-5,90);
}
# Procedure for closing window.
proc OnClose() {
DialogClose(win1);
DestroyWidget(win1);
}
# Set up dialog window.
win1 = CreateFormDialog("Dialog with Drawing Area");
win1.MarginHeight = 5;
win1.MarginWidth = 5;
# Create drawing area and attach to window margin
# on top, left, and right. Add callback for when
# the drawing area is exposed.
da = CreateDrawingArea(win1,150,225);
da.TopWidget = win1;
da.LeftWidget = win1;
da.RightWidget = win1;
WidgetAddCallback(da.ExposeCallback,OnRedraw);
# Create Close button attached to drawing area on
# on top and to window margin on left and right.
class XmPushButton closeButton;
closeButton = CreatePushButton(win1,"Close");
closeButton.TopWidget = da;
closeButton.TopOffset = 5;
closeButton.leftWidget = win1;
closeButton.rightWidget = win1;
closeButton.bottomWidget = win1;
WidgetAddCallback(closeButton.ActivateCallback,OnClose);
# Open dialog window and keep script active.
# until window is closed.
DialogOpen(win1);
DialogWaitForClose(win1);