Debian Codegraph @

src/cdogs/font.h

raw symbols SCIP
1 /*
2 Copyright (c) 2014-2015, 2019-2022 Cong Xu
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 Redistributions of source code must retain the above copyright notice, this
9 list of conditions and the following disclaimer.
10 Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
18 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 POSSIBILITY OF SUCH DAMAGE.
25 */
26 #pragma once
27
28 #include <SDL_surface.h>
29
30 #include "c_array.h"
31 #include "vector.h"
32
33 #define ARROW_LEFT "\x11"
34 #define ARROW_RIGHT "\x10"
35 #define ARROW_UP "\x1e"
36 #define ARROW_DOWN "\x1f"
37
38 // Defines interfaces for bitmap fonts
39
40 typedef struct
41 {
42 struct vec2i Size;
43 int Stride;
44 struct
45 {
46 int Left;
47 int Top;
48 int Right;
49 int Bottom;
50 } Padding;
51 struct vec2i Gap;
52 CArray Chars; // of Pic
53 } Font;
54
55 typedef enum
56 {
57 ALIGN_START = 0,
58 ALIGN_CENTER,
59 ALIGN_END
60 } FontAlign;
61 typedef struct
62 {
63 FontAlign HAlign;
64 FontAlign VAlign;
65 struct vec2i Area;
66 struct vec2i Pad;
67 color_t Mask;
68 } FontOpts;
69
70 extern Font gFont;
71
72 FontOpts FontOptsNew(void);
73
74 void FontLoad(
75 Font *f, const char *imgPath, const bool isProportional,
76 const struct vec2i spaceSize);
77 void FontTerminate(Font *f);
78
79 int FontW(const char c);
80 int FontH(void);
81 struct vec2i FontChSize(const char c);
82 int FontStrW(const char *s);
83 int FontSubstrW(const char *s, int len);
84 int FontStrH(const char *s);
85 struct vec2i FontStrSize(const char *s);
86 int FontStrNumLines(const char *s);
87
88 // Returns updated cursor position
89 struct vec2i FontCh(const char c, const struct vec2i pos);
90 struct vec2i FontChMask(
91 const char c, const struct vec2i pos, const color_t mask);
92 struct vec2i FontStr(const char *s, struct vec2i pos);
93 struct vec2i FontStrMask(const char *s, struct vec2i pos, const color_t mask);
94 struct vec2i FontStrMaskWrap(
95 const char *s, struct vec2i pos, color_t mask, const int width);
96 void FontStrOpt(const char *s, struct vec2i pos, const FontOpts opts);
97 void FontStrCenter(const char *s);
98
99 void FontSplitLines(const char *text, char *buf, const int width);
100
101 struct vec2i Vec2iAligned(
102 const struct vec2i v, const struct vec2i size, const FontAlign hAlign,
103 const FontAlign vAlign, const struct vec2i area);