]> git.lizzy.rs Git - nothing.git/commitdiff
(#1129) Introduce different cursor styles
authorrexim <reximkut@gmail.com>
Sun, 10 Nov 2019 19:49:40 +0000 (02:49 +0700)
committerrexim <reximkut@gmail.com>
Sun, 10 Nov 2019 19:49:40 +0000 (02:49 +0700)
assets/images/cursor-resize-diag1.bmp [new file with mode: 0644]
assets/images/cursor-resize-diag2.bmp [new file with mode: 0644]
assets/images/cursor-resize-horis.bmp [new file with mode: 0644]
assets/images/cursor-resize-vert.bmp [new file with mode: 0644]
src/game.c

diff --git a/assets/images/cursor-resize-diag1.bmp b/assets/images/cursor-resize-diag1.bmp
new file mode 100644 (file)
index 0000000..13e5772
Binary files /dev/null and b/assets/images/cursor-resize-diag1.bmp differ
diff --git a/assets/images/cursor-resize-diag2.bmp b/assets/images/cursor-resize-diag2.bmp
new file mode 100644 (file)
index 0000000..b1d51a8
Binary files /dev/null and b/assets/images/cursor-resize-diag2.bmp differ
diff --git a/assets/images/cursor-resize-horis.bmp b/assets/images/cursor-resize-horis.bmp
new file mode 100644 (file)
index 0000000..c7e6594
Binary files /dev/null and b/assets/images/cursor-resize-horis.bmp differ
diff --git a/assets/images/cursor-resize-vert.bmp b/assets/images/cursor-resize-vert.bmp
new file mode 100644 (file)
index 0000000..eb8e038
Binary files /dev/null and b/assets/images/cursor-resize-vert.bmp differ
index 413c7f9df209a812a016d29f80255b03e6c91aef..c13ad1342e4b3f47024fd41a507d59f32fd18f93 100644 (file)
 
 static int game_render_cursor(const 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;
+
+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,
@@ -39,7 +57,8 @@ typedef struct Game {
     Sound_samples *sound_samples;
     Camera camera;
     SDL_Renderer *renderer;
-    SDL_Texture *texture_cursor;
+    SDL_Texture *cursor_texs[CURSOR_STYLE_N];
+    Cursor_Style cursor_style;
     Console *console;
     int console_enabled;
     int cursor_x;
@@ -101,22 +120,26 @@ Game *create_game(const char *level_folder,
     game->settings = create_settings();
 
     game->renderer = renderer;
-    game->texture_cursor = PUSH_LT(
-        lt,
-        texture_from_bmp("./assets/images/cursor.bmp", renderer),
-        SDL_DestroyTexture);
-    if (SDL_SetTextureBlendMode(
-            game->texture_cursor,
-            SDL_ComposeCustomBlendMode(
-                SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR,
-                SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR,
-                SDL_BLENDOPERATION_ADD,
-                SDL_BLENDFACTOR_ONE,
-                SDL_BLENDFACTOR_ZERO,
-                SDL_BLENDOPERATION_ADD)) < 0) {
-        log_warn("SDL error: %s\n", SDL_GetError());
+
+    for (Cursor_Style style = 0; style < CURSOR_STYLE_N; ++style) {
+        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],
+                SDL_ComposeCustomBlendMode(
+                    SDL_BLENDFACTOR_ONE_MINUS_DST_COLOR,
+                    SDL_BLENDFACTOR_ONE_MINUS_SRC_COLOR,
+                    SDL_BLENDOPERATION_ADD,
+                    SDL_BLENDFACTOR_ONE,
+                    SDL_BLENDFACTOR_ZERO,
+                    SDL_BLENDOPERATION_ADD)) < 0) {
+            log_warn("SDL error: %s\n", SDL_GetError());
+        }
     }
 
+
     game->console = PUSH_LT(
         lt,
         create_console(game),
@@ -512,7 +535,10 @@ static int game_render_cursor(const Game *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->texture_cursor, &src, &dest) < 0) {
+    if (SDL_RenderCopy(
+            game->renderer,
+            game->cursor_texs[game->cursor_style],
+            &src, &dest) < 0) {
         return -1;
     }