SG 1 rok temu
rodzic
commit
647362dd31
6 zmienionych plików z 79 dodań i 14 usunięć
  1. 28 0
      canvas.c
  2. 32 0
      canvas.h
  3. 9 1
      engine.h
  4. 0 12
      game_engine.c
  5. 1 0
      game_engine.h
  6. 9 1
      vector.h

+ 28 - 0
canvas.c

@@ -0,0 +1,28 @@
+#include <furi.h>
+#include "canvas.h"
+
+void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...) {
+    FuriString* string = furi_string_alloc();
+    va_list args;
+    va_start(args, format);
+    furi_string_vprintf(string, format, args);
+    va_end(args);
+
+    canvas_draw_str(canvas, x, y, furi_string_get_cstr(string));
+
+    furi_string_free(string);
+}
+
+size_t canvas_printf_width(Canvas* canvas, const char* format, ...) {
+    FuriString* string = furi_string_alloc();
+    va_list args;
+    va_start(args, format);
+    furi_string_vprintf(string, format, args);
+    va_end(args);
+
+    size_t size = canvas_string_width(canvas, furi_string_get_cstr(string));
+
+    furi_string_free(string);
+
+    return size;
+}

+ 32 - 0
canvas.h

@@ -0,0 +1,32 @@
+#pragma once
+#include <stddef.h>
+#include <gui/canvas.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Print formatted string to canvas
+ * 
+ * @param canvas canvas instance
+ * @param x x position
+ * @param y y position
+ * @param format format string
+ * @param ...  arguments
+ */
+void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...);
+
+/**
+ * @brief Get width of formatted string
+ * 
+ * @param canvas canvas instance
+ * @param format format string
+ * @param ... arguments
+ * @return size_t width of formatted string
+ */
+size_t canvas_printf_width(Canvas* canvas, const char* format, ...);
+
+#ifdef __cplusplus
+}
+#endif

+ 9 - 1
engine.h

@@ -5,6 +5,10 @@
 #include "entity.h"
 #include "game_manager.h"
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct {
     float target_fps;
     bool show_fps;
@@ -14,4 +18,8 @@ typedef struct {
     size_t context_size;
 } Game;
 
-extern const Game game;
+extern const Game game;
+
+#ifdef __cplusplus
+}
+#endif

+ 0 - 12
game_engine.c

@@ -56,18 +56,6 @@ void game_engine_free(GameEngine* engine) {
     free(engine);
 }
 
-static void canvas_printf(Canvas* canvas, uint8_t x, uint8_t y, const char* format, ...) {
-    FuriString* string = furi_string_alloc();
-    va_list args;
-    va_start(args, format);
-    furi_string_vprintf(string, format, args);
-    va_end(args);
-
-    canvas_draw_str(canvas, x, y, furi_string_get_cstr(string));
-
-    furi_string_free(string);
-}
-
 static void clock_timer_callback(void* context) {
     GameEngine* engine = context;
     furi_thread_flags_set(engine->thread_id, GameThreadFlagUpdate);

+ 1 - 0
game_engine.h

@@ -1,5 +1,6 @@
 #pragma once
 #include <stdbool.h>
+#include "canvas.h"
 #include <gui/canvas.h>
 
 #ifdef __cplusplus

+ 9 - 1
vector.h

@@ -1,5 +1,9 @@
 #pragma once
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 typedef struct {
     float x;
     float y;
@@ -21,4 +25,8 @@ Vector vector_subf(Vector a, float b);
 
 Vector vector_mulf(Vector a, float b);
 
-Vector vector_divf(Vector a, float b);
+Vector vector_divf(Vector a, float b);
+
+#ifdef __cplusplus
+}
+#endif