diff options
| -rw-r--r-- | src/config.c | 21 | ||||
| -rw-r--r-- | src/config.h | 5 | ||||
| -rw-r--r-- | src/layout_editor.c | 37 | ||||
| -rw-r--r-- | src/main.c | 42 |
4 files changed, 63 insertions, 42 deletions
diff --git a/src/config.c b/src/config.c index 44951d6..ed3581d 100644 --- a/src/config.c +++ b/src/config.c @@ -13,18 +13,23 @@ static void set_defaults(UILayout *layout) { layout->titleY = 60.0f; + layout->titleX = 1920.0f / 2.0f; layout->barY = 460.0f; layout->barHeight = 50.0f; layout->barWidth = 1920.0f * 0.65f; layout->btnRadius = 55.0f; layout->helpY = 1080.0f - 80.0f; + layout->helpX = 40.0f; layout->btnCenterX = 1920.0f / 2.0f; - layout->barX = (1920.0f - layout->barWidth) / 2.0f; - layout->statusY = layout->barY + layout->barHeight + 30.0f; - layout->btnY = layout->statusY + 120.0f + 55.0f; + layout->barX = (1920.0f - layout->barWidth) / 2.0f; + layout->statusY = layout->barY + layout->barHeight + 30.0f; + layout->statusX = 1920.0f / 2.0f; + layout->btnY = layout->statusY + 120.0f + 55.0f; layout->smartPlayY = 1080.0f - 80.0f - 120.0f; + layout->smartPlayX = 1920.0f / 2.0f - 100.0f; layout->secNavY = layout->btnY + 55.0f + 80.0f + 30.0f; + layout->secNavX = 1920.0f / 2.0f; } static void chomp(char *line) @@ -94,15 +99,20 @@ static int parse_config(const char *path, UILayout *layout) if (f < 0.0f) continue; if (strcmp(key, "title_y") == 0) layout->titleY = f; + else if (strcmp(key, "title_x") == 0) layout->titleX = f; else if (strcmp(key, "bar_y") == 0) layout->barY = f; else if (strcmp(key, "bar_height") == 0) layout->barHeight = f; else if (strcmp(key, "bar_width") == 0) layout->barWidth = f; else if (strcmp(key, "btn_radius") == 0) layout->btnRadius = f; else if (strcmp(key, "help_y") == 0) layout->helpY = f; + else if (strcmp(key, "help_x") == 0) layout->helpX = f; + else if (strcmp(key, "status_x") == 0) layout->statusX = f; else if (strcmp(key, "btn_y") == 0) layout->btnY = f; else if (strcmp(key, "btn_center_x") == 0) layout->btnCenterX = f; else if (strcmp(key, "smart_play_y") == 0) layout->smartPlayY = f; + else if (strcmp(key, "smart_play_x") == 0) layout->smartPlayX = f; else if (strcmp(key, "sec_nav_y") == 0) layout->secNavY = f; + else if (strcmp(key, "sec_nav_x") == 0) layout->secNavX = f; loaded = 1; } @@ -138,15 +148,20 @@ int config_save(const char *exePath, const UILayout *layout) fprintf(fp, "# Study Player layout config\n"); fprintf(fp, "title_y=%.2f\n", layout->titleY); + fprintf(fp, "title_x=%.2f\n", layout->titleX); fprintf(fp, "bar_y=%.2f\n", layout->barY); fprintf(fp, "bar_height=%.2f\n", layout->barHeight); fprintf(fp, "bar_width=%.2f\n", layout->barWidth); fprintf(fp, "btn_radius=%.2f\n", layout->btnRadius); fprintf(fp, "help_y=%.2f\n", layout->helpY); + fprintf(fp, "help_x=%.2f\n", layout->helpX); + fprintf(fp, "status_x=%.2f\n", layout->statusX); fprintf(fp, "btn_y=%.2f\n", layout->btnY); fprintf(fp, "btn_center_x=%.2f\n", layout->btnCenterX); fprintf(fp, "smart_play_y=%.2f\n", layout->smartPlayY); + fprintf(fp, "smart_play_x=%.2f\n", layout->smartPlayX); fprintf(fp, "sec_nav_y=%.2f\n", layout->secNavY); + fprintf(fp, "sec_nav_x=%.2f\n", layout->secNavX); fclose(fp); return 1; } diff --git a/src/config.h b/src/config.h index c4300d1..57824b5 100644 --- a/src/config.h +++ b/src/config.h @@ -2,17 +2,22 @@ typedef struct { float titleY; + float titleX; float barY; float barHeight; float barWidth; float barX; float statusY; + float statusX; float btnRadius; float helpY; + float helpX; float btnY; float btnCenterX; float smartPlayY; + float smartPlayX; float secNavY; + float secNavX; } UILayout; int config_load(const char *exePath, UILayout *layout); diff --git a/src/layout_editor.c b/src/layout_editor.c index ef01640..e2d7aee 100644 --- a/src/layout_editor.c +++ b/src/layout_editor.c @@ -44,7 +44,6 @@ void layout_editor_draw(const char *exePath, UILayout *layout) { (void)exePath; - int screenW = GetScreenWidth(); Vector2 mouse = GetMousePosition(); /* --- Hit detection on press --- */ @@ -57,8 +56,8 @@ void layout_editor_draw(const char *exePath, UILayout *layout) /* 6: Section nav buttons (two circles) */ { - float secPrevX = (float)screenW / 2.0f - 65.0f; - float secNextX = (float)screenW / 2.0f + 65.0f; + float secPrevX = layout->secNavX - 65.0f; + float secNextX = layout->secNavX + 65.0f; float secBtnRadius = 35.0f; float dx1 = mouse.x - secPrevX; float dy1 = mouse.y - layout->secNavY; @@ -67,25 +66,28 @@ void layout_editor_draw(const char *exePath, UILayout *layout) if ((dx1 * dx1 + dy1 * dy1 <= secBtnRadius * secBtnRadius) || (dx2 * dx2 + dy2 * dy2 <= secBtnRadius * secBtnRadius)) { dragIndex = 6; + dragOffsetX = mouse.x - layout->secNavX; dragOffsetY = mouse.y - layout->secNavY; } } /* 5: Smart play button (HOLD) */ { - Rectangle r = { (float)screenW / 2.0f - 100.0f, + Rectangle r = { layout->smartPlayX, layout->smartPlayY, 200.0f, 80.0f }; if (CheckCollisionPointRec(mouse, r)) { dragIndex = 5; + dragOffsetX = mouse.x - layout->smartPlayX; dragOffsetY = mouse.y - layout->smartPlayY; } } /* 4: Help */ { - Rectangle r = { 40.0f, layout->helpY, HELP_W, HELP_H }; + Rectangle r = { layout->helpX, layout->helpY, HELP_W, HELP_H }; if (CheckCollisionPointRec(mouse, r)) { dragIndex = 4; + dragOffsetX = mouse.x - layout->helpX; dragOffsetY = mouse.y - layout->helpY; } } @@ -103,10 +105,11 @@ void layout_editor_draw(const char *exePath, UILayout *layout) /* 2: Status */ { - Rectangle r = { (float)screenW / 2.0f - STATUS_W / 2.0f, + Rectangle r = { layout->statusX - STATUS_W / 2.0f, layout->statusY, STATUS_W, STATUS_H }; if (CheckCollisionPointRec(mouse, r)) { dragIndex = 2; + dragOffsetX = mouse.x - layout->statusX; dragOffsetY = mouse.y - layout->statusY; } } @@ -127,10 +130,11 @@ void layout_editor_draw(const char *exePath, UILayout *layout) /* 0: Title */ { - Rectangle r = { (float)screenW / 2.0f - TITLE_W / 2.0f, + Rectangle r = { layout->titleX - TITLE_W / 2.0f, layout->titleY, TITLE_W, TITLE_H }; if (CheckCollisionPointRec(mouse, r)) { dragIndex = 0; + dragOffsetX = mouse.x - layout->titleX; dragOffsetY = mouse.y - layout->titleY; } } @@ -140,6 +144,7 @@ void layout_editor_draw(const char *exePath, UILayout *layout) if (IsMouseButtonDown(MOUSE_BUTTON_LEFT) && dragIndex >= 0) { switch (dragIndex) { case 0: /* Title */ + layout->titleX = mouse.x - dragOffsetX; layout->titleY = mouse.y - dragOffsetY; break; case 1: /* Bar group */ @@ -147,6 +152,7 @@ void layout_editor_draw(const char *exePath, UILayout *layout) layout->barY = mouse.y - dragOffsetY; break; case 2: /* Status */ + layout->statusX = mouse.x - dragOffsetX; layout->statusY = mouse.y - dragOffsetY; break; case 3: /* Play button */ @@ -154,12 +160,15 @@ void layout_editor_draw(const char *exePath, UILayout *layout) layout->btnY = mouse.y - dragOffsetY; break; case 4: /* Help */ + layout->helpX = mouse.x - dragOffsetX; layout->helpY = mouse.y - dragOffsetY; break; case 5: /* Smart play */ + layout->smartPlayX = mouse.x - dragOffsetX; layout->smartPlayY = mouse.y - dragOffsetY; break; case 6: /* Section nav */ + layout->secNavX = mouse.x - dragOffsetX; layout->secNavY = mouse.y - dragOffsetY; break; } @@ -175,7 +184,7 @@ void layout_editor_draw(const char *exePath, UILayout *layout) /* --- 0: Title --- */ { Color f = (dragIndex == 0) ? highlightColor : fillColor; - Rectangle r = { (float)screenW / 2.0f - TITLE_W / 2.0f, + Rectangle r = { layout->titleX - TITLE_W / 2.0f, layout->titleY, TITLE_W, TITLE_H }; draw_label("Title", r, f, borderColor); } @@ -209,7 +218,7 @@ void layout_editor_draw(const char *exePath, UILayout *layout) /* --- 2: Status --- */ { Color f = (dragIndex == 2) ? highlightColor : fillColor; - Rectangle r = { (float)screenW / 2.0f - STATUS_W / 2.0f, + Rectangle r = { layout->statusX - STATUS_W / 2.0f, layout->statusY, STATUS_W, STATUS_H }; draw_label("Status", r, f, borderColor); } @@ -232,14 +241,14 @@ void layout_editor_draw(const char *exePath, UILayout *layout) /* --- 4: Help --- */ { Color f = (dragIndex == 4) ? highlightColor : fillColor; - Rectangle r = { 40.0f, layout->helpY, HELP_W, HELP_H }; + Rectangle r = { layout->helpX, layout->helpY, HELP_W, HELP_H }; draw_label("Help", r, f, borderColor); } /* --- 5: Smart play button --- */ { Color f = (dragIndex == 5) ? highlightColor : fillColor; - Rectangle r = { (float)screenW / 2.0f - 100.0f, + Rectangle r = { layout->smartPlayX, layout->smartPlayY, 200.0f, 80.0f }; draw_label("HOLD", r, f, borderColor); } @@ -248,8 +257,8 @@ void layout_editor_draw(const char *exePath, UILayout *layout) { Color f = (dragIndex == 6) ? highlightColor : fillColor; float secBtnRadius = 35.0f; - float secPrevX = (float)screenW / 2.0f - 65.0f; - float secNextX = (float)screenW / 2.0f + 65.0f; + float secPrevX = layout->secNavX - 65.0f; + float secNextX = layout->secNavX + 65.0f; float secCenterY = layout->secNavY; DrawCircle((int)secPrevX, (int)secCenterY, secBtnRadius, f); @@ -264,7 +273,7 @@ void layout_editor_draw(const char *exePath, UILayout *layout) const char *secLabel = "Sec"; int secLabelW = MeasureText(secLabel, labelFontSize); - DrawText(secLabel, (int)((float)screenW / 2.0f - secLabelW / 2.0f), + DrawText(secLabel, (int)(layout->secNavX - secLabelW / 2.0f), (int)secCenterY - labelFontSize / 2, labelFontSize, labelColor); } } @@ -246,11 +246,11 @@ static bool in_padding_zone(PlayerState *s, float pos, int portion) return (pos >= start && pos < start + padNorm); } -static void draw_text_centered(Font f, const char *text, float y, float fontSize, Color color) +static void draw_text_centered(Font f, const char *text, float centerX, float y, float fontSize, Color color) { float spacing = fontSize * 0.03f; Vector2 size = MeasureTextEx(f, text, fontSize, spacing); - float x = (SCREEN_W - size.x) / 2.0f; + float x = centerX - size.x / 2.0f; DrawTextEx(f, text, (Vector2){ x, y }, fontSize, spacing, color); } @@ -385,15 +385,9 @@ static void update_frame(void) int portion = current_speaking_portion(&state, progress) + 1; int total = total_speaking_portions(&state); if (portion > total) portion = total; - char portionBuf[32]; - snprintf(portionBuf, sizeof(portionBuf), "%d/%d", portion, total); - float portionSpacing = szSmall * 0.03f; - Vector2 portionSize = MeasureTextEx(fontSmall, portionBuf, szSmall, portionSpacing); - float portionX = (SCREEN_W - portionSize.x) / 2.0f; float secBtnRadius = 35.0f; - float secBtnGap = 30.0f; - float secPrevX = portionX - secBtnGap - secBtnRadius; - float secNextX = portionX + portionSize.x + secBtnGap + secBtnRadius; + float secPrevX = layout.secNavX - 65.0f; + float secNextX = layout.secNavX + 65.0f; float secBtnY = layout.secNavY; if (button_hit(secPrevX, secBtnY, secBtnRadius)) @@ -422,7 +416,7 @@ static void update_frame(void) /* --- Smart play hold button input --- */ { - Rectangle smartBtn = { SCREEN_W/2.0f - 100.0f, layout.smartPlayY, 200.0f, 80.0f }; + Rectangle smartBtn = { layout.smartPlayX, layout.smartPlayY, 200.0f, 80.0f }; Vector2 mouse = GetMousePosition(); bool overBtn = (mouse.x >= smartBtn.x && mouse.x <= smartBtn.x + smartBtn.width && mouse.y >= smartBtn.y && mouse.y <= smartBtn.y + smartBtn.height); @@ -608,7 +602,7 @@ static void update_frame(void) if (activeTab == 0) { if (state.loaded) { - draw_text_centered(font, state.filename, layout.titleY, szFont, mutedColor); + draw_text_centered(font, state.filename, layout.titleX, layout.titleY, szFont, mutedColor); /* Progress bar */ float currentTime = state.currentTime; @@ -645,11 +639,11 @@ static void update_frame(void) int pct = (int)(progress * 100.0f); snprintf(pctBuf, sizeof(pctBuf), "%d%%", pct); bool inSilence = (find_silence_at(&state, progress) >= 0); - draw_text_centered(fontSmall, pctBuf, layout.barY - timeFontSize - 10, timeFontSize, textColor); + draw_text_centered(fontSmall, pctBuf, layout.barX + layout.barWidth / 2.0f, layout.barY - timeFontSize - 10, timeFontSize, textColor); /* Playback status */ Color statusColor = (state.playing && inSilence) ? (Color){ 160, 40, 55, 255 } : accentColor; - draw_text_centered(font, state.playing ? "PLAYING" : "PAUSED", layout.statusY, szFont, statusColor); + draw_text_centered(font, state.playing ? "PLAYING" : "PAUSED", layout.statusX, layout.statusY, szFont, statusColor); /* Buttons */ Vector2 mousePos = GetMousePosition(); @@ -676,14 +670,13 @@ static void update_frame(void) float portionY = layout.secNavY - szSmall / 2.0f; float portionSpacing = szSmall * 0.03f; Vector2 portionSize = MeasureTextEx(fontSmall, portionBuf, szSmall, portionSpacing); - float portionX = (SCREEN_W - portionSize.x) / 2.0f; + float portionX = layout.secNavX - portionSize.x / 2.0f; DrawTextEx(fontSmall, portionBuf, (Vector2){ portionX, portionY }, szSmall, portionSpacing, mutedColor); /* Section nav buttons */ float secBtnRadius = 35.0f; - float secBtnGap = 30.0f; - float secPrevX = portionX - secBtnGap - secBtnRadius; - float secNextX = portionX + portionSize.x + secBtnGap + secBtnRadius; + float secPrevX = layout.secNavX - 65.0f; + float secNextX = layout.secNavX + 65.0f; float secBtnY_draw = layout.secNavY; float sd3 = mousePos.x - secPrevX, sd4 = mousePos.y - secBtnY_draw; @@ -701,7 +694,7 @@ static void update_frame(void) /* --- Smart play hold button rendering --- */ { - Rectangle smartBtn = { SCREEN_W/2.0f - 100.0f, layout.smartPlayY, 200.0f, 80.0f }; + Rectangle smartBtn = { layout.smartPlayX, layout.smartPlayY, 200.0f, 80.0f }; Color btnFill = smartPlayHeld ? (Color){ 80, 30, 50, 220 } : (Color){ 50, 50, 70, 180 }; Color btnBorder = smartPlayHeld ? accentColor : mutedColor; Color btnTextColor = smartPlayHeld ? accentColor : textColor; @@ -716,26 +709,25 @@ static void update_frame(void) } else { - draw_text_centered(fontLarge, "Study Player", layout.titleY, szLarge, textColor); + draw_text_centered(fontLarge, "Study Player", layout.titleX, layout.titleY, szLarge, textColor); #ifdef PLATFORM_WEB - draw_text_centered(fontMed, "Use Load MP3 button above", SCREEN_H / 2.0f - 20, szMed, mutedColor); + draw_text_centered(fontMed, "Use Load MP3 button above", (float)SCREEN_W / 2.0f, SCREEN_H / 2.0f - 20, szMed, mutedColor); #else - draw_text_centered(fontMed, "Drag an MP3 file here", SCREEN_H / 2.0f - 20, szMed, mutedColor); + draw_text_centered(fontMed, "Drag an MP3 file here", (float)SCREEN_W / 2.0f, SCREEN_H / 2.0f - 20, szMed, mutedColor); #endif } /* Help text and Study mode checkbox */ { float helpSpacing = szHelp * 0.03f; - float padding = 40.0f; DrawTextEx(fontHelp, "C: pause N: play Space(hold): override V/B: prev/next Arrows: seek 0-9: jump", - (Vector2){ padding, layout.helpY }, szHelp, helpSpacing, mutedColor); + (Vector2){ layout.helpX, layout.helpY }, szHelp, helpSpacing, mutedColor); const char *label = "Study Mode"; float cbSize = 30.0f; Vector2 labelSize = MeasureTextEx(fontHelp, label, szHelp, helpSpacing); float totalW = cbSize + 10 + labelSize.x; - float cbX = SCREEN_W - totalW - padding; + float cbX = SCREEN_W - totalW - layout.helpX; float cbY = layout.helpY + (szHelp - cbSize) / 2.0f; Rectangle cbRect = { cbX, cbY, cbSize, cbSize }; |
