Exemplo n.º 1
0
func (B *Imp) editNumber(imGraphikmodus bool, Text *string, x, y uint) {
	//
	var (
		char        byte
		cursorshape scr.Shape
		temp        uint
		firstTime   bool
	)
	B.graphical = imGraphikmodus
	//  if B.usesMouse { scr.SwitchMouseCursor (true) }
	Norm(Text, B.width)
	B.overwritable = !Empty(*Text)
	Move(Text, false)
	B.index = 0
	B.write(*Text, x, y)
	B.index = B.width
	if B.TRnumerical {
		firstTime = true
		edited = false
		// Zahl beim ersten Lesen eines Zeichens zurücksetzen, s.u.
	} else {
		edited = true
	}
	for {
		getStatus(Text)
		if B.overwritable {
			cursorshape = scr.Block
		} else {
			cursorshape = scr.Understroke
		}
		if B.graphical {
			scr.WarpGr(x+scr.NX1()*B.index, y, cursorshape)
		} else {
			scr.Warp(y/scr.NY1(), x/scr.NX1()+B.index, cursorshape) // Off
		}
		for {
			char, B.command, B.depth = kbd.Read()
			switch char {
			case 0: // Command
				break
			case '0', '1', '2', '3', '4', '5', '6', '7', '8', '9':
				if B.TRnumerical {
					if firstTime {
						*Text = Clr(B.width)
						status = start
						firstTime = false
						edited = true
					}
				}
				if status == start {
					status = bp
					break
				} else if status == ee {
					if Contains(*Text, 'E', &temp) {
						if temp >= B.width-3 { // not more than 2 digits after 'E'
							break
						}
					}
				} else {
					break
				}
			case '-':
				if B.TRnumerical {
					kbd.DepositCommand(kbd.None)
					kbd.DepositByte(char)
					return
				} else {
					if Empty(*Text) || (*Text)[B.width-1] == 'E' {
						break
					}
				}
			case '.', ',':
				if status == bp {
					status = ap
					break
				}
			case 'E':
				if B.numerical || B.TRnumerical {
					if status == ap && // noch Platz für zwei Zeichen
						(*Text)[0] == space && (*Text)[1] == space {
						status = ee
						if B.numerical {
							break
						} else {
							Rem(Text, B.width-2, 2)
							*Text = *Text + "E+"
							char = 0
							break
						}
					}
				}
			case 'v':
				char = 0
				if B.TRnumerical { // || B.numerical {
					if status == bp || status == ap {
						temp = 0
						for (*Text)[temp] == space {
							temp++
						}
						if (*Text)[temp] == '-' {
							Replace(Text, temp, '+')
							break
						} else if (*Text)[temp] == '+' {
							Replace(Text, temp, '-')
							break
						} else if temp > 0 {
							Replace(Text, temp-1, '-')
							break
						}
					} else if status == ee {
						if Contains(*Text, 'E', &temp) {
							if (*Text)[temp+1] == '-' {
								Replace(Text, temp+1, '+')
								break
							} else if (*Text)[temp+1] == '+' {
								Replace(Text, temp+1, '-')
								break
							}
						}
					}
				}
			default:
				if B.TRnumerical {
					// >>> Besser wäre dies nur für den Fall, dass 'Zeichen' ein Funktionszeichen aus dem Zahlen-Modul ist:
					kbd.DepositCommand(kbd.None)
					kbd.DepositByte(char)
					return
				}
			}
		}
		if B.graphical {
			scr.WarpGr(x+scr.NX1()*B.index, y, scr.Off)
		} else {
			scr.Warp(y/scr.NY1(), x/scr.NX1()+B.index, scr.Off)
		}
		if B.command == kbd.None {
			if B.index == B.width {
				if B.overwritable {
					B.overwritable = false
				}
				if char == 0 { // change of sign or exponent
					temp = B.index
					B.index = 0
					B.write(*Text, x, y)
					B.index = temp
				} else if B.possibleNumerical(Text, x, y) {
					temp = B.index
					B.index = 0
					B.write(*Text, x, y)
					B.index = temp
					Replace(Text, B.index-1, char)
					scr.Lock()
					scr.Colours(B.cF, B.cB)
					if B.graphical {
						scr.Write1Gr(char, int(x+scr.NX1()*(B.index-1)), int(y))
					} else {
						scr.Write1(char, y/scr.NY1(), x/scr.NX1()+B.index-1)
					}
					scr.Unlock()
				} else {
				}
			} else {
				// see editText
			}
		} else {
			if B.doneNumerical(Text, x, y) {
				break
			}
		}
	}
	// if B.usesMouse { scr.SwitchMouseCursor (false) }
}
Exemplo n.º 2
0
func (B *Imp) editText(imGraphikmodus bool, Text *string, x, y uint) {
	//
	var char byte
	var cursorshape scr.Shape
	B.graphical = imGraphikmodus
	// if B.usesMouse { scr.SwitchMouseCursor (true) }
	Norm(Text, B.width)
	B.overwritable = !Empty(*Text)
	B.index = 0
	B.write(*Text, x, y)
	B.overwritable = !Empty(*Text)
	B.write(*Text, x, y)
	if B.start > 0 && B.start < B.width {
		B.index = B.start
		B.start = 0
	} else {
		B.index = 0
	}
	for {
		if B.overwritable {
			cursorshape = scr.Block
		} else {
			cursorshape = scr.Understroke
		}
		if B.graphical {
			scr.WarpGr(x+scr.NX1()*B.index, y, cursorshape)
		} else {
			scr.Warp(y/scr.NY1(), x/scr.NX1()+B.index, cursorshape)
		}
		for {
			char, B.command, B.depth = kbd.Read()
			if B.command < kbd.Go {
				break
			}
		}
		edited = char != byte(0)
		if B.graphical {
			scr.WarpGr(x+scr.NX1()*B.index, y, scr.Off)
		} else {
			scr.Warp(y/scr.NY1(), x/scr.NX1()+B.index, scr.Off)
		}
		if B.command == kbd.None {
			if B.index == B.width {
				// see editNumber
			} else {
				if B.possible(Text, x, y) {
					Replace(Text, B.index, char)
					scr.Lock()
					scr.Colours(B.cF, B.cB)
					if B.graphical {
						scr.Write1Gr(char, int(x+scr.NX1()*B.index), int(y))
					} else {
						scr.Write1(char, y/scr.NY1(), x/scr.NX1()+B.index)
					}
					scr.Unlock()
					B.index++
				}
			}
		} else {
			if B.done(Text, x, y) {
				break
			}
		}
	}
	// if B.usesMouse { scr.SwitchMouseCursor (false) }
}