Skip to content

Commit e04de50

Browse files
committed
COMMON: Fix CIRCLE command to ensure radius uses the WINDOW coordinate system
1 parent 713a246 commit e04de50

File tree

5 files changed

+113
-104
lines changed

5 files changed

+113
-104
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2021-03-28 (12.21)
2+
COMMON: Fix CIRCLE command to ensure radius uses the WINDOW coordinate system
3+
COMMON: Fix to ensure the default VIEW is maintained during resizing
4+
15
2021-03-21 (12.21)
26
COMMON: Fix square bracket field access issue
37

src/common/device.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,13 @@ void panic(const char *fmt, ...);
10691069
*/
10701070
void lwrite(const char *buf);
10711071

1072+
/**
1073+
* @ingroup dev_f
1074+
*
1075+
* resize the window coordinate system
1076+
*/
1077+
void dev_resize(int width, int height);
1078+
10721079
#if defined(__cplusplus)
10731080
}
10741081
#endif

src/common/screen.c

Lines changed: 100 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ int32_t dev_Wdy;
5050
long dev_fgcolor = 0;
5151
long dev_bgcolor = 15;
5252

53-
/**
54-
* Returns data from pointing-device
55-
* (see PEN(x), osd_getpen(x))
56-
*/
53+
//
54+
// Returns data from pointing-device
55+
// (see PEN(x), osd_getpen(x))
56+
//
5757
int dev_getpen(int code) {
5858
int result = 0;
5959
if (os_graphics) {
@@ -75,33 +75,33 @@ int dev_getpen(int code) {
7575
return result;
7676
}
7777

78-
/**
79-
* enable/disable default pointing device (pen or mouse)
80-
*/
78+
//
79+
// enable/disable default pointing device (pen or mouse)
80+
//
8181
void dev_setpenmode(int enable) {
8282
if (os_graphics) {
8383
osd_setpenmode(enable);
8484
}
8585
}
8686

87-
/**
88-
* returns the x position of cursor (in pixels)
89-
*/
87+
//
88+
// returns the x position of cursor (in pixels)
89+
//
9090
int dev_getx() {
9191
return osd_getx();
9292
}
9393

94-
/**
95-
* returns the y position of cursor (in pixels)
96-
*/
94+
//
95+
// returns the y position of cursor (in pixels)
96+
//
9797
int dev_gety() {
9898
return osd_gety();
9999
}
100100

101-
/**
102-
* sets the position of cursor
103-
* x,y are in pixels
104-
*/
101+
//
102+
// sets the position of cursor
103+
// x,y are in pixels
104+
//
105105
void dev_setxy(int x, int y, int transform) {
106106
if (x < 0 || x > os_graf_mx) {
107107
return;
@@ -118,15 +118,15 @@ void dev_setxy(int x, int y, int transform) {
118118
osd_setxy(x, y);
119119
}
120120

121-
/**
122-
* sets the currect foreground & background color
123-
* the background color is used only for texts
124-
*/
121+
//
122+
// sets the currect foreground & background color
123+
// the background color is used only for texts
124+
//
125125
void dev_settextcolor(long fg, long bg) {
126126
if (bg == -1) {
127127
bg = dev_bgcolor;
128128
}
129-
129+
130130
if ((fg <= 15) && (bg <= 15) && (fg >= 0) && (bg >= 0)) { // VGA
131131
if (bg != -1) {
132132
dev_bgcolor = bg;
@@ -137,44 +137,46 @@ void dev_settextcolor(long fg, long bg) {
137137
}
138138
}
139139

140-
/**
141-
* prints a string
142-
*/
140+
//
141+
// prints a string
142+
//
143143
void dev_print(const char *str) {
144144
osd_write(str);
145145
}
146146

147-
/**
148-
* clears the screen
149-
*/
147+
//
148+
// clears the screen
149+
//
150150
void dev_cls() {
151151
graph_reset();
152152
osd_cls();
153153
}
154154

155-
/**
156-
* returns the width of 'str' in pixels
157-
*/
155+
//
156+
// returns the width of 'str' in pixels
157+
//
158158
int dev_textwidth(const char *str) {
159159
if (os_graphics) {
160160
return osd_textwidth(str);
161161
}
162-
return strlen(str); // console
162+
// console
163+
return strlen(str);
163164
}
164165

165-
/**
166-
* returns the height of 'str' in pixels
167-
*/
166+
//
167+
// returns the height of 'str' in pixels
168+
//
168169
int dev_textheight(const char *str) {
169170
if (os_graphics) {
170171
return osd_textheight(str);
171172
}
172-
return 1; // console
173+
// console
174+
return 1;
173175
}
174176

175-
/**
176-
* changes the current foreground color
177-
*/
177+
//
178+
// changes the current foreground color
179+
//
178180
void dev_setcolor(long color) {
179181
if (color <= 15 && color >= 0) {
180182
osd_setcolor(dev_fgcolor = color);
@@ -183,9 +185,9 @@ void dev_setcolor(long color) {
183185
}
184186
}
185187

186-
/**
187-
* draw a pixel
188-
*/
188+
//
189+
// draw a pixel
190+
//
189191
void dev_setpixel(int x, int y) {
190192
x = W2X(x);
191193
y = W2Y(y);
@@ -196,9 +198,9 @@ void dev_setpixel(int x, int y) {
196198
}
197199
}
198200

199-
/**
200-
* returns the value of a pixel
201-
*/
201+
//
202+
// returns the value of a pixel
203+
//
202204
long dev_getpixel(int x, int y) {
203205
x = W2X(x);
204206
y = W2Y(y);
@@ -209,9 +211,9 @@ long dev_getpixel(int x, int y) {
209211
return 0;
210212
}
211213

212-
/**
213-
* Cohen-Sutherland clipping
214-
*/
214+
//
215+
// Cohen-Sutherland clipping
216+
//
215217
void dev_clipline(int *x1, int *y1, int *x2, int *y2, int *visible) {
216218
int done, in1, in2, sw;
217219
int c1, c2;
@@ -225,7 +227,8 @@ void dev_clipline(int *x1, int *y1, int *x2, int *y2, int *visible) {
225227
if (in1 && in2) {
226228
*visible = done = 1;
227229
} else if ((c1 & c2 & 0x1) || (c1 & c2 & 0x2) || (c1 & c2 & 0x4) || (c1 & c2 & 0x8)) {
228-
done = 1; // visible = false
230+
// visible = false
231+
done = 1;
229232
} else {
230233
// at least one point is outside
231234
if (in1) {
@@ -266,9 +269,9 @@ void dev_clipline(int *x1, int *y1, int *x2, int *y2, int *visible) {
266269
} while (!done);
267270
}
268271

269-
/**
270-
* draw line
271-
*/
272+
//
273+
// draw line
274+
//
272275
void dev_line(int x1, int y1, int x2, int y2) {
273276
int visible;
274277

@@ -282,36 +285,29 @@ void dev_line(int x1, int y1, int x2, int y2) {
282285
}
283286

284287
void dev_ellipse(int xc, int yc, int xr, int yr, double aspect, int fill) {
285-
osd_ellipse(W2X(xc), W2Y(yc), xr, yr * aspect, fill);
288+
int windowXR = xr * dev_Vdx / dev_Wdx;
289+
int windowYR = (yr * aspect) * dev_Vdx / dev_Wdx;
290+
osd_ellipse(W2X(xc), W2Y(yc), windowXR, windowYR, fill);
286291
}
287292

288293
void dev_arc(int xc, int yc, double r, double start, double end, double aspect) {
289294
osd_arc(W2X(xc), W2Y(yc), r, start, end, aspect);
290295
}
291296

292-
/**
293-
* @ingroup lgraf
294-
*
295-
* draw a line using foreground color
296-
*
297-
* @param x1 line coordinates
298-
* @param y1 line coordinates
299-
* @param x2 line coordinates
300-
* @param y2 line coordinates
301-
*/
297+
//
298+
// draw a line using foreground color
299+
//
302300
void osd_line(int x1, int y1, int x2, int y2);
303301

304-
/**
305-
* draw rectangle (filled or not)
306-
*/
302+
//
303+
// draw rectangle (filled or not)
304+
//
307305
void dev_rect(int x1, int y1, int x2, int y2, int fill) {
308-
int px1, py1, px2, py2;
309306
int c1, c2, in1, in2;
310-
311-
px1 = x1;
312-
py1 = y1;
313-
px2 = x2;
314-
py2 = y2;
307+
int px1 = x1;
308+
int py1 = y1;
309+
int px2 = x2;
310+
int py2 = y2;
315311

316312
W2D4(x1, y1, x2, y2);
317313

@@ -324,25 +320,17 @@ void dev_rect(int x1, int y1, int x2, int y2, int fill) {
324320
return;
325321
}
326322

327-
/*
328-
* check inside
329-
*/
323+
// check inside
330324
CLIPENCODE(x1, y1, c1);
331325
CLIPENCODE(x2, y2, c2);
332326
in1 = CLIPIN(c1);
333327
in2 = CLIPIN(c2);
334328
if (in1 && in2) {
335-
/*
336-
* its inside
337-
*/
329+
// its inside
338330
osd_rect(x1, y1, x2, y2, fill);
339331
} else {
340-
/*
341-
* partial inside
342-
* TODO: something fast
343-
*/
332+
// partial inside
344333
int y;
345-
346334
if (fill) {
347335
for (y = py1; y <= py2; y++) {
348336
dev_line(px1, y, px2, y);
@@ -356,17 +344,16 @@ void dev_rect(int x1, int y1, int x2, int y2, int fill) {
356344
}
357345
}
358346

359-
/**
360-
* set viewport
361-
*/
347+
//
348+
// set viewport
349+
//
362350
void dev_viewport(int x1, int y1, int x2, int y2) {
363351
if (x1 == x2 || y1 == y2) {
364352
// reset
365353
dev_Vx1 = 0;
366354
dev_Vy1 = 0;
367355
dev_Vx2 = os_graf_mx - 1;
368356
dev_Vy2 = os_graf_my - 1;
369-
370357
dev_Vdx = os_graf_mx - 1;
371358
dev_Vdy = os_graf_my - 1;
372359
} else {
@@ -379,7 +366,6 @@ void dev_viewport(int x1, int y1, int x2, int y2) {
379366
dev_Vy1 = y1;
380367
dev_Vx2 = x2;
381368
dev_Vy2 = y2;
382-
383369
dev_Vdx = ABS(x2 - x1);
384370
dev_Vdy = ABS(y2 - y1);
385371

@@ -393,30 +379,27 @@ void dev_viewport(int x1, int y1, int x2, int y2) {
393379
dev_Wy1 = dev_Vy1;
394380
dev_Wx2 = dev_Vx2;
395381
dev_Wy2 = dev_Vy2;
396-
397382
dev_Wdx = dev_Vdx;
398383
dev_Wdy = dev_Vdy;
399384
}
400385

401-
/**
402-
* set window
403-
*/
386+
//
387+
// set window
388+
//
404389
void dev_window(int x1, int y1, int x2, int y2) {
405390
if (x1 == x2 || y1 == y2) {
406391
// reset
407392
dev_Wx1 = dev_Vx1;
408393
dev_Wy1 = dev_Vy1;
409394
dev_Wx2 = dev_Vx2;
410395
dev_Wy2 = dev_Vy2;
411-
412396
dev_Wdx = dev_Vdx;
413397
dev_Wdy = dev_Vdy;
414398
} else {
415399
dev_Wx1 = x1;
416400
dev_Wy1 = y1;
417401
dev_Wx2 = x2;
418402
dev_Wy2 = y2;
419-
420403
dev_Wdx = x2 - x1;
421404
dev_Wdy = y2 - y1;
422405

@@ -425,3 +408,26 @@ void dev_window(int x1, int y1, int x2, int y2) {
425408
}
426409
}
427410
}
411+
412+
void dev_resize(int width, int height) {
413+
if (dev_Vx2 == dev_Vdx && dev_Vx2 == os_graf_mx - 1) {
414+
// viewport width is full-screen
415+
if (dev_Wx2 == dev_Wdx && dev_Wx2 == dev_Vx2) {
416+
// virtual window width is full-screen
417+
dev_Wx2 = dev_Wdx = width - 1;
418+
}
419+
dev_Vx2 = dev_Vdx = width - 1;
420+
}
421+
if (dev_Vy2 == dev_Vdy && dev_Vy2 == os_graf_my - 1) {
422+
// viewport height is full-screen
423+
if (dev_Wy2 == dev_Wdy && dev_Wy2 == dev_Vy2) {
424+
// virtual window height is full-screen
425+
dev_Wy2 = dev_Wdy = height - 1;
426+
}
427+
dev_Vy2 = dev_Vdy = height - 1;
428+
}
429+
os_graf_mx = width;
430+
os_graf_my = height;
431+
setsysvar_int(SYSVAR_XMAX, width - 1);
432+
setsysvar_int(SYSVAR_YMAX, height - 1);
433+
}

0 commit comments

Comments
 (0)