Exemple #1
0
func main() {
	var sreenHeight, cx, cy, cw, ch, midy int
	message := "Scrolling texts could be useful if the information does not fit on screen"

	w, h := openvg.Init()
	sreenHeight = h
	var speed openvg.VGfloat = 0.5
	var x openvg.VGfloat = 0
	midy = (h / 2)
	fontsize := w / 50
	cx = 0
	ch = fontsize * 2
	cw = w
	cy = midy - (ch / 2)
	var jsonData SLData

	for {
		response, err := http.Get("http://localhost:8000")

		if err == nil {
			defer response.Body.Close()
			contents, err := ioutil.ReadAll(response.Body)
			if err != nil {
				fmt.Printf("Error reading http data, %s", err)
			} else {
				fmt.Printf("Got: %s\n", string(contents))
				if err := json.Unmarshal(contents, &jsonData); err != nil {
					panic(err)
				}
				fmt.Println(jsonData)
			}
		}

		openvg.Start(w, h)
		imgw, imgh := 0, 0
		openvg.Background(255, 255, 255)

		//SLHeight = 60
		var imgPosY = openvg.VGfloat(sreenHeight - 70)
		openvg.Image(4, imgPosY, imgw, imgh, "SL.jpg")

		var TAB1 = openvg.VGfloat(4 * w / 20)
		var TAB2 = openvg.VGfloat(8 * w / 20)

		rx1, rw1, rh1 := openvg.VGfloat(cx), openvg.VGfloat(cw), openvg.VGfloat(ch)
		ty := 0
		rix := 0

		// Buses
		for ty = sreenHeight - (80 + int(rh1)); ty > 0 && rix < len(jsonData.ResponseData.Buses); ty -= ch {
			tempy := openvg.VGfloat(ty)
			//ry := openvg.VGfloat(ty)
			if rix%2 == 0 {
				openvg.FillRGB(0, 0, 0, .2)
				//openvg.Rect(rx1, tempy, rw1, rh1)
				openvg.FillRGB(0, 0, 0, 1)
				tempy = tempy + 6.0
			} else {
				openvg.FillRGB(0, 0, 0, .4)
				openvg.Rect(rx1, tempy, rw1, rh1)
				tempy = tempy + 6.0
				openvg.FillRGB(0, 0, 0, 1)
			}
			openvg.Text(rx1, tempy, jsonData.ResponseData.Buses[rix].LineNumber, "sans", fontsize)
			drawTypeOfTransport(rx1+60, tempy+2, rw1, ch-20, jsonData.ResponseData.Buses[rix].TransportMode)

			openvg.Text(rx1+100, tempy, jsonData.ResponseData.Buses[rix].StopPointDesignation, "sans", fontsize)
			openvg.Text(rx1+TAB1, tempy, jsonData.ResponseData.Buses[rix].DisplayTime, "sans", fontsize)
			var dest = jsonData.ResponseData.Buses[rix].Destination
			dest = replaceAO(dest)
			openvg.Text(rx1+TAB2, tempy, dest, "sans", fontsize)

			//openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
			//openvg.Background(255,255,0)
			rix = rix + 1
		}
		var trainIx = 0
		for ty = ty - 20; ty > 0 && trainIx < len(jsonData.ResponseData.Trains); ty -= ch {
			tempy := openvg.VGfloat(ty)
			//ry := openvg.VGfloat(ty)
			if rix%2 == 0 {
				openvg.FillRGB(0, 0, 0, .2)
				//openvg.Rect(rx1, tempy, rw1, rh1)
				openvg.FillRGB(0, 0, 0, 1)
				tempy = tempy + 6.0
			} else {
				openvg.FillRGB(0, 0, 0, .4)
				openvg.Rect(rx1, tempy, rw1, rh1)
				tempy = tempy + 6.0
				openvg.FillRGB(0, 0, 0, 1)
			}
			openvg.Text(rx1, tempy, jsonData.ResponseData.Trains[trainIx].LineNumber, "sans", fontsize)
			drawTypeOfTransport(rx1+55, tempy+4, rw1, ch-20, jsonData.ResponseData.Trains[trainIx].TransportMode)
			openvg.Text(rx1+TAB1, tempy, jsonData.ResponseData.Trains[trainIx].DisplayTime, "sans", fontsize)
			var dest = jsonData.ResponseData.Trains[trainIx].Destination
			dest = replaceAO(dest)
			openvg.Text(rx1+TAB2, tempy, dest, "sans", fontsize)

			//openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
			//openvg.Background(255,255,0)
			trainIx = trainIx + 1
			rix = rix + 1
		}

		//openvg.End()
		openvg.SaveEnd("dump.raw")

		time.Sleep(60 * time.Second)
	}

	bufio.NewReader(os.Stdin).ReadBytes('\n')

	rx, ry, rw, rh := openvg.VGfloat(cx), openvg.VGfloat(cy), openvg.VGfloat(cw), openvg.VGfloat(ch)
	// scroll the text, only in the clipping rectangle
	for x = 0; x < rw+speed; x += speed {
		openvg.Start(w, h)
		openvg.Background(255, 255, 255)
		openvg.FillRGB(0, 0, 0, .2)
		openvg.Rect(rx, ry, rw, rh)
		openvg.ClipRect(cx, cy, cw, ch)
		openvg.Translate(x, ry+openvg.VGfloat(fontsize/2))
		openvg.FillRGB(0, 0, 0, 1)
		openvg.Text(0, 0, message, "sans", fontsize)
		openvg.ClipEnd()
		openvg.End()
	}
	bufio.NewReader(os.Stdin).ReadBytes('\n')
	openvg.Finish()
	os.Exit(0)
}
Exemple #2
0
// interact controls the display of the deck
func interact(filename, searchterm string, w, h, slidenum int, gp float64) {
	openvg.SaveTerm()
	defer openvg.RestoreTerm()
	var d deck.Deck
	var err error
	d, err = deck.Read(filename, w, h)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}
	openvg.RawTerm()
	r := bufio.NewReader(os.Stdin)
	lastslide := len(d.Slide) - 1
	if slidenum > lastslide {
		slidenum = lastslide
	}
	if slidenum < 0 {
		slidenum = 0
	}
	if len(searchterm) > 0 {
		sr := deck.Search(d, searchterm)
		if sr >= 0 {
			slidenum = sr
		}
	}
	n := slidenum
	xray := 1
	initial := 0
	imap := make(map[string]image.Image)
	// respond to keyboard commands, 'q' to exit
	for cmd := byte('0'); cmd != 'q'; cmd = readcmd(r) {
		switch cmd {
		// read/reload
		case 'r', 18: // r, Ctrl-R
			d, err = deck.Read(filename, w, h)
			if err != nil {
				fmt.Fprintf(os.Stderr, "%v\n", err)
				return
			}
			loadimage(d, imap)
			openvg.Background(0, 0, 0)
			xray = 1
			showslide(d, imap, n)

		// save slide
		case 's', 19: // s, Ctrl-S
			openvg.SaveEnd(fmt.Sprintf("%s-slide-%04d", filename, n))

		// first slide
		case '0', '1', 1, '^': // 0,1,Ctrl-A,^
			initial++
			if initial == 1 {
				loadimage(d, imap)
				n = slidenum
			} else {
				n = 0
			}
			showslide(d, imap, n)

		// last slide
		case '*', 5, '$': // *, Crtl-E, $
			n = lastslide
			showslide(d, imap, n)

		// next slide
		case '+', 'n', '\n', ' ', '\t', '=', 14: // +,n,newline,space,tab,equal,Crtl-N
			n++
			if n > lastslide {
				n = 0
			}
			showslide(d, imap, n)

		// previous slide
		case '-', 'p', 8, 16, 127: // -,p,Backspace,Ctrl-P,Del
			n--
			if n < 0 {
				n = lastslide
			}
			showslide(d, imap, n)

		// x-ray
		case 'x', 24: // x, Ctrl-X
			xray++
			showslide(d, imap, n)
			if xray%2 == 0 {
				showgrid(d, n, gp)
			}
		// Escape sequence from remotes
		case 27:
			remote, rerr := r.ReadString('~')
			if len(remote) > 2 && rerr == nil {
				switch remote[1] {
				case '3': // blank screen
					openvg.Start(d.Canvas.Width, d.Canvas.Height)
					openvg.FillColor("black")
					openvg.Rect(0, 0, openvg.VGfloat(d.Canvas.Width), openvg.VGfloat(d.Canvas.Height))
					openvg.End()

				case '5': // back
					n--
					if n < 0 {
						n = lastslide
					}
					showslide(d, imap, n)
				case '6': // forward
					n++
					if n > lastslide {
						n = 0
					}
					showslide(d, imap, n)
				}
			}
		// search
		case '/', 6: // slash, Ctrl-F
			openvg.RestoreTerm()
			searchterm, serr := r.ReadString('\n')
			openvg.RawTerm()
			if serr != nil {
				continue
			}
			if len(searchterm) > 2 {
				ns := deck.Search(d, searchterm[0:len(searchterm)-1])
				if ns >= 0 {
					showslide(d, imap, ns)
					n = ns
				}
			}
		}
	}
}