15 int source_bitmap_width_px,
17 float display_scale) {
18 if (source_bitmap_width_px <= 0 || max_tile_count <= 0 ||
22 if (mouse_x < 0.0f || mouse_y < 0.0f) {
26 const int tile_x =
static_cast<int>(mouse_x / (8.0f * display_scale));
27 const int tile_y =
static_cast<int>(mouse_y / (8.0f * display_scale));
28 if (tile_x < 0 || tile_y < 0) {
32 const int tiles_per_row = source_bitmap_width_px / 8;
33 if (tiles_per_row <= 0) {
37 const int tile8_id = tile_x + (tile_y * tiles_per_row);
38 if (tile8_id < 0 || tile8_id >= max_tile_count) {
45 int source_bitmap_width_px,
46 float min_scale = 1.0f,
47 float max_scale = 4.0f) {
48 if (source_bitmap_width_px <= 0 || available_width_px <= 0.0f ||
49 min_scale <= 0.0f || max_scale < min_scale) {
55 constexpr float kHorizontalChromeAllowance = 24.0f;
56 const float usable_width =
57 std::max(1.0f, available_width_px - kHorizontalChromeAllowance);
58 const float fit_scale =
59 usable_width /
static_cast<float>(source_bitmap_width_px);
60 if (fit_scale < min_scale) {
64 constexpr float kAbsoluteMinimumReadableScale = 0.35f;
65 return std::clamp(fit_scale, kAbsoluteMinimumReadableScale, max_scale);
67 return std::clamp(fit_scale, min_scale, max_scale);
71 int source_bitmap_height_px,
73 float preferred_height_px = 0.0f,
74 float min_height_px = 220.0f,
75 float max_height_px = 520.0f) {
76 if (min_height_px <= 0.0f) {
79 max_height_px = std::max(min_height_px, max_height_px);
81 constexpr float kVerticalChromeAllowance = 18.0f;
82 const float sheet_height =
83 source_bitmap_height_px > 0 && display_scale > 0.0f
84 ? (
static_cast<float>(source_bitmap_height_px) * display_scale) +
85 kVerticalChromeAllowance
89 preferred_height_px > 0.0f ? preferred_height_px : sheet_height;
90 target_height = std::clamp(target_height, min_height_px, max_height_px);
92 if (available_height_px <= 0.0f) {
96 const float clamped_max_height =
97 std::min(max_height_px, std::max(1.0f, available_height_px));
98 const float clamped_min_height = std::min(min_height_px, clamped_max_height);
99 return std::clamp(target_height, clamped_min_height, clamped_max_height);
float ComputeTile8SourcePanelHeight(float available_height_px, int source_bitmap_height_px, float display_scale, float preferred_height_px=0.0f, float min_height_px=220.0f, float max_height_px=520.0f)