FreeBASIC  0.91.0
gfx_cls.c
Go to the documentation of this file.
1 /* screen clearing routine */
2 
3 #include "fb_gfx.h"
4 
5 
6 /*:::::*/
7 void fb_GfxClear(int mode)
8 {
10  int i, dirty, dirty_len;
11  int reset_gfx_pos;
12  int reset_console_start = 0, reset_console_end = 0;
13  int new_x = -1, new_y = -1;
14 
15  fb_hPrepareTarget(context, NULL);
16  fb_hSetPixelTransfer(context, context->bg_color);
17 
18  DRIVER_LOCK();
19 
20  if( mode == 0xFFFF0000 ) {
21  if( context->flags & CTX_VIEWPORT_SET )
22  mode = 1;
23  else {
24  int con_y_start = fb_ConsoleGetTopRow();
25  int con_y_end = fb_ConsoleGetBotRow();
26  if( con_y_start==0 && (con_y_end==__fb_gfx->text_h-1) )
27  /* No VIEW PRINT range set */
28  mode = 0;
29  else
30  mode = 2;
31  }
32  }
33 
34  switch (mode) {
35 
36  case 0:
37  /* Clear entire screen */
38  {
39  int cursor_y = fb_ConsoleGetTopRow();
40 
41  context->pixel_set(context->line[0], context->bg_color, __fb_gfx->w * __fb_gfx->h);
42  dirty = 0;
43  dirty_len = __fb_gfx->h;
44 
45  new_x = 0;
46  new_y = cursor_y;
47 
48  reset_console_end = __fb_gfx->text_h;
49 
50  reset_gfx_pos = TRUE;
51  }
52  break;
53 
54  case 2:
55  /* Clear text viewport */
56  {
57  int con_y_start = fb_ConsoleGetTopRow();
58  int con_y_end = fb_ConsoleGetBotRow();
59  int y_start = con_y_start * __fb_gfx->font->h;
60  int y_end = (con_y_end + 1) * __fb_gfx->font->h;
61  int view_height = y_end - y_start;
62 
63  context->pixel_set(context->line[y_start], context->bg_color, __fb_gfx->w * view_height);
64  dirty = y_start;
65  dirty_len = view_height;
66 
67  new_x = 0;
68  new_y = con_y_start;
69 
70  reset_console_start = con_y_start;
71  reset_console_end = con_y_end + 1;
72 
73  reset_gfx_pos = FALSE;
74  }
75  break;
76 
77  case 1:
78  default:
79  /* Clear graphics viewport if set */
80  {
81  unsigned char *dest = context->line[context->view_y] + (context->view_x * __fb_gfx->bpp);
82  for (i = 0; i < context->view_h; i++) {
83  context->pixel_set(dest, context->bg_color, context->view_w);
84  dest += __fb_gfx->pitch;
85  }
86  dirty = context->view_y;
87  dirty_len = context->view_h;
88 
89  reset_gfx_pos = TRUE;
90  }
91  break;
92  }
93  SET_DIRTY(context, dirty, dirty_len);
94 
95  if( reset_gfx_pos ) {
96  context->last_x = context->view_x + (context->view_w >> 1);
97  context->last_y = context->view_y + (context->view_h >> 1);
98  }
99 
100  fb_hClearCharCells( 0, reset_console_start,
101  __fb_gfx->text_w, reset_console_end,
102  context->work_page,
103  32,
104  context->fg_color, context->bg_color );
105 
106  if( new_x!=-1 || new_y!=-1 ) {
107  fb_GfxLocate( new_y + 1, new_x + 1, -1 );
108  }
109 
110  DRIVER_UNLOCK();
111 }