Skip to content

Commit

Permalink
ft: safe area debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
markkimsal committed Sep 29, 2024
1 parent fe930c9 commit a766ef4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 6 additions & 2 deletions zig-src/src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const GameModes = @import("modes/game_modes.zig");
const GameModeType = @import("modes/game_modes.zig").GameModeType;
const SpriteMod = @import("sprite.zig");

const ANDROID = false;
const ANDROID = true;

const heap_alloc = std.heap.c_allocator;
pub var mode: *sdl.SDL_DisplayMode = undefined;
Expand All @@ -29,6 +29,10 @@ pub fn main() !void {
_ = sdl.SDL_SetHint(sdl.SDL_HINT_MOUSE_TOUCH_EVENTS, "1");
_ = sdl.SDL_SetHint(sdl.SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
_ = sdl.SDL_SetHint(sdl.SDL_HINT_ANDROID_TRAP_BACK_BUTTON, "1");
} else {
_ = sdl.SDL_SetHint(sdl.SDL_HINT_MOUSE_TOUCH_EVENTS, "0");
_ = sdl.SDL_SetHint(sdl.SDL_HINT_TOUCH_MOUSE_EVENTS, "0");
_ = sdl.SDL_SetHint(sdl.SDL_HINT_ANDROID_TRAP_BACK_BUTTON, "1");
}

mode = heap_alloc.create(sdl.SDL_DisplayMode) catch sdlPanic();
Expand Down Expand Up @@ -123,7 +127,7 @@ pub fn main() !void {

// try renderer.setColorRGB(0xF7, 0xA4, 0x1D);
// if (sdl.SDL_SetRenderDrawColor(renderer, 0xF7, 0xA4, 0x1D, 255) < 0) {}
if (sdl.SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00) < 0) {}
if (sdl.SDL_SetRenderDrawColor(renderer, 0x20, 0x10, 0x10, 0xFF) < 0) {}

// try renderer.clear();
if (sdl.SDL_RenderClear(renderer) > 0) {}
Expand Down
13 changes: 9 additions & 4 deletions zig-src/src/modes/attract.zig
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub const AttractMode = struct {
const display_mode = MainModule.mode;
// _ = display_mode;

var rect = sdl.SDL_Rect{ .x = @as(c_int, @intFromFloat(event.tfinger.x * 100.0)), .y = @as(c_int, @intFromFloat(event.tfinger.y * 100.0)), .w = 2, .h = 2 };
var rect = sdl.SDL_Rect{ .x = @as(c_int, @intFromFloat(event.tfinger.x * 100.0)), .y = @as(c_int, @intFromFloat(event.tfinger.y * 100.0)), .w = 10, .h = 10 };
// sdl.SDL_Log("\nfinger up x: %f finger up y: %f.\n", event.tfinger.x * 100, event.tfinger.y * 100);
// sdl.SDL_Log("\nfinger up x: %d finger up y: %d.\n", @as(c_int, @intFromFloat(event.tfinger.x * 100)), @as(c_int, @intFromFloat(event.tfinger.y * 100)));
// sdl.SDL_Log("\n1. touch event at :%d %d.\n", rect.x, rect.y);
Expand Down Expand Up @@ -200,6 +200,11 @@ pub const AttractMode = struct {
rect.x = @as(c_int, @divFloor(display_mode.w * rect.x, 100));
rect.y = @as(c_int, @divFloor(display_mode.h * rect.y, 100));

rect.x -= 5;
rect.y -= 5;
rect.y += 50; // safe area

debug_rect_ = rect;
// const rect = sdl.SDL_Rect{ .x = @as(c_int, @intFromFloat(event.tfinger.x * 100.0)), .y = @as(c_int, @intFromFloat(event.tfinger.y * 100.0)), .w = 2, .h = 2 };
var result_rect = sdl.SDL_Rect{ .x = 0, .y = 7, .w = 0, .h = 0 };
for (self.menu_items.items) |*item| {
Expand Down Expand Up @@ -313,7 +318,7 @@ pub const Color = extern struct {
};

fn create_menu_items(menu_items: *std.ArrayList(MenuItem), font: ?*sdl.TTF_Font, renderer: *sdl.SDL_Renderer) void {
var menu_item1 = MenuItem.init(sdl.SDL_Rect{ .x = 330, .y = 77, .w = 0, .h = 0 });
var menu_item1 = MenuItem.init(sdl.SDL_Rect{ .x = 330, .y = 60, .w = 0, .h = 0 });
menu_item1.set_text(font, renderer, "Press [ENTER] to start.");
menu_item1.set_on_click(
struct {
Expand All @@ -326,7 +331,7 @@ fn create_menu_items(menu_items: *std.ArrayList(MenuItem), font: ?*sdl.TTF_Font,
);
menu_items.append(menu_item1) catch {};

var menu_item2 = MenuItem.init(sdl.SDL_Rect{ .x = 330, .y = 110, .w = 0, .h = 0 });
var menu_item2 = MenuItem.init(sdl.SDL_Rect{ .x = 330, .y = 100, .w = 0, .h = 0 });
menu_item2.set_text(font, renderer, "[N] Next Song");
menu_item2.set_on_click(
struct {
Expand All @@ -340,7 +345,7 @@ fn create_menu_items(menu_items: *std.ArrayList(MenuItem), font: ?*sdl.TTF_Font,
);
menu_items.append(menu_item2) catch {};

var menu_item3 = MenuItem.init(sdl.SDL_Rect{ .x = 330, .y = 140, .w = 0, .h = 0 });
var menu_item3 = MenuItem.init(sdl.SDL_Rect{ .x = 330, .y = 130, .w = 0, .h = 0 });
menu_item3.set_text(font, renderer, "[H] for Help");
menu_item3.set_on_click(
struct {
Expand Down

0 comments on commit a766ef4

Please sign in to comment.