예제 #1
0
파일: window.go 프로젝트: tanema/amore
// ShowMessageBox will present a message box at the top of the screen.
// if attached to the window it will be attached to the top bar. the box type will style
// the message box and icon. The first button will be the primary enter action, and
// the last button will be the escape/cancel action
func ShowMessageBox(title, message string, buttons []string, box_type MessageBoxType, attachtowindow bool) string {
	var sdlwindow *sdl.Window
	if attachtowindow {
		sdlwindow = getCurrent().sdl_window
	}

	sdl_buttons := []sdl.MessageBoxButtonData{}
	for i, button_text := range buttons {
		new_button := sdl.MessageBoxButtonData{
			ButtonId: int32(i),
			Text:     button_text,
		}
		if i == 0 {
			new_button.Flags |= sdl.MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT
		}
		if i == len(buttons)-1 {
			new_button.Flags |= sdl.MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT
		}
		sdl_buttons = append(sdl_buttons, new_button)
	}

	messageboxdata := sdl.MessageBoxData{
		Flags:      uint32(box_type),
		Window:     sdlwindow,
		Title:      title,
		Message:    message,
		NumButtons: int32(len(sdl_buttons)),
		Buttons:    sdl_buttons,
	}

	var _, buttonid = sdl.ShowMessageBox(&messageboxdata)
	return buttons[buttonid]
}
예제 #2
0
func main() {
	buttons := []sdl.MessageBoxButtonData{
		{0, 0, "no"},
		{sdl.MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT, 1, "yes"},
		{sdl.MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT, 2, "cancel"},
	}

	colorScheme := sdl.MessageBoxColorScheme{
		Colors: [5]sdl.MessageBoxColor{
			sdl.MessageBoxColor{255, 0, 0},
			sdl.MessageBoxColor{0, 255, 0},
			sdl.MessageBoxColor{255, 255, 0},
			sdl.MessageBoxColor{0, 0, 255},
			sdl.MessageBoxColor{255, 0, 255},
		},
	}

	messageboxdata := sdl.MessageBoxData{
		sdl.MESSAGEBOX_INFORMATION,
		nil,
		"example message box",
		"select a button",
		int32(len(buttons)),
		buttons,
		&colorScheme,
	}

	var buttonid int32
	var err error
	if err, buttonid = sdl.ShowMessageBox(&messageboxdata); err != nil {
		fmt.Println("error displaying message box")
		return
	}

	if buttonid == -1 {
		fmt.Println("no selection")
	} else {
		fmt.Println("selection was", buttons[buttonid].Text)
	}
}