ui/draw.hpp: one place for the pixel loops of fill and copy
67 file-local helpers (fill/rect/copy/copy_region/... in 39 screens) now call draw::fill, draw::copy_clipped or draw::copy_unclipped. Only the loops moved: every screen keeps its own wrapper with its bounds check and error text, so the contracts are unchanged. Eight helpers with special behaviour stay as they are (bank, season promotion, toto, tax animation, ...). Verified: 9 headless careers and the scripted UI walk (German and English data, 38 screens, about 5,460 steps each) give the same fingerprints as before. ctest: 209 of 211; other_games_ui_tests and ui_preparation_tests fail the same way without this change. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
901f3dec1c
commit
fb3c2fe757
40 files changed
+171
-206
No files matched your search
@@ -15,6 +15,7 @@
|
||||
#include "game/schedule.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -32,8 +33,7 @@ void fill(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
}
|
||||
void copy(Image& out,const Image& source,int sx,int sy,int x,int y,int w,int h,int transparent=-1) {
|
||||
if(sx<0||sy<0||sx+w>source.width||sy+h>source.height)throw FormatError("achievements: Source KB56 bounds");
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx){const uint8_t c=source.pixels[size_t(sy+yy)*size_t(source.width)+size_t(sx+xx)];
|
||||
if(c!=transparent&&x+xx>=0&&y+yy>=0&&x+xx<out.width&&y+yy<out.height)out.at(x+xx,y+yy)=c;}
|
||||
draw::copy_clipped(out, source, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
uint16_t rd16(const std::vector<uint8_t>& b,size_t at){return uint16_t(b.at(at))|uint16_t(uint16_t(b.at(at+1))<<8);}
|
||||
// FNT files consume the game's single-byte encoding; only JSON/test boundaries use UTF-8.
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -270,17 +271,13 @@ void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int
|
||||
if (sx < 0 || sy < 0 || sx + w > src.width || sy + h > src.height ||
|
||||
x < 0 || y < 0 || x + w > out.width || y + h > out.height)
|
||||
throw FormatError("advertising: original VGA crop outside image");
|
||||
for (int yy = 0; yy < h; ++yy)
|
||||
for (int xx = 0; xx < w; ++xx)
|
||||
out.at(x + xx, y + yy) = src.pixels[size_t(sy + yy) * src.width + sx + xx];
|
||||
draw::copy_unclipped(out, src, sx, sy, x, y, w, h, -1);
|
||||
}
|
||||
|
||||
void fill_rect(Image& image, int x, int y, int width, int height, uint8_t color) {
|
||||
if (x < 0 || y < 0 || width < 0 || height < 0 || x + width > image.width || y + height > image.height)
|
||||
throw FormatError("advertising: rectangle outside image");
|
||||
for (int yy = y; yy < y + height; ++yy)
|
||||
for (int xx = x; xx < x + width; ++xx)
|
||||
image.at(xx, yy) = color;
|
||||
draw::fill(image, x, y, width, height, color);
|
||||
}
|
||||
|
||||
void rectangle(Image& image, int x, int y, int width, int height, uint8_t color) {
|
||||
|
||||
@@ -8,11 +8,16 @@
|
||||
#include "game/table.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
namespace bmh::ui { namespace {
|
||||
constexpr uint32_t kFirst=::bmh::layout::First, kLeague=::bmh::layout::AlltimeTable_Layout_ExecutableField;
|
||||
std::string original_text(const TextDb& t,uint32_t at){if(at<::bmh::layout::TextPointerTable||((at-::bmh::layout::TextPointerTable)&3U))throw FormatError("alltime: invalid TEXTD address");return original_to_utf8(t[(at-::bmh::layout::TextPointerTable)/4]);}
|
||||
void fill(Image&o,int x,int y,int w,int h,uint8_t c){for(int j=0;j<h;++j)for(int i=0;i<w;++i)o.at(x+i,y+j)=c;}
|
||||
void copy(Image&o,const Image&s,int sx,int sy,int x,int y,int w,int h,int tr=-1){if(sx<0||sy<0||x<0||y<0||sx+w>s.width||sy+h>s.height||x+w>o.width||y+h>o.height)throw FormatError("alltime: Original asset bounds");for(int j=0;j<h;++j)for(int i=0;i<w;++i){auto c=s.pixels[size_t(sy+j)*s.width+sx+i];if(c!=tr)o.at(x+i,y+j)=c;}}
|
||||
void fill(Image&o,int x,int y,int w,int h,uint8_t c){
|
||||
draw::fill(o, x, y, w, h, c);
|
||||
}
|
||||
void copy(Image&o,const Image&s,int sx,int sy,int x,int y,int w,int h,int tr=-1){if(sx<0||sy<0||x<0||y<0||sx+w>s.width||sy+h>s.height||x+w>o.width||y+h>o.height)throw FormatError("alltime: Original asset bounds");
|
||||
draw::copy_unclipped(o, s, sx, sy, x, y, w, h, tr);
|
||||
}
|
||||
std::string source_number(uint32_t value,uint8_t flags){
|
||||
const unsigned width=flags&0x3f;std::string digits=std::to_string(value);
|
||||
const bool grouped=(flags&0x40)==0&&width>3;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
#include "game/messages.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -23,9 +24,11 @@ std::string_view at(const TextDb& t,uint32_t a){if(a<kTextBase||(a-kTextBase)%4)
|
||||
bool in(int x,int y,int x0,int y0,int x1,int y1){return x>=x0&&x<=x1&&y>=y0&&y<=y1;}
|
||||
void copy(Image& o,const Image& s,int sx,int sy,int x,int y,int w,int h,int transparent=-1){
|
||||
if(sx<0||sy<0||x<0||y<0||w<0||h<0||sx+w>s.width||sy+h>s.height||x+w>o.width||y+h>o.height)throw FormatError("balance: sprite bounds "+std::to_string(sx)+","+std::to_string(sy)+" "+std::to_string(w)+"x"+std::to_string(h)+" source "+std::to_string(s.width)+"x"+std::to_string(s.height)+" dest "+std::to_string(o.width)+"x"+std::to_string(o.height));
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx){auto p=s.pixels[size_t(sy+yy)*size_t(s.width)+size_t(sx+xx)];if(transparent<0||p!=transparent)o.at(x+xx,y+yy)=p;}
|
||||
draw::copy_unclipped(o, s, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
void fill(Image& o,int x,int y,int w,int h,uint8_t c){
|
||||
draw::fill(o, x, y, w, h, c);
|
||||
}
|
||||
void fill(Image& o,int x,int y,int w,int h,uint8_t c){for(int yy=std::max(y,0);yy<std::min(y+h,o.height);++yy)for(int xx=std::max(x,0);xx<std::min(x+w,o.width);++xx)o.at(xx,yy)=c;}
|
||||
std::string calc7(uint32_t v){return format_number(GameState{},int32_t(v),7);}
|
||||
std::string calc8(uint32_t v){return format_number(GameState{},int32_t(v),8);}
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,6 +20,7 @@
|
||||
#include "game/messages.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -31,8 +32,7 @@ std::string money(int64_t value) {
|
||||
return result;
|
||||
}
|
||||
void rect(Image& image, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(image.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(image.width, x + w); ++xx) image.at(xx, yy) = color;
|
||||
draw::fill(image, x, y, w, h, color);
|
||||
}
|
||||
void line(Image& image, int x0, int y0, int x1, int y1, uint8_t color) {
|
||||
int dx = std::abs(x1 - x0), sx = x0 < x1 ? 1 : -1;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "game/club_info.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -22,15 +23,10 @@ void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int
|
||||
throw FormatError("club info: Original asset rectangle outside source: " + std::to_string(sx) + "," +
|
||||
std::to_string(sy) + " " + std::to_string(w) + "x" + std::to_string(h) + " in " +
|
||||
std::to_string(src.width) + "x" + std::to_string(src.height));
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const uint8_t value = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
if (value != transparent && x + xx >= 0 && y + yy >= 0 &&
|
||||
x + xx < out.width && y + yy < out.height) out.at(x + xx, y + yy) = value;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
void rect(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx) out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
std::string padded(uint64_t value, int width = 2) {
|
||||
std::string s = std::to_string(value);
|
||||
|
||||
@@ -12,21 +12,18 @@
|
||||
#include <cmath>
|
||||
#include <stdexcept>
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
void rect(Image& out,int x,int y,int w,int h,uint8_t c) {
|
||||
for(int yy=std::max(0,y);yy<std::min(out.height,y+h);++yy)
|
||||
for(int xx=std::max(0,x);xx<std::min(out.width,x+w);++xx)out.at(xx,yy)=c;
|
||||
draw::fill(out, x, y, w, h, c);
|
||||
}
|
||||
void copy(Image& out,const Image& src,int sx,int sy,int x,int y,int w,int h,int transparent=-1) {
|
||||
if(sx<0||sy<0||sx+w>src.width||sy+h>src.height)
|
||||
throw FormatError("club player detail: original atlas bounds "+std::to_string(sx)+","+std::to_string(sy)+
|
||||
":"+std::to_string(w)+"x"+std::to_string(h)+" in "+std::to_string(src.width)+"x"+std::to_string(src.height));
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx){
|
||||
const auto c=src.pixels.at(size_t(sy+yy)*src.width+sx+xx);
|
||||
if(c!=transparent&&x+xx>=0&&x+xx<out.width&&y+yy>=0&&y+yy<out.height)out.at(x+xx,y+yy)=c;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
std::string number(int64_t value,int width=1,bool grouped=false) {
|
||||
auto n=std::to_string(value);const bool negative=value<0;
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -30,10 +31,7 @@ void copy_region(Image& target, const Image& source, int sx, int sy, int x, int
|
||||
if (sx < 0 || sy < 0 || x < 0 || y < 0 || width < 0 || height < 0 ||
|
||||
sx + width > source.width || sy + height > source.height || x + width > target.width || y + height > target.height)
|
||||
throw FormatError("contracts: invalid original widget bounds");
|
||||
for (int yy = 0; yy < height; ++yy) for (int xx = 0; xx < width; ++xx) {
|
||||
const uint8_t value = source.pixels[size_t(sy + yy) * size_t(source.width) + size_t(sx + xx)];
|
||||
if (!transparent || value != 0) target.at(x + xx, y + yy) = value;
|
||||
}
|
||||
draw::copy_unclipped(target, source, sx, sy, x, y, width, height, transparent ? 0 : -1);
|
||||
}
|
||||
|
||||
// Forward declaration; fill() is defined below and is used by frame().
|
||||
@@ -56,8 +54,7 @@ void frame(Image& out, const LeImage& exe, const Image& widgets, int x, int y, i
|
||||
void fill(Image& target, int x, int y, int width, int height, uint8_t color) {
|
||||
if (x < 0 || y < 0 || width < 0 || height < 0 || x + width > target.width || y + height > target.height)
|
||||
throw FormatError("contracts: invalid fill bounds");
|
||||
for (int row = 0; row < height; ++row)
|
||||
std::fill_n(target.pixels.begin() + size_t(y + row) * size_t(target.width) + size_t(x), size_t(width), color);
|
||||
draw::fill(target, x, y, width, height, color);
|
||||
}
|
||||
|
||||
// Formats a number right-aligned in `width` characters; with `grouped`, '.' is inserted as thousands separator
|
||||
|
||||
+3
-4
@@ -20,6 +20,7 @@
|
||||
#include "game/state.hpp"
|
||||
#include "game/season.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -34,8 +35,7 @@ void copy(Image& dst,const Image& src,int sx,int sy,int x,int y,int w,int h) {
|
||||
// FormatError2 passes ff as the VGA plane bitmask. The copy is opaque and an
|
||||
// out-of-bounds rectangle is rejected in full by SourceMaskCopy.
|
||||
if(!valid_rect(dst,src,sx,sy,x,y,w,h))return;
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx)
|
||||
dst.at(x+xx,y+yy)=src.pixels[size_t(sy+yy)*size_t(src.width)+size_t(sx+xx)];
|
||||
draw::copy_unclipped(dst, src, sx, sy, x, y, w, h, -1);
|
||||
}
|
||||
void copy_key0(Image& dst,const Image& src,int sx,int sy,int x,int y,int w,int h) {
|
||||
if(!valid_rect(dst,src,sx,sy,x,y,w,h))return;
|
||||
@@ -45,8 +45,7 @@ void copy_key0(Image& dst,const Image& src,int sx,int sy,int x,int y,int w,int h
|
||||
}
|
||||
}
|
||||
void fill(Image& out,int x,int y,int w,int h,uint8_t c) {
|
||||
for(int yy=std::max(0,y);yy<std::min(out.height,y+h);++yy)
|
||||
for(int xx=std::max(0,x);xx<std::min(out.width,x+w);++xx)out.at(xx,yy)=c;
|
||||
draw::fill(out, x, y, w, h, c);
|
||||
}
|
||||
void source_frame(Image& out,int x,int y) {
|
||||
for(int xx=x-1;xx<=x+38;++xx)if(xx>=0&&xx<out.width&&y-1>=0&&y-1<out.height)out.at(xx,y-1)=0x46;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "game/messages.hpp"
|
||||
#include "game/schedule.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
#include "formats/textd.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
@@ -20,12 +21,10 @@ namespace {
|
||||
void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h) {
|
||||
if (sx < 0 || sy < 0 || x < 0 || y < 0 || sx+w>src.width || sy+h>src.height ||
|
||||
x+w>out.width || y+h>out.height) throw FormatError("desk records: Original asset bounds");
|
||||
for(int yy=0;yy<h;++yy) for(int xx=0;xx<w;++xx)
|
||||
out.at(x+xx,y+yy)=src.pixels[size_t(sy+yy)*size_t(src.width)+size_t(sx+xx)];
|
||||
draw::copy_unclipped(out, src, sx, sy, x, y, w, h, -1);
|
||||
}
|
||||
void fill_rect(Image& out,int x,int y,int w,int h,uint8_t color) {
|
||||
for(int yy=std::max(0,y);yy<std::min(out.height,y+h);++yy)
|
||||
for(int xx=std::max(0,x);xx<std::min(out.width,x+w);++xx) out.at(xx,yy)=color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
uint8_t source_team_color(const GameState& g,int team) {
|
||||
const size_t count=std::min<size_t>(g.manager_teams.size(),4);
|
||||
|
||||
+3
-7
@@ -11,23 +11,19 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "game/messages.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
void rect(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx) out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h, bool transparent = false) {
|
||||
if (sx < 0 || sy < 0 || sx + w > src.width || sy + h > src.height)
|
||||
throw FormatError("desktop: sprite outside original atlas");
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const auto color = src.pixels[size_t(sy + yy) * src.width + sx + xx];
|
||||
if (x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height && (!transparent || color))
|
||||
out.at(x + xx, y + yy) = color;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent ? 0 : -1);
|
||||
}
|
||||
void border(Image& out, int x, int y) {
|
||||
rect(out, x - 1, y - 1, 40, 1, 0x46); rect(out, x - 1, y - 1, 1, 40, 0x46);
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
#pragma once
|
||||
// The pixel loops shared by the screens: filling a rectangle and copying a rectangle of a picture
|
||||
// (an atlas) into another, with or without a transparent colour.
|
||||
//
|
||||
// Nearly every screen had its own copy of these loops in an anonymous namespace (about 75 copies).
|
||||
// The screens keep their own small wrappers, because what they check before drawing differs and is
|
||||
// part of their contract: some reject a source rectangle outside the atlas with their own error
|
||||
// text, some reject a destination outside the screen, some clip silently. Only the loops are here.
|
||||
//
|
||||
// Conventions: `key` is the transparent palette index; a value outside 0..255 (the default -1)
|
||||
// copies every pixel. Rectangles are x, y, width, height; empty or negative sizes draw nothing.
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "formats/vga.hpp"
|
||||
|
||||
namespace bmh::ui::draw {
|
||||
|
||||
// Fills the part of the rectangle that lies inside the image.
|
||||
inline void fill(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
const int x0 = std::max(0, x), y0 = std::max(0, y);
|
||||
const int x1 = std::min(out.width, x + w), y1 = std::min(out.height, y + h);
|
||||
for (int yy = y0; yy < y1; ++yy)
|
||||
for (int xx = x0; xx < x1; ++xx) out.pixels[size_t(yy) * size_t(out.width) + size_t(xx)] = color;
|
||||
}
|
||||
|
||||
// True when the rectangle lies completely inside the image (and has no negative size).
|
||||
inline bool inside(const Image& image, int x, int y, int w, int h) {
|
||||
return x >= 0 && y >= 0 && w >= 0 && h >= 0 && x + w <= image.width && y + h <= image.height;
|
||||
}
|
||||
|
||||
// Copies w x h pixels from (sx, sy) of `src` to (x, y) of `out`; pixels that fall outside `out` are
|
||||
// skipped. The source rectangle must lie inside `src` (the caller checks that and reports its own error).
|
||||
inline void copy_clipped(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h, int key = -1) {
|
||||
for (int yy = 0; yy < h; ++yy) {
|
||||
const int ty = y + yy;
|
||||
if (ty < 0 || ty >= out.height) continue;
|
||||
for (int xx = 0; xx < w; ++xx) {
|
||||
const int tx = x + xx;
|
||||
if (tx < 0 || tx >= out.width) continue;
|
||||
const uint8_t c = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
if (int(c) != key) out.pixels[size_t(ty) * size_t(out.width) + size_t(tx)] = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The same without clipping: both rectangles must lie inside their images (checked by the caller).
|
||||
inline void copy_unclipped(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h, int key = -1) {
|
||||
for (int yy = 0; yy < h; ++yy)
|
||||
for (int xx = 0; xx < w; ++xx) {
|
||||
const uint8_t c = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
if (int(c) != key) out.pixels[size_t(y + yy) * size_t(out.width) + size_t(x + xx)] = c;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace bmh::ui::draw
|
||||
+3
-6
@@ -18,18 +18,15 @@
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/sprite_font.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
void copy(Image& d,const Image& s,int sx,int sy,int x,int y,int w,int h,bool transparent=false) {
|
||||
for(int yy=0;yy<h;++yy) for(int xx=0;xx<w;++xx) {
|
||||
const auto p=s.pixels[size_t(sy+yy)*size_t(s.width)+size_t(sx+xx)];
|
||||
if(x+xx>=0&&y+yy>=0&&x+xx<d.width&&y+yy<d.height&&(!transparent||p)) d.at(x+xx,y+yy)=p;
|
||||
}
|
||||
draw::copy_clipped(d, s, sx, sy, x, y, w, h, transparent ? 0 : -1);
|
||||
}
|
||||
void fill(Image& im,int x,int y,int w,int h,uint8_t c) {
|
||||
for(int yy=std::max(0,y);yy<std::min(im.height,y+h);++yy)
|
||||
for(int xx=std::max(0,x);xx<std::min(im.width,x+w);++xx) im.at(xx,yy)=c;
|
||||
draw::fill(im, x, y, w, h, c);
|
||||
}
|
||||
Image source_base(const Image& original,bool plain_background,bool has_header_footer_text) {
|
||||
if(!plain_background) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/pending_offer.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -42,10 +43,7 @@ void copy_region(Image& target, const Image& source, int sx, int sy, int x, int
|
||||
sx + width > source.width || sy + height > source.height ||
|
||||
x + width > target.width || y + height > target.height)
|
||||
throw FormatError("incoming transfer: invalid original sprite bounds");
|
||||
for (int yy = 0; yy < height; ++yy) for (int xx = 0; xx < width; ++xx) {
|
||||
const auto value = source.pixels[size_t(sy + yy) * size_t(source.width) + size_t(xx + sx)];
|
||||
if (transparent_index < 0 || value != transparent_index) target.at(x + xx, y + yy) = value;
|
||||
}
|
||||
draw::copy_unclipped(target, source, sx, sy, x, y, width, height, transparent_index);
|
||||
}
|
||||
|
||||
// Formats a number right-aligned in `width` characters ('%' padding, as the original font expects);
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "game/season.hpp"
|
||||
#include "ui/desk_state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -38,13 +39,10 @@ void copy(Image& out,const Image& src,int sx,int sy,int x,int y,int w,int h,int
|
||||
throw FormatError("pairings: Original atlas bounds (source "+std::to_string(src.width)+"x"+
|
||||
std::to_string(src.height)+", crop "+std::to_string(sx)+","+std::to_string(sy)+" "+
|
||||
std::to_string(w)+"x"+std::to_string(h)+", destination "+std::to_string(x)+","+std::to_string(y)+")");
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx) {
|
||||
const uint8_t v=src.pixels[size_t(sy+yy)*size_t(src.width)+size_t(sx+xx)];if(v!=transparent)out.at(x+xx,y+yy)=v;
|
||||
}
|
||||
draw::copy_unclipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
void fill(Image& out,int x,int y,int w,int h,uint8_t color) {
|
||||
for(int yy=std::max(0,y);yy<std::min(out.height,y+h);++yy)
|
||||
for(int xx=std::max(0,x);xx<std::min(out.width,x+w);++xx)out.at(xx,yy)=color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "game/table.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -92,15 +93,11 @@ void copy_region(Image& out, const Image& source, int sx, int sy, int x, int y,
|
||||
sx + width > source.width || sy + height > source.height ||
|
||||
x + width > out.width || y + height > out.height)
|
||||
throw FormatError("league table: original atlas bounds");
|
||||
for (int dy = 0; dy < height; ++dy) for (int dx = 0; dx < width; ++dx) {
|
||||
const auto pixel = source.pixels[size_t(sy + dy) * size_t(source.width) + size_t(sx + dx)];
|
||||
if (pixel != transparent) out.at(x + dx, y + dy) = pixel;
|
||||
}
|
||||
draw::copy_unclipped(out, source, sx, sy, x, y, width, height, transparent);
|
||||
}
|
||||
|
||||
void fill_region(Image& out, int x, int y, int width, int height, uint8_t color) {
|
||||
for (int dy = y; dy < y + height; ++dy)
|
||||
for (int dx = x; dx < x + width; ++dx) out.at(dx, dy) = color;
|
||||
draw::fill(out, x, y, width, height, color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-6
@@ -12,6 +12,7 @@
|
||||
#include "formats/savestate.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -77,15 +78,11 @@ LineupState project(const StaticMemory& memory, const LeImage& exe, const std::v
|
||||
return out;
|
||||
}
|
||||
void rect(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0,y); yy < std::min(out.height,y+h); ++yy)
|
||||
for (int xx = std::max(0,x); xx < std::min(out.width,x+w); ++xx) out.at(xx,yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h, int transparent = -1) {
|
||||
if (sx < 0 || sy < 0 || sx+w > src.width || sy+h > src.height) throw FormatError("lineup: original atlas bounds " + std::to_string(sx) + "," + std::to_string(sy) + ":" + std::to_string(w) + "x" + std::to_string(h) + " in " + std::to_string(src.width) + "x" + std::to_string(src.height));
|
||||
for (int yy=0; yy<h; ++yy) for (int xx=0; xx<w; ++xx) {
|
||||
const auto c=src.pixels.at(size_t(sy+yy)*src.width+sx+xx);
|
||||
if (c != transparent && x+xx>=0 && x+xx<out.width && y+yy>=0 && y+yy<out.height) out.at(x+xx,y+yy)=c;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
std::string number(uint64_t value, int width = 2) {
|
||||
auto s=std::to_string(value);
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// validating substitution, formation, position and tactic proposals against the copied context, serialising
|
||||
// a proposal to JSON, and rendering the lineup, formation and tactics pages. Proposals are descriptive only.
|
||||
#include "ui/live_intervention.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
#include "formats/binary.hpp"
|
||||
|
||||
@@ -157,9 +158,7 @@ std::string live_intervention_proposal_json(const LiveInterventionProposal& p) {
|
||||
|
||||
namespace {
|
||||
void fill(Image& image, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int py = std::max(0, y); py < std::min(image.height, y + h); ++py)
|
||||
for (int px = std::max(0, x); px < std::min(image.width, x + w); ++px)
|
||||
image.at(px, py) = color;
|
||||
draw::fill(image, x, y, w, h, color);
|
||||
}
|
||||
|
||||
struct Glyph { char ch; std::array<uint8_t, 7> rows; };
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/live_set_piece.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -24,12 +25,7 @@ void copy_region(Image& target, const Image& source, int sx, int sy, int dx, int
|
||||
int width, int height, int transparent = -1) {
|
||||
if (sx < 0 || sy < 0 || width < 0 || height < 0 || sx + width > source.width || sy + height > source.height)
|
||||
throw FormatError("live matchday: original asset crop out of bounds");
|
||||
for (int y = 0; y < height; ++y) for (int x = 0; x < width; ++x) {
|
||||
const uint8_t pixel = source.pixels[size_t(sy + y) * size_t(source.width) + size_t(sx + x)];
|
||||
const int tx = dx + x, ty = dy + y;
|
||||
if (pixel != transparent && tx >= 0 && ty >= 0 && tx < target.width && ty < target.height)
|
||||
target.at(tx, ty) = pixel;
|
||||
}
|
||||
draw::copy_clipped(target, source, sx, sy, dx, dy, width, height, transparent);
|
||||
}
|
||||
|
||||
void pattern_rect(Image& target, const LeImage& exe, int x, int y, int width, int height) {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/game_end.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -23,11 +24,7 @@ void copy(Image& out, const Image& source, int sx, int sy, int dx, int dy, int w
|
||||
bool transparent = false) {
|
||||
if (sx < 0 || sy < 0 || sx + w > source.width || sy + h > source.height)
|
||||
throw FormatError("mailbox: sprite outside original atlas");
|
||||
for (int y = 0; y < h; ++y) for (int x = 0; x < w; ++x) {
|
||||
const auto c = source.pixels[size_t(sy + y) * source.width + sx + x];
|
||||
if ((!transparent || c) && dx + x >= 0 && dy + y >= 0 &&
|
||||
dx + x < out.width && dy + y < out.height) out.at(dx + x, dy + y) = c;
|
||||
}
|
||||
draw::copy_clipped(out, source, sx, sy, dx, dy, w, h, transparent ? 0 : -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-8
@@ -7,6 +7,7 @@
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/dialog_frame.hpp"
|
||||
#include "ui/button_frame.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
#include "formats/league_visibility.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -21,19 +22,13 @@ namespace bmh::ui {
|
||||
namespace {
|
||||
|
||||
void rect(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(y, 0); yy < std::min(y + h, out.height); ++yy)
|
||||
for (int xx = std::max(x, 0); xx < std::min(x + w, out.width); ++xx) out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
|
||||
void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h, bool transparent = false) {
|
||||
if (sx < 0 || sy < 0 || sx + w > src.width || sy + h > src.height)
|
||||
throw FormatError("manager: sprite outside original atlas");
|
||||
for (int yy = 0; yy < h; ++yy)
|
||||
for (int xx = 0; xx < w; ++xx) {
|
||||
const auto c = src.pixels[size_t(sy + yy) * src.width + sx + xx];
|
||||
if (x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height && (!transparent || c))
|
||||
out.at(x + xx, y + yy) = c;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent ? 0 : -1);
|
||||
}
|
||||
|
||||
void border(Image& out, int x, int y) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "game/messages.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -28,11 +29,7 @@ void copy_transparent(Image& target, const Image& source, int sx, int sy,
|
||||
sx + width > source.width || sy + height > source.height ||
|
||||
dx + width > target.width || dy + height > target.height)
|
||||
throw FormatError("minute statistics: Original KB36 crop outside image");
|
||||
for (int y = 0; y < height; ++y)
|
||||
for (int x = 0; x < width; ++x) {
|
||||
const uint8_t pixel = source.pixels[size_t(sy + y) * size_t(source.width) + size_t(sx + x)];
|
||||
if (pixel != transparent) target.at(dx + x, dy + y) = pixel;
|
||||
}
|
||||
draw::copy_unclipped(target, source, sx, sy, dx, dy, width, height, transparent);
|
||||
}
|
||||
|
||||
// SourceBarColor / SourceBarColor2 scan each current 18-byte series. Their
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -17,14 +18,10 @@ void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int
|
||||
if (sx < 0 || sy < 0 || x < 0 || y < 0 || w < 0 || h < 0 ||
|
||||
sx + w > src.width || sy + h > src.height || x + w > out.width || y + h > out.height)
|
||||
throw FormatError("opportunities: Original sprite bounds");
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const auto pixel = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
if (pixel != transparent) out.at(x + xx, y + yy) = pixel;
|
||||
}
|
||||
draw::copy_unclipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
void fill(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = y; yy < y + h; ++yy) for (int xx = x; xx < x + w; ++xx)
|
||||
out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
std::string original_text(const TextDb& texts, uint32_t at) {
|
||||
if (at < ::bmh::layout::TextPointerTable || ((at - ::bmh::layout::TextPointerTable) & 3U))
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -19,18 +20,12 @@ void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int
|
||||
if (sx < 0 || sy < 0 || x < 0 || y < 0 || w < 0 || h < 0 ||
|
||||
sx + w > src.width || sy + h > src.height || x + w > out.width || y + h > out.height)
|
||||
throw FormatError("other games: Original atlas bounds");
|
||||
for (int yy = 0; yy < h; ++yy)
|
||||
for (int xx = 0; xx < w; ++xx) {
|
||||
const uint8_t color = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
if (color != transparent) out.at(x + xx, y + yy) = color;
|
||||
}
|
||||
draw::copy_unclipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
|
||||
void fill(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
if (w <= 0 || h <= 0) return;
|
||||
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx)
|
||||
out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
|
||||
std::string source_number(unsigned value, unsigned width = 0) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "formats/textd.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -45,18 +46,14 @@ void copy_region(Image& target, const Image& source, int sx, int sy, int x, int
|
||||
sx + width > source.width || sy + height > source.height ||
|
||||
x + width > target.width || y + height > target.height)
|
||||
throw FormatError("outgoing transfer: invalid Source sprite bounds");
|
||||
for (int yy = 0; yy < height; ++yy) for (int xx = 0; xx < width; ++xx) {
|
||||
const auto pixel = source.pixels[size_t(sy + yy) * size_t(source.width) + size_t(sx + xx)];
|
||||
if (transparent < 0 || pixel != transparent) target.at(x + xx, y + yy) = pixel;
|
||||
}
|
||||
draw::copy_unclipped(target, source, sx, sy, x, y, width, height, transparent);
|
||||
}
|
||||
|
||||
// Fills a rectangle with one palette index; throws if it leaves the image.
|
||||
void fill_rect(Image& out, int x, int y, int width, int height, uint8_t color) {
|
||||
if (x < 0 || y < 0 || width < 0 || height < 0 || x + width > out.width || y + height > out.height)
|
||||
throw FormatError("outgoing transfer: invalid Source rectangle");
|
||||
for (int yy = y; yy < y + height; ++yy)
|
||||
std::fill_n(out.pixels.begin() + size_t(yy) * size_t(out.width) + size_t(x), width, color);
|
||||
draw::fill(out, x, y, width, height, color);
|
||||
}
|
||||
|
||||
// Number with '.' as thousands separator, no padding.
|
||||
|
||||
+3
-4
@@ -14,6 +14,7 @@
|
||||
#include "game/messages.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -23,8 +24,7 @@ Bytes block(const SaveState& save, uint32_t address) {
|
||||
}
|
||||
void copy(Image& out,const Image& src,int sx,int sy,int x,int y,int w,int h,int transparent=-1) {
|
||||
if(sx<0||sy<0||sx+w>src.width||sy+h>src.height)throw FormatError("pitch: original atlas bounds");
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx){const auto c=src.pixels.at(size_t(sy+yy)*src.width+sx+xx);
|
||||
if(c!=transparent&&x+xx>=0&&y+yy>=0&&x+xx<out.width&&y+yy<out.height)out.at(x+xx,y+yy)=c;}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
void source_mask_copy(Image& out,const Image& src,int sx,int sy,int x,int y,int w,int h,
|
||||
int transparent=-1) {
|
||||
@@ -41,8 +41,7 @@ void source_mask_copy(Image& out,const Image& src,int sx,int sy,int x,int y,int
|
||||
}
|
||||
}
|
||||
void rect(Image& out,int x,int y,int w,int h,uint8_t color){
|
||||
for(int yy=std::max(0,y);yy<std::min(out.height,y+h);++yy)
|
||||
for(int xx=std::max(0,x);xx<std::min(out.width,x+w);++xx)out.at(xx,yy)=color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
const char* kind_name(PitchRequestKind k){switch(k){case PitchRequestKind::none:return "none";
|
||||
case PitchRequestKind::move_player:return "move_player";case PitchRequestKind::swap_players:return "swap_players";
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "formats/savestate.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -95,17 +96,13 @@ void context(PlayerCardState& out,const StaticMemory& memory,const Bytes& club_h
|
||||
}
|
||||
}
|
||||
void rect(Image& out,int x,int y,int w,int h,uint8_t c) {
|
||||
for(int yy=std::max(0,y);yy<std::min(out.height,y+h);++yy)
|
||||
for(int xx=std::max(0,x);xx<std::min(out.width,x+w);++xx)out.at(xx,yy)=c;
|
||||
draw::fill(out, x, y, w, h, c);
|
||||
}
|
||||
void copy(Image& out,const Image& src,int sx,int sy,int x,int y,int w,int h,int transparent=-1) {
|
||||
if(sx<0||sy<0||sx+w>src.width||sy+h>src.height)
|
||||
throw FormatError("player card: original atlas bounds "+std::to_string(sx)+","+std::to_string(sy)+
|
||||
":"+std::to_string(w)+"x"+std::to_string(h)+" in "+std::to_string(src.width)+"x"+std::to_string(src.height));
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx){
|
||||
const auto c=src.pixels.at(size_t(sy+yy)*src.width+sx+xx);
|
||||
if(c!=transparent&&x+xx>=0&&x+xx<out.width&&y+yy>=0&&y+yy<out.height)out.at(x+xx,y+yy)=c;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
std::string number(int64_t value,int width=1,bool grouped=false) {
|
||||
auto n=std::to_string(value);const bool negative=value<0;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "ui/game_end.hpp"
|
||||
#include "ui/host_path.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
#include "formats/fbm.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
@@ -42,8 +43,7 @@ std::string_view text_at(const TextDb& texts, uint32_t address) {
|
||||
return texts[(address - kTextBase) / 4];
|
||||
}
|
||||
void rect(Image& image, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(image.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(image.width, x + w); ++xx) image.at(xx, yy) = color;
|
||||
draw::fill(image, x, y, w, h, color);
|
||||
}
|
||||
bool has_file_kind_extension(const std::filesystem::path& path, SaveLoadFileKind kind) {
|
||||
std::string ext = path_to_utf8(path.extension());
|
||||
@@ -58,9 +58,7 @@ std::string_view file_kind_extension(SaveLoadFileKind kind) {
|
||||
void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h) {
|
||||
if (sx < 0 || sy < 0 || sx + w > src.width || sy + h > src.height)
|
||||
throw FormatError("save/load: Original widget outside atlas");
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx)
|
||||
if (x + xx >= 0 && x + xx < out.width && y + yy >= 0 && y + yy < out.height)
|
||||
out.at(x + xx, y + yy) = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, -1);
|
||||
}
|
||||
void pattern(Image& out, const LeImage& exe, int x, int y, int w, int h) {
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx)
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "formats/textd.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -20,9 +21,7 @@ constexpr int kMaxEntrants = 32;
|
||||
constexpr int kPlacementSlots = 8;
|
||||
|
||||
void fill(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx)
|
||||
out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
|
||||
void source_badge_frame(Image& out, int x, int y) {
|
||||
|
||||
+2
-7
@@ -2,6 +2,7 @@
|
||||
// Implementation of SetupScreen (setup.hpp): layout tables read from the executable, shared render and hit-testing, and the limits between managers and league/world options.
|
||||
#include "formats/executable_layout.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
@@ -19,13 +20,7 @@ void copy_rect(Image& dst, const Image& src, int sx, int sy, int dx, int dy,
|
||||
int width, int height, bool transparent = false) {
|
||||
if (sx < 0 || sy < 0 || sx + width > src.width || sy + height > src.height)
|
||||
throw FormatError("setup: original sprite rectangle outside atlas");
|
||||
for (int y = 0; y < height; ++y)
|
||||
for (int x = 0; x < width; ++x) {
|
||||
auto c = src.pixels[size_t(sy + y) * src.width + sx + x];
|
||||
if (dx + x >= 0 && dy + y >= 0 && dx + x < dst.width && dy + y < dst.height &&
|
||||
(!transparent || c != 0))
|
||||
dst.at(dx + x, dy + y) = c;
|
||||
}
|
||||
draw::copy_clipped(dst, src, sx, sy, dx, dy, width, height, transparent ? 0 : -1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
+2
-3
@@ -20,14 +20,13 @@
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
// Fills a w*h rectangle with one palette index, clipped to the image. Used for panels, shadows and backgrounds.
|
||||
void fill(Image& im, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(im.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(im.width, x + w); ++xx)
|
||||
im.at(xx, yy) = color;
|
||||
draw::fill(im, x, y, w, h, color);
|
||||
}
|
||||
// Draws a 1-pixel rectangle outline (w*h, clipped to the image). Used for hover and press highlights.
|
||||
void outline(Image& im, int x, int y, int w, int h, uint8_t color) {
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -25,18 +26,13 @@ void copy_transparent(Image& out, const Image& src, int sx, int sy, int x, int y
|
||||
if (sx < 0 || sy < 0 || x < 0 || y < 0 || w < 0 || h < 0 ||
|
||||
sx + w > src.width || sy + h > src.height || x + w > out.width || y + h > out.height)
|
||||
throw FormatError("statistics rankings: Original sprite bounds");
|
||||
for (int yy = 0; yy < h; ++yy)
|
||||
for (int xx = 0; xx < w; ++xx) {
|
||||
const uint8_t color = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
if (color != 0xc0) out.at(x + xx, y + yy) = color;
|
||||
}
|
||||
draw::copy_unclipped(out, src, sx, sy, x, y, w, h, 0xc0);
|
||||
}
|
||||
|
||||
void fill(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
if (x < 0 || y < 0 || w < 0 || h < 0 || x + w > out.width || y + h > out.height)
|
||||
throw FormatError("statistics rankings: Original button bounds");
|
||||
for (int yy = y; yy < y + h; ++yy)
|
||||
for (int xx = x; xx < x + w; ++xx) out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
|
||||
uint8_t original_name_color(const GameState& game, int runtime_team) {
|
||||
|
||||
@@ -6,18 +6,17 @@
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h, int transparent = -1) {
|
||||
if (sx<0||sy<0||x<0||y<0||w<0||h<0||sx+w>src.width||sy+h>src.height||x+w>out.width||y+h>out.height)
|
||||
throw FormatError("strengths: Original atlas bounds");
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx) {
|
||||
const auto v=src.pixels[size_t(sy+yy)*size_t(src.width)+size_t(sx+xx)]; if(v!=transparent)out.at(x+xx,y+yy)=v;
|
||||
}
|
||||
draw::copy_unclipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
void fill(Image& out,int x,int y,int w,int h,uint8_t c) {
|
||||
for(int yy=y;yy<y+h;++yy)for(int xx=x;xx<x+w;++xx)out.at(xx,yy)=c;
|
||||
draw::fill(out, x, y, w, h, c);
|
||||
}
|
||||
std::string number(unsigned value,int width) {
|
||||
auto s=std::to_string(value);if(int(s.size())<width)s.insert(0,size_t(width-int(s.size())),'%');return s;
|
||||
|
||||
+3
-7
@@ -9,6 +9,7 @@
|
||||
#include "formats/savestate.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -57,17 +58,12 @@ TacticsState project(const StaticMemory& memory, const Bytes& managers, const By
|
||||
return s;
|
||||
}
|
||||
void rect(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx) out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h, bool transparent = false) {
|
||||
if (sx < 0 || sy < 0 || sx + w > src.width || sy + h > src.height)
|
||||
throw FormatError("tactics: sprite outside original atlas");
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const auto c = src.pixels.at(size_t(sy + yy) * src.width + sx + xx);
|
||||
if (x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height && (!transparent || c))
|
||||
out.at(x + xx, y + yy) = c;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent ? 0 : -1);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "game/season.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -20,15 +21,10 @@ void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int
|
||||
int transparent = -1) {
|
||||
if (sx < 0 || sy < 0 || w < 0 || h < 0 || sx + w > src.width || sy + h > src.height)
|
||||
throw FormatError("team statistics: Source asset bounds");
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const uint8_t value = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
if (value != transparent && x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height)
|
||||
out.at(x + xx, y + yy) = value;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
void rect(Image& out, int x, int y, int w, int h, uint8_t value) {
|
||||
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx) out.at(xx, yy) = value;
|
||||
draw::fill(out, x, y, w, h, value);
|
||||
}
|
||||
void source_frame(Image& out, const Image& widgets, const LeImage& exe,
|
||||
int x, int y, int w, int h, uint8_t color) {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -25,15 +26,11 @@ void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int
|
||||
if (sx < 0 || sy < 0 || x < 0 || y < 0 || w < 0 || h < 0 ||
|
||||
sx + w > src.width || sy + h > src.height || x + w > out.width || y + h > out.height)
|
||||
throw FormatError("top scorers: Original sprite bounds");
|
||||
for (int yy = 0; yy < h; ++yy)
|
||||
for (int xx = 0; xx < w; ++xx)
|
||||
out.at(x + xx, y + yy) = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
draw::copy_unclipped(out, src, sx, sy, x, y, w, h, -1);
|
||||
}
|
||||
|
||||
void fill(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = y; yy < y + h; ++yy)
|
||||
for (int xx = x; xx < x + w; ++xx)
|
||||
out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
|
||||
std::string source_number(unsigned value, unsigned width = 0) {
|
||||
|
||||
+3
-7
@@ -12,6 +12,7 @@
|
||||
#include "formats/savestate.hpp"
|
||||
#include "game/state.hpp"
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -84,17 +85,12 @@ TrainingState project(const StaticMemory& memory, const Bytes& records, const By
|
||||
validate(s); return s;
|
||||
}
|
||||
void rect(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx) out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
void copy(Image& out, const Image& atlas, int sx, int sy, int x, int y, int w, int h, int transparent = -1) {
|
||||
if (sx < 0 || sy < 0 || sx + w > atlas.width || sy + h > atlas.height)
|
||||
throw FormatError("training: sprite outside original atlas");
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const auto c = atlas.pixels[size_t(sy + yy) * atlas.width + sx + xx];
|
||||
if (c != transparent && x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height)
|
||||
out.at(x + xx, y + yy) = c;
|
||||
}
|
||||
draw::copy_clipped(out, atlas, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
const char* request_name(TrainingRequestKind kind) {
|
||||
switch (kind) {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "ui/manager.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/game_end.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -28,15 +29,10 @@ constexpr size_t kMoney = 0x314;
|
||||
void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int h, int transparent = -1) {
|
||||
if (sx < 0 || sy < 0 || sx + w > src.width || sy + h > src.height)
|
||||
throw FormatError("training camp: sprite outside original atlas");
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const uint8_t color = src.pixels[size_t(sy + yy) * src.width + sx + xx];
|
||||
if (x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height && color != transparent)
|
||||
out.at(x + xx, y + yy) = color;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
void rect(Image& out, int x, int y, int w, int h, uint8_t color) {
|
||||
for (int yy = std::max(0, y); yy < std::min(out.height, y + h); ++yy)
|
||||
for (int xx = std::max(0, x); xx < std::min(out.width, x + w); ++xx) out.at(xx, yy) = color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
int32_t rd32(const std::vector<uint8_t>& v, size_t at) {
|
||||
return int32_t(uint32_t(v.at(at)) | uint32_t(v.at(at + 1)) << 8 | uint32_t(v.at(at + 2)) << 16 |
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "game/state.hpp"
|
||||
#include "game/messages.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -27,18 +28,14 @@ constexpr size_t kManagerRecordSize = 0xb0c;
|
||||
|
||||
// Fills a rectangle with one palette index, clipped to the image.
|
||||
void rect(Image& out,int x,int y,int w,int h,uint8_t color) {
|
||||
for(int yy=std::max(0,y);yy<std::min(out.height,y+h);++yy)
|
||||
for(int xx=std::max(0,x);xx<std::min(out.width,x+w);++xx)out.at(xx,yy)=color;
|
||||
draw::fill(out, x, y, w, h, color);
|
||||
}
|
||||
// Copies a w*h block from a source image to the output at (x,y), clipped to the output.
|
||||
// Pixels equal to `key` are skipped (transparent); throws if the source rectangle is invalid.
|
||||
void copy(Image& out,const Image& source,int sx,int sy,int x,int y,int w,int h,int key=-1) {
|
||||
if(sx<0||sy<0||w<0||h<0||sx+w>source.width||sy+h>source.height)
|
||||
throw FormatError("transfer market: Original asset rectangle outside source");
|
||||
for(int yy=0;yy<h;++yy)for(int xx=0;xx<w;++xx) {
|
||||
const auto pixel=source.pixels.at(size_t(sy+yy)*size_t(source.width)+size_t(sx+xx));
|
||||
if(pixel!=key&&x+xx>=0&&x+xx<out.width&&y+yy>=0&&y+yy<out.height)out.at(x+xx,y+yy)=pixel;
|
||||
}
|
||||
draw::copy_clipped(out, source, sx, sy, x, y, w, h, key);
|
||||
}
|
||||
// Decimal text of n, left-padded to `width` with '%' characters (used to align number columns).
|
||||
std::string padded(uint64_t n,int width=2) {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "formats/vga.hpp"
|
||||
#include "game/messages.hpp"
|
||||
#include "ui/setup.hpp"
|
||||
#include "ui/draw.hpp"
|
||||
|
||||
namespace bmh::ui {
|
||||
namespace {
|
||||
@@ -22,11 +23,7 @@ void copy(Image& out, const Image& src, int sx, int sy, int x, int y, int w, int
|
||||
int transparent = -1) {
|
||||
if (sx < 0 || sy < 0 || sx + w > src.width || sy + h > src.height)
|
||||
throw FormatError("World Cup statistics: Source atlas bounds");
|
||||
for (int yy = 0; yy < h; ++yy) for (int xx = 0; xx < w; ++xx) {
|
||||
const uint8_t value = src.pixels[size_t(sy + yy) * size_t(src.width) + size_t(sx + xx)];
|
||||
if (value != transparent && x + xx >= 0 && y + yy >= 0 && x + xx < out.width && y + yy < out.height)
|
||||
out.at(x + xx, y + yy) = value;
|
||||
}
|
||||
draw::copy_clipped(out, src, sx, sy, x, y, w, h, transparent);
|
||||
}
|
||||
|
||||
void draw_text(const Font& font, Image& out, int x, int baseline, const std::string& value, uint8_t color) {
|
||||
|
||||
Reference in new issue
Block a user