Exemple #1
0
func init() {
	lower := "abcdefghijklmnopqrstuvwxyz0123456789-=[];,./\\'"
	upper := "ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}:<>?|\""
	shift_mapping = make(map[gin.KeyId]byte)
	for i := range lower {
		shift_mapping[gin.KeyId(lower[i])] = upper[i]
	}
	shift_mapping[' '] = 0
}
Exemple #2
0
func getKeysFromString(str string) []gin.KeyId {
	parts := strings.Split(str, "+")
	var kids []gin.KeyId
	for _, part := range parts {
		part = osSpecifyKey(part)
		var kid gin.KeyId
		switch {
		case len(part) == 1: // Single character - should be ascii
			kid = gin.KeyId(part[0])

		case part == "ctrl":
			kid = gin.EitherControl

		case part == "shift":
			kid = gin.EitherShift

		case part == "alt":
			kid = gin.EitherAlt

		case part == "gui":
			kid = gin.EitherGui

		case part == "space":
			kid = gin.Space

		case part == "rmouse":
			kid = gin.MouseRButton

		case part == "lmouse":
			kid = gin.MouseLButton

		case part == "vwheel":
			kid = gin.MouseWheelVertical

		case part == "up":
			kid = gin.Up

		case part == "down":
			kid = gin.Down

		default:
			key := gin.In().GetKeyByName(part)
			if key == nil {
				panic(fmt.Sprintf("Unknown key '%s'", part))
			}
			kid = key.Id()
		}
		kids = append(kids, kid)
	}
	return kids
}
Exemple #3
0
// TODO: Make sure that events are given in sorted order (by timestamp)
// TODO: Adjust timestamp on events so that the oldest timestamp is newer than the
//       newest timestemp from the events from the previous call to GetInputEvents
//       Actually that should be in system
func (osx *osxSystemObject) GetInputEvents() ([]gin.OsEvent, int64) {
	var first_event *C.KeyEvent
	cp := (*unsafe.Pointer)(unsafe.Pointer(&first_event))
	var length C.int
	var horizon C.longlong
	C.GetInputEvents(cp, &length, &horizon)
	osx.horizon = int64(horizon)
	c_events := (*[1000]C.KeyEvent)(unsafe.Pointer(first_event))[:length]
	events := make([]gin.OsEvent, length)
	for i := range c_events {
		wx, wy := osx.rawCursorToWindowCoords(int(c_events[i].cursor_x), int(c_events[i].cursor_y))
		events[i] = gin.OsEvent{
			KeyId:     gin.KeyId(c_events[i].index),
			Press_amt: float64(c_events[i].press_amt),
			Timestamp: int64(c_events[i].timestamp),
			X:         wx,
			Y:         wy,
		}
	}
	return events, osx.horizon
}
Exemple #4
0
func editMode() {
	draggingAndZooming(editor.GetViewer())
	if ui.FocusWidget() == nil {
		for name := range editors {
			if key_map[fmt.Sprintf("%s editor", name)].FramePressCount() > 0 && ui.FocusWidget() == nil {
				ui.RemoveChild(editor)
				editor_name = name
				editor = editors[editor_name]
				loadAllRegistries()
				editor.Reload()
				ui.AddChild(editor)
			}
		}

		if key_map["save"].FramePressCount() > 0 && chooser == nil {
			path, err := editor.Save()
			if err != nil {
				base.Warn().Printf("Failed to save: %v", err.Error())
			}
			if path != "" && err == nil {
				base.SetStoreVal(fmt.Sprintf("last %s path", editor_name), base.TryRelative(datadir, path))
			}
		}

		if key_map["load"].FramePressCount() > 0 && chooser == nil {
			callback := func(path string, err error) {
				ui.DropFocus()
				ui.RemoveChild(anchor)
				chooser = nil
				anchor = nil
				err = editor.Load(path)
				if err != nil {
					base.Warn().Printf("Failed to load: %v", err.Error())
				} else {
					base.SetStoreVal(fmt.Sprintf("last %s path", editor_name), base.TryRelative(datadir, path))
				}
			}
			chooser = gui.MakeFileChooser(filepath.Join(datadir, fmt.Sprintf("%ss", editor_name)), callback, gui.MakeFileFilter(fmt.Sprintf(".%s", editor_name)))
			anchor = gui.MakeAnchorBox(gui.Dims{wdx, wdy})
			anchor.AddChild(chooser, gui.Anchor{0.5, 0.5, 0.5, 0.5})
			ui.AddChild(anchor)
			ui.TakeFocus(chooser)
		}

		// Don't select tabs in an editor if we're doing some other sort of command
		ok_to_select := true
		for _, v := range key_map {
			if v.FramePressCount() > 0 {
				ok_to_select = false
				break
			}
		}
		if ok_to_select {
			for i := 1; i <= 9; i++ {
				if gin.In().GetKey(gin.KeyId('0'+i)).FramePressCount() > 0 {
					editor.SelectTab(i - 1)
				}
			}
		}
	}
}