' QCheck component for Rapid-Q by William Yu

TYPE MCheckBox EXTENDS QCanvas
PUBLIC:
  Caption AS STRING
  Checked AS INTEGER
  HiLightColor AS INTEGER

PRIVATE:
  MyFont AS QFont

  SUB DrawComponent
    IF MCheckBox.Checked THEN
      MCheckBox.FillRect(0,0,18,18,&H007B00)
      MCheckBox.Line(0,0,18,0,&H00FF00)
      MCheckBox.Line(0,0,0,18,&H00FF00)
      MCheckBox.Line(18,1,18,18,0)
      MCheckBox.Line(1,18,18,18,0)
      MCheckBox.Line(3,3,15,3,0)
      MCheckBox.Line(3,3,3,15,0)
      MCheckBox.Line(15,4,15,15,&H00FF00)
      MCheckBox.Line(4,15,15,15,&H00FF00)
      MCheckBox.Line(2,7,8,13,&H00FFFF)
      MCheckBox.Line(3,7,8,12,&H00FFFF)
      MCheckBox.Line(8,12,14,1,&H00FFFF)
      MCheckBox.Line(9,12,15,1,&H00FFFF)
    ELSE
      MCheckBox.FillRect(0,0,18,18,&H007B00)
      MCheckBox.Line(0,0,18,0,&H00FF00)
      MCheckBox.Line(0,0,0,18,&H00FF00)
      MCheckBox.Line(18,1,18,18,0)
      MCheckBox.Line(1,18,18,18,0)
      MCheckBox.Line(3,3,15,3,0)
      MCheckBox.Line(3,3,3,15,0)
      MCheckBox.Line(15,4,15,15,&H00FF00)
      MCheckBox.Line(4,15,15,15,&H00FF00)
    END IF
    MCheckBox.TextOut(24, 3, MCheckBox.Caption, 0, -1)
  END SUB

  EVENT OnMouseUp (BUT AS INTEGER, X AS INTEGER, Y AS INTEGER)
    IF BUT <> 0 THEN
       EXIT EVENT
    END IF
    IF X<=18 AND X >= 0 AND Y <= 18 AND Y >= 0 THEN
      IF MCheckBox.Checked THEN
         MCheckBox.Checked = 0
      ELSE
         MCheckBox.Checked = 1
      END IF
      MCheckBox.DrawComponent
    END IF
  END EVENT

  EVENT OnPaint
    MCheckBox.DrawComponent
  END EVENT

  '-- Default values
  CONSTRUCTOR
    Height = 30
    Width = 100
    HiLightColor = &H00FF00
    Caption = "CheckBox"
    Checked = 0
    MyFont.Name = "Arial"
    MyFont.Size = 9
    Font = MCheckBox.MyFont
  END CONSTRUCTOR
END TYPE


SUB Checked
  ShowMessage("Checked")
END SUB


CREATE Form AS QFORM
  Width = 150
  Height = 160
  Color = (128 SHL 16) OR (208 SHL 8) OR 159
  CREATE CheckBox1 AS MCheckBox
    Left = 10: Top = 10
    Checked = 1
    Caption = "I'm Checked"
  END CREATE
  CREATE CheckBox2 AS MCheckBox
    Left = 10: Top = 35
    Caption = "Oranges"
  END CREATE
  CREATE CheckBox3 AS MCheckBox
    Left = 10: Top = 60
    Caption = "Grapes"
  END CREATE
  CREATE CheckBox4 AS MCheckBox
    Left = 10: Top = 85
    Caption = "Option"
    OnClick = Checked
  END CREATE
  Center
  ShowModal
END CREATE
