Share the drawing of the wide push button between the dialogs

Transfer market, pitch, lineup, bank, offer editor, advertising, manager, player card,
player detail, club info, league pairings, other games, top scorers, stadium,
training, game end and the contract tabs drew the same button frame with their own
copies. They now call draw_wide_button_frame (ui/button_frame.hpp), which a test
compares pixel for pixel with the former drawing. Buttons whose drawing differs by a
pixel (statistics rankings, team statistics, opportunities, analytics) are left alone.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-11-08 19:04:28 +01:00
1 parent 23201fa637
commit 5b845fbab3
16 files changed
+156 -150

No files matched your search

+3
View File
@@ -157,6 +157,9 @@ bmh_add_data_test(NAME ui_environment_tests REQUIRED_OPTIONS BMH_TEST_UI_ENVIRON
add_executable(ui_achievements_tests achievements_tests.cpp)
target_link_libraries(ui_achievements_tests PRIVATE bmhui)
bmh_add_data_test(NAME ui_achievements_tests COMMAND ui_achievements_tests "${BMH_DATA}")
add_executable(ui_button_frame_tests button_frame_tests.cpp)
target_link_libraries(ui_button_frame_tests PRIVATE bmhui)
add_test(NAME ui_button_frame_tests COMMAND ui_button_frame_tests)
add_executable(ui_sprite_font_tests sprite_font_tests.cpp)
target_link_libraries(ui_sprite_font_tests PRIVATE bmhui)
bmh_add_data_test(NAME ui_sprite_font_tests COMMAND ui_sprite_font_tests "${BMH_DATA}")
+15 -6
View File
@@ -3,7 +3,10 @@
// raised - drop shadow at the right and bottom, bevel art at y=74 of the widget image;
// pressed - no shadow, the button moved two pixels down and right, bevel art at y=44.
// A button without a lasting state (Kaufen, Verkaufen, Angebot, Abbruch, ...) is shown pressed while the mouse button is
// held down; the screens keep the held button in `pressed_*` members and draw it with this helper.
// held down; the screens keep the held button in `pressed_*` members and draw it with this helper. Buttons that carry a
// lasting state (a selected competition, a toggle that is on) use the same pressed look.
//
// This is the single place of the drawing; the dialogs only choose the position, width, state and label.
#pragma once
#include <algorithm>
@@ -16,14 +19,19 @@ namespace bmh::ui {
// Draws the frame of a button of the given width (10 pixels high) with its top left corner at (x,y).
// Returns the offset (0 raised, 2 pressed) that the label must be moved by; the label colour mode of the
// pressed look is the one after the raised one in the executable (Advertising_Button_RuntimeField + 1).
inline int draw_wide_button_frame(Image& out, const Image& art, int x, int y, int width, bool pressed) {
// transparent: a palette index of the widget image that is not copied (the dialogs that draw over a picture use 0xc0), -1 none.
// background: the colour that replaces the drop shadow of a pressed button; -1 takes the pixel under the button's
// lower left corner, as the original does.
inline int draw_wide_button_frame(Image& out, const Image& art, int x, int y, int width, bool pressed,
int transparent = -1, int background = -1) {
constexpr int height = 10;
const auto put = [&](int sx, int sy, int dx, int dy, int w, int h) {
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
const int tx = dx + xx, ty = dy + yy, px = sx + xx, py = sy + yy;
if (tx < 0 || ty < 0 || tx >= out.width || ty >= out.height || px < 0 || py < 0 ||
px >= art.width || py >= art.height) continue;
out.at(tx, ty) = art.pixels[size_t(py) * size_t(art.width) + size_t(px)];
const uint8_t color = art.pixels[size_t(py) * size_t(art.width) + size_t(px)];
if (color != transparent) out.at(tx, ty) = color;
}
};
const auto fill = [&](int fx, int fy, int w, int h, uint8_t color) {
@@ -32,9 +40,10 @@ inline int draw_wide_button_frame(Image& out, const Image& art, int x, int y, in
};
if (pressed) {
// the place of the shadow shows the background again
const uint8_t background = out.at(std::min(x, out.width - 1), std::min(y + height, out.height - 1));
fill(x, y, width + 1, 2, background);
fill(x, y, 2, height + 1, background);
const uint8_t shade = background >= 0 ? uint8_t(background)
: out.at(std::clamp(x, 0, out.width - 1), std::clamp(y + height, 0, out.height - 1));
fill(x, y, width + 1, 2, shade);
fill(x, y, 2, height + 1, shade);
x += 2;
y += 2;
} else {
+67
View File
@@ -0,0 +1,67 @@
// SPDX-License-Identifier: GPL-3.0-only
// button_frame.hpp: the shared wide push button must produce exactly the pixels of the drawing that every dialog used
// before it was shared (the reference below is that drawing, written out once). Needs no game data: the art is synthetic.
#include <algorithm>
#include <cstdio>
#include "ui/button_frame.hpp"
using namespace bmh;
namespace {
int failures = 0;
// The drawing as the dialogs had it: shadow or erased frame, left part, repeated 8 pixel strips, right end.
int reference(Image& out, const Image& art, int x, int y, int width, bool pressed, int key, int bg) {
const auto copy = [&](int sx, int sy, int dx, int dy, int w, int h) {
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
const uint8_t c = art.pixels[size_t(sy + yy) * art.width + size_t(sx + xx)];
if (c != key && dx + xx >= 0 && dx + xx < out.width && dy + yy >= 0 && dy + yy < out.height)
out.at(dx + xx, dy + yy) = c;
}
};
const auto rect = [&](int rx, int ry, int w, int h, uint8_t c) {
for (int yy = std::max(0, ry); yy < std::min(out.height, ry + h); ++yy)
for (int xx = std::max(0, rx); xx < std::min(out.width, rx + w); ++xx) out.at(xx, yy) = c;
};
if (pressed) {
const uint8_t c = bg >= 0 ? uint8_t(bg) : out.at(x, y + 10);
rect(x, y, width + 1, 2, c); rect(x, y, 2, 11, c); x += 2; y += 2;
} else { rect(x + 2, y + 10, width, 2, 0x40); rect(x + width, y + 2, 2, 10, 0x40); }
const int sy = pressed ? 44 : 74;
copy(24, sy, x, y, 31, 10);
int at = 31, left = width - 31;
while (left > 20) { const int n = std::min(8, left - 20); copy(24, sy + 10, x + at, y, n, 10); at += n; left -= n; }
copy(45 - left, sy + 20, x + at, y, left, 10);
return pressed ? 2 : 0;
}
} // namespace
int main() {
Image art(80, 110);
for (size_t i = 0; i < art.pixels.size(); ++i) art.pixels[i] = uint8_t((i * 37 + i / 7) % 251);
art.at(30, 80) = 0xc0; art.at(31, 80) = 0xc0; // transparent samples inside the used slices
art.at(30, 50) = 0xc0;
for (const int width : {32, 51, 56, 60, 64, 70, 75, 80, 94, 125})
for (const bool pressed : {false, true})
for (const int key : {-1, 0xc0})
for (const int bg : {-1, 0x42}) {
Image a(320, 240), b(320, 240);
for (size_t i = 0; i < a.pixels.size(); ++i) a.pixels[i] = b.pixels[i] = uint8_t(i % 97 + 3);
const int shift_a = ui::draw_wide_button_frame(a, art, 61, 166, width, pressed, key, bg);
const int shift_b = reference(b, art, 61, 166, width, pressed, key, bg);
if (shift_a != shift_b || a.pixels != b.pixels) {
std::fprintf(stderr, "FAIL: width %d pressed %d key %d background %d\n", width, int(pressed), key, bg);
++failures;
}
}
// a button at the very edge of the picture is clipped, not an error
Image edge(320, 240);
ui::draw_wide_button_frame(edge, art, 300, 232, 75, true);
ui::draw_wide_button_frame(edge, art, -10, -3, 75, false);
if (failures) return 1;
std::puts("PASS shared wide button frame");
return 0;
}
+3 -7
View File
@@ -4,6 +4,7 @@
// views and converts button and row clicks into ClubInfoRequest values. It does not change the game itself.
#include "formats/executable_layout.hpp"
#include "ui/club_info.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <array>
@@ -317,13 +318,8 @@ Image ClubInfoScreen::render() const {
const bool active = (x == 1 && pressed_button_ == (projection_.has_squad ? ClubInfoButton::view : ClubInfoButton::category)) ||
(x == 60 && pressed_button_ == ClubInfoButton::statistics) ||
(x == 120 && pressed_button_ == ClubInfoButton::category);
if (active) { const uint8_t base = out.at(x, 225); rect(out, x, 215, width + 1, 2, base); rect(out, x, 215, 2, height + 1, base); x += 2; }
else { rect(out, x + 2, 225, width, 2, 0x40); rect(out, x + width, 217, 2, height, 0x40); }
const int sy = active ? 44 : 74;
copy(out, widgets_, 24, sy, x, 215 + (active ? 2 : 0), 31, 10);
int at = 31, remain = width - 31;
while (remain > 20) { const int n = std::min(8, remain - 20); copy(out, widgets_, 24, sy + 10, x + at, 215 + (active ? 2 : 0), n, 10); at += n; remain -= n; }
copy(out, widgets_, 45 - remain, sy + 20, x + at, 215 + (active ? 2 : 0), remain, 10);
(void)height;
x += draw_wide_button_frame(out, widgets_, x, 215, width, active); // button_frame.hpp
if (!label.empty()) {
const int mode = exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(active));
const int label_baseline = active ? 224 : 222;
+7 -8
View File
@@ -5,6 +5,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/club_player_detail.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <cmath>
@@ -139,14 +140,12 @@ void ClubPlayerDetailScreen::frame(Image& out,int x,int y,int w,int h) const {
}
void ClubPlayerDetailScreen::button(Image& out,int x,int y,int width,std::string_view value,bool active) const {
const int height=width>31?10:9;
if(active){const auto base=out.at(x,y+height);rect(out,x,y,width+1,2,base);rect(out,x,y,2,height+1,base);x+=2;y+=2;}
else {rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
if(width>31){
const int sy=active?44:74;
copy(out,widgets_,24,sy,x,y,31,10);int at=31,remaining=width-31;
while(remaining>20){const int n=std::min(8,remaining-20);copy(out,widgets_,24,sy+10,x+at,y,n,10);at+=n;remaining-=n;}
copy(out,widgets_,45-remaining,sy+20,x+at,y,remaining,10);
}else frame(out,x,y,width,height);
if(width>31){const int shift=draw_wide_button_frame(out,widgets_,x,y,width,active);x+=shift;y+=shift;} // button_frame.hpp
else{
if(active){const auto base=out.at(x,y+height);rect(out,x,y,width+1,2,base);rect(out,x,y,2,height+1,base);x+=2;y+=2;}
else {rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
frame(out,x,y,width,height);
}
const int font=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(active));
if(font==3){text(out,x,y+height/2+2,value,0,x+width);return;}
int length=0;for(unsigned char c:value){const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);length+=g?exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField2+g*2)-exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField+g*2):2;}
+3 -9
View File
@@ -453,15 +453,9 @@ Image ContractsScreen::render() const {
const std::array<std::string,4> tabs{original_to_utf8(texts_[117]),original_to_utf8(texts_[118]),original_to_utf8(texts_[119]),original_to_utf8(texts_[120])};
for (int i = 0; i < (state_.mode_three?4:3); ++i) {
const int x = i * 60 + 2, w = i == 3 ? 71 : 51;
if(i!=tab_) {fill(out,x+2,225,w,2,0x40);fill(out,x+w,217,2,10,0x40);}
else {const uint8_t color=out.at(x,225);fill(out,x,215,w+1,2,color);fill(out,x,215,2,11,color);}
const int source_y = i == tab_ ? 44 : 74;
const int dest_y = 215 + (i == tab_ ? 2 : 0);
const int dest_x = x + (i == tab_ ? 2 : 0);
copy_region(out, widgets_, 24, source_y, dest_x, dest_y, 31, 10);
int tab_at = 31, remain = w - 31;
while (remain > 20) { const int n = std::min(8, remain - 20); copy_region(out, widgets_, 24, source_y + 10, dest_x + tab_at, dest_y, n, 10); tab_at += n; remain -= n; }
if (remain > 0) copy_region(out, widgets_, 45 - remain, source_y + 20, dest_x + tab_at, dest_y, remain, 10);
const int shift = draw_wide_button_frame(out, widgets_, x, 215, w, i == tab_); // button_frame.hpp
const int dest_y = 215 + shift;
const int dest_x = x + shift;
sprite_font_.draw(out, dest_x + w/2 - sprite_font_.text_width(tabs[size_t(i)])/2, dest_y+7, tabs[size_t(i)], exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + (i==tab_)));
}
+2 -6
View File
@@ -5,6 +5,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/game_end.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <cctype>
@@ -176,12 +177,7 @@ std::string source_number(int32_t value, unsigned minimum_digits) {
}
void button(Image& o,const Image& a,const SpriteFont& sf,const LeImage& exe,int x,int y,int w,
std::string_view label,bool selected=false){
if(selected){const auto under=o.at(x,y+10);fill(o,x,y,w+1,2,under);fill(o,x,y,2,11,under);x+=2;y+=2;}
else {fill(o,x+2,y+10,w,2,0x40);fill(o,x+w,y+2,2,10,0x40);}
const int sy=selected?44:74;
copy(o,a,24,sy,x,y,31,10);int used=31;
while(w-used>20){int n=std::min(8,w-used-20);copy(o,a,24,sy+10,x+used,y,n,10);used+=n;}
copy(o,a,45-(w-used),sy+20,x+used,y,w-used,10);
const int shift=draw_wide_button_frame(o,a,x,y,w,selected);x+=shift;y+=shift;
sf.draw(o,x+w/2-sf.text_width(label)/2,y+7,label,exe.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
}
std::string_view text_at(const TextDb& texts,uint32_t address) {
+3 -9
View File
@@ -4,6 +4,7 @@
// session. It also defines the constants and time conversion helper declared in the header.
#include "formats/executable_layout.hpp"
#include "ui/league_pairings.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <cstdio>
@@ -250,15 +251,8 @@ Image LeaguePairingsScreen::render() const {
for(int n=0;n<8;++n) {
const int x=1+(n/4)*74,y=176+(n%4)*13;
const bool selected=pressed_button_==n||(state_.source.preferences&(1u<<n));
int dx=x,dy=y;
if(selected) {
const uint8_t background=out.at(x,y+10);fill(out,x,y,71,2,background);fill(out,x,y,2,11,background);
dx+=2;dy+=2;
} else {fill(out,x+2,y+10,70,2,0x40);fill(out,x+70,y+2,2,10,0x40);}
const int sy=selected?44:74;copy(out,widgets_,24,sy,dx,dy,31,10);
int used=31;while(70-used>20) {const int amount=std::min(8,70-used-20);
copy(out,widgets_,24,sy+10,dx+used,dy,amount,10);used+=amount;}
const int left=70-used;copy(out,widgets_,45-left,sy+20,dx+used,dy,left,10);
const int shift=draw_wide_button_frame(out,widgets_,x,y,70,selected); // button_frame.hpp
const int dx=x+shift,dy=y+shift;
const auto label=original_to_utf8(state_.buttons[size_t(n)]);
sprite_.draw(out,dx+35-sprite_.text_width(label)/2,dy+7,label,exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + uint32_t(selected)));
}
+3 -14
View File
@@ -5,6 +5,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/manager.hpp"
#include "ui/button_frame.hpp"
#include "formats/league_visibility.hpp"
#include <algorithm>
@@ -341,20 +342,8 @@ void ManagerScreen::sprite_text(Image& out, int x, int y, std::string_view value
}
}
void ManagerScreen::button(Image& out, int x, int y, int w, std::string_view label, bool selected) const {
if (selected) {
const auto c = out.at(x, y + 10);
rect(out, x, y, w + 1, 2, c); rect(out, x, y, 2, 11, c); x += 2; y += 2;
} else {
rect(out, x + 2, y + 10, w, 2, 0x40); rect(out, x + w, y + 2, 2, 10, 0x40);
}
int sy = selected ? 44 : 74;
copy(out, widgets_, 24, sy, x, y, 31, 10);
int k = 31;
for (; w - k > 20;) {
int n = std::min(8, w - k - 20);
copy(out, widgets_, 24, sy + 10, x + k, y, n, 10); k += n;
}
copy(out, widgets_, 45 - (w - k), sy + 20, x + k, y, w - k, 10);
const int shift = draw_wide_button_frame(out, widgets_, x, y, w, selected);
x += shift; y += shift;
int font = exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected));
sprite_text(out, x + w / 2 - sprite_text_width(label) / 2, y + 7, label, font);
}
+3 -19
View File
@@ -4,6 +4,7 @@
// only requested through pending() and takes effect when the session returns a new state.
#include "formats/executable_layout.hpp"
#include "ui/other_games.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <cstdlib>
@@ -192,25 +193,8 @@ void OtherGamesScreen::draw_button(Image& out, int x, int y, int width,
const bool down = pressed || selected;
// FormatError3 shifts both a selected competition and a held button by (+2,+2).
// Keep this Original inset; selection is not an unshifted alternate skin.
const int dx = x + (down ? 2 : 0), dy = y + (down ? 2 : 0);
if (down) {
const uint8_t background = out.at(x, y + 10);
fill(out, x, y, width + 1, 2, background);
fill(out, x, y, 2, 11, background);
} else {
fill(out, x + 2, y + 10, width, 2, 0x40);
fill(out, x + width, y + 2, 2, 10, 0x40);
}
const int sy = down ? 44 : 74;
copy(out, widgets_, 24, sy, dx, dy, 31, 10, 0xc0);
int used = 31;
while (width - used > 20) {
const int count = std::min(8, width - used - 20);
copy(out, widgets_, 24, sy + 10, dx + used, dy, count, 10, 0xc0);
used += count;
}
const int tail = width - used;
copy(out, widgets_, 45 - tail, sy + 20, dx + used, dy, tail, 10, 0xc0);
const int shift = draw_wide_button_frame(out, widgets_, x, y, width, down, 0xc0);
const int dx = x + shift, dy = y + shift;
const auto label = original_to_utf8(std::string(raw_label));
sprite_.draw(out, dx + width / 2 - sprite_.text_width(label) / 2, dy + 7, label,
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + (down ? 1u : 0u)));
+10 -12
View File
@@ -4,6 +4,7 @@
// authoritative positions; changes only appear after the session acknowledges a new lineup and extras.
#include "formats/executable_layout.hpp"
#include "ui/pitch.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <cstdlib>
@@ -243,11 +244,11 @@ void PitchScreen::text(Image& out,int x,int baseline,std::string_view value,uint
}
void PitchScreen::button(Image& out,int x,int y,std::string_view value,bool selected)const{
constexpr int width=43,height=10;
if(selected){ // FormatError3 erases the upper/left frame, then offsets its pressed atlas by two pixels.
rect(out,x,y,width+1,2,0x42);rect(out,x,y,2,height+1,0x42);x+=2;y+=2;
}else{rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
const int sy=selected?44:74,font=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected));
copy(out,widgets_,24,sy,x,y,31,10);copy(out,widgets_,33,sy+20,x+31,y,12,10);
// FormatError3 erases the upper/left frame (colour 0x42 here), then offsets its pressed atlas by two pixels
// (button_frame.hpp).
const int shift=draw_wide_button_frame(out,widgets_,x,y,width,selected,-1,0x42);x+=shift;y+=shift;
(void)height;
const int font=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected));
if(font==3)text(out,x+width/2-font_.text_width(value)/2,y+7,value,0);
else {int length=0;for(unsigned char c:value){const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);length+=g?exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField2+g*2)-exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField+g*2):2;}
int xx=x+width/2-length/2;for(unsigned char c:value){if(c<=31||c>=128)continue;const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);
@@ -258,13 +259,10 @@ void PitchScreen::diamond_button(Image& out,int x,int y,std::string_view value,b
// FormatError3: width60, height9 normalized to 10, with pressed frame and
// runtime font byte Advertising_Button_RuntimeField+selected. Match the original +2 pressed offset.
constexpr int width=60,height=10;
int dx=x,dy=y;const int mode=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + unsigned(selected));
if(selected){const uint8_t bg=out.at(x,y+height);rect(out,x,y,width+1,2,bg);rect(out,x,y,2,height+1,bg);dx+=2;dy+=2;}
else{rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
const int row=selected?44:74;copy(out,widgets_,24,row,dx,dy,31,10,0xc0);
int used=31;while(width-used>20){const int amount=std::min(8,width-used-20);
copy(out,widgets_,24,row+10,dx+used,dy,amount,10,0xc0);used+=amount;}
const int tail=width-used;copy(out,widgets_,45-tail,row+20,dx+used,dy,tail,10,0xc0);
const int mode=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + unsigned(selected));
const int shift=draw_wide_button_frame(out,widgets_,x,y,width,selected,0xc0); // button_frame.hpp
const int dx=x+shift,dy=y+shift;
(void)height;
if(mode==3){const auto native_value=utf8_to_original(value);
text(out,dx+width/2-font_.text_width(native_value)/2,dy+7,native_value,0);}
else sprite_.draw(out,dx+width/2-sprite_.text_width(value)/2,dy+7,value,mode);
+7 -8
View File
@@ -5,6 +5,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/player_card.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <cmath>
@@ -225,14 +226,12 @@ void PlayerCardScreen::frame(Image& out,int x,int y,int w,int h) const {
}
void PlayerCardScreen::button(Image& out,int x,int y,int width,std::string_view value,bool active) const {
const int height=width>31?10:9;
if(active){const auto base=out.at(x,y+height);rect(out,x,y,width+1,2,base);rect(out,x,y,2,height+1,base);x+=2;y+=2;}
else {rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
if(width>31){
const int sy=active?44:74;
copy(out,widgets_,24,sy,x,y,31,10);int at=31,remaining=width-31;
while(remaining>20){const int n=std::min(8,remaining-20);copy(out,widgets_,24,sy+10,x+at,y,n,10);at+=n;remaining-=n;}
copy(out,widgets_,45-remaining,sy+20,x+at,y,remaining,10);
}else frame(out,x,y,width,height);
if(width>31){const int shift=draw_wide_button_frame(out,widgets_,x,y,width,active);x+=shift;y+=shift;} // button_frame.hpp
else{
if(active){const auto base=out.at(x,y+height);rect(out,x,y,width+1,2,base);rect(out,x,y,2,height+1,base);x+=2;y+=2;}
else {rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
frame(out,x,y,width,height);
}
const int font=exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(active));
if(font==3){text(out,x,y+height/2+2,value,0,x+width);return;}
int length=0;for(unsigned char c:value){const int g=exe_.u8(::bmh::layout::ClubInfo_Raw_RuntimeField3 + c);length+=g?exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField2+g*2)-exe_.u16(::bmh::layout::ClubInfo_Raw_RuntimeField+g*2):2;}
+13 -16
View File
@@ -4,6 +4,7 @@
// construction. Source-tick timing for the calculator is advanced by the caller.
#include "formats/executable_layout.hpp"
#include "ui/stadium.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <bit>
@@ -714,26 +715,22 @@ void StadiumScreen::original_button(Image& out, int x, int y, int w, int h,
// wide buttons requested with height 9 are drawn 10 px high
const int visible_h = w > 31 && h == 9 ? 10 : h;
if (visible_h != 10 && !(w <= 31 && visible_h == 9)) throw FormatError("stadium: unsupported Original button height");
if (selected) {
const auto under = out.at(x, y + visible_h);
fill(out, x, y, w <= 31 ? w + 1 : w, 2, under); fill(out, x, y, 2, visible_h + 1, under); x += 2; y += 2;
} else { fill(out, x + 2, y + visible_h, w, 2, 0x40); fill(out, x + w, y + 2, 2, visible_h, 0x40); }
if (w <= 31) {
source_frame(out, widgets_, exe_, x, y, w, visible_h, false);
if (w > 31) {
// wide buttons: the shared frame (button_frame.hpp)
const int shift = draw_wide_button_frame(out, widgets_, x, y, w, selected);
x += shift; y += shift;
sprite_font_.draw(out, x + w / 2 - sprite_font_.text_width(original_to_utf8(label)) / 2,
y + visible_h / 2 + 2, original_to_utf8(label), exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
y + 7, original_to_utf8(label), exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
return;
}
const int sy = selected ? 44 : 74;
copy_crop(out, widgets_, 24, sy, x, y, 31, 10);
int used = 31;
while (w - used > 20) {
const int n = std::min(8, w - used - 20);
copy_crop(out, widgets_, 24, sy + 10, x + used, y, n, 10); used += n;
}
copy_crop(out, widgets_, 45 - (w - used), sy + 20, x + used, y, w - used, 10);
if (selected) {
const auto under = out.at(x, y + visible_h);
fill(out, x, y, w + 1, 2, under); fill(out, x, y, 2, visible_h + 1, under); x += 2; y += 2;
} else { fill(out, x + 2, y + visible_h, w, 2, 0x40); fill(out, x + w, y + 2, 2, visible_h, 0x40); }
// narrow buttons (w <= 31): the four-pixel frame around a pattern
source_frame(out, widgets_, exe_, x, y, w, visible_h, false);
sprite_font_.draw(out, x + w / 2 - sprite_font_.text_width(original_to_utf8(label)) / 2,
y + 7, original_to_utf8(label), exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
y + visible_h / 2 + 2, original_to_utf8(label), exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + int(selected)));
}
// Creates a request stamped with the identity of the current state (manager, club, scope, sequence and revision).
+3 -19
View File
@@ -2,6 +2,7 @@
// Implementation of TopScorersScreen (top_scorers.hpp): list and podium drawing, footer button handling including drag-off cancel, and request construction.
#include "formats/executable_layout.hpp"
#include "ui/top_scorers.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <sstream>
@@ -109,25 +110,8 @@ void TopScorersScreen::draw_text(Image& out, int x, int baseline, std::string_vi
void TopScorersScreen::draw_button(Image& out, int x, int y, int width,
std::string_view original_label, bool pressed) const {
const int dx = x + (pressed ? 2 : 0), dy = y + (pressed ? 2 : 0);
if (pressed) {
const auto background = out.at(x, y + 10);
fill(out, x, y, width + 1, 2, background);
fill(out, x, y, 2, 11, background);
} else {
fill(out, x + 2, y + 10, width, 2, 0x40);
fill(out, x + width, y + 2, 2, 10, 0x40);
}
const int source_y = pressed ? 44 : 74;
copy(out, button_art_, 24, source_y, dx, dy, 31, 10);
int used = 31;
while (width - used > 20) {
const int count = std::min(8, width - used - 20);
copy(out, button_art_, 24, source_y + 10, dx + used, dy, count, 10);
used += count;
}
const int tail = width - used;
copy(out, button_art_, 45 - tail, source_y + 20, dx + used, dy, tail, 10);
const int shift = draw_wide_button_frame(out, button_art_, x, y, width, pressed);
const int dx = x + shift, dy = y + shift;
const auto label = original_to_utf8(std::string(original_label));
sprite_.draw(out, dx + width / 2 - sprite_.text_width(label) / 2, dy + 7, label,
exe_.u8(::bmh::layout::Advertising_Button_RuntimeField + uint32_t(pressed)));
+10 -12
View File
@@ -2,6 +2,7 @@
// Implementation of TrainingScreen and the training projections (training.hpp): initialization state, skill bars under the pointer, request construction and JSON output.
#include "formats/executable_layout.hpp"
#include "ui/training.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <numeric>
@@ -189,19 +190,16 @@ void TrainingScreen::sprite_text(Image& out, int x, int baseline, std::string_vi
}
}
void TrainingScreen::button(Image& out, int x, int y, int width, int height, std::string_view label, bool active) const {
if (!active) {
rect(out, x + 2, y + height, width, 2, 0x40); rect(out, x + width, y + 2, 2, height, 0x40);
} else {
const uint8_t base = out.pixels.at(size_t(y + height) * out.width + x);
rect(out, x, y, width + 1, 2, base); rect(out, x, y, 2, height + 1, base); x += 2; y += 2;
}
if (height < 11 && width > 31) {
const int shift = active ? -30 : 0;
copy(out, widgets_, 24, 74 + shift, x, y, 31, 10);
int cursor = 31, left = width - 31;
while (left > 20) { const int n = std::min(8, left - 20); copy(out, widgets_, 24, 84 + shift, x + cursor, y, n, 10); cursor += n; left -= n; }
copy(out, widgets_, 45 - left, 94 + shift, x + cursor, y, left, 10);
if (height == 10 && width > 31) {
const int shift = draw_wide_button_frame(out, widgets_, x, y, width, active); // button_frame.hpp
x += shift; y += shift;
} else {
if (!active) {
rect(out, x + 2, y + height, width, 2, 0x40); rect(out, x + width, y + 2, 2, height, 0x40);
} else {
const uint8_t base = out.pixels.at(size_t(y + height) * out.width + x);
rect(out, x, y, width + 1, 2, base); rect(out, x, y, 2, height + 1, base); x += 2; y += 2;
}
// PatternStartsAt(0,0x12): original four-pixel frame and patterned interior.
for (int yy = 4; yy < height - 3; ++yy) for (int xx = 4; xx < width - 3; ++xx)
out.at(x + xx, y + yy) = exe_.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + ((yy - 4) % 16) * 16 + (xx - 4) % 16);
+4 -5
View File
@@ -3,6 +3,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/transfer_market.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
#include <charconv>
@@ -447,13 +448,11 @@ void TransferMarketScreen::original_text(Image& out,int x,int baseline,std::stri
// Active buttons look pressed (the frame is drawn on the other side).
void TransferMarketScreen::button(Image& out,int x,int y,int width,std::string_view label,bool active) const {
const int height=width>31?10:9;
if(active){const uint8_t c=out.at(x,y+height);rect(out,x,y,width+1,2,c);rect(out,x,y,2,height+1,c);x+=2;y+=2;}
else{rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
if(width>31) {
const int sy=active?44:74;copy(out,widgets_,24,sy,x,y,31,10);int at=31,left=width-31;
while(left>20){const int n=std::min(8,left-20);copy(out,widgets_,24,sy+10,x+at,y,n,10);at+=n;left-=n;}
copy(out,widgets_,45-left,sy+20,x+at,y,left,10);
const int shift=draw_wide_button_frame(out,widgets_,x,y,width,active);x+=shift;y+=shift; // button_frame.hpp
} else {
if(active){const uint8_t c=out.at(x,y+height);rect(out,x,y,width+1,2,c);rect(out,x,y,2,height+1,c);x+=2;y+=2;}
else{rect(out,x+2,y+height,width,2,0x40);rect(out,x+width,y+2,2,height,0x40);}
for(int yy=4;yy<height-3;++yy)for(int xx=4;xx<width-3;++xx)
out.at(x+xx,y+yy)=exe_.u8(::bmh::layout::Advertising_PatternRect_RuntimeField+(yy-4)%16*16+(xx-4)%16);
copy(out,widgets_,0,0,x,y,4,4);copy(out,widgets_,4,0,x+width-4,y,4,4);