93 lines
2.2 KiB
C
93 lines
2.2 KiB
C
#include "editor.h"
|
|
#include "raylib.h"
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
|
|
#include <ft2build.h>
|
|
#include <stdlib.h>
|
|
#include FT_FREETYPE_H
|
|
|
|
FT_Library library;
|
|
FT_Face face;
|
|
|
|
EditorState editor_state;
|
|
Font editor_font;
|
|
|
|
#define ERROR(module, error) \
|
|
{ \
|
|
printf("ERROR (%s): %s\n", (module), (error)); \
|
|
}
|
|
|
|
int main() {
|
|
FT_Error error = FT_Init_FreeType(&library);
|
|
if (error) {
|
|
ERROR("freetype", FT_Error_String(error))
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
error = FT_New_Face(library, "/usr/share/fonts/noto/NotoSans-Regular.ttf",
|
|
0, &face);
|
|
|
|
if (error) {
|
|
ERROR("freetype", FT_Error_String(error))
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
error = FT_Set_Char_Size(face, 0, 16 * 18, 800, 600);
|
|
|
|
if (error) {
|
|
ERROR("freetype", FT_Error_String(error))
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
FT_UInt idx = FT_Get_Char_Index(face, '&');
|
|
printf("Index: %d\n", idx);
|
|
|
|
error = FT_Load_Glyph(face, 32, FT_LOAD_DEFAULT);
|
|
|
|
if (error) {
|
|
ERROR("freetype", FT_Error_String(error))
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
|
|
|
|
if (error) {
|
|
ERROR("freetype", FT_Error_String(error))
|
|
exit(EXIT_FAILURE);
|
|
}
|
|
|
|
FT_GlyphSlot slot = face->glyph;
|
|
|
|
sds init_text = sdsnew("Das ist nur ein Test String🙂!");
|
|
editor_state = init_editor_state(init_text);
|
|
|
|
printf("%s\n", editor_state.text);
|
|
|
|
InitWindow(800, 600, "editor");
|
|
|
|
Image img = (Image){.data = slot->bitmap.buffer,
|
|
.width = slot->bitmap.width,
|
|
.height = slot->bitmap.rows,
|
|
.format = PIXELFORMAT_UNCOMPRESSED_GRAYSCALE,
|
|
.mipmaps = 1};
|
|
|
|
Texture2D tex = LoadTextureFromImage(img);
|
|
|
|
while (!WindowShouldClose()) {
|
|
BeginDrawing();
|
|
ClearBackground(BLACK);
|
|
|
|
DrawText(editor_state.text, 8, 8, 18, RAYWHITE);
|
|
DrawRectangle(8 * editor_state.cursor_pos + 8, 8, 2, 18, GREEN);
|
|
|
|
DrawTexture(tex, 40, 40, WHITE);
|
|
|
|
EndDrawing();
|
|
}
|
|
|
|
CloseWindow();
|
|
|
|
return 0;
|
|
}
|