-
Notifications
You must be signed in to change notification settings - Fork 9
/
display.c
156 lines (136 loc) · 3.54 KB
/
display.c
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include "pcb.h"
static void
hide_item_layer(PcbItem *item, int layer)
{
if (item->canvas_item[layer]) {
goo_canvas_item_remove(item->canvas_item[layer]);
item->canvas_item[layer] = NULL;
}
}
void
hide_item(PcbItem *item)
{
int i;
for (i = 0; i < pcb.layers; i++)
hide_item_layer(item, i);
}
static void
show_point(PcbItem *item, int layer)
{
#define rad 3.0
#define siz 3.5
if (item->flags & PCB_POI)
item->canvas_item[layer] =
goo_canvas_rect_new(pcb.layer[layer].olay,
item->p.x - siz, item->p.y - siz, siz * 2, siz * 2,
"stroke-color", "black", "fill-color",
item->flags & PCB_SELECTED ? "red" : "yellow", NULL);
else if (item->flags & PCB_BEND)
item->canvas_item[layer] =
goo_canvas_ellipse_new(pcb.layer[layer].olay,
item->p.x, item->p.y, 2, 2,
"stroke-color", "black", "fill-color",
item->flags & PCB_SELECTED ? "green" : "black", NULL);
else
item->canvas_item[layer] =
goo_canvas_ellipse_new(pcb.layer[layer].olay,
item->p.x, item->p.y, rad, rad,
"stroke-color", "black", "fill-color",
item->flags & PCB_SELECTED ? "green" : "white", NULL);
#undef rad
#undef siz
}
static void
show_line(PcbItem *item, int layer)
{
item->canvas_item[layer] = goo_canvas_polyline_new_line(pcb.layer[layer].olay,
item->l.point[0]->p.x, item->l.point[0]->p.y,
item->l.point[1]->p.x, item->l.point[1]->p.y,
"stroke-color", item->flags & PCB_SELECTED ? "green" : "black",
NULL);
}
static void
show_item_layer(PcbItem *item, int layer)
{
if (!pcb.layer->olay)
return;
hide_item_layer(item, layer);
if (!(item->layers & LAYER(layer)))
return;
switch (item->type) {
case PCB_POINT:
show_point(item, layer);
break;
case PCB_LINE:
show_line(item, layer);
break;
}
}
void
show_item(PcbItem *item)
{
int i;
for (i = 0; i < pcb.layers; i++)
show_item_layer(item, i);
}
void
undisplay(void)
{
gtk_container_remove(GTK_CONTAINER(pcb.scrolled),
GTK_WIDGET(pcb.layer[pcb.curlayer].canvas));
}
void
redisplay(void)
{
gtk_container_add(GTK_CONTAINER(pcb.scrolled),
GTK_WIDGET(pcb.layer[pcb.curlayer].canvas));
gtk_widget_show_all(pcb.window);
}
void
show_overlays(int layer)
{
PcbItem *cur;
g_print("show overlays on layer %d\n", layer);
pcb.layer[layer].olay = goo_canvas_group_new(pcb.layer[layer].root,
"x", 0.0, "y", 0.0, "width", pcb.width, "height", pcb.height, NULL);
for (cur = pcb.items; cur; cur = cur->next)
show_item_layer(cur, layer);
}
void
hide_overlays(int layer)
{
PcbItem *cur;
g_print("hide overlays on layer %d\n", layer);
if (pcb.layer[layer].olay) {
goo_canvas_item_remove(pcb.layer[layer].olay);
pcb.layer[layer].olay = NULL;
}
for (cur = pcb.items; cur; cur = cur->next)
cur->canvas_item[layer] = NULL;
}
void
init_display()
{
int i;
pcb.scale = 1.0;
for (i = 0; i < pcb.layers; i++) {
pcb.layer[i].canvas = GOO_CANVAS(goo_canvas_new());
gtk_object_ref(GTK_OBJECT(pcb.layer[i].canvas));
goo_canvas_set_bounds(pcb.layer[i].canvas,
0, 0, pcb.width, pcb.height);
pcb.layer[i].root =
goo_canvas_get_root_item(pcb.layer[i].canvas);
goo_canvas_image_new(pcb.layer[i].root, pcb.layer[i].img, 0, 0,
NULL);
init_layer_events(pcb.layer[i].root);
show_overlays(i);
}
pcb.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(pcb.window), 800, 600);
gtk_window_set_title(GTK_WINDOW(pcb.window), pcb.filename);
init_window_events(pcb.window);
pcb.scrolled = gtk_scrolled_window_new(NULL, NULL);
gtk_widget_show(pcb.scrolled);
gtk_container_add(GTK_CONTAINER(pcb.window), pcb.scrolled);
redisplay();
}