Subversion Repositories Kolibri OS

Rev

Rev 9053 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. package kernel
  2.  
  3. import "os"
  4. import "colors"
  5.  
  6. const (
  7.     Btn1=2;
  8.     Btn2=3;
  9.     BtnExit=1;
  10. )
  11.  
  12. type Button struct { // structure gui button
  13.     label string
  14.     x int
  15.     y int
  16.     id int
  17. }
  18.  
  19. func NewButton() Button {
  20.     object := Button{"Text",0,0,Btn1} // default data
  21.     return object
  22. }
  23.  
  24. func (button *Button) make() {
  25.     os.CreateButton(button.x, button.y, len(button.label)*15, 30, button.id, colors.Blue);
  26.     os.WriteText(button.x,button.y, 0x11000000 | colors.White, button.label)
  27. }
  28.  
  29. func RedrawAll(bar_pos int){
  30.     os.Redraw(1)
  31.     os.Window(500,250,420,200, "Example GoLang")
  32.     os.DrawLine(32, 80, 150, 80, colors.Green)
  33.     os.DrawBar(bar_pos, 90, 100, 30, colors.Red);
  34.  
  35.     b1 := NewButton()
  36.     b1.label = " <- "
  37.     b1.x = 32
  38.     b1.y = 128
  39.     b1.id = Btn1
  40.     b1.make()
  41.  
  42.     b2 := NewButton()
  43.     b2.label = " -> "
  44.     b2.x = 310
  45.     b2.y = 128
  46.     b2.id = Btn2
  47.     b2.make()
  48. }
  49.  
  50. func Main() {
  51.     var pos = 160;
  52.     //time := os.GetTime()
  53.     //os.DebugOutStr("Time: ")
  54.     //os.DebugOutHex(time)
  55.     for true {
  56.         switch os.Event() {
  57.                         case os.EVENT_REDRAW:
  58.                 RedrawAll(pos)
  59.                 break
  60.             case os.EVENT_BUTTON:
  61.             switch os.GetButtonID() {
  62.                 case Btn1:
  63.                     pos-=32
  64.                     RedrawAll(pos)
  65.                     break
  66.                 case Btn2:
  67.                     pos+=32
  68.                     RedrawAll(pos);
  69.                     break
  70.                 case BtnExit:
  71.                     os.Exit()
  72.             }
  73.                 }
  74.         }
  75. }
  76.