ExampleTextWriter.Mod 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. MODULE ExampleTextWriter; (** AUTHOR "TF"; PURPOSE "Template/Example for component windows"; *)
  2. (** This program shows the implementation of a multi instance component containing window *)
  3. IMPORT
  4. Strings, WMGraphics, WMComponents, WMWindowManager,
  5. WMEditors, TextUtilities, Math;
  6. TYPE
  7. Window* = OBJECT (WMComponents.FormWindow)
  8. VAR editor : WMEditors.Editor;
  9. PROCEDURE &New*;
  10. BEGIN
  11. NEW(editor); editor.bounds.SetExtents(800, 700);
  12. editor.fillColor.Set(WMGraphics.White);
  13. Init(editor.bounds.GetWidth(), editor.bounds.GetHeight(), FALSE);
  14. SetContent(editor);
  15. WMWindowManager.DefaultAddWindow(SELF);
  16. SetTitle(Strings.NewString("TextWriter Example"));
  17. WriteToEditor;
  18. END New;
  19. PROCEDURE WriteToEditor;
  20. VAR
  21. tw : TextUtilities.TextWriter;
  22. i : LONGINT;
  23. buffer : ARRAY 256 OF CHAR;
  24. BEGIN
  25. NEW(tw, editor.text);
  26. tw.SetFontSize(20);
  27. tw.String("This is a simple text. Count from 0 to 10 : "); tw.Ln;
  28. FOR i := 0 TO 10 DO tw.Int(i, 5) END; tw.Ln;
  29. tw.SetFontStyle({WMGraphics.FontBold});
  30. tw.String("This is bold. ");
  31. tw.SetFontStyle({WMGraphics.FontItalic});
  32. tw.String("This is italic.");
  33. tw.SetFontStyle({WMGraphics.FontBold});
  34. tw.SetFontColor(WMGraphics.Red);
  35. tw.String("This is bold red."); tw.Ln;
  36. tw.SetBgColor(WMGraphics.Black);
  37. tw.SetFontColor(WMGraphics.White);
  38. tw.String("This is bold white on black");
  39. tw.Ln;
  40. tw.SetFontStyle({});
  41. tw.SetBgColor(WMGraphics.White);
  42. tw.SetFontColor(WMGraphics.Black);
  43. buffer := "This is a bit fancy! It modulates the vertical offset with a cosine function and fades out.";
  44. i := 0;
  45. tw.SetFontStyle({WMGraphics.FontBold});
  46. WHILE buffer[i] # 0X DO
  47. tw.SetFontColor(WMGraphics.RGBAToColor(i * 2, i * 2, i * 2, 0FFH));
  48. tw.SetVerticalOffset(ENTIER(15 * Math.cos(i/4)));
  49. tw.Char(buffer[i]);
  50. INC(i)
  51. END;
  52. tw.Update;
  53. END WriteToEditor;
  54. END Window;
  55. PROCEDURE Open*;
  56. VAR inst, i2 : Window;
  57. BEGIN
  58. NEW(inst);
  59. NEW(i2);
  60. i2.editor.SetText(inst.editor.text);
  61. END Open;
  62. END ExampleTextWriter.
  63. System.Free ExampleTextWriter ~
  64. ExampleTextWriter.Open