Share the calculator window and the dialog frame between the dialogs

The calculator panel and its keys (bank, offer editor, advertising, contracts, stadium,
balance plan, alternate game end) and the window frame (ten dialogs) are drawn by
ui/calculator_widgets.hpp and ui/dialog_frame.hpp; a test compares them with the former
drawings. The calculator keys of bank, offer editor, advertising and contracts now show
the pressed look while the mouse button is held.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Sonnet 5.5 committed 2026-11-08 19:17:55 +01:00
1 parent 5b845fbab3
commit cafd6c1573
21 files changed
+245 -159

No files matched your search

+15 -22
View File
@@ -6,7 +6,9 @@
#include "formats/executable_layout.hpp"
#include "game/environment.hpp"
#include "ui/advertising.hpp"
#include "ui/dialog_frame.hpp"
#include "ui/button_frame.hpp"
#include "ui/calculator_widgets.hpp"
#include "ui/game_end.hpp"
#include <algorithm>
@@ -801,8 +803,15 @@ bool AdvertisingScreen::press(int x, int y) {
if (x >= 89 && x <= 154) id = 0;
else if (x >= 164 && x <= 229 && offer_acceptable()) id = 1;
}
const bool changed = id != pressed_button_;
// a key of the open spending calculator
int key = -1;
if (spending_calculator_open_ && !notification_open() && !pending_ && !close_requested_)
for (int i = 0; i < 15; ++i)
if (calculator_key_hit(x, y, 103 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2),
55 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i)))) key = i;
const bool changed = id != pressed_button_ || key != pressed_key_;
pressed_button_ = id;
pressed_key_ = key;
return changed;
}
@@ -813,30 +822,13 @@ void AdvertisingScreen::pattern_rect(Image& out, int x, int y, int width, int he
}
void AdvertisingScreen::source_frame(Image& out, int x, int y, int width, int height, bool shadow) const {
if (shadow) { fill_rect(out, x + 2, y + height, width, 2, 0x40); fill_rect(out, x + width, y + 2, 2, height, 0x40); }
pattern_rect(out, x + 4, y + 4, width - 7, height - 7);
copy(out, widgets_, 0, 0, x, y, 4, 4);
copy(out, widgets_, 4, 0, x + width - 4, y, 4, 4);
copy(out, widgets_, 0, 4, x, y + height - 4, 4, 4);
copy(out, widgets_, 4, 4, x + width - 4, y + height - 4, 4, 4);
for (int at = 4; at < width - 4; at += 74) {
const int n = std::min(74, width - 4 - at);
copy(out, widgets_, 0, 104, x + at, y, n, 4);
copy(out, widgets_, 0, 108, x + at, y + height - 4, n, 4);
}
for (int at = 4; at < height - 4; at += 96) {
const int n = std::min(96, height - 4 - at);
copy(out, widgets_, 0, 8, x, y + at, 4, n);
copy(out, widgets_, 4, 8, x + width - 4, y + at, 4, n);
}
draw_dialog_frame(out, widgets_, exe_, x, y, width, height, shadow); // dialog_frame.hpp
}
void AdvertisingScreen::draw_spending_calculator(Image& out) const {
constexpr int x0 = 103, y0 = 55;
if (calculator_.width < 113 || calculator_.height < 150) return;
copy(out, calculator_, 0, 0, x0, y0, 113, 136);
fill_rect(out, x0 + 113, y0 + 2, 2, 136, 0x40);
fill_rect(out, x0 + 2, y0 + 136, 113, 2, 0x40);
draw_calculator_panel(out, calculator_, x0, y0); // calculator_widgets.hpp
const std::string& title = selected_spending_slot_ == 16 ? state_.merchandise_calculator_title :
state_.budget_calculator_title;
const std::string bytes = utf8_to_original(title);
@@ -846,9 +838,9 @@ void AdvertisingScreen::draw_spending_calculator(Image& out) const {
for (int i = 0; i < 15; ++i) {
const int x = x0 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2);
const int y = y0 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i));
copy(out, calculator_, 0, 136, x, y, 15, 14);
const int p = draw_calculator_key(out, calculator_, x, y, pressed_key_ == i);
// Render calls the raw font renderer for key legends.
text(out, x + 5, y + 9, keys.substr(size_t(i), 1), 98, 15, false);
text(out, x + 5 + p, y + 9 + p, keys.substr(size_t(i), 1), 98, 15, false);
}
for (int i = 0; i < 8; ++i) {
const int x = x0 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i + 15) * 2);
@@ -1064,6 +1056,7 @@ bool AdvertisingScreen::move(int x, int y) {
bool AdvertisingScreen::click(int x, int y) {
pressed_button_ = -1; // the release ends the pressed look
pressed_key_ = -1;
pointer_position_ = std::array<int, 2>{x, y};
if (close_requested_ || pending_ || x < 0 || y < 0 || x >= 320 || y >= 240) return false;
if (notification_open()) return dismiss_notification();
+1
View File
@@ -178,6 +178,7 @@ private:
void pattern_rect(Image&, int x, int y, int width, int height) const;
void source_frame(Image&, int x, int y, int width, int height, bool shadow = true) const;
void button(Image&, int x, int y, int width, std::string_view label, bool pressed = false) const;
int pressed_key_ = -1; // spending calculator key held down by the mouse
int pressed_button_ = -1; // offer button held down by the mouse (0 cancel, 1 accept)
};
+3 -3
View File
@@ -5,6 +5,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/balance_plan.hpp"
#include "ui/calculator_widgets.hpp"
#include <algorithm>
#include <charconv>
@@ -100,12 +101,11 @@ void BalanceScreen::draw_buttons(Image& o)const{
button(170,63,at(texts_,::bmh::layout::BalancePlan_DrawButtons_TextPointer+uint32_t(state_.draft.view)*4),0);button(245,63,at(texts_,::bmh::layout::BalancePlan_DrawButtons_TextPointer2),1);
}
void BalanceScreen::draw_calculator(Image& o)const{
if(!calculator_open_)return;const int cx=state_.calculator_x,cy=state_.calculator_y;copy(o,calculator_art_,0,0,cx,cy,113,136);
fill(o,cx+113,cy+2,2,136,0x40);fill(o,cx+2,cy+136,113,2,0x40);
if(!calculator_open_)return;const int cx=state_.calculator_x,cy=state_.calculator_y;draw_calculator_panel(o,calculator_art_,cx,cy); // calculator_widgets.hpp
auto draw=[&](int x,int baseline,std::string_view raw,uint8_t color,bool gradient=true){const int w=body_.text_width(raw),top=baseline-body_.baseline;if(x<0||top<0||x+w>o.width||top+body_.height>o.height)return;if(!gradient||!state_.gradient){body_.draw(o,x,top,raw,color);return;}Image mask(std::max(1,w),body_.height);body_.draw(mask,0,0,raw,1);int idx=0;while(idx<32&&exe_.u8(::bmh::layout::Advertising_Text_RuntimeField2+uint32_t(idx))!=color)++idx;for(int yy=0;yy<body_.height;++yy)for(int xx=0;xx<w;++xx)if(mask.at(xx,yy))o.at(x+xx,top+yy)=idx<32?exe_.u8(::bmh::layout::Advertising_Text_RuntimeField+uint32_t(idx*6+yy)):color;};
std::string title(at(texts_,active_profile_.source_text_address));draw(cx+8+(105-8)/2-body_.text_width(title)/2,cy+14,title,0x62);
const bool flash=current_milliseconds_<calculator_flash_until_;
for(int i=0;i<15;++i){int x=cx+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+uint32_t(i)*2),y=cy+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+uint32_t(i));const bool down=pressed_calculator_control_==i||(flash&&flash_calculator_control_==i);copy(o,calculator_art_,down?15:0,136,x+(down?1:0),y+(down?1:0),down?14:15,down?13:14);draw(x+(down?6:5),y+(down?10:9),kKeys.substr(size_t(i),1),0x62,false);}
for(int i=0;i<15;++i){int x=cx+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+uint32_t(i)*2),y=cy+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+uint32_t(i));const bool down=pressed_calculator_control_==i||(flash&&flash_calculator_control_==i);draw_calculator_key(o,calculator_art_,x,y,down);draw(x+(down?6:5),y+(down?10:9),kKeys.substr(size_t(i),1),0x62,false);}
for(size_t i=0;i<8;++i)if(active_profile_.presets[i]){int x=cx+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+uint32_t(i+15)*2),y=cy+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+uint32_t(i+15));auto t=calc7(*active_profile_.presets[i]);draw(x+47-body_.text_width(t),y+12,t,0x62);}
auto value=calculator_value_edited_?calc8(calculator_value_):calc7(calculator_value_);const int value_x=cx+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+23*2),value_y=cy+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+23);draw(value_x+47-body_.text_width(value),value_y+12,value,0x00);
}
+14 -6
View File
@@ -6,6 +6,7 @@
#include "formats/executable_layout.hpp"
#include "ui/bank.hpp"
#include "ui/button_frame.hpp"
#include "ui/calculator_widgets.hpp"
#include "ui/game_end.hpp"
#include <algorithm>
@@ -586,9 +587,7 @@ BankRequest BankScreen::finish_credit() {
void BankScreen::draw_calculator(Image& out) const {
// BalanceFromGame uses the 113x136 source crop from KB6 at the caller's
// a449d/a449f origin, then draws the source text and 23 calculator cells.
copy_region(out, calculator_art_, 0, 0, 103, 55, 113, 136);
rect(out, 105, 191, 113, 2, 0x40);
rect(out, 216, 57, 2, 136, 0x40);
draw_calculator_panel(out, calculator_art_, 103, 55); // calculator_widgets.hpp
std::string title = texts_.strings.size() > 838 ? texts_[838] : std::string{};
title += state_.account_text.empty() ? money(state_.balance) : state_.account_text;
const int title_width = font_.text_width(title);
@@ -597,8 +596,8 @@ void BankScreen::draw_calculator(Image& out) const {
for (int i = 0; i < 15; ++i) {
const int x = 103 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2);
const int y = 55 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i));
copy_region(out, calculator_art_, 0, 136, x, y, 15, 14);
body_baseline_raw(out, x + 5, y + 9, std::string(1, "0123456789DRCJN"[i]), 0x62, false);
const int p = draw_calculator_key(out, calculator_art_, x, y, pressed_key_ == i);
body_baseline_raw(out, x + 5 + p, y + 9 + p, std::string(1, "0123456789DRCJN"[i]), 0x62, false);
}
for (int i = 0; i < 8; ++i) {
if (calculator_presets_[size_t(i)] == UINT32_MAX) continue;
@@ -1003,6 +1002,14 @@ bool BankScreen::press(int x, int y) {
dialog = int(source_dialog_button_at(question ? TaxDialogKind::question : TaxDialogKind::acknowledgement, false, x, y));
const bool dialog_changed = dialog != pressed_dialog_;
pressed_dialog_ = dialog;
// a key of the open calculator
int key = -1;
if (calculator_open_ && !pending_)
for (int i = 0; i < 15; ++i)
if (calculator_key_hit(x, y, 103 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2),
55 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i)))) key = i;
const bool key_changed = key != pressed_key_;
pressed_key_ = key;
int id = -1;
const bool has_buttons = (exchange_open_ || property_open_ || deposit_open_ || credit_open_) && !calculator_open_ &&
!credit_notice_open_ && !credit_fee_confirmation_open_ && !property_notice_open_ && !investment_warning_open_ && !pending_;
@@ -1012,11 +1019,12 @@ bool BankScreen::press(int x, int y) {
}
const bool changed = id != pressed_button_;
pressed_button_ = id;
return changed || dialog_changed;
return changed || dialog_changed || key_changed;
}
BankRequest BankScreen::click(int x, int y, bool right) {
pressed_button_ = -1; // the release ends the pressed look
pressed_dialog_ = int(GameEndTaxDialog::Button::none);
pressed_key_ = -1;
if (credit_notice_open_) {
if (right || (x >= 95 && x <= 220 && y >= 166 && y <= 176)) {
credit_notice_open_ = false;
+2 -1
View File
@@ -156,7 +156,8 @@ private:
bool credit_fees_accepted_ = false;
bool selling_shares_ = false;
int pressed_button_ = -1; // 0 left, 1 right bottom button while the mouse button is held
int pressed_dialog_ = 0; // GameEndTaxDialog::Button (0 none) of an open notice/question held down by the mouse
int pressed_key_ = -1; // calculator key held down by the mouse
int pressed_dialog_ = 0; // GameEndTaxDialog::Button (0 none) of an open notice/question held down by the mouse
bool calculator_stock_count_ = false;
bool calculator_property_count_ = false;
int selected_stock_ = 11;
+54 -2
View File
@@ -4,7 +4,10 @@
#include <algorithm>
#include <cstdio>
#include "formats/diamond_image.hpp"
#include "ui/button_frame.hpp"
#include "ui/calculator_widgets.hpp"
#include "ui/dialog_frame.hpp"
using namespace bmh;
@@ -37,10 +40,58 @@ int reference(Image& out, const Image& art, int x, int y, int width, bool presse
return pressed ? 2 : 0;
}
// The window frame as every dialog drew it before it was shared.
void reference_frame(Image& o, const Image& a, const LeImage& exe, int x, int y, int w, int h, bool shadow) {
const auto fill = [&](int fx, int fy, int fw, int fh, uint8_t c) {
for (int yy = std::max(0, fy); yy < std::min(o.height, fy + fh); ++yy)
for (int xx = std::max(0, fx); xx < std::min(o.width, fx + fw); ++xx) o.at(xx, yy) = c;
};
const auto copy = [&](int sx, int sy, int dx, int dy, int cw, int ch) {
for (int yy = 0; yy < ch; ++yy) for (int xx = 0; xx < cw; ++xx)
o.at(dx + xx, dy + yy) = a.pixels[size_t(sy + yy) * a.width + size_t(sx + xx)];
};
if (shadow) { fill(x + 2, y + h, w, 2, 0x40); fill(x + w, y + 2, 2, h, 0x40); }
for (int yy = 4; yy < h - 3; ++yy) for (int xx = 4; xx < w - 3; ++xx)
o.at(x + xx, y + yy) = exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + size_t((yy - 4) & 15) * 16 + size_t((xx - 4) & 15));
copy(0, 0, x, y, 4, 4); copy(4, 0, x + w - 4, y, 4, 4); copy(0, 4, x, y + h - 4, 4, 4); copy(4, 4, x + w - 4, y + h - 4, 4, 4);
for (int at = 4; at < w - 4; at += 74) { const int n = std::min(74, w - 4 - at); copy(0, 104, x + at, y, n, 4); copy(0, 108, x + at, y + h - 4, n, 4); }
for (int at = 4; at < h - 4; at += 96) { const int n = std::min(96, h - 4 - at); copy(0, 8, x, y + at, 4, n); copy(4, 8, x + w - 4, y + at, 4, n); }
}
void frames_and_calculator(const Image& art) {
const LeImage exe = diamond_constants_image();
for (const auto [w, h] : {std::pair{217, 99}, std::pair{319, 90}, std::pair{113, 140}, std::pair{42, 42}, std::pair{300, 200}})
for (const bool shadow : {false, true}) {
Image a(320, 240, 5), b(320, 240, 5);
ui::draw_dialog_frame(a, art, exe, 0, 11, w, h, shadow); // inside the picture: the reference does not clip
reference_frame(b, art, exe, 0, 11, w, h, shadow);
if (a.pixels != b.pixels) { std::fprintf(stderr, "FAIL: dialog frame %dx%d shadow %d\n", w, h, int(shadow)); ++failures; }
}
// the calculator: the panel is the 113x136 picture with its shadow, a key the 15x14 (pressed 14x13) picture
Image big(130, 160);
for (size_t i = 0; i < big.pixels.size(); ++i) big.pixels[i] = uint8_t((i * 29 + 5) % 253);
for (const bool pressed : {false, true}) {
Image a(320, 240, 7), b(320, 240, 7);
const int shift = ui::draw_calculator_key(a, big, 50, 60, pressed);
const int p = pressed ? 1 : 0;
for (int yy = 0; yy < 14 - p; ++yy) for (int xx = 0; xx < 15 - p; ++xx)
b.at(50 + p + xx, 60 + p + yy) = big.pixels[size_t(136 + yy) * big.width + size_t(15 * p + xx)];
if (shift != p || a.pixels != b.pixels) { std::fprintf(stderr, "FAIL: calculator key pressed %d\n", int(pressed)); ++failures; }
}
Image panel(320, 240, 7), expected(320, 240, 7);
ui::draw_calculator_panel(panel, big, 103, 55);
for (int yy = 0; yy < 136; ++yy) for (int xx = 0; xx < 113; ++xx) expected.at(103 + xx, 55 + yy) = big.pixels[size_t(yy) * big.width + size_t(xx)];
for (int yy = 0; yy < 136; ++yy) for (int xx = 0; xx < 2; ++xx) expected.at(103 + 113 + xx, 55 + 2 + yy) = 0x40;
for (int yy = 0; yy < 2; ++yy) for (int xx = 0; xx < 113; ++xx) expected.at(103 + 2 + xx, 55 + 136 + yy) = 0x40;
if (panel.pixels != expected.pixels) { std::fprintf(stderr, "FAIL: calculator panel\n"); ++failures; }
if (!ui::calculator_key_hit(103, 70, 103, 70) || ui::calculator_key_hit(119, 70, 103, 70) ||
ui::calculator_key_hit(103, 84, 103, 70)) { std::fprintf(stderr, "FAIL: calculator key hit test\n"); ++failures; }
}
} // namespace
int main() {
Image art(80, 110);
Image art(80, 120);
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;
@@ -61,7 +112,8 @@ int main() {
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);
frames_and_calculator(art);
if (failures) return 1;
std::puts("PASS shared wide button frame");
std::puts("PASS shared button, dialog frame and calculator widgets");
return 0;
}
+50
View File
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: GPL-3.0-only
// The number calculator window of the game (bank, offers, advertising, contracts, stadium, ...): its panel with the
// drop shadow and its keys. The position of the keys and presets comes from tables of the executable, the labels and
// the title are drawn by each dialog; only the shared pictures are drawn here.
// panel: 113x136 picture from the calculator art at (0,0), shadow 2 pixels right and below.
// key: 15x14 picture at (0,136) of the art; a key held down by the mouse is the 14x13 picture at (15,136) drawn one
// pixel down and right, and its legend moves by the same pixel.
#pragma once
#include <algorithm>
#include <cstdint>
#include "formats/vga.hpp"
namespace bmh::ui {
// A key of the calculator window is 16x14 pixels wide for hit tests; this tells whether (x,y) lies in the key at (kx,ky).
inline bool calculator_key_hit(int x, int y, int kx, int ky) { return x >= kx && x < kx + 16 && y >= ky && y < ky + 14; }
// Draws the calculator panel with its top left corner at (x0,y0).
inline void draw_calculator_panel(Image& out, const Image& art, int x0, int y0) {
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 auto fill = [&](int fx, int fy, int w, int h) {
for (int yy = std::max(0, fy); yy < std::min(out.height, fy + h); ++yy)
for (int xx = std::max(0, fx); xx < std::min(out.width, fx + w); ++xx) out.at(xx, yy) = 0x40;
};
put(0, 0, x0, y0, 113, 136);
fill(x0 + 113, y0 + 2, 2, 136);
fill(x0 + 2, y0 + 136, 113, 2);
}
// Draws the picture of the key whose top left corner is (x,y). Returns the offset (0 or 1) by which the legend moves.
inline int draw_calculator_key(Image& out, const Image& art, int x, int y, bool pressed) {
const int p = pressed ? 1 : 0;
for (int yy = 0; yy < 14 - p; ++yy) for (int xx = 0; xx < 15 - p; ++xx) {
const int tx = x + p + xx, ty = y + p + yy, px = 15 * p + xx, py = 136 + yy;
if (tx < 0 || ty < 0 || tx >= out.width || ty >= out.height || px >= art.width || py >= art.height) continue;
out.at(tx, ty) = art.pixels[size_t(py) * size_t(art.width) + size_t(px)];
}
return p;
}
} // namespace bmh::ui
+2 -5
View File
@@ -5,6 +5,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/club_player_detail.hpp"
#include "ui/dialog_frame.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
@@ -132,11 +133,7 @@ void ClubPlayerDetailScreen::text(Image& out,int x,int baseline,std::string_view
out.at(x+xx,baseline-font.baseline+yy)=projection_.gradient_text?exe_.u8(::bmh::layout::Advertising_Text_RuntimeField+gradient*6+yy):color;
}
void ClubPlayerDetailScreen::frame(Image& out,int x,int y,int w,int h) const {
for(int yy=4;yy<h-3;++yy)for(int xx=4;xx<w-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+w-4,y,4,4);
copy(out,widgets_,0,4,x,y+h-4,4,4);copy(out,widgets_,4,4,x+w-4,y+h-4,4,4);
for(int at=4;at<w-4;at+=74){const int n=std::min(74,w-4-at);copy(out,widgets_,0,104,x+at,y,n,4);copy(out,widgets_,0,108,x+at,y+h-4,n,4);}
for(int at=4;at<h-4;at+=96){const int n=std::min(96,h-4-at);copy(out,widgets_,0,8,x,y+at,4,n);copy(out,widgets_,4,8,x+w-4,y+at,4,n);}
draw_dialog_frame(out,widgets_,exe_,x,y,w,h,false); // dialog_frame.hpp
}
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;
+15 -21
View File
@@ -4,7 +4,9 @@
// input into ContractRequest values. Applying an offer or insurance is left to the session.
#include "formats/executable_layout.hpp"
#include "ui/contracts.hpp"
#include "ui/dialog_frame.hpp"
#include "ui/button_frame.hpp"
#include "ui/calculator_widgets.hpp"
#include "ui/game_end.hpp"
#include <algorithm>
@@ -47,22 +49,7 @@ void pattern(Image& out, const LeImage& exe, int x, int y, int width, int height
// Draws a panel in the original style: optional drop shadow, tiled pattern inside, four 4x4 corners
// and edge strips (copied in pieces of at most 74 pixels horizontally and 96 vertically).
void frame(Image& out, const LeImage& exe, const Image& widgets, int x, int y, int width, int height, bool shadow = true) {
if (shadow) { fill(out, x + 2, y + height, width, 2, 0x40); fill(out, x + width, y + 2, 2, height, 0x40); }
pattern(out, exe, x + 4, y + 4, width - 7, height - 7);
copy_region(out, widgets, 0, 0, x, y, 4, 4);
copy_region(out, widgets, 4, 0, x + width - 4, y, 4, 4);
copy_region(out, widgets, 0, 4, x, y + height - 4, 4, 4);
copy_region(out, widgets, 4, 4, x + width - 4, y + height - 4, 4, 4);
for (int at = 4; at < width - 4; at += 74) {
const int n = std::min(74, width - 4 - at);
copy_region(out, widgets, 0, 104, x + at, y, n, 4);
copy_region(out, widgets, 0, 108, x + at, y + height - 4, n, 4);
}
for (int at = 4; at < height - 4; at += 96) {
const int n = std::min(96, height - 4 - at);
copy_region(out, widgets, 0, 8, x, y + at, 4, n);
copy_region(out, widgets, 4, 8, x + width - 4, y + at, 4, n);
}
draw_dialog_frame(out, widgets, exe, x, y, width, height, shadow); // dialog_frame.hpp
}
// Fills a rectangle with one palette index; throws if it leaves the image.
@@ -542,14 +529,13 @@ Image ContractsScreen::render() const {
} else if (page_ == Page::calculator) {
// Calculator: background image at (10,10), drop shadow, label, 15 keys (digits and the letters D, R, C, J, N),
// 8 preset buttons and the current input right-aligned. Key and preset positions come from tables in the executable.
copy_region(out, calculator_, 0, 0, 10, 10, 113, 136);
fill(out,123,12,2,136,0x40);fill(out,12,146,113,2,0x40);
draw_calculator_panel(out, calculator_, 10, 10); // calculator_widgets.hpp
const auto label=calculator_bonus_index_==-2?db(::bmh::layout::Contracts_Out_ExecutableField19):calculator_bonus_index_<0?db(::bmh::layout::Contracts_Out_ExecutableField14):db(::bmh::layout::Contracts_Out_ExecutableField4+calculator_bonus_index_*4);
centered(18,115,24,label,98);
for(int i=0;i<15;++i) {
const int x=10+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+i*2), y=10+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+i);
copy_region(out,calculator_,0,136,x,y,15,14);
text(out,x+5,y+9,std::string(1,"0123456789DRCJN"[i]),98,-1);
const int p=draw_calculator_key(out,calculator_,x,y,pressed_key_==i);
text(out,x+5+p,y+9+p,std::string(1,"0123456789DRCJN"[i]),98,-1);
}
for(int i=0;i<8;++i) {
const int x=10+exe_.u16(::bmh::layout::Advertising_Click_RuntimeField+(i+15)*2), y=10+exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2+i+15);
@@ -597,13 +583,21 @@ bool ContractsScreen::press(int x, int y) {
else if (x >= 261 && x <= 312 && !team && state_.mode_three) id = 2;
}
}
const bool changed = id != pressed_button_;
// a key of the open calculator
int key = -1;
if (page_ == Page::calculator)
for (int i = 0; i < 15; ++i)
if (calculator_key_hit(x, y, 10 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2),
10 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i)))) key = i;
const bool changed = id != pressed_button_ || key != pressed_key_;
pressed_button_ = id;
pressed_key_ = key;
return changed;
}
bool ContractsScreen::click(int x, int y, bool right) {
pressed_button_ = -1; // the release ends the pressed look
pressed_key_ = -1;
if (page_ == Page::result) {
if (x >= 95 && x <= 220 && y >= 166 && y <= 176) { page_ = result_return_; result_backdrop_.reset(); state_.feedback.clear(); return true; }
return false;
+1
View File
@@ -117,6 +117,7 @@ private:
enum class Page : uint8_t { roster, player_offer, team_premiums, calculator, insurance, result };
ContractsState state_;
int pressed_button_ = -1; // button below the panel held down by the mouse
int pressed_key_ = -1; // calculator key held down by the mouse
LeImage exe_;
Font font_;
Font large_font_;
+2 -13
View File
@@ -4,6 +4,7 @@
// acknowledged DeskState updates. It also provides desk_request_json() and desk_menu_name().
#include "formats/executable_layout.hpp"
#include "ui/desktop.hpp"
#include "ui/dialog_frame.hpp"
#include <algorithm>
#include <limits>
@@ -147,19 +148,7 @@ void DesktopScreen::sprite_text(Image& out, int x, int baseline, std::string_vie
}
void DesktopScreen::frame(Image& out, int x, int y, int w, int h) const {
if (w < 8 || h < 8) throw FormatError("desktop: invalid drawer size");
for (int yy = 4; yy < h - 3; ++yy) for (int xx = 4; xx < w - 3; ++xx)
if (x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height)
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 + w - 4, y, 4, 4);
copy(out, widgets_, 0, 4, x, y + h - 4, 4, 4); copy(out, widgets_, 4, 4, x + w - 4, y + h - 4, 4, 4);
for (int k = 4; k < w - 4; k += 74) {
const int n = std::min(74, w - 4 - k);
copy(out, widgets_, 0, 104, x + k, y, n, 4); copy(out, widgets_, 0, 108, x + k, y + h - 4, n, 4);
}
for (int k = 4; k < h - 4; k += 96) {
const int n = std::min(96, h - 4 - k);
copy(out, widgets_, 0, 8, x, y + k, 4, n); copy(out, widgets_, 4, 8, x + w - 4, y + k, 4, n);
}
draw_dialog_frame(out, widgets_, exe_, x, y, w, h, false); // dialog_frame.hpp
}
void DesktopScreen::digits(Image& out, int value, int sx, int sy, int w, int h, int x, int y, int base, int gap) const {
int count = 1;
+54
View File
@@ -0,0 +1,54 @@
// SPDX-License-Identifier: GPL-3.0-only
// The frame of a panel or dialog window as the game draws it everywhere: an optional drop shadow (2 pixels right and
// below), the 16x16 background pattern that the executable carries, the four 4x4 corners of the widget image and its edge
// strips (copied in pieces of at most 74 pixels horizontally and 96 vertically).
#pragma once
#include <algorithm>
#include <cstdint>
#include "formats/executable_layout.hpp"
#include "formats/le.hpp"
#include "formats/vga.hpp"
namespace bmh::ui {
// Draws the frame of the window with top left corner (x,y) and size w x h.
inline void draw_dialog_frame(Image& out, const Image& widgets, const LeImage& exe,
int x, int y, int w, int h, bool shadow = true) {
const auto fill = [&](int fx, int fy, int fw, int fh, uint8_t color) {
for (int yy = std::max(0, fy); yy < std::min(out.height, fy + fh); ++yy)
for (int xx = std::max(0, fx); xx < std::min(out.width, fx + fw); ++xx) out.at(xx, yy) = color;
};
const auto put = [&](int sx, int sy, int dx, int dy, int cw, int ch) {
for (int yy = 0; yy < ch; ++yy) for (int xx = 0; xx < cw; ++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 >= widgets.width || py >= widgets.height) continue;
out.at(tx, ty) = widgets.pixels[size_t(py) * size_t(widgets.width) + size_t(px)];
}
};
if (shadow) { fill(x + 2, y + h, w, 2, 0x40); fill(x + w, y + 2, 2, h, 0x40); }
for (int yy = 4; yy < h - 3; ++yy) for (int xx = 4; xx < w - 3; ++xx) {
const int tx = x + xx, ty = y + yy;
if (tx < 0 || ty < 0 || tx >= out.width || ty >= out.height) continue;
out.at(tx, ty) = exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField +
size_t((yy - 4) & 15) * 16 + size_t((xx - 4) & 15));
}
put(0, 0, x, y, 4, 4);
put(4, 0, x + w - 4, y, 4, 4);
put(0, 4, x, y + h - 4, 4, 4);
put(4, 4, x + w - 4, y + h - 4, 4, 4);
for (int at = 4; at < w - 4; at += 74) {
const int n = std::min(74, w - 4 - at);
put(0, 104, x + at, y, n, 4);
put(0, 108, x + at, y + h - 4, n, 4);
}
for (int at = 4; at < h - 4; at += 96) {
const int n = std::min(96, h - 4 - at);
put(0, 8, x, y + at, 4, n);
put(4, 8, x + w - 4, y + at, 4, n);
}
}
} // namespace bmh::ui
+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/dialog_frame.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
@@ -155,12 +156,7 @@ private:
}
};
void frame(Image& o,const Image& a,const LeImage& exe,int x,int y,int w,int h,bool shadow) {
if(shadow){fill(o,x+2,y+h,w,2,0x40);fill(o,x+w,y+2,2,h,0x40);}
for(int yy=4;yy<h-3;++yy)for(int xx=4;xx<w-3;++xx)
o.at(x+xx,y+yy)=exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField+size_t((yy-4)&15)*16+size_t((xx-4)&15));
copy(o,a,0,0,x,y,4,4);copy(o,a,4,0,x+w-4,y,4,4);copy(o,a,0,4,x,y+h-4,4,4);copy(o,a,4,4,x+w-4,y+h-4,4,4);
for(int at=4;at<w-4;at+=74){int n=std::min(74,w-4-at);copy(o,a,0,104,x+at,y,n,4);copy(o,a,0,108,x+at,y+h-4,n,4);}
for(int at=4;at<h-4;at+=96){int n=std::min(96,h-4-at);copy(o,a,0,8,x,y+at,4,n);copy(o,a,4,8,x+w-4,y+at,4,n);}
draw_dialog_frame(o,a,exe,x,y,w,h,shadow); // dialog_frame.hpp
}
std::string source_number(int32_t value, unsigned minimum_digits) {
const bool negative = value < 0;
+2 -1
View File
@@ -4,6 +4,7 @@
// It reports state through phase(), value() and accepted_value(); the caller decides what to do with them.
#include "formats/executable_layout.hpp"
#include "ui/game_end_alternate.hpp"
#include "ui/calculator_widgets.hpp"
#include <algorithm>
#include <utility>
@@ -180,7 +181,7 @@ Image GameEndAlternateScoreScreen::render(std::optional<unsigned> pressed) const
for (unsigned i=0; i<15; ++i) {
const int p=pressed && *pressed==i ? 1:0;
const int x=x0+assets_.exe.u16(::bmh::layout::Advertising_Click_RuntimeField+2*i),y=y0+assets_.exe.u8(::bmh::layout::Advertising_Click_RuntimeField2+i);
copy(out,assets_.calculator,15*p,136,x+p,y+p,15-p,14-p);
draw_calculator_key(out,assets_.calculator,x,y,p!=0);
draw_text(out,x+p+5,y+p+9,keys.substr(i,1),0x62,false);
}
for (unsigned i=0; i<8; ++i) {
+2 -15
View File
@@ -5,6 +5,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/manager.hpp"
#include "ui/dialog_frame.hpp"
#include "ui/button_frame.hpp"
#include "formats/league_visibility.hpp"
@@ -307,21 +308,7 @@ void ManagerScreen::small_text(Image& out, int x, int baseline, std::string_view
out.at(x + xx, baseline - 5 + y) = exe_.u8(::bmh::layout::Advertising_Text_RuntimeField + gradient * 6 + y);
}
void ManagerScreen::frame(Image& out, int x, int y, int w, int h, bool shadow) const {
if (shadow) {
rect(out, x + 2, y + h, w, 2, 0x40);
rect(out, x + w, y + 2, 2, h, 0x40);
}
pattern(out, x + 4, y + 4, w - 7, h - 7);
copy(out, widgets_, 0, 0, x, y, 4, 4); copy(out, widgets_, 4, 0, x + w - 4, y, 4, 4);
copy(out, widgets_, 0, 4, x, y + h - 4, 4, 4); copy(out, widgets_, 4, 4, x + w - 4, y + h - 4, 4, 4);
for (int k = 4; k < w - 4; k += 74) {
int n = std::min(74, w - 4 - k);
copy(out, widgets_, 0, 104, x + k, y, n, 4); copy(out, widgets_, 0, 108, x + k, y + h - 4, n, 4);
}
for (int k = 4; k < h - 4; k += 96) {
int n = std::min(96, h - 4 - k);
copy(out, widgets_, 0, 8, x, y + k, 4, n); copy(out, widgets_, 4, 8, x + w - 4, y + k, 4, n);
}
draw_dialog_frame(out, widgets_, exe_, x, y, w, h, shadow); // dialog_frame.hpp
}
int ManagerScreen::sprite_text_width(std::string_view value) const {
int width = 0;
+13 -6
View File
@@ -6,6 +6,7 @@
#include "formats/executable_layout.hpp"
#include "ui/outgoing_transfer.hpp"
#include "ui/button_frame.hpp"
#include "ui/calculator_widgets.hpp"
#include <algorithm>
#include <charconv>
@@ -395,9 +396,7 @@ void OutgoingTransferScreen::draw_editor_fields(Image& out) const {
void OutgoingTransferScreen::draw_calculator(Image& out) const {
constexpr int x0 = kCalculatorX, y0 = kCalculatorY;
if (!calculator_open_ || !active_profile_.supported) return;
copy_region(out, calculator_art_, 0, 0, x0, y0, 113, 136);
fill_rect(out, x0 + 113, y0 + 2, 2, 136, 0x40);
fill_rect(out, x0 + 2, y0 + 136, 113, 2, 0x40);
draw_calculator_panel(out, calculator_art_, x0, y0); // calculator_widgets.hpp
std::string title;
if (active_profile_.source_text_address)
title = std::string(text_at(texts_, active_profile_.source_text_address));
@@ -427,8 +426,8 @@ void OutgoingTransferScreen::draw_calculator(Image& out) const {
for (int i = 0; i < 15; ++i) {
const int x = x0 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2);
const int y = y0 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i));
copy_region(out, calculator_art_, 0, 136, x, y, 15, 14);
draw_body(x + 5, y + 9, keys.substr(size_t(i), 1), 0x62, false);
const int p = draw_calculator_key(out, calculator_art_, x, y, pressed_key_ == i);
draw_body(x + 5 + p, y + 9 + p, keys.substr(size_t(i), 1), 0x62, false);
}
for (size_t i = 0; i < active_profile_.presets.size(); ++i) {
if (!active_profile_.presets[i]) continue;
@@ -489,13 +488,21 @@ bool OutgoingTransferScreen::press(int x, int y) {
for (size_t i = 0; i < kFooterButtonX.size(); ++i)
if (x >= kFooterButtonX[i] && x <= kFooterButtonX[i] + kFooterButtonWidth && y >= kFooterButtonY &&
y <= kFooterButtonY + kFooterButtonHeight) id = int(i);
const bool changed = id != pressed_button_;
// a key of the open calculator
int key = -1;
if (!closed_ && !pending_ && calculator_open_ && active_profile_.supported)
for (int i = 0; i < 15; ++i)
if (calculator_key_hit(x, y, kCalculatorX + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2),
kCalculatorY + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i)))) key = i;
const bool changed = id != pressed_button_ || key != pressed_key_;
pressed_button_ = id;
pressed_key_ = key;
return changed;
}
OutgoingTransferRequest OutgoingTransferScreen::click(int x, int y, bool right, bool double_click) {
pressed_button_ = -1; // the release ends the pressed look
pressed_key_ = -1;
if (closed_ || pending_) return {};
if (double_click && !right && !calculator_open_ && y > 0x12 && y < 0x21) {
state_.quote_loan = !state_.quote_loan;
+1
View File
@@ -128,6 +128,7 @@ private:
bool calculator_open_ = false;
bool closed_ = false;
int pressed_button_ = -1; // footer button held down by the mouse
int pressed_key_ = -1; // calculator key held down by the mouse
std::optional<OutgoingTransferRequest> pending_;
OutgoingTransferIdentity identity() const;
+2 -5
View File
@@ -5,6 +5,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/player_card.hpp"
#include "ui/dialog_frame.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
@@ -218,11 +219,7 @@ void PlayerCardScreen::text(Image& out,int x,int baseline,std::string_view value
out.at(x+xx,baseline-font.baseline+yy)=state_.lineup.gradient_text?exe_.u8(::bmh::layout::Advertising_Text_RuntimeField+gradient*6+yy):color;
}
void PlayerCardScreen::frame(Image& out,int x,int y,int w,int h) const {
for(int yy=4;yy<h-3;++yy)for(int xx=4;xx<w-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+w-4,y,4,4);
copy(out,widgets_,0,4,x,y+h-4,4,4);copy(out,widgets_,4,4,x+w-4,y+h-4,4,4);
for(int at=4;at<w-4;at+=74){const int n=std::min(74,w-4-at);copy(out,widgets_,0,104,x+at,y,n,4);copy(out,widgets_,0,108,x+at,y+h-4,n,4);}
for(int at=4;at<h-4;at+=96){const int n=std::min(96,h-4-at);copy(out,widgets_,0,8,x,y+at,4,n);copy(out,widgets_,4,8,x+w-4,y+at,4,n);}
draw_dialog_frame(out,widgets_,exe_,x,y,w,h,false); // dialog_frame.hpp
}
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;
+2 -15
View File
@@ -5,6 +5,7 @@
#include "formats/native_save_version.hpp"
#include "formats/executable_layout.hpp"
#include "ui/save_load.hpp"
#include "ui/dialog_frame.hpp"
#include "ui/button_frame.hpp"
#include <algorithm>
@@ -247,21 +248,7 @@ bool SaveLoadScreen::info_press(int x, int y) {
}
void SaveLoadScreen::frame(Image& out, int x, int y, int width, int height) const {
pattern(out, exe_, x + 4, y + 4, width - 7, height - 7);
copy(out, widgets_, 0, 0, x, y, 4, 4);
copy(out, widgets_, 4, 0, x + width - 4, y, 4, 4);
copy(out, widgets_, 0, 4, x, y + height - 4, 4, 4);
copy(out, widgets_, 4, 4, x + width - 4, y + height - 4, 4, 4);
for (int at = 4; at < width - 4; at += 74) {
const int count = std::min(74, width - 4 - at);
copy(out, widgets_, 0, 104, x + at, y, count, 4);
copy(out, widgets_, 0, 108, x + at, y + height - 4, count, 4);
}
for (int at = 4; at < height - 4; at += 96) {
const int count = std::min(96, height - 4 - at);
copy(out, widgets_, 0, 8, x, y + at, 4, count);
copy(out, widgets_, 4, 8, x + width - 4, y + at, 4, count);
}
draw_dialog_frame(out, widgets_, exe_, x, y, width, height, false); // dialog_frame.hpp
}
void SaveLoadScreen::button(Image& out, int x, int y, int width, std::string_view label, bool pressed) const {
+5 -22
View File
@@ -4,7 +4,9 @@
// construction. Source-tick timing for the calculator is advanced by the caller.
#include "formats/executable_layout.hpp"
#include "ui/stadium.hpp"
#include "ui/dialog_frame.hpp"
#include "ui/button_frame.hpp"
#include "ui/calculator_widgets.hpp"
#include <algorithm>
#include <bit>
@@ -73,23 +75,7 @@ void source_shadow(Image& out, int x, int y, int w, int h) {
// corner pieces from the widget atlas, and the edge strips tiled in runs of 74 px (top/bottom) and 96 px (left/right).
void source_frame(Image& out, const Image& atlas, const LeImage& exe,
int x, int y, int w, int h, bool shadow = true) {
if (shadow) { fill(out, x + 2, y + h, w, 2, 0x40); fill(out, x + w, y + 2, 2, h, 0x40); }
for (int yy = 4; yy < h - 3; ++yy) for (int xx = 4; xx < w - 3; ++xx)
out.at(x + xx, y + yy) = exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + size_t((yy - 4) & 15) * 16 + size_t((xx - 4) & 15));
copy_crop(out, atlas, 0, 0, x, y, 4, 4);
copy_crop(out, atlas, 4, 0, x + w - 4, y, 4, 4);
copy_crop(out, atlas, 0, 4, x, y + h - 4, 4, 4);
copy_crop(out, atlas, 4, 4, x + w - 4, y + h - 4, 4, 4);
for (int at = 4; at < w - 4; at += 74) {
const int n = std::min(74, w - 4 - at);
copy_crop(out, atlas, 0, 104, x + at, y, n, 4);
copy_crop(out, atlas, 0, 108, x + at, y + h - 4, n, 4);
}
for (int at = 4; at < h - 4; at += 96) {
const int n = std::min(96, h - 4 - at);
copy_crop(out, atlas, 0, 8, x, y + at, 4, n);
copy_crop(out, atlas, 4, 8, x + w - 4, y + at, 4, n);
}
draw_dialog_frame(out, atlas, exe, x, y, w, h, shadow); // dialog_frame.hpp
}
// Draws text with its baseline at `baseline` (skipped entirely if it would leave the screen vertically).
// In gradient mode (executable flag == 2) a color found in the 32-entry gradient table is recolored per glyph row
@@ -870,9 +856,7 @@ Image StadiumScreen::render_block_expansion(Image out) const {
Image StadiumScreen::render_block_calculator(Image out) const {
if (!block_calculator_open_ || block_calculator_cancel_wait_ || !state_.block_expansion) return out;
const int x0 = block_calculator_x_, y0 = block_calculator_y_;
copy_crop(out, calculator_art_, 0, 0, x0, y0, 113, 136);
fill(out, x0 + 113, y0 + 2, 2, 136, 0x40);
fill(out, x0 + 2, y0 + 136, 113, 2, 0x40);
draw_calculator_panel(out, calculator_art_, x0, y0); // calculator_widgets.hpp
const auto& editor = *state_.block_expansion;
const std::string title = texts_[1118];
const int width = font_.text_width(title);
@@ -883,8 +867,7 @@ Image StadiumScreen::render_block_calculator(Image out) const {
const int x = x0 + exe_.u16(::bmh::layout::Advertising_Click_RuntimeField + size_t(i) * 2);
const int y = y0 + exe_.u8(::bmh::layout::Advertising_Click_RuntimeField2 + size_t(i));
const bool pressed = block_calculator_pressed_key_ == i;
copy_crop(out, calculator_art_, pressed ? 15 : 0, 136, x + (pressed ? 1 : 0),
y + (pressed ? 1 : 0), 15 - int(pressed), 14 - int(pressed));
draw_calculator_key(out, calculator_art_, x, y, pressed);
text_at(out, x + 5 + int(pressed), y + 9 + int(pressed), keys.substr(size_t(i), 1), 0x62, false);
}
const uint32_t current = uint32_t(editor.quote.current_capacity_thousands) * 1000;
+3 -16
View File
@@ -3,6 +3,7 @@
#include "formats/badge_policy.hpp"
#include "formats/executable_layout.hpp"
#include "ui/team_statistics.hpp"
#include "ui/dialog_frame.hpp"
#include <algorithm>
#include <cstddef>
@@ -31,22 +32,8 @@ void rect(Image& out, int x, int y, int w, int h, uint8_t value) {
}
void source_frame(Image& out, const Image& widgets, const LeImage& exe,
int x, int y, int w, int h, uint8_t color) {
for (int yy = 0; yy < h - 7; ++yy) for (int xx = 0; xx < w - 7; ++xx)
out.at(x + 4 + xx, y + 4 + yy) = exe.u8(::bmh::layout::Advertising_PatternRect_RuntimeField + (yy & 15) * 16 + (xx & 15));
copy(out, widgets, 0, 0, x, y, 4, 4); copy(out, widgets, 4, 0, x + w - 4, y, 4, 4);
copy(out, widgets, 0, 4, x, y + h - 4, 4, 4); copy(out, widgets, 4, 4, x + w - 4, y + h - 4, 4, 4);
for (int xx = 4; xx < w - 4; xx += 74) {
const int amount = std::min(74, w - 4 - xx);
copy(out, widgets, 0, 104, x + xx, y, amount, 4); copy(out, widgets, 0, 108, x + xx, y + h - 4, amount, 4);
}
for (int yy = 4; yy < h - 4; yy += 96) {
const int amount = std::min(96, h - 4 - yy);
copy(out, widgets, 0, 8, x, y + yy, 4, amount); copy(out, widgets, 4, 8, x + w - 4, y + yy, 4, amount);
}
int ramp = 0; while (ramp < 32 && exe.u8(::bmh::layout::Advertising_Text_RuntimeField2 + ramp) != color) ++ramp;
const uint8_t shadow = exe.u8(::bmh::layout::Advertising_Text_RuntimeField + ramp * 6 + 5);
rect(out, x + 2, y + h, w, 2, 0x40); rect(out, x + w, y + 2, 2, h, 0x40);
(void)shadow;
(void)color;
draw_dialog_frame(out, widgets, exe, x, y, w, h, true); // dialog_frame.hpp
}
std::string source_field(int value, int width) {
std::string s = std::to_string(value);