Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

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