本文整理汇总了Golang中github.com/runningwild/glop/gui.Gui类的典型用法代码示例。如果您正苦于以下问题:Golang Gui类的具体用法?Golang Gui怎么用?Golang Gui使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gui类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Respond
func (c *Console) Respond(ui *gui.Gui, group gui.EventGroup) bool {
if found, event := group.FindEvent(GetDefaultKeyMap()["console"].Id()); found && event.Type == gin.Press {
if group.Focus {
ui.DropFocus()
} else {
ui.TakeFocus(c)
}
return true
}
if group.Focus {
// if found, event := group.FindEvent(gin.Left); found && event.Type == gin.Press {
// c.xscroll += 250
// }
// if found, event := group.FindEvent(gin.Right); found && event.Type == gin.Press {
// c.xscroll -= 250
// }
}
if c.xscroll > 0 {
c.xscroll = 0
}
if found, event := group.FindEvent(gin.AnySpace); found && event.Type == gin.Press {
c.xscroll = 0
}
return group.Focus
}
示例2: Think
func (gp *GamePanel) Think(ui *gui.Gui, t int64) {
gp.scriptThinkOnce()
gp.AnchorBox.Think(ui, t)
if !gp.Active() {
return
}
if gp.game != nil {
gp.game.modal = (ui.FocusWidget() != nil)
}
if gp.last_think == 0 {
gp.last_think = t
}
dt := t - gp.last_think
gp.last_think = t
gp.game.Think(dt)
if gp.main_bar != nil {
if gp.game.selected_ent != nil {
gp.main_bar.SelectEnt(gp.game.selected_ent)
} else {
gp.main_bar.SelectEnt(gp.game.hovered_ent)
}
}
}
示例3: Respond
func (m *MainBar) Respond(g *gui.Gui, group gui.EventGroup) bool {
if g.FocusWidget() != nil {
return false
}
cursor := group.Events[0].Key.Cursor()
if cursor != nil {
m.mx, m.my = cursor.Point()
if m.my > m.layout.Background.Data().Dy() {
return false
}
}
buttons := m.no_actions_buttons
if m.ent != nil && len(m.ent.Actions) > m.layout.Actions.Count {
buttons = m.all_buttons
}
for _, button := range buttons {
if button.Respond(group, m) {
return true
}
}
if found, event := group.FindEvent(gin.MouseLButton); found && event.Type == gin.Press {
for _, button := range buttons {
if button.handleClick(m.mx, m.my, m) {
return true
}
}
if m.ent != nil {
index := m.pointInsideAction(m.mx, m.my)
if index != -1 {
m.state.Actions.clicked = m.ent.Actions[index]
}
}
}
if found, event := group.FindEvent(gin.MouseWheelVertical); found {
x := int(m.layout.Conditions.X)
y := int(m.layout.Conditions.Y)
x2 := int(m.layout.Conditions.X + m.layout.Conditions.Width)
y2 := int(m.layout.Conditions.Y + m.layout.Conditions.Height)
if m.mx >= x && m.my >= y && m.mx < x2 && m.my < y2 {
m.state.Conditions.scroll_pos += event.Key.FramePressAmt()
}
}
return cursor != nil
}
示例4: Think
func (hdt *houseRelicsTab) Think(ui *gui.Gui, t int64) {
defer hdt.VerticalTable.Think(ui, t)
rbx, rby := hdt.viewer.WindowToBoard(gin.In().GetCursor("Mouse").Point())
bx := roundDown(rbx - hdt.drag_anchor.x + 0.5)
by := roundDown(rby - hdt.drag_anchor.y + 0.5)
if hdt.temp_relic != nil {
hdt.temp_relic.X = bx
hdt.temp_relic.Y = by
hdt.temp_relic.Dx += gin.In().GetKey(gin.Right).FramePressCount()
hdt.temp_relic.Dx -= gin.In().GetKey(gin.Left).FramePressCount()
if hdt.temp_relic.Dx < 1 {
hdt.temp_relic.Dx = 1
}
if hdt.temp_relic.Dx > 10 {
hdt.temp_relic.Dx = 10
}
hdt.temp_relic.Dy += gin.In().GetKey(gin.Up).FramePressCount()
hdt.temp_relic.Dy -= gin.In().GetKey(gin.Down).FramePressCount()
if hdt.temp_relic.Dy < 1 {
hdt.temp_relic.Dy = 1
}
if hdt.temp_relic.Dy > 10 {
hdt.temp_relic.Dy = 10
}
hdt.markTempSpawnValidity()
} else {
_, _, spawn_at := hdt.house.Floors[0].RoomFurnSpawnAtPos(roundDown(rbx), roundDown(rby))
if spawn_at != nil {
hdt.spawn_name.SetText(spawn_at.Name)
} else if hdt.spawn_name.IsBeingEdited() {
hdt.typed_name = hdt.spawn_name.GetText()
} else {
hdt.spawn_name.SetText(hdt.typed_name)
}
}
if hdt.temp_relic == nil && gin.In().GetKey('n').FramePressCount() > 0 && ui.FocusWidget() == nil {
hdt.newSpawn()
}
}
示例5: main
func main() {
sys = system.Make(gos.GetSystemInterface())
sys.Startup()
wdx := 1000
wdy := 500
render.Init()
var ui *gui.Gui
render.Queue(func() {
sys.CreateWindow(50, 150, wdx, wdy)
sys.EnableVSync(true)
err := gl.Init()
if err != nil {
f, err2 := os.Create(filepath.Join(datadir, "gl_log.txt"))
if err2 != nil {
fmt.Printf("Unable to write log to a file:%v\n%v\v", err, err2)
} else {
fmt.Fprintf(f, "%v\n", err)
f.Close()
}
}
ui, _ = gui.Make(gin.In(), gui.Dims{wdx, wdy}, filepath.Join(datadir, "fonts", "luxisr.ttf"))
font, err := loadFont()
if err != nil {
panic(err.Error())
}
dict = gui.MakeDictionary(font, 15)
})
render.Purge()
anchor := gui.MakeAnchorBox(gui.Dims{wdx, wdy})
ui.AddChild(anchor)
var event_handler handler
gin.In().RegisterEventListener(&event_handler)
actions_list := gui.MakeVerticalTable()
keyname_list := gui.MakeVerticalTable()
both_lists := gui.MakeHorizontalTable()
both_lists.AddChild(actions_list)
both_lists.AddChild(keyname_list)
anchor.AddChild(both_lists, gui.Anchor{1, 0.5, 1, 0.5})
var actions []string
for action := range action_map {
actions = append(actions, action)
}
sort.Strings(actions)
for _, action := range actions {
actions_list.AddChild(gui.MakeTextLine("standard", action, 150, 1, 1, 1, 1))
keyname_list.AddChild(gui.MakeTextLine("standard", commands[action].Cmd, 100, 1, 1, 1, 1))
}
current_anim := gui.MakeTextLine("standard", "", 300, 1, 1, 1, 1)
current_state := gui.MakeTextLine("standard", "", 300, 1, 1, 1, 1)
frame_data := gui.MakeVerticalTable()
frame_data.AddChild(current_anim)
frame_data.AddChild(current_state)
anchor.AddChild(frame_data, gui.Anchor{0, 1, 0, 1})
speed := 100
speed_text := gui.MakeTextLine("standard", "Speed: 100%", 150, 1, 1, 1, 1)
anchor.AddChild(speed_text, gui.Anchor{0, 0, 0, 0})
var box1, box2 boxdata
box1.name = "box1"
box1.sb = makeSpriteBox(nil)
anchor.AddChild(box1.sb, gui.Anchor{0.5, 0.5, 0.25, 0.5})
box1.load(GetStoreVal("box1"))
box := box1
box2.name = "box2"
box2.sb = makeSpriteBox(nil)
anchor.AddChild(box2.sb, gui.Anchor{0.5, 0.5, 0.45, 0.5})
box2.load(GetStoreVal("box2"))
box2.sb.top = true
box_other := box2
box2.sb.r, box2.sb.g, box2.sb.b = 0.2, 0.1, 0.4
box1.sb.r, box1.sb.g, box1.sb.b = 0.4, 0.2, 0.8
error_msg = gui.MakeTextLine("standard", "", wdx, 1, 0.5, 0.5, 1)
anchor.AddChild(error_msg, gui.Anchor{0, 0, 0, 0.1})
var chooser gui.Widget
// curdir := GetStoreVal("curdir")
// if curdir == "" {
// curdir = "."
// } else {
// _,err := os.Stat(filepath.Join(datadir, curdir))
// if err == nil {
// go func() {
// anim, err := sprite.LoadSprite(filepath.Join(datadir, curdir))
// loaded <- loadResult{ anim, err }
// } ()
// } else {
// curdir = "."
// }
// }
// var profile_output *os.File
then := time.Now()
sys.Think()
for key_map["quit"].FramePressCount() == 0 {
//.........这里部分代码省略.........
示例6: Think
func (m *MainBar) Think(g *gui.Gui, t int64) {
if g.FocusWidget() != nil {
return
}
if m.ent != nil {
// If an action is selected and we can't see it then we scroll just enough
// so that we can.
min := 0.0
max := float64(len(m.ent.Actions) - m.layout.Actions.Count)
selected_index := -1
for i := range m.ent.Actions {
if m.ent.Actions[i] == m.state.Actions.selected {
selected_index = i
break
}
}
if selected_index != -1 {
if min < float64(selected_index-m.layout.Actions.Count+1) {
min = float64(selected_index - m.layout.Actions.Count + 1)
}
if max > float64(selected_index) {
max = float64(selected_index)
}
}
m.state.Actions.selected = m.game.current_action
if m.state.Actions.scroll_target > max {
m.state.Actions.scroll_target = max
}
if m.state.Actions.scroll_target < min {
m.state.Actions.scroll_target = min
}
if m.state.Actions.clicked != nil {
if m.state.Actions.selected != m.state.Actions.clicked {
if m.state.Actions.clicked.Preppable(m.ent, m.game) {
m.state.Actions.clicked.Prep(m.ent, m.game)
m.game.SetCurrentAction(m.state.Actions.clicked)
}
}
m.state.Actions.clicked = nil
}
// We similarly need to scroll through conditions
c := m.layout.Conditions
d := base.GetDictionary(int(c.Size))
max_scroll := d.MaxHeight() * float64(len(m.ent.Stats.ConditionNames()))
max_scroll -= m.layout.Conditions.Height
// This might end up with a max that is negative, but we'll cap it at zero
if m.state.Conditions.scroll_pos > max_scroll {
m.state.Conditions.scroll_pos = max_scroll
}
if m.state.Conditions.scroll_pos < 0 {
m.state.Conditions.scroll_pos = 0
}
} else {
m.state.Conditions.scroll_pos = 0
m.state.Actions.scroll_pos = 0
m.state.Actions.scroll_target = 0
}
// Do a nice scroll motion towards the target position
m.state.Actions.scroll_pos *= 0.8
m.state.Actions.scroll_pos += 0.2 * m.state.Actions.scroll_target
// Handle mouseover stuff after doing all of the scroll stuff since we don't
// want to give a mouseover for something that the mouse isn't over after
// scrolling something.
m.state.MouseOver.active = false
if m.ent != nil {
c := m.layout.Conditions
if pointInsideRect(m.mx, m.my, int(c.X), int(c.Y), int(c.Width), int(c.Height)) {
pos := c.Y + c.Height + m.state.Conditions.scroll_pos - float64(m.my)
index := int(pos / base.GetDictionary(int(c.Size)).MaxHeight())
if index >= 0 && index < len(m.ent.Stats.ConditionNames()) {
m.state.MouseOver.active = true
m.state.MouseOver.text = m.ent.Stats.ConditionNames()[index]
m.state.MouseOver.location = mouseOverConditions
}
}
if index := m.pointInsideAction(m.mx, m.my); index != -1 {
m.state.MouseOver.active = true
m.state.MouseOver.text = m.ent.Actions[index].String()
m.state.MouseOver.location = mouseOverActions
}
}
buttons := m.no_actions_buttons
if m.ent != nil && len(m.ent.Actions) > m.layout.Actions.Count {
buttons = m.all_buttons
}
for _, button := range buttons {
button.Think(m.region.X, m.region.Y, m.mx, m.my, t)
}
}