Drawing shapes


/* main.sma */
use core
use base
use display
use gui
      
_main_
Component root {
  Frame f ("Drawing shapes", 0, 0, 300, 250)
  Exit quit (0, 1)
  f.close->quit
      
  FillColor fc (200, 50, 50)
  Component rot_rect {
    Translation t (50, 50)
    Rotation rot (45, 50, 25)
    Rectangle rect (0, 0, 100, 50, 0, 0)
  }
  Polygon p {
    Point p1 (200, 50)
    Point p2 (170, 100)
    Point p3 (230, 100)
  }
}
      

            

The gui module contains usual graphic shapes, style properties and affine transformations. Style properties and transformations are full-fledge components that are added to the tree. They act as context modifiers. Each time a new Component is created, a new context is pushed on the context stack with values identical to the previous one. The context is pop out when the component is closed. Thus the FillColor component is applied both on the rectangle and the polygon while the Translation and the Rotation are only applied to the rectangle as they are added to the sub-component rot_rect.