示例#1
0
文件: main.go 项目: CaptainSoOmA/Uni
func paint(f figure, fo format, x0, y0, x, y int) {
	//
	var a, b uint
	if x >= x0 {
		a = uint(x - x0)
	} else {
		a = uint(x0 - x)
	}
	if y >= y0 {
		b = uint(y - y0)
	} else {
		b = uint(y0 - y)
	}
	switch f {
	case line:
		switch fo {
		case border:
			scr.Line(x0, y0, x, y)
		case inv:
			scr.LineInv(x0, y0, x, y)
		case full:
			// scr.StrichAusgeben (x0, y0, x, y, Staerke)
		}
	case rectangle:
		switch fo {
		case border:
			scr.Rectangle(x0, y0, x, y)
		case inv:
			scr.RectangleInv(x0, y0, x, y)
		case full:
			scr.RectangleFull(x0, y0, x, y)
		}
	case circle:
		if b > a {
			a = b
		}
		switch fo {
		case border:
			scr.Circle(x0, y0, a)
		case inv:
			scr.CircleInv(x0, y0, a)
		case full:
			scr.CircleFull(x0, y0, a)
		}
	case ellipse:
		switch fo {
		case border:
			/*
			     scr.Ellipse ((x0 + x) / 2, (y0 + y) / 2, a, b)
			   case invers:
			     scr.EllipseInv ((x0 + x) / 2, (y + y0) / 2, a, b)
			   case full:
			     scr.EllipseFull ((x0 + x) / 2, (y0 + y) / 2, a, b)
			*/
			scr.Ellipse(x0, y0, a, b)
		case inv:
			scr.EllipseInv(x0, y0, a, b)
		case full:
			scr.EllipseFull(x0, y0, a, b)
		}
	}
	//  scr.Colour (paintColour), (* Wörkeraund: Bildschirm....Invertieren f *)
}
示例#2
0
文件: main.go 项目: CaptainSoOmA/Uni
func main() {
	//
	if !scr.MouseEx() {
		return
	}
	var symbol [Nfigure]byte
	symbol[line] = 'S'      // "Strecke"
	symbol[rectangle] = 'R' // "Rechteck"
	symbol[circle] = 'K'    // "Kreis"
	symbol[ellipse] = 'E'   // "Ellipse"
	X, Y := 0, 0
	X1, Y1 := scr.NX(), scr.NY()
	//  Farbe, Papier:= col.LightWhite, col.Black
	Farbe, Papier := col.Black, col.LightWhite
	col.ScreenF, col.ScreenB = Farbe, Papier
	scr.Cls()
	paintColour := Farbe
	scr.Colour(paintColour)
	//  Staerke = 3
	bx := box.New()
	bx.Wd(20)
	bx.Colours(Papier, Farbe)
	Name := env.Par(1)
	if str.Empty(Name) {
		Name = "temp"
	}
	scr.Save(0, 0, 20, 1)
	for {
		bx.Edit(&Name, 0, 0)
		if !str.Empty(Name) {
			str.RemSpaces(&Name)
			break
		}
	}
	scr.Restore(0, 0, 20, 1)
	img.Get(Name, uint(X), uint(Y))
	scr.MouseCursor(true)
	Figur := figure(rectangle)
	var x, y, x0, y0 int
loop:
	for {
		scr.Colour(paintColour)
		Zeichen, Kommando, T := kbd.Read()
		switch Kommando {
		case kbd.None:
			x, y = scr.MousePosGr()
			scr.SwitchTransparence(true)
			scr.Write1Gr(Zeichen, x, y-int(scr.NY1()))
			//    scr.WarpMouse (x + scr.NX1(), y)
		case kbd.Esc:
			break loop
		case kbd.Back:
			switch T {
			case 0:
				x, y = scr.MousePosGr()
				x -= int(scr.NX1())
				scr.Colour(Papier)
				scr.Write1Gr(' ', x, y-int(scr.NY1()))
				//        scr.RectangleFull (x, y - scr.NY1(), x + scr.NX1(), y)
				//        scr.WarpMouseGr (x, y)
				scr.Colour(paintColour)
			default:
				scr.Cls()
			}
			/*
			   case kbd.Ins:
			     img.Write (X, Y, X1, Y1 - 16, Name)
			     box.Edit (Feld, Name, scr.Zeilenzahl () - 1, 0)
			     img.Get (X, Y, Name)
			*/
		case kbd.Help:
			paintColour = sel.Colour()
			//    case kbd.LookFor:
			//      Staerke = Strichstaerken.Staerke()
		case kbd.Enter:
			if T > 0 {
				x0, y0 = scr.MousePosGr()
				//        scr.Fill1 (x0, y0)
			}
		case kbd.PrintScr:
			img.Print(uint(X), uint(Y), X1, Y1-16)
		case kbd.Tab:
			if T == 0 {
				if Figur+1 < Nfigure {
					Figur++
				} else {
					Figur = figure(0)
				}
			} else {
				if Figur > 0 {
					Figur--
				} else {
					Figur = figure(Nfigure - 1)
				}
			}
			scr.Colours(col.White, Papier)
			scr.Write1(symbol[Figur], scr.NY()-1, 0)
		case kbd.Here:
			x0, y0 = scr.MousePosGr()
			scr.CircleFull(x0, y0, 3/2)
		case kbd.Pull:
			x, y = scr.MousePosGr()
			scr.Line(x0, y0, x, y)
			x0, y0 = x, y
		case kbd.Hither:
			x, y = scr.MousePosGr()
			scr.Line(x0, y0, x, y)
		case kbd.There:
			x0, y0 = scr.MousePosGr()
			x, y = x0, y0
		case kbd.Push:
			paint(Figur, inv, x0, y0, x, y)
			x, y = scr.MousePosGr()
			paint(Figur, inv, x0, y0, x, y)
		case kbd.Thither:
			paint(Figur, inv, x0, y0, x, y)
			//      scr.Colour (paintColour)
			x, y = scr.MousePosGr()
			paint(Figur, border, x0, y0, x, y)
			x0, y0 = x, y
		case kbd.This:
			x0, y0 = scr.MousePosGr()
			x, y = x0, y0
		case kbd.Move:
			scr.LineInv(x0, y0, x, y)
			x, y = scr.MousePosGr()
			scr.LineInv(x0, y0, x, y)
		case kbd.Thus:
			scr.LineInv(x0, y0, x, y)
			x, y = scr.MousePosGr()
			scr.Line(x0, y0, x, y)
			x0, y0 = x, y
		}
	}
	scr.Save(0, 0, 20, 1)
	for {
		bx.Edit(&Name, 0, 0)
		// TODO make sure, that "Name" is x{x|y} where x is letter, y is digit
		if !str.Empty(Name) {
			str.RemSpaces(&Name)
			break
		}
	}
	scr.Restore(0, 0, 20, 1)
	img.Put(Name, uint(X), uint(Y), X1, Y1)
	ker.Terminate()
}
示例#3
0
文件: imp.go 项目: CaptainSoOmA/Uni
func Edit() {
	//
	Write()
	errh.Hint("Graph editieren: Hilfe per F1, fertig: Abbruchtaste (Esc)")
	scr.MouseCursor(true)
loop:
	for {
		K, i := kbd.Command()
		//    errh.DelHint()
		switch K {
		case kbd.Esc:
			break loop
		case kbd.Help:
			errh.WriteHelp(help)
		case kbd.Here: // neue Ecke oder Namen vorhandener Ecke ändern:
			if Graph.ExPred(node.UnderMouse) {
				if i > 0 {
					Ecke = Graph.Get().(*node.Imp) // aktuell: Ecke
					Ecke.Edit()
					Graph.Put(Ecke)
				}
			} else {
				Ecke.Clr()
				Ecke.Locate()
				Ecke.Write(true, true)
				Ecke.Edit()
				Graph.Ins(Ecke)
			}
		case kbd.Del: // Ecke entfernen
			if Graph.ExPred(node.UnderMouse) {
				wr(false, false)
				Graph.Del()
			}
		case kbd.There: // Ecke verschieben
			switch i {
			case 0:
				if Graph.ExPred(node.UnderMouse) {
					wr(false, false)
					wr(false, true)
				loop1:
					for {
						geschoben := false
						kk, _ := kbd.Command()
						switch kk {
						case kbd.Push:
							geschoben = true
							wr(false, true)
							Ecke = Graph.Get().(*node.Imp)
							Ecke.Locate()
							Graph.Put(Ecke)
							wr(false, true)
						case kbd.Thither:
							wr(false, true)
							if geschoben {
								Graph.Put(Ecke)
							}
							wr(true, false)
							break loop1
						}
					}
				}
			default: // Ecke entfernen
				if Graph.ExPred(node.UnderMouse) {
					wr(false, false)
					Graph.Del()
				}
			}
		case kbd.This: // Ecken verbinden / Kante entfernen:
			x0, y0 := scr.MousePosGr()
			x, y := x0, y0
			if Graph.ExPred(node.UnderMouse) {
				Ecke = Graph.Get().(*node.Imp) // Ecke aktuell
				Graph.Position(true)           // Ecke auch postaktuell
			loop2:
				for {
					kk, _ := kbd.Command()
					switch kk {
					case kbd.Move:
						scr.LineInv(x0, y0, x, y)
						x, y = scr.MousePosGr()
						scr.LineInv(x0, y0, x, y)
					case kbd.Thus:
						scr.LineInv(x0, y0, x, y)
						if Graph.ExPred(node.UnderMouse) {
							Ecke1 = Graph.Get().(*node.Imp) // Ecke1 aktuell
							g := Graph.Directed()
							if g {
								Kante.Write(Ecke, Ecke1, g, false, false)
							}
							Kante.Edit(Ecke, Ecke1, g)
							Graph.Edge1(Kante)
							if Kante.Val() == 0 {
								Kante.Write(Ecke, Ecke1, g, false, false)
								Graph.Del1()
							}
						}
						break loop2
					}
				}
			}
		case kbd.PrintScr:
			//      img.Write (".tmp.Graph", 0, 0, scr.NX(), scr.NY())
			//      img.Print()
		}
	}
	errh.DelHint()
}