Skip to content

Commit e13068f

Browse files
committed
add font stuff
1 parent 0620810 commit e13068f

23 files changed

+35316
-144
lines changed

Makefile

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
SRC = $(wildcard source/*.c)
2-
DEPS = $(wildcard source/*.h)
3-
OBJ = $(addsuffix .o,$(subst source/,bin/,$(basename ${SRC})))
4-
LIBS = -lSDL2 -lSDL2_ttf
5-
FLAGS = -std=c99 -Wall -Wextra -Werror -pedantic -g -I./lib
1+
SRC = $(wildcard source/*.c)
2+
DEPS = $(wildcard source/*.h)
3+
OBJ = $(addsuffix .o,$(subst source/,bin/,$(basename $(SRC))))
4+
LIBS = -lSDL3
5+
FLAGS = -std=c99 -Wall -Wextra -pedantic -g -I./lib
6+
EMBEDDED = $(addsuffix .h,$(subst assets/,source/assets/,$(basename $(wildcard assets/*))))
67

7-
compile: ./bin $(OBJ) $(SRC) $(DEPS)
8+
compile: $(EMBEDDED) ./bin $(OBJ) $(SRC) $(DEPS)
89
$(CC) $(OBJ) $(LIBS) -o yterm
910

1011
./bin:
1112
mkdir -p bin
1213

14+
source/assets/%.h: assets/%.bmp ./source/assets
15+
xxd -i $< > $@
16+
17+
./source/assets:
18+
mkdir -p source/assets
19+
1320
bin/%.o: source/%.c $(DEPS)
1421
$(CC) -c $< $(FLAGS) -o $@
1522

TODO.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# TODO
2+
- Add line wrapping

assets/basil_8x8.bmp

64.1 KB
Binary file not shown.

assets/default_7x16.bmp

112 KB
Binary file not shown.

assets/trinity_12x18.bmp

234 KB
Binary file not shown.

font.ttf

-79.3 KB
Binary file not shown.

lib/stb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit f0569113c93ad095470c54bf34a17b36646bbbb5

source/app.c

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@ void App_Init(App* app, char** env) {
1515

1616
// init video
1717
app->video = Video_Init();
18-
SDL_StartTextInput();
19-
Video_OpenFont(&app->video, "./font.ttf");
18+
SDL_StartTextInput(app->video.window);
19+
20+
// init colourscheme and font
21+
LoadConfig(&app->colours, &app->video);
2022

2123
// init tabs
2224
app->tabs = NULL;
2325
app->tabAmount = 0;
2426
app->currentTab = 0;
2527
App_AddTab(app);
2628

27-
// init colourscheme
28-
LoadConfig(&app->colours);
29-
3029
// init screen
3130
app->screen = TextScreen_New(
3231
app->video.windowSize.x / app->video.charWidth,
@@ -87,28 +86,28 @@ void App_Update(App* app) {
8786

8887
while (SDL_PollEvent(&e)) {
8988
switch (e.type) {
90-
case SDL_QUIT: {
89+
case SDL_EVENT_QUIT: {
9190
app->running = false;
9291
continue;
9392
}
94-
case SDL_KEYDOWN:
95-
case SDL_TEXTINPUT: {
96-
if (e.type == SDL_KEYDOWN) {
97-
const uint8_t* keys = SDL_GetKeyboardState(NULL);
93+
case SDL_EVENT_KEY_DOWN:
94+
case SDL_EVENT_TEXT_INPUT: {
95+
if (e.type == SDL_EVENT_KEY_DOWN) {
96+
const bool* keys = SDL_GetKeyboardState(NULL);
9897

9998
if (!ShiftPressed(keys) || !keys[SDL_SCANCODE_LCTRL]) {
10099
goto doInput;
101100
}
102101

103102
if (
104-
(e.key.keysym.scancode == SDL_SCANCODE_LCTRL) ||
105-
(e.key.keysym.scancode == SDL_SCANCODE_LSHIFT) ||
106-
(e.key.keysym.scancode == SDL_SCANCODE_RSHIFT)
103+
(e.key.scancode == SDL_SCANCODE_LCTRL) ||
104+
(e.key.scancode == SDL_SCANCODE_LSHIFT) ||
105+
(e.key.scancode == SDL_SCANCODE_RSHIFT)
107106
) {
108107
goto doInput;
109108
}
110109

111-
switch (e.key.keysym.scancode) {
110+
switch (e.key.scancode) {
112111
case SDL_SCANCODE_T: {
113112
App_AddTab(app);
114113
app->currentTab = app->tabAmount - 1;
@@ -141,28 +140,24 @@ void App_Update(App* app) {
141140
HandleInputEvent(&e, App_CurrentTab(app));
142141
break;
143142
}
144-
case SDL_WINDOWEVENT: {
145-
switch (e.window.event) {
146-
case SDL_WINDOWEVENT_RESIZED: {
147-
app->video.windowSize.x = e.window.data1;
148-
app->video.windowSize.y = e.window.data2;
149-
150-
Vec2 newSize = {
151-
e.window.data1 / app->video.charWidth,
152-
e.window.data2 / app->video.charHeight
153-
};
154-
TextScreen_Resize(&app->screen, newSize);
155-
156-
Vec2 newTabSize = App_GetUsableArea(app);
157-
158-
for (size_t i = 0; i < app->tabAmount; ++ i) {
159-
TextScreen_Resize(&app->tabs[i].buffer, newTabSize);
160-
}
161-
162-
SetTerminalSize(App_CurrentTab(app));
163-
break;
164-
}
143+
case SDL_EVENT_WINDOW_RESIZED: {
144+
app->video.windowSize.x = e.window.data1;
145+
app->video.windowSize.y = e.window.data2;
146+
147+
Vec2 newSize = {
148+
e.window.data1 / app->video.charWidth,
149+
e.window.data2 / app->video.charHeight
150+
};
151+
TextScreen_Resize(&app->screen, newSize);
152+
153+
Vec2 newTabSize = App_GetUsableArea(app);
154+
155+
for (size_t i = 0; i < app->tabAmount; ++ i) {
156+
TextScreen_Resize(&app->tabs[i].buffer, newTabSize);
165157
}
158+
159+
SetTerminalSize(App_CurrentTab(app));
160+
break;
166161
}
167162
}
168163
}

source/assets.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "util.h"
2+
#include "assets.h"
3+
#include "config.h"
4+
5+
// assets
6+
#include "assets/basil_8x8.h"
7+
#include "assets/default_7x16.h"
8+
#include "assets/trinity_12x18.h"
9+
10+
typedef struct {
11+
const char* fileName;
12+
const uint8_t* contents;
13+
size_t size;
14+
} Asset;
15+
16+
void WriteAssets(void) {
17+
Asset assets[] = {
18+
{
19+
.fileName = "fonts/basil_8x8.bmp",
20+
.contents = assets_basil_8x8_bmp,
21+
.size = assets_basil_8x8_bmp_len
22+
},
23+
{
24+
.fileName = "fonts/default_7x16.bmp",
25+
.contents = assets_default_7x16_bmp,
26+
.size = assets_default_7x16_bmp_len
27+
},
28+
{
29+
.fileName = "fonts/trinity_12x18.bmp",
30+
.contents = assets_trinity_12x18_bmp,
31+
.size = assets_trinity_12x18_bmp_len
32+
}
33+
};
34+
35+
for (size_t i = 0; i < ARRAY_LEN(assets); ++ i) {
36+
Asset* asset = &assets[i];
37+
38+
char assetPath[2048];
39+
strcpy(assetPath, GetConfigPath());
40+
strcat(assetPath, asset->fileName);
41+
42+
FILE* file = fopen(assetPath, "wb");
43+
44+
if (file == NULL) {
45+
FATAL("Failed to open file '%s': %s\n", assetPath, strerror(errno));
46+
}
47+
48+
fwrite(asset->contents, 1, asset->size, file);
49+
fclose(file);
50+
}
51+
}

source/assets.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef YTERM_ASSETS_H
2+
#define YTERM_ASSETS_H
3+
4+
void WriteAssets(void);
5+
6+
#endif

0 commit comments

Comments
 (0)