func (g *GUI) Update(dt float64) int { // Update the mouse variables g.mouse.Pos() g.lPressed = input.NewKey(input.K_LBUTTON).Down() g.lReleased = input.NewKey(input.K_LBUTTON).Up() g.rPressed = input.NewKey(input.K_RBUTTON).Down() g.rReleased = input.NewKey(input.K_RBUTTON).Up() g.mouse.WheelMovement() // Update all controls for e := g.ctrls.Front(); e != nil; e = e.Next() { e.Value.(*GUIObject).Update(dt) } // Handle Enter/Leave if g.enterLeave > 0 { done := true for e := g.ctrls.Front(); e != nil; e = e.Next() { if !e.Value.(*GUIObject).IsDone() { done = false break } } if !done { return 0 } else { if g.enterLeave == 1 { return -1 } else { g.enterLeave = 0 } } } // Handle keys key := input.GetKey() if ((g.navMode&GUI_LEFTRIGHT) == GUI_LEFTRIGHT && key == input.K_LEFT) || ((g.navMode&GUI_UPDOWN) == GUI_UPDOWN && key == input.K_UP) { ctrl := g.ctrlFocus if ctrl == nil { e := g.ctrls.Front() if e == nil { return 0 } ctrl = e.Value.(*GUIObject) if ctrl == nil { return 0 } } for e := elementById(ctrl.Id, g.ctrls).Prev(); ; e = e.Prev() { if e == nil && (g.navMode&GUI_CYCLED) == GUI_CYCLED || g.ctrlFocus == nil { ctrl = g.ctrls.Back().Value.(*GUIObject) } else { ctrl = e.Value.(*GUIObject) } if ctrl == g.ctrlFocus { break } if ctrl.Static == false || ctrl.Visible == true || ctrl.Enabled == true { break } } if ctrl != g.ctrlFocus { if g.ctrlFocus != nil { g.ctrlFocus.Focus(false) } if ctrl != nil { ctrl.Focus(true) } g.ctrlFocus = ctrl } } else if ((g.navMode&GUI_LEFTRIGHT) == GUI_LEFTRIGHT && key == input.K_RIGHT) || ((g.navMode&GUI_UPDOWN) == GUI_UPDOWN && key == input.K_DOWN) { ctrl := g.ctrlFocus if ctrl == nil { e := g.ctrls.Back() if e == nil { return 0 } ctrl = e.Value.(*GUIObject) if ctrl == nil { return 0 } } for e := elementById(ctrl.Id, g.ctrls).Next(); ; e = e.Next() { if e == nil && (g.navMode&GUI_CYCLED) == GUI_CYCLED || g.ctrlFocus == nil { ctrl = g.ctrls.Front().Value.(*GUIObject) } else { ctrl = e.Value.(*GUIObject) } if ctrl == g.ctrlFocus { break } if ctrl.Static == false || ctrl.Visible == true || ctrl.Enabled == true { break } } if ctrl != g.ctrlFocus { if g.ctrlFocus != nil { g.ctrlFocus.Focus(false) } if ctrl != nil { ctrl.Focus(true) } g.ctrlFocus = ctrl } } else if g.ctrlFocus != nil && key > 0 && key != input.K_LBUTTON && key != input.K_RBUTTON { if g.ctrlFocus.KeyClick(key, input.GetChar()) { return g.ctrlFocus.Id } } // Handle mouse lDown := input.NewKey(input.K_LBUTTON).State() rDown := input.NewKey(input.K_RBUTTON).State() if g.ctrlLock != nil { ctrl := g.ctrlLock if !lDown && !rDown { g.ctrlLock = nil } if g.process(ctrl) { return ctrl.Id } } else { for e := g.ctrls.Front(); e != nil; e = e.Next() { ctrl := e.Value.(*GUIObject) if ctrl.Rect.TestPoint(g.mouse.X, g.mouse.Y) && ctrl.Enabled { if g.ctrlOver != ctrl { if g.ctrlOver != nil { g.ctrlOver.MouseOver(false) } ctrl.MouseOver(true) g.ctrlOver = ctrl } if g.process(ctrl) { return ctrl.Id } else { return 0 } } } if g.ctrlOver != nil { g.ctrlOver.MouseOver(false) g.ctrlOver = nil } } return 0 }
func (h *HGE) Input_GetChar() int { return input.GetChar() }