% Nom du fichier: Drawing.sim % Description: Exemple qui montre les possibilites graphiques de WT % Est appele DrawingWLang.sim ailleurs... % Auteur: JPH % Date: Le 9 mai 1997 % Version: 1.1 % (Implantation d'un choix de langues a l'aide de la procedure WriteLang) BEGIN EXTERNAL CLASS WindowTools; MainWindow CLASS JPHMainWindow; BEGIN REF(Button) Quit; TEXT Lang; PROCEDURE DrawTextCenterIn(X, Y, T); Integer X,Y; Text T; CenteredText(X, Y, T); PROCEDURE WriteLang(EnglishText, TexteFrancais, NorskTekst); TEXT EnglishText, TexteFrancais, NorskTekst; BEGIN IF Lang = "English" THEN DrawCenterText(EnglishText) ELSE IF Lang = "Francais" THEN DrawCenterText(TexteFrancais) ELSE IF Lang = "Norsk" THEN DrawCenterText(NorskTekst) ELSE Error("No language defined..."); END; TEXT PROCEDURE AskLanguage; BEGIN REF(RadioPanel) LangSelect; LangSelect :- MakeRadioPanel.PlaceCentered; LangSelect.AddButton("English") .AddSetButton("Francais") .AddButton("Norsk"); Quit.Wait; AskLanguage :- LangSelect.CurrentChoice; LangSelect.Hide; END; PROCEDURE EraseText; BEGIN ClearRectangle(45, 240, 410, 20); END; PROCEDURE ShowRectangleInfos; !Veuillez ignorer cette procedure... Referez-vous a l'exemple sur le texte; BEGIN TEXT SavedFont; SavedFont :- CurrentFontName; SetFont(FontName("helvetica", 8, FALSE, FALSE)); DrawTextCenterIn(150, 140, "(150, 150)"); DrawTextCenterIn(250, 210, "200"); DrawTextCenterIn(360, 175, "50"); SetFont(SavedFont); END; PROCEDURE ShowCircleInfos; !Veuillez ignorer cette procedure... Referez-vous a l'exemple sur le texte; BEGIN TEXT SavedFont; SavedFont :- CurrentFontName; SetFont(FontName("helvetica", 8, FALSE, FALSE)); SetLineWidth(1); SetFill("black"); FillCircle(250, 150, 1); DrawTextCenterIn(250, 140, "(250, 150)"); DrawLine(200, 210, 300, 210); DrawLine(200, 205, 200, 215); DrawLine(300, 205, 300, 215); DrawTextCenterIn(250, 220, "100"); SetFont(SavedFont); END; PROCEDURE ShowArcInfos; BEGIN TEXT SavedFont; SavedFont :- CurrentFontName; SetFont(FontName("helvetica", 8, FALSE, FALSE)); DrawTextCenterIn(360, 150, "0"); DrawtextCenterIn(250, 90, "90"); DrawTextCenterIn(136, 150, "180"); DrawTextCenterIn(250, 212, "270"); SetLineWidth(1); DrawLine(145, 150, 150, 150); DrawLine(350, 150, 355, 150); DrawLine(250, 95, 250, 100); DrawLine(250, 200, 250, 205); SetFill("black"); FillCircle(150, 100, 2); DrawTextCenterIn(130, 90, "(150, 100)"); DrawLine(150, 220, 350, 220); DrawLine(150, 215, 150, 225); DrawLine(350, 215, 350, 225); DrawTextCenterIn(250, 230, "200"); DrawLine(370, 100, 370, 200); DrawLine(365, 100, 375, 100); DrawLine(365, 200, 375, 200); DrawTextCenterIn(390, 150, "100"); DrawArc(240, 140, 20, 20, 90, 125); !distorted for the ellipse; DrawTextCenterIn(258, 155, "135"); DrawTextCenterIn(270, 148, "o"); SetFont(SavedFont); END; PROCEDURE PointsEx; BEGIN INTEGER i, u; U := ClockTime; Clear; DrawCenterText("DrawPoint(x, y)"); FOR i := 1 STEP 1 UNTIL 2000 DO DrawPoint(RandInt(1, 500, U), RandInt(1, 500, U)); Quit.Wait; END; PROCEDURE LinesEx; BEGIN INTEGER i, u; U := ClockTime; ClockTime; Clear; DrawCenterText("DrawLine(x1, y1, x2, y2)"); for i := 1 STEP 1 UNTIL 20 DO BEGIN SetLineWidth(i); DrawLine(20*i, 50, 20*i, 200); DrawLine(20*i, 300, 20*i, 450); END; SetLineWidth(2); DrawLine(410, 50, 490, 250); DrawLine(410, 450, 490, 250); Quit.Wait; EraseText; DrawCenterText("DrawInvertLine(0, 0, 490, 250)"); DrawInvertLine(0, 0, 490, 250); Quit.Wait; EraseText; DrawCentertext("DrawInvertPoint(x, y)"); FOR i := 1 STEP 1 UNTIL 500 DO DrawInvertPoint(RandInt(1, 500, U), RandInt(1, 500, U)); Quit.Wait; END; PROCEDURE RectanglesEx; BEGIN Clear; DrawCenterText("DrawRectangle(150, 150, 200, 50)"); DrawRectangle(150, 150, 200, 50); ShowRectangleInfos; Quit.Wait; Clear; DrawCenterText("FillRectangle(x, y, width, height)"); FillRectangle(150, 150, 200, 50); SetFill("gray25"); FillRectangle(150, 300, 200, 50); Quit.Wait; EraseText; DrawCenterText("InvertRectangle(x, y, width, height)"); InvertRectangle(225, 100, 50, 300); Quit.Wait; InvertRectangle(225, 225, 50, 50); Quit.Wait; EraseText; DrawCenterText("ClearRectangle(x, y, width, height)"); !Maintenant, vous pouvez comprendre EraseText; ClearRectangle(200, 320, 100, 10); Quit.Wait; END; PROCEDURE PolygonsEx; BEGIN INTEGER ARRAY X(1:5), Y(1:5); INTEGER i; Clear; X(1) := 100; Y(1) := 100; X(2) := 150; Y(2) := 20; X(3) := 200; Y(3) := 100; WriteLang("Polygons require arrays of X and Y coordinates", "Les polygones demandent des tableaux en X et Y", "Please, fill me!"); DrawPolygon(X, Y, 3); Quit.Wait; EraseText; DrawCenterText("DrawPolygon(X array, Y array, n)"); X(1) := 320; Y(1) := 100; X(2) := 305; Y(2) := 50; X(3) := 350; Y(3) := 20; X(4) := 395; Y(4) := 50; X(5) := 380; Y(5) := 100; DrawPolygon(X, Y, 5); Quit.Wait; EraseText; WriteLang("And you have to specify every vertex every time!", "Et il faut specifier tous les points a chaque fois!", "Please, fill me!"); X(1) := 100; Y(1) := 400; X(2) := 150; Y(2) := 350; X(3) := 250; Y(3) := 320; X(4) := 350; Y(4) := 350; X(5) := 400; Y(5) := 400; SetFill("black"); FillPolygon(X, Y, 5); Quit.Wait; EraseText; WriteLang("Lets go on with the arcs, now!", "Passons maintenant aux arcs!!!", "Please, fill me!"); Sleep(2); EraseText; SetFill("black"); FillArc(130, 50, 50, 40, 100, 150); FillArc(330, 50, 50, 40, 100, 150); FillCircle(250, 250, 40); SetFill("gray33"); FillArc(100, 320, 300, 120, 210, 120); Quit.Wait; END; PROCEDURE ArcsEx; BEGIN INTEGER i; Clear; DrawCenterText("DrawCircle(250, 150, 100)"); ShowCircleInfos; SetLineWidth(2); DrawCircle(250, 150, 51); Quit.Wait; EraseText; Clear; SetLineWidth(2); SetFill("gray33"); DrawCenterText("FillArc(150, 100, 200, 100, 90, 135)"); FillArc(150, 100, 200, 100, 90, 135); DrawArc(150, 100, 200, 100, 0, 360); ShowArcInfos; Quit.Wait; Clear; SetLineWidth(2); DrawCircle(250, 150, 51); DrawTextCenterIn(250, 75, "Tic... Toc..."); FOR i := 1 STEP 1 UNTIL 8 DO BEGIN INTEGER Angle1, Angle2; Angle1 := 90-45*i; Angle2 := 45*i; EraseText; DrawCenterText("FillArc(200, 100, 100, 100, " & int_as_text(Angle1) & ", " & int_as_text(Angle2) & ")"); FillArc(200, 100, 100, 100, Angle1, Angle2); Sleep(1); END; Quit.Wait; END; SetSize (500, 500); Show; Quit :- MakeButton("Ok").PlaceUpRight; Lang :- AskLanguage; WriteLang("Welcome", "Bienvenue", "Vilkommen"); Quit.Wait; Clear; WriteLang("Intro to WindowTools graphical capabilities", "Intro aux possibilites graphiques de WindowTools", "Please, fill me!"); Quit.Wait; PointsEx; LinesEx; RectanglesEx; PolygonsEx; ArcsEx; Clear; WriteLang("The end...", "Fin...", "Please, fill me!"); !end?; Quit.Wait; % MixedEx; END; REF(JPHMainWindow) MyWindow; MyWindow :- NEW JPHMainWindow("Drawing"); END;