File: graphics.c

package info (click to toggle)
chdrv 1.0.13-0.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,204 kB
  • ctags: 1,069
  • sloc: ansic: 8,972; perl: 412; asm: 234; makefile: 195; sh: 36
file content (126 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download
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
#include "input.h"
#include "chinese.h"
#include "portable.h"

#define is_num(c) (((c)<='9')&&((c)>='0'))

void get_number(CHAR c)
{
  grpara[grnum] = grpara[grnum]*10+(c-'0');
}

void graphics_line()
{
  int fg,bg;

  switch( grpara[5])
    {
    case GR_LINE:
      fg = COLOR_DEFAULT_FG;
      bg = COLOR_DEFAULT_BG;
      ch_ansicolor(grpara[4],0);
      mon_drawline(grpara[0],grpara[1],grpara[2],grpara[3]);
      ch_ansicolor(fg,bg);
      break;
    case GR_FILLREC:
    case GR_RECTANGLE:
      fg = COLOR_DEFAULT_FG;
      bg = COLOR_DEFAULT_BG;
      ch_ansicolor(grpara[4],0);
      mon_drawline(grpara[0],grpara[1],grpara[0],grpara[3]);
      mon_drawline(grpara[0],grpara[3],grpara[2],grpara[3]);
      mon_drawline(grpara[2],grpara[3],grpara[2],grpara[1]);
      mon_drawline(grpara[2],grpara[1],grpara[0],grpara[1]);
      ch_ansicolor(fg,bg);
      break;
    }
}



void graphics_sequence_set(CHAR c)
{
  /****************************************/
  /* all space in graphics set is ignored */
  /****************************************/

  if (isspace(c))
    return;
  switch(chstate)
    {
    case STATE_LINE:
      if (grnum < 5)
	{
	  if (is_num(c))
	    get_number(c);
	  else if (c == ',') 
	    {
	      grnum++;
	    }
	  else if (c == ';')
	    {
	      graphics_line();
	      chstate = state = STATE_NORMAL;
	    }
	  else
	    {
	      chstate = state = STATE_NORMAL;
	    }
	}
      else if (grnum == 5)
	{
	  if ((grpara[5] == GR_LINE)&&(c == 'F'))
	    {
	      grpara[5] = GR_FILLREC;
	    }
	  else if (c == 'B')
	    {
	      grpara[5] = GR_RECTANGLE;
	    }
	  else if (c == ',')
	    {
	      grnum++;
	    }
	  else 
	    {
	      graphics_line();
	      chstate = state = STATE_NORMAL;
	    }
	}
      else
	{
	  if (is_num(c))
	    get_number(c);
	  else if (c == ',')
	    {
	      grnum++;
	      if (grnum == 10)
		{
		  chstate = state = STATE_NORMAL;
		}
	    }
	  else if (c == ';')
	    {
	      graphics_line();
	      chstate = state = STATE_NORMAL;
	    }
	  else
	    {
	      chstate = state = STATE_NORMAL;
	    }
	}
      break;
    case STATE_CIRCLE:
    case STATE_PAINT:
      chstate = state = STATE_NORMAL;
      SYSERR("Function not implement");
      break;
    }
}