summaryrefslogtreecommitdiff
path: root/osd.c
blob: 40703d4c8db0c03e5d275f374d9e1a9049dd8142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//#include <math.h>
#include <stdio.h>
#include <glib.h>
#include "point.h"
//#include "coord.h"
#include "graphics.h"
//#include "transform.h"
//#include "route.h"
#include "vehicle.h"
#include "container.h"
#include "osd.h"

struct osd {
	struct graphics *gr;
	struct graphics_gc *bg;
	struct graphics_gc *white;
	struct graphics_gc *green;
	struct graphics_font *font;

	char command[256];
	char road_name[256];	
};

void
osd_set_next_command(char *new_command,char *new_road){
	extern struct container *co;
	// struct osd *this=co->osd;
	strcpy(co->osd->command,new_command);
	strcpy(co->osd->road_name,new_road);
	osd_draw(co->osd, co);
}

void
osd_draw(struct osd *osd, struct container *co)
{
	double *speed;
	struct point p;

	if (! co->vehicle)
		return;

	speed=vehicle_speed_get(co->vehicle);
	osd->gr->draw_mode(osd->gr, draw_mode_begin);
	p.x=0;
	p.y=0;
	osd->gr->draw_rectangle(osd->gr, osd->bg, &p, 360, 80);
	p.x=10;
	p.y=20;
//	osd->gr->draw_text(osd->gr, osd->green, NULL, osd->font, osd->command, &p, 0x13000, 0);
	char osd_data[256];
	sprintf(osd_data,"%.1f km/h",(*speed));
	osd->gr->draw_text(osd->gr, osd->green, NULL, osd->font, osd_data, &p, 0x13000, 0);
	p.x=10;
	p.y=40;
	osd->gr->draw_text(osd->gr, osd->green, NULL, osd->font, osd->command, &p, 0x13000, 0);
//	osd->gr->draw_text(osd->gr, osd->green, NULL, osd->font, "Overlay", &p, 0x10000, 0);
//	printf("Text %s should appear\n",osd->command);
	osd->gr->draw_mode(osd->gr, draw_mode_end);
}


struct osd *
osd_new(struct container *co)
{	
	printf("Spawning an OSD\n");
	struct osd *this=g_new0(struct osd, 1);
	struct point p;
	p.x=100;
	p.y=10;
	this->gr=co->gra->overlay_new(co->gra, &p, 360, 80);
	this->bg=this->gr->gc_new(this->gr);
	this->gr->gc_set_foreground(this->bg, 0, 0, 0);
	this->white=this->gr->gc_new(this->gr);
	this->gr->gc_set_foreground(this->white, 0xffff, 0xffff, 0xffff);
	this->gr->gc_set_linewidth(this->white, 10);
	this->green=this->gr->gc_new(this->gr);
	this->gr->gc_set_foreground(this->green, 0x0, 0xffff, 0x0);
	this->gr->gc_set_linewidth(this->green, 10);
	
	this->font=this->gr->font_new(this->gr, 200);
	osd_draw(this, co);
	return this;	
}