GoldFish Engine
Quite simple and lightweight game engine
Loading...
Searching...
No Matches
gf_graphic_common.c
1
#define GF_EXPOSE_DRAW
2
#define GF_EXPOSE_TEXTURE
3
#define GF_EXPOSE_FONT
4
5
#include <
gf_pre.h
>
6
7
/* External library */
8
9
/* Interface */
10
#include <
gf_graphic.h
>
11
12
/* Engine */
13
#include <
gf_draw.h
>
14
#include <
gf_font.h
>
15
16
/* Standard */
17
#include <string.h>
18
19
void
gf_graphic_fill_rect(
gf_draw_t
* draw,
double
x,
double
y,
double
w,
double
h,
gf_graphic_color_t
color) { gf_graphic_fill_polygon(draw, color,
GF_GRAPHIC_2D
, 4, x, y, x, y + h, x + w, y + h, x + w, y); }
20
21
void
gf_graphic_text(
gf_draw_t
* draw,
double
x,
double
y,
double
size,
const
char
* text,
gf_graphic_color_t
color) {
22
int
i;
23
double
mx = 0;
24
gf_font_glyph_t
* glyph;
25
double
zoom = 0;
26
if
(draw->
font
!= NULL) {
27
zoom = size / draw->
font
->
bbox
.
height
;
28
for
(i = 0; text[i] != 0; i++) {
29
if
((glyph = gf_font_get(draw->
font
, text[i])) != NULL) {
30
double
fax = glyph->
bbox
.
width
;
31
double
fay = glyph->
bbox
.
height
;
32
double
fx = glyph->
bbox
.
x
;
33
double
fy = (draw->
font
->
bbox
.
height
+ draw->
font
->
bbox
.
y
) - (glyph->
bbox
.
height
+ glyph->
bbox
.
y
);
34
gf_graphic_draw_texture_2d(draw, x + mx + fx * zoom, y + fy * zoom, zoom * fax, zoom * fay, glyph->
texture
, color);
35
mx += zoom * glyph->
dwidth
[0];
36
}
37
}
38
}
39
}
40
41
double
gf_graphic_text_width(
gf_draw_t
* draw,
double
size,
const
char
* text) {
42
int
i;
43
double
mx = 0;
44
gf_font_glyph_t
* glyph;
45
double
zoom = 0;
46
if
(draw->
font
!= NULL) {
47
zoom = size / draw->
font
->
bbox
.
height
;
48
for
(i = 0; text[i] != 0; i++) {
49
if
((glyph = gf_font_get(draw->
font
, text[i])) != NULL) {
50
mx += zoom * glyph->
dwidth
[0];
51
}
52
}
53
}
54
return
mx;
55
}
56
57
void
gf_graphic_draw_texture_2d(
gf_draw_t
* draw,
double
x,
double
y,
double
w,
double
h,
gf_texture_t
* texture,
gf_graphic_color_t
color) {
58
if
(texture != NULL) gf_graphic_draw_texture_polygon(draw, texture, color,
GF_GRAPHIC_2D
, 4, 0.0, 0.0, x, y, 0.0, 1.0, x, y + h, 1.0, 1.0, x + w, y + h, 1.0, 0.0, x + w, y);
59
}
gf_draw.h
Drawing interface.
gf_font.h
Font.
gf_graphic.h
Graphic interface.
GF_GRAPHIC_2D
#define GF_GRAPHIC_2D
Dimension parameter for 2D.
Definition
gf_graphic.h:26
gf_pre.h
Required headers before anything.
gf_draw_t
Drawing interface.
Definition
draw.h:108
gf_draw_t::font
gf_font_t * font
Current font.
Definition
draw.h:108
gf_font_bbox_t::y
int y
Y coord.
Definition
font.h:67
gf_font_bbox_t::width
int width
Width.
Definition
font.h:67
gf_font_bbox_t::x
int x
X coord.
Definition
font.h:67
gf_font_bbox_t::height
int height
Height.
Definition
font.h:67
gf_font_glyph_t
Glyph.
Definition
font.h:95
gf_font_glyph_t::dwidth
int dwidth[2]
Device width.
Definition
font.h:95
gf_font_glyph_t::bbox
gf_font_bbox_t bbox
Bounding box.
Definition
font.h:95
gf_font_glyph_t::texture
gf_texture_t * texture
Texture.
Definition
font.h:95
gf_font_t::bbox
gf_font_bbox_t bbox
Bounding box.
Definition
font.h:115
gf_graphic_color_t
Color.
Definition
graphic.h:44
gf_texture_t
Texture.
Definition
texture.h:49
src
gf_graphic_common.c
Generated by
1.9.8