GadgetSeed  0.9.6
graphics_object.c
[詳解]
1 /** @file
2  @brief グラフィックス集合体描画
3 
4  @date 2017.05.04
5  @author Takashi SHUDO
6 */
7 
8 #include "graphics_object.h"
9 #include "graphics.h"
10 #include "font.h"
11 #include "tprintf.h"
12 
13 static int sc_numerator = 0x10000;
14 static int sc_denominator = 0x10000;
15 
16 static inline short SC(short val)
17 {
18  return (((int)val) * sc_numerator)/sc_denominator;
19 }
20 
21 /**
22  @brief 描画するグラフィックオブジェクトの拡大率を設定する
23 
24  @param[in] numerator 拡大率分子
25  @param[in] denominator 各倍率分母
26 */
27 void set_graph_obj_scale(int numerator, int denominator)
28 {
29  sc_numerator = numerator;
30  sc_denominator = denominator;
31 }
32 
33 static void set_box(short x, short y, struct st_box *box, const int arg[4])
34 {
35  box->pos.x = SC(arg[0]) + x;
36  box->pos.y = SC(arg[1]) + y;
37  box->sur.width = SC(arg[2]);
38  box->sur.height = SC(arg[3]);
39 }
40 
41 /**
42  @brief グラフィックオブジェクトを描画する
43 
44  @param[in] x X座標
45  @param[in] y Y座標
46  @param[in] gobj グラフィックオブジェクト
47 */
48 void draw_graph_object(short x, short y, const struct st_graph_object *gobj)
49 {
50  const struct st_graph_object *go = gobj;
51 
52  //tprintf("g_obj %d, %d\n", x, y);
53 
54  while((go != 0) && (go->type != GO_TYPE_OBJECT_END)) {
55  //tprintf("type : %d %d %d %d %d %d %d\n", go->type,
56  // go->arg[0], go->arg[1], go->arg[2], go->arg[3], go->arg[4], go->arg[5]);
57  switch(go->type) {
58  case GO_TYPE_MODE:
59  set_draw_mode(go->arg[0]);
60  break;
61 
62  case GO_TYPE_FORECOLOR:
63  set_forecolor(go->arg[0]);
64  break;
65 
66  case GO_TYPE_BACKCOLOR:
67  set_backcolor(go->arg[0]);
68  break;
69 
70  case GO_TYPE_FONT:
71  (void)set_font_by_name((char *)(go->data));
72  break;
73 
74  case GO_TYPE_TEXT:
75  draw_str(SC(go->arg[0])+x, SC(go->arg[1])+y, (unsigned char *)(go->data));
76  break;
77 
79  {
80  struct st_box box;
81  set_box(x, y, &box, go->arg);
82  draw_str_in_box(&box, go->arg[4], go->arg[5], (unsigned char *)(go->data));
83  }
84  break;
85 
87  {
88  draw_fill_circle(SC(go->arg[0])+x, SC(go->arg[1])+y,
89  SC(go->arg[2]));
90  }
91  break;
92 
93  case GO_TYPE_BOX:
94  {
95  struct st_box box;
96  set_box(x, y, &box, go->arg);
97  draw_box(&box);
98  }
99  break;
100 
101  case GO_TYPE_ROUND_BOX:
102  {
103  struct st_box box;
104  set_box(x, y, &box, go->arg);
105  //tprintf("round_box %d %d %d %d %d\n",
106  // box.px, box.py, box.width, box.height, go->arg[4]);
107  draw_round_box(&box, SC(go->arg[4]));
108  }
109  break;
110 
112  {
113  struct st_box box;
114  set_box(x, y, &box, go->arg);
115  //tprintf("round_box %d %d %d %d %d\n",
116  // box.px, box.py, box.width, box.height, go->arg[4]);
117  draw_round_fill_box(&box, SC(go->arg[4]));
118  }
119  break;
120 
121  case GO_TYPE_FILL_BOX:
122  {
123  struct st_box box;
124  set_box(x, y, &box, go->arg);
125  //tprintf("box %d %d %d %d\n",
126  // box.px, box.py, box.width, box.height);
127  draw_fill_box(&box);
128  }
129  break;
130 
131  case GO_TYPE_VERTEX4:
132  {
133  draw_vertex4_region(SC(go->arg[0])+x, SC(go->arg[1])+y,
134  SC(go->arg[2])+x, SC(go->arg[3])+y,
135  SC(go->arg[4])+x, SC(go->arg[5])+y,
136  SC(go->arg[6])+x, SC(go->arg[7])+y);
137  }
138  break;
139 
140  case GO_TYPE_SECTOR:
141  {
142  draw_sector(SC(go->arg[0])+x, SC(go->arg[1])+y,
143  SC(go->arg[2]), SC(go->arg[3]),
144  go->arg[4]);
145  }
146  break;
147 
148  default:
149  break;
150  }
151 
152  go++;
153  }
154 }
void draw_round_box(struct st_box *box, short r)
角の丸い四角を描画する
Definition: graphics.c:1406
short y
Y座標
Definition: graphics.h:73
グラフィックス集合体描画
#define GO_TYPE_VERTEX4
塗りつぶした4頂点の領域
void draw_round_fill_box(struct st_box *box, short r)
塗りつぶした角の丸い四角を描画する
Definition: graphics.c:1421
struct st_surface sur
面の大きさ
Definition: graphics.h:83
void set_graph_obj_scale(int numerator, int denominator)
描画するグラフィックオブジェクトの拡大率を設定する
struct st_position pos
左上頂点の位置
Definition: graphics.h:82
#define GO_TYPE_ROUND_FILL_BOX
角の丸い塗りつぶした四角
#define GO_TYPE_FILL_CIRCLE
塗りつぶした円
short height
高さ
Definition: graphics.h:78
void set_backcolor(unsigned int color)
描画の背景色を設定する
Definition: graphics.c:392
void draw_sector(short x, short y, short er, short ir, char q)
扇形を描画する
Definition: graphics.c:1732
#define GO_TYPE_BACKCOLOR
バックカラー設定
void draw_str(short x, short y, uchar *str)
文字列を描画する
Definition: font.c:494
長(正)方形
Definition: graphics.h:81
#define GO_TYPE_FORECOLOR
フォアカラー設定
グラフィック集合体各要素
#define GO_TYPE_OBJECT_END
グラフィックオブジェクト配列終端
#define GO_TYPE_MODE
描画モード設定
short width
Definition: graphics.h:77
#define GO_TYPE_TEXT_IN_BOX
四角形内文字列
void draw_graph_object(short x, short y, const struct st_graph_object *gobj)
グラフィックオブジェクトを描画する
struct st_fontset * set_font_by_name(char *name)
カレントフォントセットをフォント名で設定する
Definition: font.c:226
void draw_str_in_box(struct st_box *box, int hattr, int vattr, unsigned char *str)
四角形内に文字列を描画する
Definition: font.c:589
int type
グラフィックオブジェクト種別
void draw_box(struct st_box *box)
四角を描画する
Definition: graphics.c:1391
#define GO_TYPE_FILL_BOX
塗りつぶした四角
void * data
グラフィックオブジェクトその他データ
void set_draw_mode(unsigned char mode)
描画モードを設定する
Definition: graphics.c:414
void set_forecolor(unsigned int color)
描画の色を設定する
Definition: graphics.c:370
void draw_fill_box(struct st_box *box)
塗りつぶした四角を描画する
Definition: graphics.c:1435
#define GO_TYPE_SECTOR
扇形
#define GO_TYPE_FONT
フォント設定
void draw_vertex4_region(short x0, short y0, short x1, short y1, short x2, short y2, short x3, short y3)
塗りつぶした4頂点の領域を描画する
Definition: graphics.c:1510
void draw_fill_circle(short x0, short y0, short r)
塗りつぶした円を描画する
Definition: graphics.c:1253
#define GO_TYPE_BOX
四角
#define GO_TYPE_ROUND_BOX
角の丸い四角
#define GO_TYPE_TEXT
文字列
int arg[8]
グラフィックオブジェクト描画データ
グラフィックライブラリ
フォント
short x
X座標
Definition: graphics.h:72
機能限定printf