1 /**@(#)
2 **/
3 /**
4 tv_screen_draw.c:
5 Basic drawing operations into tv_screen.
6 **/
7
8 #include <stdio.h>
9 #include <tina/sys.h>
10 #include <tina/sysfuncs.h>
11 #include <tina/math.h>
12 #include <tina/tv.h>
13 #include <tina/tv_screen.h>
14
15 void tv_screen_flush(Tv_screen * tv_screen)
16 {
17 if (tv_screen == NULL)
18 return;
19
20 /* flushes whole display not just current tv_screen */
21 XFlush(tv_screen->display);
22 }
23
24 void tv_screen_erase(Tv_screen * tv_screen)
25 {
26 if (tv_screen)
27 {
28 XClearWindow(tv_screen->display, tv_screen->window);
29 }
30 }
31
32
33 void tv_screen_point(Tv_screen * tv_screen, Ipos pos)
34 {
35 if (tv_screen == NULL)
36 return;
37
38 XDrawPoint(tv_screen->display, tv_screen->window, tv_screen->gc, pos.x, pos.y);
39 }
40
41 void tv_screen_dot(Tv_screen * tv_screen, Ipos pos)
42 {
43 int x0, x1, x2;
44 int y0, y1, y2;
45
46 if (tv_screen == NULL)
47 return;
48
49 x1 = pos.x;
50 y1 = pos.y;
51 x0 = x1 - 1;
52 y0 = y1 - 1;
53 x2 = x1 + 1;
54 y2 = y1 + 1;
55 XDrawLine(tv_screen->display, tv_screen->window, tv_screen->gc, x0, y0, x2, y0);
56 XDrawLine(tv_screen->display, tv_screen->window, tv_screen->gc, x0, y1, x2, y1);
57 XDrawLine(tv_screen->display, tv_screen->window, tv_screen->gc, x0, y2, x2, y2);
58 }
59
60 void tv_screen_line(Tv_screen * tv_screen, Ipos pos1, Ipos pos2)
61 {
62 if (tv_screen == NULL)
63 return;
64
65 XDrawLine(tv_screen->display, tv_screen->window, tv_screen->gc,
66 pos1.x, pos1.y, pos2.x, pos2.y);
67 }
68
69 void tv_screen_polyline(Tv_screen * tv_screen, List * points)
70 {
71 int npoints, i;
72 List *ptr;
73 XPoint *xpoints;
74 Ipos pos = {Ipos_id};
75
76 if (tv_screen == NULL)
77 return;
78
79 npoints = list_length(points);
80 xpoints = (XPoint *) ralloc((unsigned) npoints * sizeof(XPoint));
81 for (ptr = points, i = 0; ptr != NULL; ptr = ptr->next, ++i)
82 {
83 pos = *((Ipos *) ptr->to);
84 xpoints[i].x = pos.x;
85 xpoints[i].y = pos.y;
86 }
87 XDrawLines(tv_screen->display, tv_screen->window, tv_screen->gc,
88 xpoints, npoints, CoordModeOrigin);
89 rfree((void *) xpoints);
90 }
91
92 void tv_screen_circle(Tv_screen * tv_screen, Ipos centre, int radius)
93 {
94 int cx = centre.x;
95 int cy = centre.y;
96
97 if (tv_screen == NULL)
98 return;
99
100 XDrawArc(tv_screen->display, tv_screen->window, tv_screen->gc,
101 cx - radius, cy - radius, 2 * radius, 2 * radius, 0, 64 * 360);
102 }
103
104 void tv_screen_rect(Tv_screen * tv_screen, Ipos pos1, Ipos pos2)
105 {
106 int x1 = pos1.x, y1 = pos1.y;
107 int x2 = pos2.x, y2 = pos2.y;
108
109 if (tv_screen == NULL)
110 return;
111
112 if (x1 == x2 && y1 == y2)
113 { /* a single point */
114 XDrawPoint(tv_screen->display, tv_screen->window, tv_screen->gc, x1, y1);
115 return;
116 }
117 ORDER(int, x1, x2);
118 ORDER(int, y1, y2);
119 XDrawLine(tv_screen->display, tv_screen->window, tv_screen->gc, x1, y1, x1, y2 - 1);
120 XDrawLine(tv_screen->display, tv_screen->window, tv_screen->gc, x1, y2, x2 - 1, y2);
121 XDrawLine(tv_screen->display, tv_screen->window, tv_screen->gc, x2, y2, x2, y1 + 1);
122 XDrawLine(tv_screen->display, tv_screen->window, tv_screen->gc, x2, y1, x1 + 1, y1);
123 }
124
125 void tv_screen_fillrect(Tv_screen * tv_screen, Ipos pos1, Ipos pos2)
126 {
127 int x1 = pos1.x, y1 = pos1.y;
128 int x2 = pos2.x, y2 = pos2.y;
129
130 if (tv_screen == NULL)
131 return;
132
133 XFillRectangle(tv_screen->display, tv_screen->window, tv_screen->gc,
134 x1, y1, x2 - x1, y2 - y1);
135 }
136
137 void tv_screen_text(Tv_screen * tv_screen, char *string, Ipos pos)
138 {
139 if (tv_screen == NULL)
140 return;
141
142 XDrawString(tv_screen->display, tv_screen->window, tv_screen->gc,
143 pos.x, pos.y, string, strlen(string));
144 }
145
146 void tv_screen_raster(Tv_screen * tv_screen, int x1, int x2, int y, char *raster)
147 {
148 /* indexed between 0 and x2-x1 */
149 XImage *xraster;
150 XWindowAttributes attr;
151
152 if (tv_screen == NULL)
153 return;
154
155 XGetWindowAttributes(tv_screen->display, tv_screen->window, &attr);
156 xraster = XCreateImage(tv_screen->display, attr.visual,
157 tv_screen->depth, ZPixmap, 0, raster, x2 - x1, 1, 8, 0);
158 XPutImage(tv_screen->display, tv_screen->window, tv_screen->gc,
159 xraster, 0, 0, x1, y, x2 - x1, 1);
160 XFree((char *) xraster);
161 }
162
163 void tv_screen_image(Tv_screen * tv_screen, int x, int y, int w, int h, char *data)
164 /* height and width */
165 {
166 XImage *xim;
167 XWindowAttributes attr;
168
169 if (tv_screen == NULL)
170 return;
171
172 XGetWindowAttributes(tv_screen->display, tv_screen->window, &attr);
173 xim = XCreateImage(tv_screen->display, attr.visual,
174 tv_screen->depth, ZPixmap, 0, data, w, h, 8, 0);
175 XPutImage(tv_screen->display, tv_screen->window, tv_screen->gc,
176 xim, 0, 0, x, y, w, h);
177 XFree((char *) xim);
178 }
179
180 void tv_screen_show_picture(Tv_screen * tv_screen, Tv_picture * picture)
181 {
182 XCopyArea(tv_screen->display, picture->pixmap, tv_screen->window,
183 tv_screen->gc, 0, 0, tv_screen->width, tv_screen->height, 0, 0);
184 }
185
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.