FreeBASIC  0.91.0
gfx_box.c
Go to the documentation of this file.
1 /* internal box drawing routine. Used both by VIEW and LINE. */
2 
3 #include "fb_gfx.h"
4 
5 /* Assumes x1,y1 to be upper left corner and x2,y2 lower right one.
6  * Assumes coordinates to be physical ones.
7  * Also assumes color is already masked. */
8 
9 /*:::::*/
10 void fb_hGfxBox(int x1, int y1, int x2, int y2, unsigned int color, int full, unsigned int style)
11 {
13  unsigned char *dest, rot;
14  int clipped_x1, clipped_y1, clipped_x2, clipped_y2, w, h, bit;
15 
16  if ((x2 < context->view_x) || (y2 < context->view_y) ||
17  (x1 >= context->view_x + context->view_w) || (y1 >= context->view_y + context->view_h))
18  return;
19 
20  clipped_x1 = MAX(x1, context->view_x);
21  clipped_y1 = MAX(y1, context->view_y);
22  clipped_x2 = MIN(x2, context->view_x + context->view_w - 1);
23  clipped_y2 = MIN(y2, context->view_y + context->view_h - 1);
24 
25  DRIVER_LOCK();
26 
27  if (full) {
28  w = clipped_x2 - clipped_x1 + 1;
29  h = clipped_y2 - clipped_y1 + 1;
30  dest = context->line[clipped_y1] + (clipped_x1 * context->target_bpp);
31  for (; h; h--) {
32  context->pixel_set(dest, color, w);
33  dest += context->target_pitch;
34  }
35  }
36  else {
37  bit = 0x8000;
38  if (style != 0xFFFF) {
39  rot = (clipped_x1 - x1) & 0xF;
40  RORW(bit, rot);
41  }
42  if (y2 < context->view_y + context->view_h) {
43  if (style == 0xFFFF)
44  context->pixel_set(context->line[y2] + (clipped_x1 * context->target_bpp), color, clipped_x2 - clipped_x1 + 1);
45  else {
46  for (w = clipped_x1; w <= clipped_x2; w++) {
47  if (style & bit)
48  context->put_pixel(context, w, y2, color);
49  RORW1(bit);
50  }
51  }
52  }
53  else if (style != 0xFFFF) {
54  rot = (clipped_x2 - clipped_x1 + 1) & 0xF;
55  RORW(bit, rot);
56  }
57  if (style != 0xFFFF) {
58  rot = ((x2 - clipped_x2) + (clipped_x1 - x1)) & 0xF;
59  RORW(bit, rot);
60  }
61 
62  if (y1 >= context->view_y) {
63  if (style == 0xFFFF)
64  context->pixel_set(context->line[y1] + (clipped_x1 * context->target_bpp), color, clipped_x2 - clipped_x1 + 1);
65  else {
66  for (w = clipped_x1; w <= clipped_x2; w++) {
67  if (style & bit)
68  context->put_pixel(context, w, y1, color);
69  RORW1(bit);
70  }
71  }
72  }
73  else if (style != 0xFFFF) {
74  rot = (clipped_x2 - clipped_x1 + 1) & 0xF;
75  RORW(bit, rot);
76  }
77  if (style != 0xFFFF) {
78  rot = ((x2 - clipped_x2) + (clipped_y1 - y1)) & 0xF;
79  RORW(bit, rot);
80  }
81  if (x2 < context->view_x + context->view_w) {
82  for (h = clipped_y1; h <= clipped_y2; h++) {
83  if (style & bit)
84  context->put_pixel(context, x2, h, color);
85  RORW1(bit);
86  }
87  }
88  else if (style != 0xFFFF) {
89  rot = (clipped_y2 - clipped_y1 + 1) & 0xF;
90  RORW(bit, rot);
91  }
92  if (style != 0xFFFF) {
93  rot = ((y2 - clipped_y2) + (clipped_y1 - y1)) & 0xF;
94  RORW(bit, rot);
95  }
96  if (x1 >= context->view_x) {
97  for (h = clipped_y1; h <= clipped_y2; h++) {
98  if (style & bit)
99  context->put_pixel(context, x1, h, color);
100  RORW1(bit);
101  }
102  }
103  }
104 
105  SET_DIRTY(context, clipped_y1, clipped_y2 - clipped_y1 + 1);
106 
107  DRIVER_UNLOCK();
108 }