Module Simula

Class RTS_Drawing

All Implemented Interfaces:
Runnable

public class RTS_Drawing extends RTS_Simset
Additional System class Drawing.

The class "Drawing" introduce basic graphical capabilities. It has the class "simset" as prefix, so set-handling facilities are thus immediately available.

 Simset class Drawing(title,width,height); Value title; Text title; Integer width,height;
 begin ref(Head) RENDERING_SET;
             Integer CURRENT_BACKGROUND_COLOR,CURRENT_DRAW_COLOR,CURRENT_FILL_COLOR,CURRENT_STROKE_WIDTH;
       ref(Font) CURRENT_FONT; ! Java Class Font is not visible in Simula ;

       ref(Head) Procedure renderingSet; renderingSet :- RENDERING_SET;
       Integer white,lightGray,gray,darkGray,black,red,pink,orange,yellow,green,magenta,cyan,blue;  
       Integer Procedure color(r,g,b); Integer r,g,b; ...   
       Procedure setBackgroundColor(color); Integer color; CURRENT_BACKGROUND_COLOR := color;  
       Procedure setDrawColor(color); Integer color; CURRENT_DRAW_COLOR := color;  
       Procedure setFillColor(color); Integer color; CURRENT_FILL_COLOR := color;
       Procedure setStroke(width); Real width; CURRENT_STROKE_WIDTH := width; 

       Procedure setFontStylePlain;      CURRENT_FONT :- CURRENT_FONT.deriveFont(Font.PLAIN);  
       Procedure setFontStyleBold;       CURRENT_FONT :- CURRENT_FONT.deriveFont(Font.BOLD); 
       Procedure setFontStyleItalic;     CURRENT_FONT :- CURRENT_FONT.deriveFont(Font.ITALIC); 
       Procedure setFontStyleBoldItalic; CURRENT_FONT :- CURRENT_FONT.deriveFont(Font.BOLD|Font.ITALIC); 
          
       Procedure setFontSize(size); Real size; CURRENT_FONT :- CURRENT_FONT.deriveFont(size); 
       Real Procedure getFontSize; getFontSize := CURRENT_FONT.getSize2D;

       Link class ShapeElement; ...
       Link class TextElement; ...

       ref(TextElement) Procedure drawText(t,x,y); Value t; Text t; Long Real x1,y1,x2,y2;
       begin ref(TextElement) elt; drawText :- elt :- new TextElement(t,x,y); end;

       ref(ShapeElement) Procedure drawLine(x1,y1,x2,y2); Long Real x1,y1,x2,y2;
       begin ref(ShapeElement) elt; drawLine :- elt :- new ShapeElement; elt.drawLine(x1,y1,x2,y2); end;
      
       ref(ShapeElement) Procedure drawEllipse(x,y,width,height); Long Real x,y,width,height;
       begin ref(ShapeElement) elt; drawEllipse :- elt :- new ShapeElement; elt.drawEllipse(x,y,width,height); end;
       
       ref(ShapeElement) Procedure drawRectangle(double x,double y,double width,double height)
       begin ref(ShapeElement) elt; drawRectangle :- elt :- new ShapeElement; elt.drawRectangle(x,y,width,height); end;
       
       ref(ShapeElement) Procedure drawRoundRectangle(x,y,width,height,arcw,arch); Long Real x,y,width,height,arcw,arch;
       begin ref(ShapeElement) elt; drawRoundRectangle :- elt :- new ShapeElement; elt.drawRoundRectangle(x,y,width,height,arcw,arch); end;
      
       ref(ShapeElement) Procedure fillEllipse(x,y,width,height); Long Real x,y,width,height;
       begin ref(ShapeElement) elt; fillEllipse :- elt :- new ShapeElement; elt.fillEllipse(x,y,width,height); end;
       
       ref(ShapeElement) Procedure fillRectangle(x,y,width,height); Long Real x,y,width,height;
       begin ref(ShapeElement) elt; fillRectangle :- elt :- new ShapeElement; elt.fillRectangle(x,y,width,height); end;
       
       ref(ShapeElement) Procedure fillRoundRectangle(x,y,width,height,arcw,arch); Long Real x,y,width,height,arcw,arch;
       begin ref(ShapeElement) elt; fillRoundRectangle :- elt :- new ShapeElement; elt.fillRoundRectangle(x,y,width,height,arcw,arch); end;

       RENDERING_SET  :-  new head;
       CURRENT_BACKGROUND_COLOR := white;
       CURRENT_DRAW_COLOR=black;
       CURRENT_FILL_COLOR=gray;
       CURRENT_STROKE_WIDTH := 2.5;
       CURRENT_FONT=new Font(Font.SANS_SERIF,12,Font.PLAIN); ! Font size 12 ;

 end Drawing;
 
When used as a prefix to a block or a class, "simulation" introduces simulation-oriented features through the class "process" and associated procedures.

The variable RENDERING_SET refers to a set of graphical elements to be rendered. The members of the rendering set are ShapeElements and TextElements. The elements are rendered in the order defined by the RENDERING_SET, starting with RENDERING_SET.first.

Link to GitHub: Source File.

Author:
Øystein Myhre Andersen
  • Field Details

    • DEBUG

      private static final boolean DEBUG
      DEBUG on/off
      See Also:
    • _white_1

      public static final int _white_1
      The color white.
      See Also:
    • _lightGray_1

      public static final int _lightGray_1
      The color lightGray.
      See Also:
    • _gray_1

      public static final int _gray_1
      The color gray.
      See Also:
    • _darkGray_1

      public static final int _darkGray_1
      The color darkGray.
      See Also:
    • _black_1

      public static final int _black_1
      The color black.
      See Also:
    • _red_1

      public static final int _red_1
      The color red.
      See Also:
    • _pink_1

      public static final int _pink_1
      The color pink.
      See Also:
    • _orange_1

      public static final int _orange_1
      The color orange.
      See Also:
    • _yellow_1

      public static final int _yellow_1
      The color yellow.
      See Also:
    • _green_1

      public static final int _green_1
      The color green.
      See Also:
    • _magenta_1

      public static final int _magenta_1
      The color magenta.
      See Also:
    • _cyan_1

      public static final int _cyan_1
      The color cyan.
      See Also:
    • _blue_1

      public static final int _blue_1
      The color blue.
      See Also:
    • frame

      final JFrame frame
      The current Frame.
    • canvas

      final RTS_Drawing.DrawCanvas canvas
      The current canvas.
    • strategy

      final BufferStrategy strategy
      The buffer strategy.
    • RENDERING_SET

      public final RTS_Head RENDERING_SET
      The redering set.
    • currentBackgroundColor

      Color currentBackgroundColor
      The current background color
    • currentDrawColor

      Color currentDrawColor
      The current draw color
    • currentFillColor

      Color currentFillColor
      The current currentBackgroundColor
    • currentStroke

      Stroke currentStroke
      The current stroke
    • currentFont

      Font currentFont
      The current font
  • Constructor Details

    • RTS_Drawing

      public RTS_Drawing(RTS_RTObject SL, RTS_TXT title, int width, int height)
      Create a new Drawing Canvas.
      Parameters:
      SL - staticLink
      title - panel's title
      width - the width of the panel
      height - the height of the panel
  • Method Details

    • renderingSet

      public RTS_Head renderingSet()
      Returns the rendering set.
      Returns:
      the rendering set.
    • repaintMe

      public void repaintMe()
      Request a repaint.
    • setFontStylePlain

      public void setFontStylePlain()
      set font style plain
    • setFontStyleBold

      public void setFontStyleBold()
      set font style bold
    • setFontStyleItalic

      public void setFontStyleItalic()
      set font style italic
    • setFontStyleBoldItalic

      public void setFontStyleBoldItalic()
      Set font style bold and italic.
    • setStroke

      public void setStroke(float size)
      Set stroke size.
      Parameters:
      size - the stroke size.
    • setFontSize

      public void setFontSize(float size)
      Set font size.
      Parameters:
      size - the font size.
    • getFontSize

      public float getFontSize()
      Get font size.
      Returns:
      the font size.
    • setBackgroundColor

      public void setBackgroundColor(int color)
      Set background color.
      Parameters:
      color - the background color
    • setDrawColor

      public void setDrawColor(int color)
      Set draw color.
      Parameters:
      color - the draw color
    • setFillColor

      public void setFillColor(int color)
      Set fill color.
      Parameters:
      color - the fill color
    • color

      public int color(int red, int green, int blue)
       integer procedure color(r,g,b); integer r,g,b; ... ... ;
       
      Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.
      Parameters:
      red - the red component
      green - the green component
      blue - the blue component
      Returns:
      the resulting color
    • drawText

      public RTS_TextElement drawText(RTS_TXT t, double x, double y)
      Draw Text.
      Parameters:
      t - the text
      x - the X coordinate
      y - the Y coordinate
      Returns:
      the resulting _TextElement
    • drawLine

      public RTS_ShapeElement drawLine(double x1, double y1, double x2, double y2)
      Draw Line
      Parameters:
      x1 - the X coordinate of the start point
      y1 - the Y coordinate of the start point
      x2 - the X coordinate of the end point
      y2 - the Y coordinate of the end point
      Returns:
      the resulting _ShapeElement
    • drawEllipse

      public RTS_ShapeElement drawEllipse(double x, double y, double w, double h)
      Draw Ellipse.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      w - the width of the ellipse
      h - the height of the ellipse
      Returns:
      the resulting _ShapeElement
    • drawRectangle

      public RTS_ShapeElement drawRectangle(double x, double y, double w, double h)
      Draw Rectangle.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      w - the width of the rectangle
      h - the height of the rectangle
      Returns:
      the resulting _ShapeElement
    • drawRoundRectangle

      public RTS_ShapeElement drawRoundRectangle(double x, double y, double w, double h, double arcw, double arch)
      Draw Rounded Rectangle.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      w - the width of the rectangle
      h - the height of the rectangle
      arcw - the width of the arc to use to round off the corners
      arch - the height of the arc to use to round off the corners
      Returns:
      the resulting _ShapeElement
    • fillEllipse

      public RTS_ShapeElement fillEllipse(double x, double y, double w, double h)
      Fill Ellipse.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      w - the width of the ellipse
      h - the height of the ellipse
      Returns:
      the resulting _ShapeElement
    • fillRectangle

      public RTS_ShapeElement fillRectangle(double x, double y, double w, double h)
      Fill Rectangle.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      w - the width of the rectangle
      h - the height of the rectangle
      Returns:
      the resulting _ShapeElement
    • fillRoundRectangle

      public RTS_ShapeElement fillRoundRectangle(double x, double y, double w, double h, double arcw, double arch)
      Fill Rounded Rectangle.
      Parameters:
      x - the X coordinate
      y - the Y coordinate
      w - the width of the rectangle
      h - the height of the rectangle
      arcw - the width of the arc to use to round off the corners
      arch - the height of the arc to use to round off the corners
      Returns:
      the resulting _ShapeElement
    • _STM

      public RTS_Drawing _STM()
      Description copied from class: RTS_RTObject
      Method representing the Statements in this Block
      This method is virtual and must be redefined in blocks.
      Overrides:
      _STM in class RTS_Simset
      Returns:
      a pointer to this _RTObject