Skip to content

Commit

Permalink
Merge branch 'erik-750-slider' into erik-800-transform-fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Corry committed Dec 5, 2023
2 parents 75ea839 + ff2a254 commit f14aca7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

cmake_minimum_required(VERSION 3.22)

# Avoid testing the C compiler.
PROJECT(MakeTags NONE)

project(cli)
# NONE means skip testing the C compiler.
project(pixel_display NONE)

enable_testing()
add_subdirectory(tests)
32 changes: 20 additions & 12 deletions src/pixel_display.toit
Original file line number Diff line number Diff line change
Expand Up @@ -322,18 +322,6 @@ abstract class PixelDisplay implements Window:

// Clean determines if we should clean or draw the dirty area.
update_frame_buffer clean/bool refresh_dimensions -> none:
width_target := 64
width := ?
max_height := ?
while true:
width = min driver_.width (width_target - 8)
max_height = max
round_down (max_canvas_height_ width) y_rounding_
y_rounding_
if max_height < driver_.height: break
if width >= driver_.width: break
width_target += width_target

redraw := : | l t r b |
if clean:
clean_rect_ l t r b
Expand Down Expand Up @@ -368,6 +356,26 @@ abstract class PixelDisplay implements Window:
redraw.call l (t + h) r b
return

// Start with a width target of (slightly less than) 64 pixels, but ask
// the canvas how tall the patches can be. It will normally try pick a
// height that keeps things inside a 4k page.
width_target := 64
width := ?
max_height := ?
while true:
// Canvas sizes must often be slightly less than 4k in order to fit into
// a 4k page with object header overhead. By subtracting 8 here we get nice
// heights like 8, 16, 24, 32 that almost fill the max canvas size.
width = min driver_.width (width_target - 8)
max_height = max
round_down (max_canvas_height_ width) y_rounding_
y_rounding_
// Don't widen any more if the patches are already too flat to fill the full height.
if max_height <= driver_.height: break
// Don't widen any more if the patches already cover the whole width.
if width >= driver_.width: break
width_target += width_target

// The algorithm below requires that x aligns with 8 pixels, the resolution
// of the dirty map.
start_x := round_down (max 0 dirty_left_) 8
Expand Down
11 changes: 6 additions & 5 deletions tests/png-visualizer.toit
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ class SeveralColorPngVisualizer extends PngVisualizingDriver_:
abstract class PngVisualizingDriver_ extends AbstractDriver:
width /int ::= ?
height /int ::= ?
width_ /int := 0 // Rounded up to a multiple of 8.
height_ /int := 0 // Rounded up to a multiple of 8.
width_ := 0 // Rounded up depending on the bit depth.
height_ := 0 // Rounded up depending on the bit depth.
outline_buffer_ /ByteArray? := null
buffer_ /ByteArray := #[]
temp_buffer_/ByteArray := #[]
Expand All @@ -73,7 +73,6 @@ abstract class PngVisualizingDriver_ extends AbstractDriver:

constructor .width .height basename/string --.outline/int?=null:
png_basename_ = basename
///
width_ = round_up width x_rounding
height_ = round_up height y_rounding
buffer_ = ByteArray
Expand Down Expand Up @@ -200,11 +199,13 @@ abstract class PngVisualizingDriver_ extends AbstractDriver:
draw_byte_outline_ outline/int pixels/ByteArray patch_width/int --dotted=false -> none:
bottom_left := pixels.size - patch_width
// Dotted line along top and bottom.
for x := 0; x < patch_width; x += dotted ? 2 : 1:
x_step := dotted ? 2 : 1
for x := 0; x < patch_width; x += x_step:
pixels[x] = outline
pixels[bottom_left + x] = outline
// Dotted line along left and right.
for y := 0; y < pixels.size; y += patch_width * (dotted ? 2 : 1):
y_step := patch_width * (dotted ? 2 : 1)
for y := 0; y < pixels.size; y += y_step:
pixels[y] = outline
pixels[y + patch_width - 1] = outline

Expand Down

0 comments on commit f14aca7

Please sign in to comment.