#include "system/nth_alloc.h"
#include "ui/console.h"
#include "ui/edit_field.h"
+#include "ui/cursor.h"
#include "system/str.h"
#include "sdl/texture.h"
#include "game/level/level_editor/background_layer.h"
#include "game/level/level_editor.h"
#include "game/settings.h"
-static int game_render_cursor(const Game *game);
-
-const char *cursor_style_tex_files[CURSOR_STYLE_N] = {
- "./assets/images/cursor.bmp",
- "./assets/images/cursor-resize-vert.bmp",
- "./assets/images/cursor-resize-horis.bmp",
- "./assets/images/cursor-resize-diag1.bmp",
- "./assets/images/cursor-resize-diag2.bmp"
-};
-
typedef enum Game_state {
GAME_STATE_LEVEL = 0,
GAME_STATE_LEVEL_PICKER,
Sound_samples *sound_samples;
Camera camera;
SDL_Renderer *renderer;
- SDL_Texture *cursor_texs[CURSOR_STYLE_N];
- Cursor_Style cursor_style;
Console *console;
+ Cursor cursor;
int console_enabled;
- int cursor_x;
- int cursor_y;
} Game;
static
game->renderer = renderer;
for (Cursor_Style style = 0; style < CURSOR_STYLE_N; ++style) {
- game->cursor_texs[style] = PUSH_LT(
+ game->cursor.texs[style] = PUSH_LT(
lt,
texture_from_bmp(cursor_style_tex_files[style], renderer),
SDL_DestroyTexture);
if (SDL_SetTextureBlendMode(
- game->cursor_texs[style],
+ game->cursor.texs[style],
SDL_ComposeCustomBlendMode(
SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR,
SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR,
}
game->console_enabled = 0;
- game->cursor_x = 0;
- game->cursor_y = 0;
-
game_switch_state(game, GAME_STATE_LEVEL_PICKER);
return game;
}
}
- if (game_render_cursor(game) < 0) {
+ if (cursor_render(&game->cursor, game->renderer) < 0) {
return -1;
}
return 0;
} break;
- case SDL_MOUSEMOTION: {
- game->cursor_x = event->motion.x;
- game->cursor_y = event->motion.y;
- } break;
-
case SDL_KEYDOWN: {
if (event->key.keysym.sym == SDLK_q && event->key.keysym.mod & KMOD_CTRL) {
game_switch_state(game, GAME_STATE_QUIT);
return game->state == GAME_STATE_QUIT;
}
-// Private Functions
-
-static int game_render_cursor(const Game *game)
-{
- trace_assert(game);
-
- SDL_Rect src = {0, 0, 32, 32};
- SDL_Rect dest = {game->cursor_x, game->cursor_y, 32, 32};
- if (SDL_RenderCopy(
- game->renderer,
- game->cursor_texs[game->cursor_style],
- &src, &dest) < 0) {
- return -1;
- }
-
- return 0;
-}
-
int game_load_level(Game *game, const char *level_filename)
{
trace_assert(game);
return 0;
}
-
-void game_set_cursor(Game *game, Cursor_Style style)
-{
- trace_assert(game);
- trace_assert(style < CURSOR_STYLE_N);
- game->cursor_style = style;
-}
typedef struct Game Game;
-typedef enum {
- CURSOR_STYLE_POINTER = 0,
- CURSOR_STYLE_RESIZE_VERT,
- CURSOR_STYLE_RESIZE_HORIS,
- CURSOR_STYLE_RESIZE_DIAG1,
- CURSOR_STYLE_RESIZE_DIAG2,
-
- CURSOR_STYLE_N
-} Cursor_Style;
-
Game *create_game(const char *platforms_file_path,
const char *sound_sample_files[],
size_t sound_sample_files_count,
int game_over_check(const Game *game);
int game_load_level(Game *game, const char *filepath);
-void game_set_cursor(Game *game, Cursor_Style style);
#endif // GAME_H_
--- /dev/null
+#include "system/stacktrace.h"
+#include "cursor.h"
+
+int cursor_render(const Cursor *cursor, SDL_Renderer *renderer)
+{
+ trace_assert(cursor);
+ trace_assert(renderer);
+
+ int cursor_x, cursor_y;
+ SDL_GetMouseState(&cursor_x, &cursor_y);
+
+ const SDL_Rect src = {0, 0, 32, 32};
+ const SDL_Rect dest = {cursor_x, cursor_y, 32, 32};
+ if (SDL_RenderCopy(
+ renderer,
+ cursor->texs[cursor->style],
+ &src, &dest) < 0) {
+ return -1;
+ }
+
+ return 0;
+}
--- /dev/null
+#ifndef CURSOR_H_
+#define CURSOR_H_
+
+#include <SDL2/SDL.h>
+
+typedef enum {
+ CURSOR_STYLE_POINTER = 0,
+ CURSOR_STYLE_RESIZE_VERT,
+ CURSOR_STYLE_RESIZE_HORIS,
+ CURSOR_STYLE_RESIZE_DIAG1,
+ CURSOR_STYLE_RESIZE_DIAG2,
+
+ CURSOR_STYLE_N
+} Cursor_Style;
+
+static const char * const cursor_style_tex_files[CURSOR_STYLE_N] = {
+ "./assets/images/cursor.bmp",
+ "./assets/images/cursor-resize-vert.bmp",
+ "./assets/images/cursor-resize-horis.bmp",
+ "./assets/images/cursor-resize-diag1.bmp",
+ "./assets/images/cursor-resize-diag2.bmp"
+};
+
+typedef struct {
+ SDL_Texture *texs[CURSOR_STYLE_N];
+ Cursor_Style style;
+} Cursor;
+
+int cursor_render(const Cursor *cursor, SDL_Renderer *renderer);
+
+#endif // CURSOR_H_