From e74f65e68f8c99afd6f472a0dec60e0a04faf1e6 Mon Sep 17 00:00:00 2001 From: Erik Corry Date: Mon, 11 Dec 2023 11:32:27 +0100 Subject: [PATCH] Kebabify code. (#68) No non-automated changes. --- src/bar_code.toit | 90 ++-- src/common.toit | 236 ++++----- src/element.toit | 240 +++++----- src/four_gray.toit | 34 +- src/gradient.toit | 202 ++++---- src/gray_scale.toit | 24 +- src/one_byte.toit | 84 ++-- src/pixel_display.toit | 426 ++++++++--------- src/png.toit | 58 +-- src/several_color.toit | 24 +- src/slider.toit | 96 ++-- src/style.toit | 388 +++++++-------- src/three_color.toit | 18 +- src/true_color.toit | 142 +++--- src/two_bit_texture.toit | 88 ++-- src/two_color.toit | 62 +-- tests/barcode_visualized.toit | 26 +- tests/bitmap_2_visualized.toit | 64 +-- tests/bitmap_visualized.toit | 32 +- tests/drop_shadow_gray_window_visualized.toit | 30 +- tests/drop_shadow_window_visualized.toit | 30 +- tests/four_gray_bitmap_2_visualized.toit | 54 +-- tests/gradient_bounds_visualized.toit | 22 +- tests/gradient_style_visualized.toit | 24 +- tests/gradient_visualized.toit | 34 +- tests/gray_scale.toit | 24 +- tests/gray_scale_bitmap_2_visualized.toit | 64 +-- tests/gray_scale_visualized.toit | 20 +- tests/invalidate.toit | 128 ++--- tests/mixed_text_rotated_visualized.toit | 42 +- tests/mixed_text_visualized.toit | 46 +- tests/mixed_texture_rotated_visualized.toit | 26 +- tests/mixed_texture_visualized.toit | 42 +- tests/png-visualizer.toit | 448 +++++++++--------- tests/rounded_gray_window_visualized.toit | 28 +- tests/rounded_several_window_visualized.toit | 24 +- ...rounded_three_color_window_visualized.toit | 18 +- .../rounded_two_color_window_visualized.toit | 18 +- tests/rounded_window_visualized.toit | 28 +- tests/several_color.toit | 24 +- tests/simple.toit | 122 ++--- tests/simple_several_window_visualized.toit | 22 +- .../simple_three_color_window_visualized.toit | 16 +- tests/simple_two_color_window_visualized.toit | 16 +- tests/slider_visualized.toit | 22 +- tests/style_test.toit | 96 ++-- tests/text_visualized.toit | 46 +- tests/texture_test_slow.toit | 130 ++--- tests/three_color_bitmap_2_visualized.toit | 50 +- tests/transform_test.toit | 100 ++-- tests/true_color.toit | 40 +- tests/true_color_portrait_visualized.toit | 24 +- tests/true_color_visualized.toit | 24 +- tests/two_color_bitmap_2_visualized.toit | 50 +- 54 files changed, 2133 insertions(+), 2133 deletions(-) diff --git a/src/bar_code.toit b/src/bar_code.toit index 92c8afd..a9b3bc8 100644 --- a/src/bar_code.toit +++ b/src/bar_code.toit @@ -8,30 +8,30 @@ import .common import .element show CustomElement Element import .style -EAN_13_QUIET_ZONE_WIDTH ::= 9 -EAN_13_START_WIDTH ::= 3 -EAN_13_MIDDLE_WIDTH ::= 5 -EAN_13_DIGIT_WIDTH ::= 7 -EAN_13_BOTTOM_SPACE ::= 5 -EAN_13_WIDTH ::= 2 * EAN_13_QUIET_ZONE_WIDTH + 2 * EAN_13_START_WIDTH + EAN_13_MIDDLE_WIDTH + 12 * EAN_13_DIGIT_WIDTH -EAN_13_HEIGHT ::= 83 +EAN-13-QUIET-ZONE-WIDTH ::= 9 +EAN-13-START-WIDTH ::= 3 +EAN-13-MIDDLE-WIDTH ::= 5 +EAN-13-DIGIT-WIDTH ::= 7 +EAN-13-BOTTOM-SPACE ::= 5 +EAN-13-WIDTH ::= 2 * EAN-13-QUIET-ZONE-WIDTH + 2 * EAN-13-START-WIDTH + EAN-13-MIDDLE-WIDTH + 12 * EAN-13-DIGIT-WIDTH +EAN-13-HEIGHT ::= 83 // Encoding of L digits. R digits are the bitwise-not of this and G digits are // the R digits in reverse order. -EAN_13_L_CODES_ ::= [0x0d, 0x19, 0x13, 0x3d, 0x23, 0x31, 0x2f, 0x3b, 0x37, 0x0b] -EAN_13_G_CODES_ ::= [0x27, 0x33, 0x1b, 0x21, 0x1d, 0x39, 0x05, 0x11, 0x09, 0x17] +EAN-13-L-CODES_ ::= [0x0d, 0x19, 0x13, 0x3d, 0x23, 0x31, 0x2f, 0x3b, 0x37, 0x0b] +EAN-13-G-CODES_ ::= [0x27, 0x33, 0x1b, 0x21, 0x1d, 0x39, 0x05, 0x11, 0x09, 0x17] // Encoding of the first (invisible) digit. -EAN_13_FIRST_CODES_ ::= [0x00, 0x0b, 0x0d, 0x0e, 0x13, 0x19, 0x1c, 0x15, 0x16, 0x1a] +EAN-13-FIRST-CODES_ ::= [0x00, 0x0b, 0x0d, 0x0e, 0x13, 0x19, 0x1c, 0x15, 0x16, 0x1a] /// Element that draws a standard EAN-13 bar code. class BarCodeEanElement extends CustomElement: color_/int? := 0 background_ := 0xff sans10_ ::= Font.get "sans10" - number_height_ := EAN_13_BOTTOM_SPACE + number-height_ := EAN-13-BOTTOM-SPACE type -> string: return "bar-code-ean" - set_attribute_ key/string value -> none: + set-attribute_ key/string value -> none: if key == "color": if color_ != value: invalidate @@ -52,7 +52,7 @@ class BarCodeEanElement extends CustomElement: $code_: The 13 digit product code. $x: The left edge of the barcode in the coordinate system of the transform. $y: The top edge of the barcode in the coordinate system of the transform. - Use $set_styles to set the background to white and the color to black. + Use $set-styles to set the background to white and the color to black. See $Element.constructor for the other parameters. */ constructor @@ -68,9 +68,9 @@ class BarCodeEanElement extends CustomElement: // of the digits, so we need to take that into account when calculating // the bounding box. code_ = code - number_height_ = (sans10_.text_extent "8")[1] - height := EAN_13_HEIGHT + number_height_ - EAN_13_BOTTOM_SPACE - w := EAN_13_WIDTH + number-height_ = (sans10_.text-extent "8")[1] + height := EAN-13-HEIGHT + number-height_ - EAN-13-BOTTOM-SPACE + w := EAN-13-WIDTH h := height + 1 super --x = x @@ -84,59 +84,59 @@ class BarCodeEanElement extends CustomElement: --border = border l_ digit: - return EAN_13_L_CODES_[digit & 0xf] + return EAN-13-L-CODES_[digit & 0xf] g_ digit: - return EAN_13_G_CODES_[digit & 0xf] + return EAN-13-G-CODES_[digit & 0xf] r_ digit: return (l_ digit) ^ 0x7f // Make a white background behind the bar code and draw the digits along the // bottom. - draw_text_ canvas/Canvas: + draw-text_ canvas/Canvas: // Bar code coordinates. - text_x := EAN_13_QUIET_ZONE_WIDTH + EAN_13_START_WIDTH - text_y := EAN_13_HEIGHT + number_height_ - EAN_13_BOTTOM_SPACE + 1 + text-x := EAN-13-QUIET-ZONE-WIDTH + EAN-13-START-WIDTH + text-y := EAN-13-HEIGHT + number-height_ - EAN-13-BOTTOM-SPACE + 1 - canvas.text 1 text_y --text=code_[..1] --color=color_ --font=sans10_ + canvas.text 1 text-y --text=code_[..1] --color=color_ --font=sans10_ code_[1..7].split "": if it != "": - canvas.text text_x text_y --text=it --color=color_ --font=sans10_ - text_x += EAN_13_DIGIT_WIDTH - text_x += EAN_13_MIDDLE_WIDTH - 1 + canvas.text text-x text-y --text=it --color=color_ --font=sans10_ + text-x += EAN-13-DIGIT-WIDTH + text-x += EAN-13-MIDDLE-WIDTH - 1 code_[7..13].split "": if it != "": - canvas.text text_x text_y --text=it --color=color_ --font=sans10_ - text_x += EAN_13_DIGIT_WIDTH - marker_width := (sans10_.text_extent ">")[0] - text_x += EAN_13_START_WIDTH + EAN_13_QUIET_ZONE_WIDTH - marker_width - canvas.text text_x text_y --text=">" --color=color_ --font=sans10_ + canvas.text text-x text-y --text=it --color=color_ --font=sans10_ + text-x += EAN-13-DIGIT-WIDTH + marker-width := (sans10_.text-extent ">")[0] + text-x += EAN-13-START-WIDTH + EAN-13-QUIET-ZONE-WIDTH - marker-width + canvas.text text-x text-y --text=">" --color=color_ --font=sans10_ // Redraw routine. - custom_draw canvas/Canvas: - draw_text_ canvas + custom-draw canvas/Canvas: + draw-text_ canvas - x := EAN_13_QUIET_ZONE_WIDTH - long_height := EAN_13_HEIGHT - short_height := EAN_13_HEIGHT - EAN_13_BOTTOM_SPACE + x := EAN-13-QUIET-ZONE-WIDTH + long-height := EAN-13-HEIGHT + short-height := EAN-13-HEIGHT - EAN-13-BOTTOM-SPACE // Start bars: 101. - canvas.rectangle x 0 --w=1 --h=long_height --color=color_ - canvas.rectangle x + 2 0 --w=1 --h=long_height --color=color_ + canvas.rectangle x 0 --w=1 --h=long-height --color=color_ + canvas.rectangle x + 2 0 --w=1 --h=long-height --color=color_ x += 3 - first_code := EAN_13_FIRST_CODES_[code_[0] & 0xf] + first-code := EAN-13-FIRST-CODES_[code_[0] & 0xf] // Left digits using the L or G mapping. for i := 1; i < 7; i++: digit := code_[i] - code := ((first_code >> (6 - i)) & 1) == 0 ? (l_ digit) : (g_ digit) + code := ((first-code >> (6 - i)) & 1) == 0 ? (l_ digit) : (g_ digit) for b := 6; b >= 0; b--: if ((1 << b) & code) != 0: - canvas.rectangle x 0 --w=1 --h=short_height --color=color_ + canvas.rectangle x 0 --w=1 --h=short-height --color=color_ x++ // Middle bars: 01010 - canvas.rectangle x + 1 0 --w=1 --h=long_height --color=color_ - canvas.rectangle x + 3 0 --w=1 --h=long_height --color=color_ + canvas.rectangle x + 1 0 --w=1 --h=long-height --color=color_ + canvas.rectangle x + 3 0 --w=1 --h=long-height --color=color_ x += 5 // Left digits using the R mapping. for i := 7; i < 13; i++: @@ -144,8 +144,8 @@ class BarCodeEanElement extends CustomElement: code := r_ digit for b := 6; b >= 0; b--: if ((1 << b) & code) != 0: - canvas.rectangle x 0 --w=1 --h=short_height --color=color_ + canvas.rectangle x 0 --w=1 --h=short-height --color=color_ x++ // End bars: 101. - canvas.rectangle x 0 --w=1 --h=long_height --color=color_ - canvas.rectangle x + 2 0 --w=1 --h=long_height --color=color_ + canvas.rectangle x 0 --w=1 --h=long-height --color=color_ + canvas.rectangle x + 2 0 --w=1 --h=long-height --color=color_ diff --git a/src/common.toit b/src/common.toit index eb39190..41cbfaf 100644 --- a/src/common.toit +++ b/src/common.toit @@ -5,7 +5,7 @@ // TODO: Absorb this into pixel_display.toit now that textures are gone. import font show Font -import bitmap show ORIENTATION_0 ORIENTATION_90 ORIENTATION_180 ORIENTATION_270 +import bitmap show ORIENTATION-0 ORIENTATION-90 ORIENTATION-180 ORIENTATION-270 import .element show Element import .style @@ -36,7 +36,7 @@ interface Window: Remove all elements from a Window. See $remove. */ - remove_all -> none + remove-all -> none /** Called by elements that have been added to this window, when they change @@ -45,7 +45,7 @@ interface Window: is called on the display. The coordinates are in this instance's coordinate space. */ - child_invalidated x/int y/int w/int h/int -> none + child-invalidated x/int y/int w/int h/int -> none /** Finds an Element in the tree with the given id. @@ -53,7 +53,7 @@ interface Window: The return type is `any` because you want to be able to assign the result to a subtypes of $Element, for example to a variable of type Div. */ - get_element_by_id id/string -> any + get-element-by-id id/string -> any /** A canvas to draw on. @@ -77,12 +77,12 @@ abstract class Canvas: Returns a new canvas with the same dimensions and transform (coordinate system) as this one. */ - abstract create_similar -> Canvas + abstract create-similar -> Canvas - abstract set_all_pixels color/int -> none + abstract set-all-pixels color/int -> none - abstract supports_8_bit -> bool - abstract gray_scale -> bool + abstract supports-8-bit -> bool + abstract gray-scale -> bool /** Returns a new canvas that is either gray-scale or 1-bit. @@ -98,17 +98,17 @@ abstract class Canvas: The returned canvas is larger on all four edges of the canvas by the given $padding, defaulting to 0. */ - abstract make_alpha_map --padding/int=0 -> Canvas + abstract make-alpha-map --padding/int=0 -> Canvas - /// Result from $bounds_analysis: The area and the canvas are disjoint. + /// Result from $bounds-analysis: The area and the canvas are disjoint. static DISJOINT ::= 0 - /// Result from $bounds_analysis: The area is a subset of the canvas. - static AREA_IN_CANVAS ::= 1 - /// Result from $bounds_analysis: The canvas is a subset of the area. - static CANVAS_IN_AREA ::= 2 - /// Result from $bounds_analysis: The area and the canvas are identical. + /// Result from $bounds-analysis: The area is a subset of the canvas. + static AREA-IN-CANVAS ::= 1 + /// Result from $bounds-analysis: The canvas is a subset of the area. + static CANVAS-IN-AREA ::= 2 + /// Result from $bounds-analysis: The area and the canvas are identical. static COINCIDENT ::= 3 - /// Result from $bounds_analysis: The areas overlap, but neither is a subset of the other. + /// Result from $bounds-analysis: The areas overlap, but neither is a subset of the other. static OVERLAP ::= 4 /** @@ -121,7 +121,7 @@ abstract class Canvas: All the drawing operations are automatically clipped to the area of the canvas, and this is often sufficient clipping. */ - bounds_analysis x/int y/int w/int h/int -> int: + bounds-analysis x/int y/int w/int h/int -> int: if h == 0 or w == 0 or width_ == 0 or height_ == 0: return DISJOINT transform.xywh x y w h: | x2 y2 w2 h2 | right := x2 + w2 @@ -129,30 +129,30 @@ abstract class Canvas: if right < 0 or bottom < 0 or x2 >= width_ or y2 >= height_: return DISJOINT if x2 >= 0 and y2 >= 0 and right <= width_ and bottom <= height_: if x2 == 0 and y2 == 0 and right == width_ and bottom == height_: return COINCIDENT - return AREA_IN_CANVAS - if x2 <= 0 and y2 <= 0 and right >= width_ and bottom >= height_: return CANVAS_IN_AREA + return AREA-IN-CANVAS + if x2 <= 0 and y2 <= 0 and right >= width_ and bottom >= height_: return CANVAS-IN-AREA return OVERLAP /** Constant to indicate that all pixels are transparent. For use with $composit. */ - static ALL_TRANSPARENT ::= #[0] + static ALL-TRANSPARENT ::= #[0] /** Constant to indicate that all pixels are opaque. For use with $composit. */ - static ALL_OPAQUE ::= #[0xff] + static ALL-OPAQUE ::= #[0xff] /** - Mixes the $frame_canvas and the $painting_canvas together and draws + Mixes the $frame-canvas and the $painting-canvas together and draws them on the reciever. The opacity arguments determine the transparency (alpha) of the two canvas arguments. They can be either canvases returned from - $make_alpha_map, or they can be $ALL_OPAQUE or - $ALL_TRANSPARENT. + $make-alpha-map, or they can be $ALL-OPAQUE or + $ALL-TRANSPARENT. */ - abstract composit frame_opacity frame_canvas/Canvas painting_opacity painting_canvas/Canvas + abstract composit frame-opacity frame-canvas/Canvas painting-opacity painting-canvas/Canvas /** Draws a solid rectangle on the canvas in the given color. @@ -168,8 +168,8 @@ abstract class Canvas: The text is automatically clipped to the area of the canvas so it is not an error for the text to be outside the canvas. - The orientation is normally $ORIENTATION_0 (from "import bitmap"), but can be - $ORIENTATION_90, $ORIENTATION_180, or $ORIENTATION_270, representing + The orientation is normally $ORIENTATION-0 (from "import bitmap"), but can be + $ORIENTATION-90, $ORIENTATION-180, or $ORIENTATION-270, representing anti-clockwise rotation. The $x and $y represent the origin (bottom left corner) of the text. The text may extend below and to the left of this point if it contains @@ -196,21 +196,21 @@ abstract class Canvas: The bitmap is automatically clipped to the area of the canvas so it is not an error for the bitmap to be outside the canvas. - Using $source_line_stride a number of bytes can be skipped at the + Using $source-line-stride a number of bytes can be skipped at the end of each line. This is useful if the bitmap is padded, or the source is an uncompressed PNG which has a zero at the start of each line. - The $orientation argument can be $ORIENTATION_0, $ORIENTATION_90, - $ORIENTATION_180, or $ORIENTATION_270, from "import bitmap", + The $orientation argument can be $ORIENTATION-0, $ORIENTATION-90, + $ORIENTATION-180, or $ORIENTATION-270, from "import bitmap", representing anti-clockwise rotation of the drawn bitmap. */ abstract bitmap x/int y/int -> none --pixels/ByteArray --alpha/ByteArray // 2-element byte array. --palette/ByteArray // 6-element byte array. - --source_width/int // In pixels. - --source_line_stride/int // In bytes. - --orientation/int=ORIENTATION_0 + --source-width/int // In pixels. + --source-line-stride/int // In bytes. + --orientation/int=ORIENTATION-0 /** Draws the given 8-bit pixmap on the canvas. @@ -234,7 +234,7 @@ abstract class Canvas: The $orientation argument can be ORIENTATION_0, ORIENTATION_90, ORIENTATION_180, or ORIENTATION_270, from "import bitmap", representing anti-clockwise rotation of the drawn pixmap. - Using $source_line_stride a number of bytes can be skipped at the + Using $source-line-stride a number of bytes can be skipped at the end of each line. This is useful if the pixmap is padded, or the source is an uncompressed PNG which has a zero at the start of each line. @@ -243,9 +243,9 @@ abstract class Canvas: --pixels/ByteArray --alpha/ByteArray=#[] --palette/ByteArray=#[] - --source_width/int - --orientation/int=ORIENTATION_0 - --source_line_stride/int=source_width: + --source-width/int + --orientation/int=ORIENTATION-0 + --source-line-stride/int=source-width: throw "Unimplemented" /** @@ -259,18 +259,18 @@ abstract class Canvas: representing anti-clockwise rotation of the drawn pixmap. This method is only available on true-color canvases. */ - rgb_pixmap x/int y/int + rgb-pixmap x/int y/int --r/ByteArray --g/ByteArray --b/ByteArray - --source_width/int - --orientation/int=ORIENTATION_0: + --source-width/int + --orientation/int=ORIENTATION-0: throw "UNSUPPORTED" // Only on true color canvas. -TRANSFORM_IDENTITY_ ::= Transform.with_ --x1=1 --x2=0 --y1=0 --y2=1 --tx=0 --ty=0 -TRANSFORM_90_ ::= Transform.with_ --x1=0 --x2=-1 --y1=1 --y2=0 --tx=0 --ty=0 -TRANSFORM_180_ ::= Transform.with_ --x1=-1 --x2=0 --y1=0 --y2=-1 --tx=0 --ty=0 -TRANSFORM_270_ ::= Transform.with_ --x1=0 --x2=1 --y1=-1 --y2=0 --tx=0 --ty=0 +TRANSFORM-IDENTITY_ ::= Transform.with_ --x1=1 --x2=0 --y1=0 --y2=1 --tx=0 --ty=0 +TRANSFORM-90_ ::= Transform.with_ --x1=0 --x2=-1 --y1=1 --y2=0 --tx=0 --ty=0 +TRANSFORM-180_ ::= Transform.with_ --x1=-1 --x2=0 --y1=0 --y2=-1 --tx=0 --ty=0 +TRANSFORM-270_ ::= Transform.with_ --x1=0 --x2=1 --y1=-1 --y2=0 --tx=0 --ty=0 /** Classic 3x3 matrix for 2D transformations. @@ -289,7 +289,7 @@ class Transform: ty_/int ::= ? constructor.identity: - return TRANSFORM_IDENTITY_ + return TRANSFORM-IDENTITY_ constructor.with_ --x1/int --y1/int --x2/int --y2/int --tx/int --ty/int: x1_ = x1 @@ -356,49 +356,49 @@ class Transform: /** Finds the extent of a rectangle after it has been transformed with the transform. - - $x_in: The left edge before the transformation is applied. - - $y_in: The top edge before the transformation is applied. - - $w_in: The width before the transformation is applied. - - $h_in: The height before the transformation is applied. + - $x-in: The left edge before the transformation is applied. + - $y-in: The top edge before the transformation is applied. + - $w-in: The width before the transformation is applied. + - $h-in: The height before the transformation is applied. - $block: A block that is called with arguments left top width height in the transformed coordinate space. */ - xywh x_in/int y_in/int w_in/int h_in/int [block]: - x_transformed := x x_in y_in - y_transformed := y x_in y_in - w_transformed := width w_in h_in - h_transformed := height w_in h_in + xywh x-in/int y-in/int w-in/int h-in/int [block]: + x-transformed := x x-in y-in + y-transformed := y x-in y-in + w-transformed := width w-in h-in + h-transformed := height w-in h-in x2 := min - x_transformed - x_transformed + w_transformed + x-transformed + x-transformed + w-transformed y2 := min - y_transformed - y_transformed + h_transformed - w2 := w_transformed.abs - h2 := h_transformed.abs + y-transformed + y-transformed + h-transformed + w2 := w-transformed.abs + h2 := h-transformed.abs block.call x2 y2 w2 h2 /** Finds a point and an orientation after it has been transformed with the transform. - - $x_in: The x coordinate before the transformation is applied. - - $y_in: The y coordinate before the transformation is applied. - - $o_in: The orientation before the transformation is applied. + - $x-in: The x coordinate before the transformation is applied. + - $y-in: The y coordinate before the transformation is applied. + - $o-in: The orientation before the transformation is applied. - $block: A block that is called with arguments x y orientation in the transformed coordinate space. */ - xyo x_in/int y_in/int o_in/int [block]: - x_transformed := x x_in y_in - y_transformed := y x_in y_in - o_transformed/int := ? - if x1_ > 0: o_transformed = o_in + ORIENTATION_0 - else if y1_ < 0: o_transformed = o_in + ORIENTATION_90 - else if x1_ < 0: o_transformed = o_in + ORIENTATION_180 - else: o_transformed = o_in + ORIENTATION_270 - block.call x_transformed y_transformed (o_transformed & 3) + xyo x-in/int y-in/int o-in/int [block]: + x-transformed := x x-in y-in + y-transformed := y x-in y-in + o-transformed/int := ? + if x1_ > 0: o-transformed = o-in + ORIENTATION-0 + else if y1_ < 0: o-transformed = o-in + ORIENTATION-90 + else if x1_ < 0: o-transformed = o-in + ORIENTATION-180 + else: o-transformed = o-in + ORIENTATION-270 + block.call x-transformed y-transformed (o-transformed & 3) /** Returns a new transform which represents this transform rotated left around the origin in the space of this transform. */ - rotate_left -> Transform: + rotate-left -> Transform: return Transform.with_ --x1 = -x2_ --y1 = -y2_ @@ -411,7 +411,7 @@ class Transform: Returns a new transform which represents this transform rotated right around the origin in the space of this transform. */ - rotate_right -> Transform: + rotate-right -> Transform: return Transform.with_ --x1 = x2_ --y1 = y2_ @@ -435,10 +435,10 @@ class Transform: // Used for font rendering. orientation_: - if x1_ > 0: return ORIENTATION_0 - if y1_ < 0: return ORIENTATION_90 - if x1_ < 0: return ORIENTATION_180 - else: return ORIENTATION_270 + if x1_ > 0: return ORIENTATION-0 + if y1_ < 0: return ORIENTATION-90 + if x1_ < 0: return ORIENTATION-180 + else: return ORIENTATION-270 /** Returns the transformed x coordinate of the given point ($x, $y). @@ -480,62 +480,62 @@ class TextExtent_: // grows towards the bottom, whereas the y-axis of fonts grows towards the // top. constructor text font alignment: - box := font.text_extent text - if alignment != ALIGN_LEFT: - displacement = -(font.pixel_width text) - if alignment == ALIGN_CENTER: displacement >>= 1 + box := font.text-extent text + if alignment != ALIGN-LEFT: + displacement = -(font.pixel-width text) + if alignment == ALIGN-CENTER: displacement >>= 1 w = box[0] h = box[1] x = box[2] + displacement y = -box[1] - box[3] -text_get_bounding_boxes_ old/string new/string alignment/int font/Font [block]: - left_doesnt_move := alignment == ALIGN_LEFT - right_doesnt_move := alignment == ALIGN_RIGHT +text-get-bounding-boxes_ old/string new/string alignment/int font/Font [block]: + left-doesnt-move := alignment == ALIGN-LEFT + right-doesnt-move := alignment == ALIGN-RIGHT // If the rendered length does not change then both ends don't move. - pixel_width_old := font.pixel_width old - if pixel_width_old == (font.pixel_width new): - left_doesnt_move = true - right_doesnt_move = true + pixel-width-old := font.pixel-width old + if pixel-width-old == (font.pixel-width new): + left-doesnt-move = true + right-doesnt-move = true length := min old.size new.size - unchanged_left := 0 - unchanged_right := 0 - if left_doesnt_move: + unchanged-left := 0 + unchanged-right := 0 + if left-doesnt-move: // Find out how many bytes are unchanged at the start of the string. - unchanged_left = length + unchanged-left = length for i := 0; i < length; i++: if old[i] != new[i]: - unchanged_left = i + unchanged-left = i break - if right_doesnt_move: + if right-doesnt-move: // Find out how many bytes are unchanged at the end of the string. - unchanged_right = length - last_character_start := 0 // Location (counting from end) of the start of the last UTF-8 sequence. + unchanged-right = length + last-character-start := 0 // Location (counting from end) of the start of the last UTF-8 sequence. for i := 0; i < length; i++: if old[old.size - 1 - i] != new[new.size - 1 - i]: - unchanged_right = last_character_start + unchanged-right = last-character-start break else if old[old.size - 1 - i]: - last_character_start = i + 1 - if unchanged_right != 0 or unchanged_left != 0: - changed_old := old.copy unchanged_left (old.size - unchanged_right) - changed_new := new.copy unchanged_left (new.size - unchanged_right) - changed_extent_old := TextExtent_ changed_old font alignment - changed_extent_new := TextExtent_ changed_new font alignment - if alignment == ALIGN_LEFT: - unchanged_width := font.pixel_width old[..unchanged_left] - changed_extent_old.x += unchanged_width - changed_extent_new.x += unchanged_width - else if alignment == ALIGN_RIGHT: - unchanged_width := font.pixel_width old[old.size - unchanged_right..] + last-character-start = i + 1 + if unchanged-right != 0 or unchanged-left != 0: + changed-old := old.copy unchanged-left (old.size - unchanged-right) + changed-new := new.copy unchanged-left (new.size - unchanged-right) + changed-extent-old := TextExtent_ changed-old font alignment + changed-extent-new := TextExtent_ changed-new font alignment + if alignment == ALIGN-LEFT: + unchanged-width := font.pixel-width old[..unchanged-left] + changed-extent-old.x += unchanged-width + changed-extent-new.x += unchanged-width + else if alignment == ALIGN-RIGHT: + unchanged-width := font.pixel-width old[old.size - unchanged-right..] // Make x relative to the text origin, which is the right edge. - changed_extent_old.x -= unchanged_width - changed_extent_new.x -= unchanged_width + changed-extent-old.x -= unchanged-width + changed-extent-new.x -= unchanged-width else: - assert: alignment == ALIGN_CENTER - assert: pixel_width_old == (font.pixel_width new) + assert: alignment == ALIGN-CENTER + assert: pixel-width-old == (font.pixel-width new) // Make x relative to the text origin, which is the middle. - unchanged_width := ((pixel_width_old + 1) >> 1) - (font.pixel_width old[..unchanged_left]) - changed_extent_old.x -= unchanged_width + changed_extent_old.displacement - changed_extent_new.x -= unchanged_width + changed_extent_new.displacement - block.call changed_extent_old changed_extent_new + unchanged-width := ((pixel-width-old + 1) >> 1) - (font.pixel-width old[..unchanged-left]) + changed-extent-old.x -= unchanged-width + changed-extent-old.displacement + changed-extent-new.x -= unchanged-width + changed-extent-new.displacement + block.call changed-extent-old changed-extent-new diff --git a/src/element.toit b/src/element.toit index 29a290e..6c9b751 100644 --- a/src/element.toit +++ b/src/element.toit @@ -2,15 +2,15 @@ // Use of this source code is governed by an MIT-style license that can be // found in the LICENSE file. -import binary show LITTLE_ENDIAN +import binary show LITTLE-ENDIAN import bitmap show * -import .four_gray as four_gray -import .true_color as true_color -import .gray_scale as gray_scale -import .one_byte as one_byte +import .four-gray as four-gray +import .true-color as true-color +import .gray-scale as gray-scale +import .one-byte as one-byte import .style show * import .common -import .pixel_display show PixelDisplay +import .pixel-display show PixelDisplay import font show Font import math @@ -20,8 +20,8 @@ An element that can be placed on a display. They can contain other Elements can be stacked up and are drawn from back to front, with transparency. */ abstract class Element implements Window: - hash_code/int ::= generate_hash_code_ - change_tracker/Window? := null + hash-code/int ::= generate-hash-code_ + change-tracker/Window? := null style_/Style? := ? classes/List? := ? id/string? := ? @@ -40,12 +40,12 @@ abstract class Element implements Window: The x and y coordinates are relative to the parent element. The $style can be used to apply a custom Style object to this element alone. Normally, you would apply a style to the whole tree of elements - using $PixelDisplay.set_styles method. + using $PixelDisplay.set-styles method. The $classes are strings that can be used to identify the element in the style sheet. You can give an element multiple classes. The $id is a string that can be used to identify the element in the style sheet. It should be unique in the whole tree of elements. It is also used - for $PixelDisplay.get_element_by_id. + for $PixelDisplay.get-element-by-id. The $background is an integer color (0xRRGGBB) or a $Background object. It can be set using styles instead of here in the constructor. The children are a $List of elements that should be contained in this element. @@ -65,12 +65,12 @@ abstract class Element implements Window: background_ = background border_ = border if children: children.do: | child/Element | - child.change_tracker = this + child.change-tracker = this - static HASH_CODE_COUNTER_ := 0 - static generate_hash_code_ -> int: - HASH_CODE_COUNTER_ += 13 - return HASH_CODE_COUNTER_ + static HASH-CODE-COUNTER_ := 0 + static generate-hash-code_ -> int: + HASH-CODE-COUNTER_ += 13 + return HASH-CODE-COUNTER_ abstract invalidate -> none @@ -80,30 +80,30 @@ abstract class Element implements Window: The return type is any because you want to be able to assign the result to a variable of type Div, which is a subtype of Element. */ - get_element_by_id id/string -> any: + get-element-by-id id/string -> any: if id == this.id: return this if children: children.do: | child/Element | - found := child.get_element_by_id id + found := child.get-element-by-id id if found: return found return null add element/Element -> none: if not children: children = [] children.add element - element.change_tracker = this + element.change-tracker = this element.invalidate remove element/Element -> none: if children: children.remove element element.invalidate - element.change_tracker = null + element.change-tracker = null - remove_all -> none: + remove-all -> none: children.do: it.invalidate - it.change_tracker = null + it.change-tracker = null children = null x= value/int -> none: @@ -116,7 +116,7 @@ abstract class Element implements Window: y_ = value invalidate - move_to x/int y/int: + move-to x/int y/int: invalidate x_ = x y_ = y @@ -139,37 +139,37 @@ abstract class Element implements Window: abstract draw canvas/Canvas -> none - child_invalidated x/int y/int w/int h/int -> none: - if change_tracker: + child-invalidated x/int y/int w/int h/int -> none: + if change-tracker: x2 := max x_ (x_ + x) y2 := max y_ (y_ + y) right := min (x_ + this.w) (x_ + x + w) bottom := min (y_ + this.h) (y_ + y + h) if x2 < right and y2 < bottom: - change_tracker.child_invalidated x2 y2 (right - x2) (bottom - y2) + change-tracker.child-invalidated x2 y2 (right - x2) (bottom - y2) abstract w -> int? abstract h -> int? - set_styles styles/List -> none: - styles_for_children := null - install_style := : | style/Style | - style.matching_styles --type=type --classes=classes --id=id: | style/Style | - style.iterate_properties: | key/string value | - set_attribute_ key value + set-styles styles/List -> none: + styles-for-children := null + install-style := : | style/Style | + style.matching-styles --type=type --classes=classes --id=id: | style/Style | + style.iterate-properties: | key/string value | + set-attribute_ key value if children: - if not styles_for_children: styles_for_children = styles.copy - styles_for_children.add style - styles.do install_style + if not styles-for-children: styles-for-children = styles.copy + styles-for-children.add style + styles.do install-style if style_: - style_.iterate_properties: | key/string value | - set_attribute_ key value - install_style.call style_ + style_.iterate-properties: | key/string value | + set-attribute_ key value + install-style.call style_ if children: children.do: | child/Element | - child.set_styles (styles_for_children or styles) + child.set-styles (styles-for-children or styles) - set_attribute_ key/string value -> none: + set-attribute_ key/string value -> none: if key == "background": if background_ != value: invalidate @@ -264,8 +264,8 @@ class Div extends Element: children invalidate: - if change_tracker and x and y and w and h: - change_tracker.child_invalidated x y w h + if change-tracker and x and y and w and h: + change-tracker.child-invalidated x y w h w -> int?: return w_ h -> int?: return h_ @@ -282,14 +282,14 @@ class Div extends Element: h_ = value if value: invalidate - set_size w/int h/int -> none: + set-size w/int h/int -> none: if w_ != w or h_ != h: if w_ and h_: invalidate w_ = w h_ = h invalidate - set_attribute_ key/string value -> none: + set-attribute_ key/string value -> none: if key == "width": w = value else if key == "height": @@ -298,14 +298,14 @@ class Div extends Element: super key value draw canvas/Canvas -> none: - old_transform := canvas.transform - canvas.transform = old_transform.translate x_ y_ + old-transform := canvas.transform + canvas.transform = old-transform.translate x_ y_ Background.draw background_ canvas 0 0 w h --no-autoclipped - custom_draw canvas + custom-draw canvas if border_: border_.draw canvas 0 0 w h - canvas.transform = old_transform + canvas.transform = old-transform - custom_draw canvas/Canvas -> none: + custom-draw canvas/Canvas -> none: if children: children.do: it.draw canvas /** @@ -326,7 +326,7 @@ class Label extends Element implements ColoredElement: type -> string: return "label" - set_attribute_ key/string value -> none: + set-attribute_ key/string value -> none: if key == "color": color = value else if key == "font": @@ -359,9 +359,9 @@ class Label extends Element implements ColoredElement: An Label is an element that is a single line of text. Unlike other elements it does not have a background and a border - the background is always transparent and the border is always invisible. - The $alignment is one of $ALIGN_LEFT, $ALIGN_CENTER, or $ALIGN_RIGHT. - The $orientation is one of $ORIENTATION_0, $ORIENTATION_90, $ORIENTATION_180, - or $ORIENTATION_270. + The $alignment is one of $ALIGN-LEFT, $ALIGN-CENTER, or $ALIGN-RIGHT. + The $orientation is one of $ORIENTATION-0, $ORIENTATION-90, $ORIENTATION-180, + or $ORIENTATION-270. The $color, $font, $orientation, and $alignment can be set using styles instead of here in the constructor. The label (text) can be set and changed later with the label setter. Like any change of appearance @@ -378,8 +378,8 @@ class Label extends Element implements ColoredElement: --color/int=0 --label/string="" --font/Font?=null - --orientation/int=ORIENTATION_0 - --alignment/int=ALIGN_LEFT: + --orientation/int=ORIENTATION-0 + --alignment/int=ALIGN-LEFT: color_ = color label_ = label alignment_ = alignment @@ -397,32 +397,32 @@ class Label extends Element implements ColoredElement: */ xywh_ [block]: if not left_: - extent/List := font_.text_extent label_ + extent/List := font_.text-extent label_ displacement := 0 - if alignment_ != ALIGN_LEFT: - displacement = (font_.pixel_width label_) - if alignment_ == ALIGN_CENTER: displacement >>= 1 + if alignment_ != ALIGN-LEFT: + displacement = (font_.pixel-width label_) + if alignment_ == ALIGN-CENTER: displacement >>= 1 l := extent[2] - displacement r := extent[2] - displacement + extent[0] t := -extent[1] - extent[3] b := extent[3] - if orientation_ == ORIENTATION_0: + if orientation_ == ORIENTATION-0: left_ = l top_ = t width_ = extent[0] height_ = extent[1] - else if orientation_ == ORIENTATION_90: + else if orientation_ == ORIENTATION-90: left_ = t top_ = -r width_ = extent[1] height_ = extent[0] - else if orientation_ == ORIENTATION_180: + else if orientation_ == ORIENTATION-180: left_ = -r top_ = b width_ = extent[0] height_ = extent[1] else: - assert: orientation_ == ORIENTATION_270 + assert: orientation_ == ORIENTATION-270 left_ = b top_ = l width_ = extent[1] @@ -440,16 +440,16 @@ class Label extends Element implements ColoredElement: return height_ invalidate: - if change_tracker and x and y and font_ and label_: + if change-tracker and x and y and font_ and label_: xywh_: | x y w h | - change_tracker.child_invalidated x y w h + change-tracker.child-invalidated x y w h label= value/string -> none: if value == label_: return - if orientation_ == ORIENTATION_0 and change_tracker and x and y: - text_get_bounding_boxes_ label_ value alignment_ font_: | old/TextExtent_ new/TextExtent_ | - change_tracker.child_invalidated (x_ + old.x) (y_ + old.y) old.w old.h - change_tracker.child_invalidated (x_ + new.x) (y_ + new.y) new.w new.h + if orientation_ == ORIENTATION-0 and change-tracker and x and y: + text-get-bounding-boxes_ label_ value alignment_ font_: | old/TextExtent_ new/TextExtent_ | + change-tracker.child-invalidated (x_ + old.x) (y_ + old.y) old.w old.h + change-tracker.child-invalidated (x_ + new.x) (y_ + new.y) new.w new.h label_ = value left_ = null // Trigger recalculation. return @@ -476,26 +476,26 @@ class Label extends Element implements ColoredElement: x := x_ y := y_ if not (x and y): return - if alignment_ != ALIGN_LEFT: - text_width := font_.pixel_width label_ - if alignment_ == ALIGN_CENTER: text_width >>= 1 - if orientation_ == ORIENTATION_0: - x -= text_width - else if orientation_ == ORIENTATION_90: - y += text_width - else if orientation_ == ORIENTATION_180: - x += text_width + if alignment_ != ALIGN-LEFT: + text-width := font_.pixel-width label_ + if alignment_ == ALIGN-CENTER: text-width >>= 1 + if orientation_ == ORIENTATION-0: + x -= text-width + else if orientation_ == ORIENTATION-90: + y += text-width + else if orientation_ == ORIENTATION-180: + x += text-width else: - assert: orientation_ == ORIENTATION_270 - y -= text_width + assert: orientation_ == ORIENTATION-270 + y -= text-width canvas.text x y --text=label_ --color=color_ --font=font_ --orientation=orientation_ /** A superclass for elements that can draw themselves. Override the - $custom_draw method in your subclass to draw on the canvas. The $w + $custom-draw method in your subclass to draw on the canvas. The $w and $h methods/fields are used to determine the size of the element for redrawing purposes. -The background is drawn before $custom_draw is called, and the border +The background is drawn before $custom-draw is called, and the border is drawn after. Drawing operations are automatically clipped to w and h. */ @@ -525,20 +525,20 @@ abstract class CustomElement extends ClippingDiv_: --border = border invalidate: - if change_tracker and x and y and w and h: - change_tracker.child_invalidated x y w h + if change-tracker and x and y and w and h: + change-tracker.child-invalidated x y w h draw canvas/Canvas -> none: if not (x and y): return - analysis := canvas.bounds_analysis x y w h + analysis := canvas.bounds-analysis x y w h if analysis == Canvas.DISJOINT: return - autoclipped := analysis == Canvas.CANVAS_IN_AREA or analysis == Canvas.COINCIDENT - old_transform := canvas.transform - canvas.transform = old_transform.translate x_ y_ + autoclipped := analysis == Canvas.CANVAS-IN-AREA or analysis == Canvas.COINCIDENT + old-transform := canvas.transform + canvas.transform = old-transform.translate x_ y_ Background.draw background_ canvas 0 0 w h --autoclipped=autoclipped - custom_draw canvas + custom-draw canvas if border_: border_.draw canvas 0 0 w h - canvas.transform = old_transform + canvas.transform = old-transform /** Override this to draw your custom element. The coordinate system is @@ -546,7 +546,7 @@ abstract class CustomElement extends ClippingDiv_: The background has already been drawn when this is called, and the frame will be drawn afterwards. */ - abstract custom_draw canvas/Canvas -> none + abstract custom-draw canvas/Canvas -> none /** A ClippingDiv_ is like a div, but it clips any draws inside of it. It can @@ -562,7 +562,7 @@ class ClippingDiv_ extends Div: */ extent --x=x_ --y=y_ --w=w_ --h=h_ [block] -> none: if border_: - border_.invalidation_area x y w h block + border_.invalidation-area x y w h block else: block.call x y w h @@ -570,15 +570,15 @@ class ClippingDiv_ extends Div: Invalidates the whole window including the decoration. */ invalidate --x=x_ --y=y_ --w=w_ --h=h_ -> none: - if change_tracker: - extent --x=x --y=y --w=w --h=h: | outer_x outer_y outer_w outer_h | - change_tracker.child_invalidated outer_x outer_y outer_w outer_h + if change-tracker: + extent --x=x --y=y --w=w --h=h: | outer-x outer-y outer-w outer-h | + change-tracker.child-invalidated outer-x outer-y outer-w outer-h - static is_all_transparent opacity -> bool: + static is-all-transparent opacity -> bool: if opacity is not ByteArray: return false return opacity.size == 1 and opacity[0] == 0 - static is_all_opaque opacity -> bool: + static is-all-opaque opacity -> bool: if opacity is not ByteArray: return false return opacity.size == 1 and opacity[0] == 0xff @@ -609,39 +609,39 @@ class ClippingDiv_ extends Div: draw canvas/Canvas -> none: // If we are outside the window and the decorations, there is nothing to do. extent: | x2 y2 w2 h2 | - if (canvas.bounds_analysis x2 y2 w2 h2) == Canvas.DISJOINT: return + if (canvas.bounds-analysis x2 y2 w2 h2) == Canvas.DISJOINT: return - old_transform := canvas.transform - canvas.transform = old_transform.translate x_ y_ + old-transform := canvas.transform + canvas.transform = old-transform.translate x_ y_ - content_opacity := content_map canvas + content-opacity := content-map canvas // If the window is 100% painting at these coordinates then we can draw the // elements of the window and no compositing is required. - if is_all_opaque content_opacity: - canvas.transform = old_transform + if is-all-opaque content-opacity: + canvas.transform = old-transform super canvas // Use the unclipped drawing method from Div. return - frame_opacity := frame_map canvas + frame-opacity := frame-map canvas - if is_all_transparent frame_opacity and is_all_transparent content_opacity: - canvas.transform = old_transform + if is-all-transparent frame-opacity and is-all-transparent content-opacity: + canvas.transform = old-transform return // The complicated case where we have to composit the tile with the border and decorations. - border_canvas := null - if not is_all_transparent frame_opacity: - border_canvas = canvas.create_similar - if border_: border_.draw border_canvas 0 0 w h + border-canvas := null + if not is-all-transparent frame-opacity: + border-canvas = canvas.create-similar + if border_: border_.draw border-canvas 0 0 w h - painting_canvas := canvas.create_similar - Background.draw background_ painting_canvas 0 0 w h --autoclipped - custom_draw painting_canvas + painting-canvas := canvas.create-similar + Background.draw background_ painting-canvas 0 0 w h --autoclipped + custom-draw painting-canvas - canvas.composit frame_opacity border_canvas content_opacity painting_canvas + canvas.composit frame-opacity border-canvas content-opacity painting-canvas - canvas.transform = old_transform + canvas.transform = old-transform type -> string: return "div" @@ -656,9 +656,9 @@ class ClippingDiv_ extends Div: The coordinate system of the canvas is the coordinate system of the window, so the top and left edges may be plotted at negative coordinates. */ - frame_map canvas/Canvas: - if not border_: return Canvas.ALL_TRANSPARENT // No border visible. - return border_.frame_map canvas w h + frame-map canvas/Canvas: + if not border_: return Canvas.ALL-TRANSPARENT // No border visible. + return border_.frame-map canvas w h /** Returns a canvas that is an alpha map for the given area that describes where @@ -669,8 +669,8 @@ class ClippingDiv_ extends Div: single-entry byte array, which means all pixels have the same transparency. The coordinate system of the canvas is the coordinate system of the window. */ - content_map canvas/Canvas: - return (border_ or NO_BORDER_).content_map canvas w h + content-map canvas/Canvas: + return (border_ or NO-BORDER_).content-map canvas w h - draw_frame canvas/Canvas: + draw-frame canvas/Canvas: if border_: border_.draw canvas 0 0 w h diff --git a/src/four_gray.toit b/src/four_gray.toit index d0733bd..13d160c 100644 --- a/src/four_gray.toit +++ b/src/four_gray.toit @@ -3,7 +3,7 @@ // found in the LICENSE file. /** -Constants useful for $PixelDisplay.four_gray. +Constants useful for $PixelDisplay.four-gray. For use with e-paper displays with four tones of gray. */ @@ -11,17 +11,17 @@ import bitmap show * import font show Font import icons show Icon import .common -import .pixel_display show PixelDisplay // For the doc comment. -import .two_bit_texture -import .two_bit_texture as two_bit +import .pixel-display show PixelDisplay // For the doc comment. +import .two-bit-texture +import .two-bit-texture as two-bit -/// Color value for use with $PixelDisplay.four_gray. +/// Color value for use with $PixelDisplay.four-gray. WHITE ::= 0 -/// Color value for use with $PixelDisplay.four_gray. -LIGHT_GRAY ::= 1 -/// Color value for use with $PixelDisplay.four_gray. -DARK_GRAY ::= 2 -/// Color value for use with $PixelDisplay.four_gray. +/// Color value for use with $PixelDisplay.four-gray. +LIGHT-GRAY ::= 1 +/// Color value for use with $PixelDisplay.four-gray. +DARK-GRAY ::= 2 +/// Color value for use with $PixelDisplay.four-gray. BLACK ::= 3 // The canvas contains two bitmapped ByteArrays, giving 4 grays. @@ -30,23 +30,23 @@ BLACK ::= 3 // 1 0 Dark gray // 1 1 Black // Starts off with all pixels white. -class Canvas_ extends two_bit.Canvas_: +class Canvas_ extends two-bit.Canvas_: constructor width/int height/int: super width height - supports_8_bit -> bool: return false - gray_scale -> bool: return true + supports-8-bit -> bool: return false + gray-scale -> bool: return true /** Creates a blank texture with the same dimensions as this one. */ - create_similar: + create-similar: result := Canvas_ width_ height_ result.transform = transform return result - static NEAREST_TABLE_ ::= #[BLACK, DARK_GRAY, LIGHT_GRAY, WHITE] + static NEAREST-TABLE_ ::= #[BLACK, DARK-GRAY, LIGHT-GRAY, WHITE] // Convert from a PNG color (0 = black, 255 = white) to a 2-bit 4-gray color. - nearest_color_ palette/ByteArray offset/int -> int: - return NEAREST_TABLE_[palette[offset] >> 6] + nearest-color_ palette/ByteArray offset/int -> int: + return NEAREST-TABLE_[palette[offset] >> 6] diff --git a/src/gradient.toit b/src/gradient.toit index 74249ab..fc19edc 100644 --- a/src/gradient.toit +++ b/src/gradient.toit @@ -40,8 +40,8 @@ class GradientBackground implements Background: rendering_/GradientRendering_? := null constructor --angle/int --.specifiers/List: - this.angle = normalize_angle_ angle - validate_specifiers_ specifiers + this.angle = normalize-angle_ angle + validate-specifiers_ specifiers operator == other -> bool: if other is not GradientBackground: return false @@ -52,7 +52,7 @@ class GradientBackground implements Background: if other.specifiers[i].percent != specifiers[i].percent: return false return true - hash_code -> int: + hash-code -> int: if not hash_: hash := 0 specifiers.do: | it | @@ -65,18 +65,18 @@ class GradientBackground implements Background: if not rendering_: rendering_ = GradientRendering_.get w h this rendering_.draw canvas x y --autoclipped=autoclipped - static normalize_angle_ angle/int -> int: + static normalize-angle_ angle/int -> int: angle %= 360 if angle < 0: angle += 360 return angle - static validate_specifiers_ specifiers -> none: - last_percent := 0 + static validate-specifiers_ specifiers -> none: + last-percent := 0 if specifiers.size == 0: throw "INVALID_ARGUMENT" specifiers.do: | specifier/GradientSpecifier | - if specifier.percent < last_percent: throw "INVALID_ARGUMENT" - last_percent = specifier.percent - if last_percent > 100: throw "INVALID_ARGUMENT" + if specifier.percent < last-percent: throw "INVALID_ARGUMENT" + last-percent = specifier.percent + if last-percent > 100: throw "INVALID_ARGUMENT" class GradientSpecification_: w/int? @@ -89,21 +89,21 @@ class GradientSpecification_: operator == other -> bool: if other is not GradientSpecification_: return false if other.w != w or other.h != h: return false - if other.hash_code != hash_code: return false + if other.hash-code != hash-code: return false return other.gradient == gradient - hash_code -> int: + hash-code -> int: if not hash_: - hash_ = (w or 0) + 3 * (h or 0) + 71 * gradient.hash_code + hash_ = (w or 0) + 3 * (h or 0) + 71 * gradient.hash-code return hash_ class GradientRendering_: - red_pixels_/ByteArray? := null - green_pixels_/ByteArray? := null - blue_pixels_/ByteArray? := null - texture_length_ /int := 0 - texture_length_repeats_ /int := 1 - draw_vertical_/bool? := null + red-pixels_/ByteArray? := null + green-pixels_/ByteArray? := null + blue-pixels_/ByteArray? := null + texture-length_ /int := 0 + texture-length-repeats_ /int := 1 + draw-vertical_/bool? := null angle_ /int h_ /int := 0 w_ /int := 0 @@ -146,55 +146,55 @@ class GradientRendering_: // corner. // This is the angle that we will use to calculate the verticalness of // the rectangle. - rangle := math.atan (w.to_float / h) // From 0 to PI/2. + rangle := math.atan (w.to-float / h) // From 0 to PI/2. rangle *= 180.0 / math.PI // From 0 to 90. - draw_vertical_ = angle < rangle - texture_length/int := ? - texture_length_repeats_ = 1 - if draw_vertical_: + draw-vertical_ = angle < rangle + texture-length/int := ? + texture-length-repeats_ = 1 + if draw-vertical_: // The gradient is more vertical than the rectangle, so we will draw // vertical lines on the rectangle. - texture_length = (h + w * (math.tan (angle * math.PI / 180.0)) + 0.01).round + texture-length = (h + w * (math.tan (angle * math.PI / 180.0)) + 0.01).round if angle == 0: // For efficiency, repeat the gradient a few times in the buffer. - texture_length = h - texture_length_repeats_ = max 1 (512 / texture_length) + texture-length = h + texture-length-repeats_ = max 1 (512 / texture-length) else: // The gradient is more horizontal than the rectangle, so we will draw // horizontal lines on the rectangle. - texture_length = (w + h * (math.tan ((90 - angle) * math.PI / 180.0)) + 0.01).round + texture-length = (w + h * (math.tan ((90 - angle) * math.PI / 180.0)) + 0.01).round if angle == 90: // For efficiency, repeat the gradient a few times in the buffer. - texture_length = w - texture_length_repeats_ = max 1 (512 / texture_length) - texture_length_ = texture_length + texture-length = w + texture-length-repeats_ = max 1 (512 / texture-length) + texture-length_ = texture-length - red_pixels_ = ByteArray texture_length * texture_length_repeats_ - green_pixels_ = ByteArray texture_length * texture_length_repeats_ - blue_pixels_ = ByteArray texture_length * texture_length_repeats_ - ranges/List := extract_ranges_ specifiers + red-pixels_ = ByteArray texture-length * texture-length-repeats_ + green-pixels_ = ByteArray texture-length * texture-length-repeats_ + blue-pixels_ = ByteArray texture-length * texture-length-repeats_ + ranges/List := extract-ranges_ specifiers ranges.do: | range | - get_colors range texture_length: | index red green blue | - red_pixels_[index] = red - green_pixels_[index] = green - blue_pixels_[index] = blue - (texture_length_repeats_ - 1).repeat: - red_pixels_.replace ((it + 1) * texture_length) red_pixels_[0..texture_length] - green_pixels_.replace ((it + 1) * texture_length) green_pixels_[0..texture_length] - blue_pixels_.replace ((it + 1) * texture_length) blue_pixels_[0..texture_length] + get-colors range texture-length: | index red green blue | + red-pixels_[index] = red + green-pixels_[index] = green + blue-pixels_[index] = blue + (texture-length-repeats_ - 1).repeat: + red-pixels_.replace ((it + 1) * texture-length) red-pixels_[0..texture-length] + green-pixels_.replace ((it + 1) * texture-length) green-pixels_[0..texture-length] + blue-pixels_.replace ((it + 1) * texture-length) blue-pixels_[0..texture-length] draw canvas/Canvas x/int y/int --autoclipped/bool -> none: - if not canvas.supports_8_bit: throw "UNSUPPORTED" + if not canvas.supports-8-bit: throw "UNSUPPORTED" angle := angle_ w := w_ h := h_ - analysis := canvas.bounds_analysis x y w h + analysis := canvas.bounds-analysis x y w h if analysis == Canvas.DISJOINT: return // Determine whether the draw operations will be automatically clipped for // us, or whether we need to do it ourselves by using slices for drawing // operations. We could also check whether we are inside a window that will // use compositing to clip everything. - if analysis == Canvas.CANVAS_IN_AREA or analysis == Canvas.COINCIDENT: autoclipped = true + if analysis == Canvas.CANVAS-IN-AREA or analysis == Canvas.COINCIDENT: autoclipped = true // CSS gradient angles are: // 0 bottom to top. @@ -202,105 +202,105 @@ class GradientRendering_: // 180 top to bottom // 270 right to left - repeats := texture_length_repeats_ - source_width := 0 + repeats := texture-length-repeats_ + source-width := 0 r := null g := null b := null - update_r_g_b_block := : | y_or_x h_or_w lines orientation offset | + update-r-g-b-block := : | y-or-x h-or-w lines orientation offset | o := offset >> 16 // Repeats != 1 implies the gradient is vertical or horizontal, which // means we don't need any clipping. if autoclipped or repeats != 1: - source_width = texture_length_ - buf_size := texture_length_ * lines - r = red_pixels_[..buf_size] - g = green_pixels_[..buf_size] - b = blue_pixels_[..buf_size] - if orientation == ORIENTATION_90: - y_or_x + o // Return value. + source-width = texture-length_ + buf-size := texture-length_ * lines + r = red-pixels_[..buf-size] + g = green-pixels_[..buf-size] + b = blue-pixels_[..buf-size] + if orientation == ORIENTATION-90: + y-or-x + o // Return value. else: - y_or_x - o // Return value. + y-or-x - o // Return value. else: - r = red_pixels_[o .. o + h_or_w] - g = green_pixels_[o .. o + h_or_w] - b = blue_pixels_[o .. o + h_or_w] - source_width = h_or_w - y_or_x // Return value. + r = red-pixels_[o .. o + h-or-w] + g = green-pixels_[o .. o + h-or-w] + b = blue-pixels_[o .. o + h-or-w] + source-width = h-or-w + y-or-x // Return value. - if draw_vertical_: + if draw-vertical_: // The gradient goes broadly vertically, and we draw in vertical strips. - orientation/int := ORIENTATION_90 + orientation/int := ORIENTATION-90 // X2 and y2 are the x, y location we are drawing the gradient, but // adjusted for orientation. x2/int := x y2/int := y + h if angle >= 90: // Top to bottom. - orientation = ORIENTATION_270 + orientation = ORIENTATION-270 x2++ y2 = y // Use fixed point with 16 bits after the decimal point. - step := ((texture_length_ - h) << 16) / w + step := ((texture-length_ - h) << 16) / w offset := 0 for i := 0; i < w; i += repeats: lines := min repeats (w - i) - skew_adjusted_y := update_r_g_b_block.call y2 h lines orientation offset - if canvas.gray_scale: - canvas.pixmap (i + x2) skew_adjusted_y --pixels=b --source_width=source_width --orientation=orientation + skew-adjusted-y := update-r-g-b-block.call y2 h lines orientation offset + if canvas.gray-scale: + canvas.pixmap (i + x2) skew-adjusted-y --pixels=b --source-width=source-width --orientation=orientation else: - canvas.rgb_pixmap (i + x2) skew_adjusted_y --r=r --g=g --b=b --source_width=source_width --orientation=orientation + canvas.rgb-pixmap (i + x2) skew-adjusted-y --r=r --g=g --b=b --source-width=source-width --orientation=orientation offset += step else: // The gradient goes broadly horizontally, and we draw in horizontal // strips. up/bool := angle >= 90 - step := ((texture_length_ - w) << 16) / h // n.16 fixed point. + step := ((texture-length_ - w) << 16) / h // n.16 fixed point. offset := 0 - loop_body := : | i lines | - skew_adjusted_x := update_r_g_b_block.call x w lines ORIENTATION_0 offset - if canvas.gray_scale: - canvas.pixmap skew_adjusted_x (i + y) --pixels=b --source_width=source_width + loop-body := : | i lines | + skew-adjusted-x := update-r-g-b-block.call x w lines ORIENTATION-0 offset + if canvas.gray-scale: + canvas.pixmap skew-adjusted-x (i + y) --pixels=b --source-width=source-width else: - canvas.rgb_pixmap skew_adjusted_x (i + y) --r=r --g=g --b=b --source_width=source_width + canvas.rgb-pixmap skew-adjusted-x (i + y) --r=r --g=g --b=b --source-width=source-width offset += step if up: - for i := 0; i < h; i += repeats: loop_body.call i (min repeats (h - i)) + for i := 0; i < h; i += repeats: loop-body.call i (min repeats (h - i)) else: assert: repeats == 1 - for i := h - 1; i >= 0; i--: loop_body.call i 1 + for i := h - 1; i >= 0; i--: loop-body.call i 1 /// Returns a list of quadruples of the form starting-percent ending-percent start-color end-color. - static extract_ranges_ specifiers/List -> List: + static extract-ranges_ specifiers/List -> List: result := [] for i := -1; i < specifiers.size; i++: from := i < 0 ? 0 : specifiers[i].percent to := i >= specifiers.size - 1 ? 100 : specifiers[i + 1].percent if to != from: - from_color := specifiers[max i 0].color - to_color := specifiers[min (i + 1) (specifiers.size - 1)].color - result.add [from, to, from_color, to_color] + from-color := specifiers[max i 0].color + to-color := specifiers[min (i + 1) (specifiers.size - 1)].color + result.add [from, to, from-color, to-color] return result - static get_colors range/List h/int [block] -> none: - from_y := range[0] * h / 100 - to_y := range[1] * h / 100 - if to_y == from_y: return - divisor := to_y - from_y - from_color := range[2] + static get-colors range/List h/int [block] -> none: + from-y := range[0] * h / 100 + to-y := range[1] * h / 100 + if to-y == from-y: return + divisor := to-y - from-y + from-color := range[2] // Use 8.16 fixed point arithmetic to avoid floating point. - r := from_color & 0xff0000 - g := (from_color & 0xff00) << 8 - b := (from_color & 0xff) << 16 - to_color := range[3] - to_r := to_color & 0xff0000 - to_g := (to_color & 0xff00) << 8 - to_b := (to_color & 0xff) << 16 - step_r := (to_r - r) / divisor - step_g := (to_g - g) / divisor - step_b := (to_b - b) / divisor - for y := from_y; y < to_y; y++: + r := from-color & 0xff0000 + g := (from-color & 0xff00) << 8 + b := (from-color & 0xff) << 16 + to-color := range[3] + to-r := to-color & 0xff0000 + to-g := (to-color & 0xff00) << 8 + to-b := (to-color & 0xff) << 16 + step-r := (to-r - r) / divisor + step-g := (to-g - g) / divisor + step-b := (to-b - b) / divisor + for y := from-y; y < to-y; y++: block.call y (r >> 16) (g >> 16) (b >> 16) - r += step_r - g += step_g - b += step_b + r += step-r + g += step-g + b += step-b diff --git a/src/gray_scale.toit b/src/gray_scale.toit index 6747b69..21ce81f 100644 --- a/src/gray_scale.toit +++ b/src/gray_scale.toit @@ -3,22 +3,22 @@ // found in the LICENSE file. /** -Constants useful for $PixelDisplay.gray_scale. +Constants useful for $PixelDisplay.gray-scale. */ import bitmap show * import font show Font import icons show Icon -import .pixel_display show PixelDisplay // For the doc comments. -import .one_byte +import .pixel-display show PixelDisplay // For the doc comments. +import .one-byte -/// Color value for use with $PixelDisplay.gray_scale. +/// Color value for use with $PixelDisplay.gray-scale. WHITE ::= 255 -/// Color value for use with $PixelDisplay.gray_scale. -LIGHT_GRAY ::= 170 -/// Color value for use with $PixelDisplay.gray_scale. -DARK_GRAY ::= 85 -/// Color value for use with $PixelDisplay.gray_scale. +/// Color value for use with $PixelDisplay.gray-scale. +LIGHT-GRAY ::= 170 +/// Color value for use with $PixelDisplay.gray-scale. +DARK-GRAY ::= 85 +/// Color value for use with $PixelDisplay.gray-scale. BLACK ::= 0 // The canvas contains a ByteArray. @@ -27,13 +27,13 @@ class Canvas_ extends OneByteCanvas_: constructor width/int height/int: super width height - supports_8_bit -> bool: return true - gray_scale -> bool: return true + supports-8-bit -> bool: return true + gray-scale -> bool: return true /** Creates a blank canvas with the same dimensions as this one. */ - create_similar: + create-similar: result := Canvas_ width_ height_ result.transform=transform return result diff --git a/src/one_byte.toit b/src/one_byte.toit index c30f80b..0ca1e01 100644 --- a/src/one_byte.toit +++ b/src/one_byte.toit @@ -10,7 +10,7 @@ import bitmap show * import font show Font import icons show Icon import .common -import .gray_scale as gray_scale_ +import .gray-scale as gray-scale_ // The canvas contains a ByteArray. // Initially all pixels are 0. @@ -22,97 +22,97 @@ abstract class OneByteCanvas_ extends Canvas: pixels_ = ByteArray size super width height - set_all_pixels color/int -> none: - bytemap_zap pixels_ color + set-all-pixels color/int -> none: + bytemap-zap pixels_ color - get_pixel_ x y: + get-pixel_ x y: return pixels_[x + width_ * y] - make_alpha_map --padding/int=0 -> gray_scale_.Canvas_: - result := gray_scale_.Canvas_ (width_ + padding) (height_ + padding) + make-alpha-map --padding/int=0 -> gray-scale_.Canvas_: + result := gray-scale_.Canvas_ (width_ + padding) (height_ + padding) result.transform=transform return result - composit frame_opacity frame_canvas/OneByteCanvas_? painting_opacity painting_canvas/OneByteCanvas_: - fo := frame_opacity is ByteArray ? frame_opacity : frame_opacity.pixels_ - po := painting_opacity is ByteArray ? painting_opacity : painting_opacity.pixels_ - composit_bytes pixels_ fo (frame_canvas ? frame_canvas.pixels_ : null) po painting_canvas.pixels_ false + composit frame-opacity frame-canvas/OneByteCanvas_? painting-opacity painting-canvas/OneByteCanvas_: + fo := frame-opacity is ByteArray ? frame-opacity : frame-opacity.pixels_ + po := painting-opacity is ByteArray ? painting-opacity : painting-opacity.pixels_ + composit-bytes pixels_ fo (frame-canvas ? frame-canvas.pixels_ : null) po painting-canvas.pixels_ false rectangle x/int y/int --w/int --h/int --color/int: transform.xywh x y w h: | x2 y2 w2 h2 | - bytemap_rectangle x2 y2 color w2 h2 pixels_ width_ + bytemap-rectangle x2 y2 color w2 h2 pixels_ width_ - text x/int y/int --text/string --color/int --font/Font --orientation/int=ORIENTATION_0: + text x/int y/int --text/string --color/int --font/Font --orientation/int=ORIENTATION-0: transform.xyo x y orientation: | x2 y2 o2 | - bytemap_draw_text x2 y2 color o2 text font pixels_ width_ + bytemap-draw-text x2 y2 color o2 text font pixels_ width_ bitmap x/int y/int -> none --pixels/ByteArray --alpha/ByteArray // 2-element byte array. --palette/ByteArray // 4 element byte array. - --source_width/int // In pixels. - --source_line_stride/int // In bytes. - --orientation/int=ORIENTATION_0: - source_byte_width := (source_width + 7) >> 3 - zero_alpha := alpha[0] + --source-width/int // In pixels. + --source-line-stride/int // In bytes. + --orientation/int=ORIENTATION-0: + source-byte-width := (source-width + 7) >> 3 + zero-alpha := alpha[0] // Fast case if the alpha is either 0 or 0xff, because we can use the // primitives that paint 1's with a particular color and leave the zeros // transparent. We don't check for the case where 0 is opaque and 1 is // transparent, because pngunzip fixes that for us. - if alpha[1] == 0xff and (zero_alpha == 0xff or zero_alpha == 0): - if zero_alpha == 0xff: // If the zeros in the bitmap are drawn (opaque). - h := (pixels.size + source_line_stride - source_byte_width ) / source_line_stride + if alpha[1] == 0xff and (zero-alpha == 0xff or zero-alpha == 0): + if zero-alpha == 0xff: // If the zeros in the bitmap are drawn (opaque). + h := (pixels.size + source-line-stride - source-byte-width ) / source-line-stride // Draw the zeros. - rectangle x y --w=source_width --h=h --color=palette[0] + rectangle x y --w=source-width --h=h --color=palette[0] // Draw the ones. transform.xyo x y orientation: | x2 y2 o2 | - bitmap_draw_bitmap x2 y2 + bitmap-draw-bitmap x2 y2 --color = palette[3] --orientation = o2 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride + --source-width = source-width + --source-line-stride = source-line-stride --destination = pixels_ - --destination_width = width_ + --destination-width = width_ --bytewise return // Unfortunately one of the alpha values is not 0 or 0xff, so we can't use // the bitmap draw primitive. We can blow it up to bytes, then use the // bitmap_draw_bytemap. - h := (pixels.size + source_line_stride - source_byte_width ) / source_line_stride - bytemap := ByteArray source_width * h - bitmap_draw_bitmap 0 0 + h := (pixels.size + source-line-stride - source-byte-width ) / source-line-stride + bytemap := ByteArray source-width * h + bitmap-draw-bitmap 0 0 --color = 1 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride + --source-width = source-width + --source-line-stride = source-line-stride --destination = bytemap - --destination_width = source_width + --destination-width = source-width --bytewise transform.xyo x y 0: | x2 y2 o2 | - bitmap_draw_bytemap x2 y2 + bitmap-draw-bytemap x2 y2 --alpha = alpha --orientation = o2 --source = bytemap - --source_width = source_width + --source-width = source-width --palette = palette --destination = pixels_ - --destination_width = width_ + --destination-width = width_ pixmap x/int y/int --pixels/ByteArray --alpha/ByteArray=#[] --palette/ByteArray=#[] - --source_width/int - --orientation/int=ORIENTATION_0 - --source_line_stride/int=source_width: + --source-width/int + --orientation/int=ORIENTATION-0 + --source-line-stride/int=source-width: transform.xyo x y orientation: | x2 y2 o2 | - bitmap_draw_bytemap x2 y2 + bitmap-draw-bytemap x2 y2 --alpha = alpha --orientation = o2 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride + --source-width = source-width + --source-line-stride = source-line-stride --palette = palette --destination = pixels_ - --destination_width = width_ + --destination-width = width_ diff --git a/src/pixel_display.toit b/src/pixel_display.toit index 7823a4f..6cd7936 100644 --- a/src/pixel_display.toit +++ b/src/pixel_display.toit @@ -11,26 +11,26 @@ import bitmap show * import font show Font import icons show Icon -import .bar_code +import .bar-code import .common import .element -import .two_color as two_color -import .three_color as three_color -import .two_bit_texture as two_bit -import .four_gray as four_gray -import .true_color as true_color -import .gray_scale as gray_scale -import .several_color as several_color -import .one_byte as one_byte +import .two-color as two-color +import .three-color as three-color +import .two-bit-texture as two-bit +import .four-gray as four-gray +import .true-color as true-color +import .gray-scale as gray-scale +import .several-color as several-color +import .one-byte as one-byte import .style -FLAG_2_COLOR ::= 0b1 -FLAG_3_COLOR ::= 0b10 -FLAG_4_COLOR ::= 0b100 -FLAG_GRAY_SCALE ::= 0b1000 -FLAG_SEVERAL_COLOR ::= 0b10000 -FLAG_TRUE_COLOR ::= 0b100000 -FLAG_PARTIAL_UPDATES ::= 0b1000000 +FLAG-2-COLOR ::= 0b1 +FLAG-3-COLOR ::= 0b10 +FLAG-4-COLOR ::= 0b100 +FLAG-GRAY-SCALE ::= 0b1000 +FLAG-SEVERAL-COLOR ::= 0b10000 +FLAG-TRUE-COLOR ::= 0b100000 +FLAG-PARTIAL-UPDATES ::= 0b1000000 /** Abstract superclass for all pixel display drivers. @@ -43,21 +43,21 @@ abstract class AbstractDriver: abstract width -> int abstract height -> int abstract flags -> int - x_rounding -> int: return 8 - y_rounding -> int: return 8 - start_partial_update speed/int -> none: - start_full_update speed/int -> none: + x-rounding -> int: return 8 + y-rounding -> int: return 8 + start-partial-update speed/int -> none: + start-full-update speed/int -> none: clean left/int top/int right/int bottom/int -> none: commit left/int top/int right/int bottom/int -> none: - draw_two_color l/int t/int r/int b/int pixels/ByteArray -> none: + draw-two-color l/int t/int r/int b/int pixels/ByteArray -> none: throw "Not a two-color driver" - draw_two_bit l/int t/int r/int b/int plane0/ByteArray plane1/ByteArray -> none: + draw-two-bit l/int t/int r/int b/int plane0/ByteArray plane1/ByteArray -> none: throw "Not a two-bit driver" - draw_gray_scale l/int t/int r/int b/int pixels/ByteArray -> none: + draw-gray-scale l/int t/int r/int b/int pixels/ByteArray -> none: throw "Not a gray-scale driver" - draw_several_color l/int t/int r/int b/int pixels/ByteArray -> none: + draw-several-color l/int t/int r/int b/int pixels/ByteArray -> none: throw "Not a several-color driver" - draw_true_color l/int t/int r/int b/int red/ByteArray green/ByteArray blue/ByteArray -> none: + draw-true-color l/int t/int r/int b/int red/ByteArray green/ByteArray blue/ByteArray -> none: throw "Not a true-color driver" close -> none: @@ -75,25 +75,25 @@ abstract class PixelDisplay implements Window: background_ := null width: return driver_.width height: return driver_.width - inner_width: return driver_.width - inner_height: return driver_.width + inner-width: return driver_.width + inner-height: return driver_.width // Need-to-redraw is tracked as a bit array of dirty bits, arranged in // SSD1306 layout so we can use bitmap_rectangle to invalidate areas. // One bit in the dirty map covers an area of 8x8 pixels of the display. static CLEAN_ ::= 0 static DIRTY_ ::= 1 - dirty_bytes_per_line_ := 0 + dirty-bytes-per-line_ := 0 dirty_ := null - dirty_left_ := 0 - dirty_top_ := 0 - dirty_right_ := 0 - dirty_bottom_ := 0 + dirty-left_ := 0 + dirty-top_ := 0 + dirty-right_ := 0 + dirty-bottom_ := 0 - dirty_accumulator_ := ByteArray 1 + dirty-accumulator_ := ByteArray 1 - x_rounding_ := 1 - y_rounding_ := 1 + x-rounding_ := 1 + y-rounding_ := 1 driver_ /AbstractDriver := ? speed_ := 50 // Speed-quality of current screen update. @@ -109,7 +109,7 @@ abstract class PixelDisplay implements Window: that the display driver is exactly square, a rotated orientation is used. The orientation is rotated by 180 degrees if $inverted is true. */ - constructor.true_color driver/AbstractDriver + constructor.true-color driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: @@ -124,7 +124,7 @@ abstract class PixelDisplay implements Window: that the display driver is exactly square, a rotated orientation is used. The orientation is rotated by 180 degrees if $inverted is true. */ - constructor.gray_scale driver/AbstractDriver + constructor.gray-scale driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: @@ -139,7 +139,7 @@ abstract class PixelDisplay implements Window: that the display driver is exactly square, a rotated orientation is used. The orientation is rotated by 180 degrees if $inverted is true. */ - constructor.several_color driver/AbstractDriver + constructor.several-color driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: @@ -154,7 +154,7 @@ abstract class PixelDisplay implements Window: that the display driver is exactly square, a rotated orientation is used. The orientation is rotated by 180 degrees if $inverted is true. */ - constructor.four_gray driver/AbstractDriver + constructor.four-gray driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: @@ -169,7 +169,7 @@ abstract class PixelDisplay implements Window: that the display driver is exactly square, a rotated orientation is used. The orientation is rotated by 180 degrees if $inverted is true. */ - constructor.three_color driver/AbstractDriver + constructor.three-color driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: @@ -184,7 +184,7 @@ abstract class PixelDisplay implements Window: that the display driver is exactly square, a rotated orientation is used. The orientation is rotated by 180 degrees if $inverted is true. */ - constructor.two_color driver/AbstractDriver + constructor.two-color driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: @@ -199,13 +199,13 @@ abstract class PixelDisplay implements Window: The orientation is rotated by 180 degrees if $inverted is true. */ constructor .driver_ --inverted/bool?=false --transform/Transform?=null --portrait/bool?=null: - x_rounding_ = driver_.x_rounding - y_rounding_ = driver_.y_rounding - height := round_up driver_.height y_rounding_ - if driver_.flags & FLAG_PARTIAL_UPDATES != 0: - dirty_bytes_per_line_ = (driver_.width >> 3) + 1 - dirty_strips := (height >> 6) + 1 // 8-tall strips of dirty bits. - dirty_ = ByteArray dirty_bytes_per_line_ * dirty_strips + x-rounding_ = driver_.x-rounding + y-rounding_ = driver_.y-rounding + height := round-up driver_.height y-rounding_ + if driver_.flags & FLAG-PARTIAL-UPDATES != 0: + dirty-bytes-per-line_ = (driver_.width >> 3) + 1 + dirty-strips := (height >> 6) + 1 // 8-tall strips of dirty bits. + dirty_ = ByteArray dirty-bytes-per-line_ * dirty-strips if transform: if portrait != null or inverted: throw "INVALID_ARGUMENT" @@ -222,25 +222,25 @@ abstract class PixelDisplay implements Window: if rotation == 0: transform_ = Transform.identity else if rotation == 90: - transform_ = (Transform.identity.translate 0 driver_.height).rotate_left + transform_ = (Transform.identity.translate 0 driver_.height).rotate-left else if rotation == 180: - transform_ = (Transform.identity.translate driver_.width driver_.height).rotate_left.rotate_left + transform_ = (Transform.identity.translate driver_.width driver_.height).rotate-left.rotate-left else: - transform_ = (Transform.identity.translate driver_.width 0).rotate_right + transform_ = (Transform.identity.translate driver_.width 0).rotate-right - if driver_.flags & FLAG_PARTIAL_UPDATES != 0: - all_is_dirty_ + if driver_.flags & FLAG-PARTIAL-UPDATES != 0: + all-is-dirty_ background= color/int -> none: if background_ != color: background_ = color - child_invalidated_ 0 0 driver_.width driver_.height + child-invalidated_ 0 0 driver_.width driver_.height - set_styles styles/List -> none: + set-styles styles/List -> none: elements_.do: if it is Element: element := it as Element - element.set_styles styles + element.set-styles styles /** Adds an element to a display. The next time the display is refreshed, this @@ -252,7 +252,7 @@ abstract class PixelDisplay implements Window: */ add element/Element -> none: elements_.add element - element.change_tracker = this + element.change-tracker = this element.invalidate /** @@ -261,30 +261,30 @@ abstract class PixelDisplay implements Window: remove element/Element -> none: elements_.remove element element.invalidate - element.change_tracker = null + element.change-tracker = null /** Removes all elements. */ - remove_all: - elements_.do: it.change_tracker = null - if elements_.size != 0: child_invalidated 0 0 driver_.width driver_.height + remove-all: + elements_.do: it.change-tracker = null + if elements_.size != 0: child-invalidated 0 0 driver_.width driver_.height elements_ = {} - get_element_by_id id/string -> any: + get-element-by-id id/string -> any: elements_.do: | child/Element | - found := child.get_element_by_id id + found := child.get-element-by-id id if found: return found return null - child_invalidated x/int y/int w/int h/int -> none: + child-invalidated x/int y/int w/int h/int -> none: transform_.xywh x y w h: | x2 y2 w2 h2 | - child_invalidated_ x2 y2 w2 h2 + child-invalidated_ x2 y2 w2 h2 - child_invalidated_ x/int y/int w/int h/int -> none: + child-invalidated_ x/int y/int w/int h/int -> none: if not dirty_: return // Some devices don't use the dirty array to track changes. - dirty_left_ = min dirty_left_ x - dirty_right_ = max dirty_right_ (x + w) - dirty_top_ = min dirty_top_ y - dirty_bottom_ = max dirty_bottom_ (y + h) + dirty-left_ = min dirty-left_ x + dirty-right_ = max dirty-right_ (x + w) + dirty-top_ = min dirty-top_ y + dirty-bottom_ = max dirty-bottom_ (y + h) // Round up the invalidated area. rx := x & 7 @@ -295,36 +295,36 @@ abstract class PixelDisplay implements Window: h = (h + ry + 7) >> 3 // x, y, w, h now measured in 8x8 blocks. - bitmap_rectangle x y DIRTY_ w h dirty_ dirty_bytes_per_line_ + bitmap-rectangle x y DIRTY_ w h dirty_ dirty-bytes-per-line_ - line_is_clean_ y: - idx := (y >> 6) * dirty_bytes_per_line_ + line-is-clean_ y: + idx := (y >> 6) * dirty-bytes-per-line_ mask := 1 << ((y >> 3) & 0b111) - dirty_accumulator_[0] = CLEAN_ - blit dirty_[idx..idx+dirty_bytes_per_line_] dirty_accumulator_ dirty_bytes_per_line_ --destination_pixel_stride=0 --operation=OR - return dirty_accumulator_[0] & mask == CLEAN_ // Only works because CLEAN_ == 0 + dirty-accumulator_[0] = CLEAN_ + blit dirty_[idx..idx+dirty-bytes-per-line_] dirty-accumulator_ dirty-bytes-per-line_ --destination-pixel-stride=0 --operation=OR + return dirty-accumulator_[0] & mask == CLEAN_ // Only works because CLEAN_ == 0 - is_dirty_ x y: - idx := (y >> 6) * dirty_bytes_per_line_ + is-dirty_ x y: + idx := (y >> 6) * dirty-bytes-per-line_ mask := 1 << ((y >> 3) & 0b111) byte := x >> 3 return dirty_[idx + byte] & mask != CLEAN_ // Only works because CLEAN_ == 0 /// For displays that don't support any form of partial update. - draw_entire_display_: - driver_.start_full_update speed_ + draw-entire-display_: + driver_.start-full-update speed_ w := driver_.width - step := round_up - max_canvas_height_ driver_.width - y_rounding_ - canvas := create_canvas_ w step - List.chunk_up 0 (round_up driver_.height y_rounding_) step: | top bottom | + step := round-up + max-canvas-height_ driver_.width + y-rounding_ + canvas := create-canvas_ w step + List.chunk-up 0 (round-up driver_.height y-rounding_) step: | top bottom | // For the Elements. // To get the translation for this tile in the driver coordinates instead // of the display coordinates, we invert the 2d transform, then translate // it, then invert it again. canvas.transform = (transform_.invert.translate 0 top).invert - canvas.set_all_pixels background_ + canvas.set-all-pixels background_ elements_.do: it.draw canvas draw_ 0 top driver_.width bottom canvas @@ -339,72 +339,72 @@ abstract class PixelDisplay implements Window: */ draw --speed/int=50 -> none: speed_ = speed - if speed < 10 or driver_.flags & FLAG_PARTIAL_UPDATES == 0: - draw_entire_display_ - if dirty_: bitmap_zap dirty_ CLEAN_ + if speed < 10 or driver_.flags & FLAG-PARTIAL-UPDATES == 0: + draw-entire-display_ + if dirty_: bitmap-zap dirty_ CLEAN_ return // Send data for the whole screen, even if only part of it changed. - if speed < 50: all_is_dirty_ + if speed < 50: all-is-dirty_ - driver_.start_partial_update speed + driver_.start-partial-update speed refreshed := false try: - refresh_dimensions ::= [driver_.width, 0, driver_.height, 0] - update_frame_buffer false refresh_dimensions - refresh_ refresh_dimensions[0] refresh_dimensions[2] refresh_dimensions[1] refresh_dimensions[3] + refresh-dimensions ::= [driver_.width, 0, driver_.height, 0] + update-frame-buffer false refresh-dimensions + refresh_ refresh-dimensions[0] refresh-dimensions[2] refresh-dimensions[1] refresh-dimensions[3] refreshed = true finally: if not refreshed: refresh_ 0 0 0 0 - all_is_clean_ + all-is-clean_ - all_is_clean_ -> none: - bitmap_zap dirty_ CLEAN_ - dirty_left_ = driver_.width - dirty_right_ = 0 - dirty_top_ = driver_.height - dirty_bottom_ = 0 + all-is-clean_ -> none: + bitmap-zap dirty_ CLEAN_ + dirty-left_ = driver_.width + dirty-right_ = 0 + dirty-top_ = driver_.height + dirty-bottom_ = 0 - all_is_dirty_ -> none: - bitmap_zap dirty_ DIRTY_ - dirty_left_ = 0 - dirty_right_ = driver_.width - dirty_top_ = 0 - dirty_bottom_ = driver_.height + all-is-dirty_ -> none: + bitmap-zap dirty_ DIRTY_ + dirty-left_ = 0 + dirty-right_ = driver_.width + dirty-top_ = 0 + dirty-bottom_ = driver_.height // Clean determines if we should clean or draw the dirty area. - update_frame_buffer clean/bool refresh_dimensions -> none: + update-frame-buffer clean/bool refresh-dimensions -> none: redraw := : | l t r b | if clean: - clean_rect_ l t r b + clean-rect_ l t r b else: - redraw_rect_ l t r b + redraw-rect_ l t r b // Perhaps we can do it all with one canvas. - l := round_down (max 0 dirty_left_) x_rounding_ - r := round_up (min driver_.width dirty_right_) x_rounding_ - t := round_down (max 0 dirty_top_) y_rounding_ - b := round_up (min driver_.height dirty_bottom_) y_rounding_ + l := round-down (max 0 dirty-left_) x-rounding_ + r := round-up (min driver_.width dirty-right_) x-rounding_ + t := round-down (max 0 dirty-top_) y-rounding_ + b := round-up (min driver_.height dirty-bottom_) y-rounding_ if l >= r or t >= b: return - if (max_canvas_height_ (r - l)) >= b - t: + if (max-canvas-height_ (r - l)) >= b - t: redraw.call l t r b return // Perhaps we can do it in two canvases, split to be as square as // possible. - if r - l > b - t and r - l >= x_rounding_ * 2: - w := round_up ((r - l) >> 1) x_rounding_ - if (max_canvas_height_ w) >= b - t: + if r - l > b - t and r - l >= x-rounding_ * 2: + w := round-up ((r - l) >> 1) x-rounding_ + if (max-canvas-height_ w) >= b - t: redraw.call l t (l + w) b redraw.call (l + w) t r b return // Perhaps we can do it in two canvases, split vertically. - else if b - t >= y_rounding_ * 2: - h := round_up ((b - t) >> 1) y_rounding_ - if (max_canvas_height_ (r - l)) >= h: + else if b - t >= y-rounding_ * 2: + h := round-up ((b - t) >> 1) y-rounding_ + if (max-canvas-height_ (r - l)) >= h: redraw.call l t r (t + h) redraw.call l (t + h) r b return @@ -412,100 +412,100 @@ abstract class PixelDisplay implements Window: // 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-target := 64 width := ? - max_height := ? + 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_ + 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 + 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 + 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 + start-x := round-down (max 0 dirty-left_) 8 // Outer loop - the coarse rectangles that are the max size of // update patches. - for y:= 0; y < driver_.height; y += max_height: - while line_is_clean_ y: + for y:= 0; y < driver_.height; y += max-height: + while line-is-clean_ y: y = (y + 8) & ~7 // Move on to next factor of 8. if y >= driver_.height: break if y >= driver_.height: break - for x := start_x; x < driver_.width; x += width: + for x := start-x; x < driver_.width; x += width: left := x right := min (x + width) driver_.width top := y - bottom := min (y + max_height) driver_.height + bottom := min (y + max-height) driver_.height // Quick check if the whole rectangle is clean. This is a little // imprecise because the same mask is used for all lines. mask := 0 for iy := top; iy < bottom; iy += 8: mask |= 1 << ((iy >> 3) & 0b111) - idx := (top >> 6) * dirty_bytes_per_line_ + (left >> 3) - end_idx := ((round_up bottom 64) >> 6) * dirty_bytes_per_line_ - dirty_accumulator_[0] = CLEAN_ - blit dirty_[idx..end_idx] dirty_accumulator_ ((right - left + 7) >> 3) --source_line_stride=dirty_bytes_per_line_ --destination_pixel_stride=0 --destination_line_stride=0 --operation=OR - if dirty_accumulator_[0] & mask == CLEAN_: + idx := (top >> 6) * dirty-bytes-per-line_ + (left >> 3) + end-idx := ((round-up bottom 64) >> 6) * dirty-bytes-per-line_ + dirty-accumulator_[0] = CLEAN_ + blit dirty_[idx..end-idx] dirty-accumulator_ ((right - left + 7) >> 3) --source-line-stride=dirty-bytes-per-line_ --destination-pixel-stride=0 --destination-line-stride=0 --operation=OR + if dirty-accumulator_[0] & mask == CLEAN_: continue // Inner loop. For each coarse rectangle, find the smallest rectangle // that covers all the dirty bits. - dirty_left := right - dirty_right := left - dirty_top := bottom - dirty_bottom := top + dirty-left := right + dirty-right := left + dirty-top := bottom + dirty-bottom := top for iy := top; iy < bottom; iy += 8: - line_mask := 1 << ((iy >> 3) & 0b111) - if dirty_accumulator_[0] & line_mask == CLEAN_: + line-mask := 1 << ((iy >> 3) & 0b111) + if dirty-accumulator_[0] & line-mask == CLEAN_: continue for ix := left; ix < right; ix += 8: - if is_dirty_ ix iy: - dirty_left = min dirty_left ix - dirty_right = max dirty_right (ix + 8) - dirty_top = min dirty_top iy - dirty_bottom = max dirty_bottom (iy + 8) - dirty_left = max dirty_left (round_down (max 0 dirty_left_) x_rounding_) - dirty_right = min dirty_right (round_up (min driver_.width dirty_right_) x_rounding_) - dirty_top = max dirty_top (round_down (max 0 dirty_top_) y_rounding_) - dirty_bottom = min dirty_bottom (round_up (min driver_.height dirty_bottom_) y_rounding_) - if dirty_left <= dirty_right and dirty_top <= dirty_bottom: - if dirty_top < refresh_dimensions[2]: refresh_dimensions[2] = dirty_top - if dirty_bottom > refresh_dimensions[3]: refresh_dimensions[3] = dirty_bottom - if dirty_left < refresh_dimensions[0]: refresh_dimensions[0] = dirty_left - if dirty_right > refresh_dimensions[1]: refresh_dimensions[1] = dirty_right - redraw.call dirty_left dirty_top dirty_right dirty_bottom - - redraw_rect_ left/int top/int right/int bottom/int -> none: - canvas := create_canvas_ (right - left) (bottom - top) + if is-dirty_ ix iy: + dirty-left = min dirty-left ix + dirty-right = max dirty-right (ix + 8) + dirty-top = min dirty-top iy + dirty-bottom = max dirty-bottom (iy + 8) + dirty-left = max dirty-left (round-down (max 0 dirty-left_) x-rounding_) + dirty-right = min dirty-right (round-up (min driver_.width dirty-right_) x-rounding_) + dirty-top = max dirty-top (round-down (max 0 dirty-top_) y-rounding_) + dirty-bottom = min dirty-bottom (round-up (min driver_.height dirty-bottom_) y-rounding_) + if dirty-left <= dirty-right and dirty-top <= dirty-bottom: + if dirty-top < refresh-dimensions[2]: refresh-dimensions[2] = dirty-top + if dirty-bottom > refresh-dimensions[3]: refresh-dimensions[3] = dirty-bottom + if dirty-left < refresh-dimensions[0]: refresh-dimensions[0] = dirty-left + if dirty-right > refresh-dimensions[1]: refresh-dimensions[1] = dirty-right + redraw.call dirty-left dirty-top dirty-right dirty-bottom + + redraw-rect_ left/int top/int right/int bottom/int -> none: + canvas := create-canvas_ (right - left) (bottom - top) // For the Elements: // To get the translation for this tile in the driver coordinates instead // of the display coordinates, we invert the 2d transform, then translate // it, then invert it again. canvas.transform = (transform_.invert.translate left top).invert - canvas.set_all_pixels background_ + canvas.set-all-pixels background_ elements_.do: it.draw canvas draw_ left top right bottom canvas - abstract max_canvas_height_ width/int -> int + abstract max-canvas-height_ width/int -> int - abstract create_canvas_ w/int h/int -> Canvas + abstract create-canvas_ w/int h/int -> Canvas abstract draw_ x y w h canvas/Canvas -> none - clean_rect_ left/int top/int right/int bottom/int -> none: + clean-rect_ left/int top/int right/int bottom/int -> none: driver_.clean left top right bottom refresh_ left/int top/int right/int bottom/int -> none: @@ -527,26 +527,26 @@ See https://docs.toit.io/language/sdk/display class TwoColorPixelDisplay_ extends PixelDisplay: constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: super driver --inverted=inverted --portrait=portrait --transform=transform - background_ = two_color.WHITE + background_ = two-color.WHITE - max_canvas_height_ width/int -> int: + max-canvas-height_ width/int -> int: height := 0 - width_rounded := round_up width 8 - height_rounded := round_up driver_.height 8 - if width_rounded * height_rounded >> 3 < 4000: + width-rounded := round-up width 8 + height-rounded := round-up driver_.height 8 + if width-rounded * height-rounded >> 3 < 4000: // If we can fit both the red and black plane in < 8k then do that. - height = height_rounded + height = height-rounded else: // Some multiple of 8 where each plane fits in one page. - height = (4000 / width_rounded) << 3 + height = (4000 / width-rounded) << 3 // We can't work well with canvases that are less than 8 pixels tall. return max 8 height - create_canvas_ w/int h/int -> Canvas: - return two_color.Canvas_ w h + create-canvas_ w/int h/int -> Canvas: + return two-color.Canvas_ w h - draw_ x/int y/int w/int h/int canvas/two_color.Canvas_ -> none: - driver_.draw_two_color x y w h canvas.pixels_ + draw_ x/int y/int w/int h/int canvas/two-color.Canvas_ -> none: + driver_.draw-two-color x y w h canvas.pixels_ /** Pixel-based display with four shades of gray, connected to a device. @@ -559,10 +559,10 @@ See https://docs.toit.io/language/sdk/display class FourGrayPixelDisplay_ extends TwoBitPixelDisplay_: constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: super driver --inverted=inverted --portrait=portrait --transform=transform - background_ = four_gray.WHITE + background_ = four-gray.WHITE - create_canvas_ w/int h/int -> Canvas: - return four_gray.Canvas_ w h + create-canvas_ w/int h/int -> Canvas: + return four-gray.Canvas_ w h /** Pixel-based display with black, white, and red, connected to a device. @@ -575,32 +575,32 @@ See https://docs.toit.io/language/sdk/display class ThreeColorPixelDisplay_ extends TwoBitPixelDisplay_: constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: super driver --inverted=inverted --portrait=portrait --transform=transform - background_ = three_color.WHITE + background_ = three-color.WHITE - create_canvas_ w/int h/int -> Canvas: - return three_color.Canvas_ w h + create-canvas_ w/int h/int -> Canvas: + return three-color.Canvas_ w h abstract class TwoBitPixelDisplay_ extends PixelDisplay: - background_ := three_color.WHITE + background_ := three-color.WHITE constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: super driver --inverted=inverted --portrait=portrait --transform=transform - max_canvas_height_ width: - width_rounded := round_up width 8 - height_rounded := round_up driver_.height 8 + max-canvas-height_ width: + width-rounded := round-up width 8 + height-rounded := round-up driver_.height 8 height := ? - if width_rounded * height_rounded >> 3 < 4000: + if width-rounded * height-rounded >> 3 < 4000: // If we can fit both the red and black plane in < 8k then do that. - height = height_rounded + height = height-rounded else: // Some multiple of 8 where each plane fits in one page. - height = (4000 / width_rounded) << 3 + height = (4000 / width-rounded) << 3 // We can't work well with canvases that are less than 8 pixels tall. return max 8 height - draw_ x/int y/int w/int h/int canvas/two_bit.Canvas_ -> none: - driver_.draw_two_bit x y w h canvas.plane_0_ canvas.plane_1_ + draw_ x/int y/int w/int h/int canvas/two-bit.Canvas_ -> none: + driver_.draw-two-bit x y w h canvas.plane-0_ canvas.plane-1_ /** Pixel-based display with up to 256 shades of gray, connected to a device. @@ -613,20 +613,20 @@ See https://docs.toit.io/language/sdk/display class GrayScalePixelDisplay_ extends PixelDisplay: constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: super driver --inverted=inverted --portrait=portrait --transform=transform - background_ = gray_scale.WHITE + background_ = gray-scale.WHITE - max_canvas_height_ width: + max-canvas-height_ width: height := 0 // Keep each color component under 2k so you can fit two on a page. - height = round_down (2000 / width) 8 + height = round-down (2000 / width) 8 // We can't work well with canvases that are less than 4 pixels tall. return height < 8 ? 4 : height - create_canvas_ w/int h/int -> Canvas: - return gray_scale.Canvas_ w h + create-canvas_ w/int h/int -> Canvas: + return gray-scale.Canvas_ w h - draw_ x/int y/int w/int h/int canvas/gray_scale.Canvas_ -> none: - driver_.draw_gray_scale x y w h canvas.pixels_ + draw_ x/int y/int w/int h/int canvas/gray-scale.Canvas_ -> none: + driver_.draw-gray-scale x y w h canvas.pixels_ /** Pixel-based display with up to 256 colors, connected to a device. @@ -641,18 +641,18 @@ class SeveralColorPixelDisplay_ extends PixelDisplay: super driver --inverted=inverted --portrait=portrait --transform=transform background_ = 0 - max_canvas_height_ width: + max-canvas-height_ width: height := 0 // Keep each color component under 2k so you can fit two on a page. - height = round_down (2000 / width) 8 + height = round-down (2000 / width) 8 // We can't work well with canvases that are less than 4 pixels tall. return height < 8 ? 4 : height - create_canvas_ w/int h/int -> Canvas: - return several_color.Canvas_ w h + create-canvas_ w/int h/int -> Canvas: + return several-color.Canvas_ w h - draw_ x/int y/int w/int h/int canvas/several_color.Canvas_ -> none: - driver_.draw_several_color x y w h canvas.pixels_ + draw_ x/int y/int w/int h/int canvas/several-color.Canvas_ -> none: + driver_.draw-several-color x y w h canvas.pixels_ /** Pixel-based display with up to 16 million colors, connected to a device. @@ -665,18 +665,18 @@ See https://docs.toit.io/language/sdk/display class TrueColorPixelDisplay_ extends PixelDisplay: constructor driver/AbstractDriver --inverted/bool=false --portrait/bool=false --transform/Transform?=null: super driver --inverted=inverted --portrait=portrait --transform=transform - background_ = true_color.WHITE + background_ = true-color.WHITE - max_canvas_height_ width: + max-canvas-height_ width: height := 0 // Keep each color component under 2k then the packed 3-colors-in-2-bytes // format is still less than a page. - height = round_down (2000 / width) 8 + height = round-down (2000 / width) 8 // We can't work well with canvases that are less than 4 pixels tall. return max 4 height - create_canvas_ w/int h/int -> Canvas: - return true_color.Canvas_ w h + create-canvas_ w/int h/int -> Canvas: + return true-color.Canvas_ w h - draw_ x/int y/int w/int h/int canvas/true_color.Canvas_ -> none: - driver_.draw_true_color x y w h canvas.red_ canvas.green_ canvas.blue_ + draw_ x/int y/int w/int h/int canvas/true-color.Canvas_ -> none: + driver_.draw-true-color x y w h canvas.red_ canvas.green_ canvas.blue_ diff --git a/src/png.toit b/src/png.toit index 01cd003..72905e5 100644 --- a/src/png.toit +++ b/src/png.toit @@ -6,12 +6,12 @@ import .common import .element import .style show * -import png_tools.png_reader +import png-tools.png-reader /** Element that draws a PNG image. The width and height of the element is determined by the image. -The image is given by a byte array, $png_file, which must be a valid PNG file. +The image is given by a byte array, $png-file, which must be a valid PNG file. The PNG file can be converted to a Toit byte array using the xxxd tool (https://github.com/toitware/xxxd). The PNG file can be compressed (a normal PNG file) or uncompressed. @@ -35,7 +35,7 @@ Only PNGs with up to 8 bits per pixel are supported. They can be transparent, and the opaque colors fully opaque. */ class Png extends CustomElement: - png_/png_reader.AbstractPng + png_/png-reader.AbstractPng /** Constructs an element that displays a PNG image, given a byte array @@ -51,14 +51,14 @@ class Png extends CustomElement: --id/string?=null --background=null --border/Border?=null - --png_file/ByteArray: - info := png_reader.PngInfo png_file - if info.uncompressed_random_access: - png_ = png_reader.PngRandomAccess png_file + --png-file/ByteArray: + info := png-reader.PngInfo png-file + if info.uncompressed-random-access: + png_ = png-reader.PngRandomAccess png-file else: - png_ = png_reader.Png png_file - if png_.bit_depth > 8: throw "UNSUPPORTED" - if png_.color_type == png_reader.COLOR_TYPE_TRUECOLOR or png_.color_type == png_reader.COLOR_TYPE_TRUECOLOR_ALPHA: throw "UNSUPPORTED" + png_ = png-reader.Png png-file + if png_.bit-depth > 8: throw "UNSUPPORTED" + if png_.color-type == png-reader.COLOR-TYPE-TRUECOLOR or png_.color-type == png-reader.COLOR-TYPE-TRUECOLOR-ALPHA: throw "UNSUPPORTED" super --x = x --y = y @@ -71,30 +71,30 @@ class Png extends CustomElement: --border = border // Redraw routine. - custom_draw canvas/Canvas: + custom-draw canvas/Canvas: y2 := 0 - while y2 < h and (canvas.bounds_analysis 0 y2 w (h - y2)) != Canvas.DISJOINT: - png_.get_indexed_image_data y2 h - --accept_8_bit=canvas.supports_8_bit - --need_gray_palette=canvas.gray_scale: | y_from/int y_to/int bits_per_pixel/int pixels/ByteArray line_stride/int palette/ByteArray alpha_palette/ByteArray | - if bits_per_pixel == 1: + while y2 < h and (canvas.bounds-analysis 0 y2 w (h - y2)) != Canvas.DISJOINT: + png_.get-indexed-image-data y2 h + --accept-8-bit=canvas.supports-8-bit + --need-gray-palette=canvas.gray-scale: | y-from/int y-to/int bits-per-pixel/int pixels/ByteArray line-stride/int palette/ByteArray alpha-palette/ByteArray | + if bits-per-pixel == 1: // Last line a little shorter because it has no stride padding. - adjust := line_stride - ((round_up w 8) >> 3) - pixels = pixels[0 .. (y_to - y_from) * line_stride - adjust] - canvas.bitmap 0 y_from + adjust := line-stride - ((round-up w 8) >> 3) + pixels = pixels[0 .. (y-to - y-from) * line-stride - adjust] + canvas.bitmap 0 y-from --pixels=pixels - --alpha=alpha_palette + --alpha=alpha-palette --palette=palette - --source_width=w - --source_line_stride=line_stride + --source-width=w + --source-line-stride=line-stride else: - adjust := line_stride - w - pixels = pixels[0 .. (y_to - y_from) * line_stride - adjust] - canvas.pixmap 0 y_from --pixels=pixels - --alpha=alpha_palette + adjust := line-stride - w + pixels = pixels[0 .. (y-to - y-from) * line-stride - adjust] + canvas.pixmap 0 y-from --pixels=pixels + --alpha=alpha-palette --palette=palette - --source_width=w - --source_line_stride=line_stride - y2 = y_to + --source-width=w + --source-line-stride=line-stride + y2 = y-to type -> string: return "png" diff --git a/src/several_color.toit b/src/several_color.toit index 1189eee..bf8b03c 100644 --- a/src/several_color.toit +++ b/src/several_color.toit @@ -5,8 +5,8 @@ import bitmap show * import font show Font import icons show Icon -import .one_byte -import .two_color as two_color +import .one-byte +import .two-color as two-color // The canvas contains a ByteArray. // Initially all pixels have the 0 color. @@ -14,18 +14,18 @@ class Canvas_ extends OneByteCanvas_: constructor width/int height/int: super width height - supports_8_bit -> bool: return true - gray_scale -> bool: return false + supports-8-bit -> bool: return true + gray-scale -> bool: return false /** Creates a blank canvas with the same dimensions as this one. */ - create_similar: + create-similar: result := Canvas_ width_ height_ result.transform=transform return result - static NO_MIXING_ ::= #[ + static NO-MIXING_ ::= #[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -44,10 +44,10 @@ class Canvas_ extends OneByteCanvas_: 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, ] - composit frame_opacity frame_canvas/OneByteCanvas_? painting_opacity painting_canvas/OneByteCanvas_: - fo := frame_opacity is ByteArray ? frame_opacity : frame_opacity.pixels_ - po := painting_opacity is ByteArray ? painting_opacity : painting_opacity.pixels_ + composit frame-opacity frame-canvas/OneByteCanvas_? painting-opacity painting-canvas/OneByteCanvas_: + fo := frame-opacity is ByteArray ? frame-opacity : frame-opacity.pixels_ + po := painting-opacity is ByteArray ? painting-opacity : painting-opacity.pixels_ // We can't mix pixels on a palette-based display so all pixels must be 0 or 0xff. - blit fo fo fo.size --lookup_table=NO_MIXING_ - blit po po fo.size --lookup_table=NO_MIXING_ - composit_bytes pixels_ fo (frame_canvas ? frame_canvas.pixels_ : null) po painting_canvas.pixels_ false + blit fo fo fo.size --lookup-table=NO-MIXING_ + blit po po fo.size --lookup-table=NO-MIXING_ + composit-bytes pixels_ fo (frame-canvas ? frame-canvas.pixels_ : null) po painting-canvas.pixels_ false diff --git a/src/slider.toit b/src/slider.toit index d26ca37..989bb3c 100644 --- a/src/slider.toit +++ b/src/slider.toit @@ -20,12 +20,12 @@ class Slider extends CustomElement: value_/num? := ? min_/num? := ? max_/num? := ? - background_lo_ := ? - background_hi_ := ? + background-lo_ := ? + background-hi_ := ? horizontal_ := ? - thumb_min_/int - thumb_max_/int? + thumb-min_/int + thumb-max_/int? boundary_/int := 0 type -> string: return "slider" @@ -33,13 +33,13 @@ class Slider extends CustomElement: /** Constructs a new slider element. You can provide a background to draw when the slider is above a certain level - ($background_hi), and a different one for when the slider is below that - level ($background_lo). If either background is omitted the slider is + ($background-hi), and a different one for when the slider is below that + level ($background-lo). If either background is omitted the slider is transparent in that section. The initial level of the slider is given by $value, and it should be between the values of $min and $max, which default to 0 and 100, respectively. The boundary between the two backgrounds is drawn in a linear position - between $thumb_min and $thumb_max, which default to 0, and height or width + between $thumb-min and $thumb-max, which default to 0, and height or width of the element, respectively. The slider supports the extra $Style keys "background-lo", "background-hi", "horizontal", "min", "max", and "value". @@ -54,21 +54,21 @@ class Slider extends CustomElement: --classes/List?=null --id/string?=null --border/Border?=null - --background_hi=null - --background_lo=null + --background-hi=null + --background-lo=null --value/num?=null --min/num?=0 --max/num?=100 - --thumb_min/int=0 - --thumb_max/int?=null + --thumb-min/int=0 + --thumb-max/int?=null --horizontal/bool=false: value_ = value min_ = min max_ = max - background_lo_ = background_lo - background_hi_ = background_hi - thumb_min_ = thumb_min - thumb_max_ = thumb_max + background-lo_ = background-lo + background-hi_ = background-hi + thumb-min_ = thumb-min + thumb-max_ = thumb-max horizontal_ = horizontal super --x=x @@ -81,18 +81,18 @@ class Slider extends CustomElement: --border = border recalculate_ - thumb_max: return thumb_max_ or (horizontal_ ? w : h) + thumb-max: return thumb-max_ or (horizontal_ ? w : h) recalculate_ -> none: if not (min_ and max_ and value_ and h): return if (min_ == max_): return value_ = max value_ min_ value_ = min value_ max_ - old_boundary := boundary_ - boundary_ = ((value_ - min_).to_float / (max_ - min_) * (thumb_max - thumb_min_) + 0.1).to_int + thumb_min_ - if boundary_ != old_boundary: - top := max old_boundary boundary_ - bottom := min old_boundary boundary_ + old-boundary := boundary_ + boundary_ = ((value_ - min_).to-float / (max_ - min_) * (thumb-max - thumb-min_) + 0.1).to-int + thumb-min_ + if boundary_ != old-boundary: + top := max old-boundary boundary_ + bottom := min old-boundary boundary_ if horizontal_: invalidate --x = x + w - top @@ -116,53 +116,53 @@ class Slider extends CustomElement: recalculate_ invalidate - custom_draw canvas/Canvas -> none: + custom-draw canvas/Canvas -> none: blend := false - if background_lo_ and boundary_ > thumb_min_: + if background-lo_ and boundary_ > thumb-min_: analysis := ? if horizontal_: - analysis = canvas.bounds_analysis 0 0 (w - boundary_) h + analysis = canvas.bounds-analysis 0 0 (w - boundary_) h else: - analysis = canvas.bounds_analysis 0 0 w (h - boundary_) + analysis = canvas.bounds-analysis 0 0 w (h - boundary_) if analysis != Canvas.DISJOINT: - if analysis == Canvas.CANVAS_IN_AREA or analysis == Canvas.COINCIDENT: - background_lo_.draw canvas 0 0 w h --autoclipped + if analysis == Canvas.CANVAS-IN-AREA or analysis == Canvas.COINCIDENT: + background-lo_.draw canvas 0 0 w h --autoclipped else: blend = true - if background_hi_ and boundary_ < thumb_max: + if background-hi_ and boundary_ < thumb-max: analysis := ? if horizontal_: - analysis = canvas.bounds_analysis (w - boundary_) 0 w h + analysis = canvas.bounds-analysis (w - boundary_) 0 w h else: - analysis = canvas.bounds_analysis 0 (h - boundary_) w h + analysis = canvas.bounds-analysis 0 (h - boundary_) w h if analysis != Canvas.DISJOINT: - if analysis == Canvas.CANVAS_IN_AREA or analysis == Canvas.COINCIDENT: - background_hi_.draw canvas 0 0 w h --autoclipped + if analysis == Canvas.CANVAS-IN-AREA or analysis == Canvas.COINCIDENT: + background-hi_.draw canvas 0 0 w h --autoclipped else: blend = true if not blend: return - lo_alpha := background_lo_ ? canvas.make_alpha_map : Canvas.ALL_TRANSPARENT - hi_alpha := background_hi_ ? canvas.make_alpha_map : Canvas.ALL_TRANSPARENT - lo := canvas.create_similar - hi := canvas.create_similar + lo-alpha := background-lo_ ? canvas.make-alpha-map : Canvas.ALL-TRANSPARENT + hi-alpha := background-hi_ ? canvas.make-alpha-map : Canvas.ALL-TRANSPARENT + lo := canvas.create-similar + hi := canvas.create-similar - if background_lo_: + if background-lo_: if horizontal_: - lo_alpha.rectangle 0 0 --w=(w - boundary_) --h=h --color=0xff + lo-alpha.rectangle 0 0 --w=(w - boundary_) --h=h --color=0xff else: - lo_alpha.rectangle 0 0 --w=w --h=(h - boundary_) --color=0xff - Background.draw background_lo_ lo 0 0 w h --autoclipped - if background_hi_: + lo-alpha.rectangle 0 0 --w=w --h=(h - boundary_) --color=0xff + Background.draw background-lo_ lo 0 0 w h --autoclipped + if background-hi_: if horizontal_: - hi_alpha.rectangle (w - boundary_) 0 --w=boundary_ --h=h --color=0xff + hi-alpha.rectangle (w - boundary_) 0 --w=boundary_ --h=h --color=0xff else: - hi_alpha.rectangle 0 (h - boundary_) --w=w --h=boundary_ --color=0xff - Background.draw background_hi_ hi 0 0 w h --autoclipped + hi-alpha.rectangle 0 (h - boundary_) --w=w --h=boundary_ --color=0xff + Background.draw background-hi_ hi 0 0 w h --autoclipped - canvas.composit hi_alpha hi lo_alpha lo + canvas.composit hi-alpha hi lo-alpha lo - set_attribute_ key/string value -> none: + set-attribute_ key/string value -> none: if key == "value": value_ = value recalculate_ @@ -173,10 +173,10 @@ class Slider extends CustomElement: max_ = value recalculate_ else if key == "background-lo": - background_lo_ = value + background-lo_ = value invalidate else if key == "background-hi": - background_hi_ = value + background-hi_ = value invalidate else if key == "horizontal": invalidate diff --git a/src/style.toit b/src/style.toit index 86d9512..3d4d003 100644 --- a/src/style.toit +++ b/src/style.toit @@ -3,18 +3,18 @@ // found in the LICENSE file. import bitmap -import bitmap show ORIENTATION_0 ORIENTATION_90 ORIENTATION_180 ORIENTATION_270 +import bitmap show ORIENTATION-0 ORIENTATION-90 ORIENTATION-180 ORIENTATION-270 import font show Font import .common import .element as element -import .one_byte as one_byte +import .one-byte as one-byte -ALIGN_LEFT ::= 0 -ALIGN_CENTER ::= 1 -ALIGN_RIGHT ::= 2 +ALIGN-LEFT ::= 0 +ALIGN-CENTER ::= 1 +ALIGN-RIGHT ::= 2 -EMPTY_STYLE_ ::= Style +EMPTY-STYLE_ ::= Style /** A background is anything that can draw itself on an element as a background. @@ -32,13 +32,13 @@ interface Background: static draw background canvas/Canvas x/int y/int w/int h/int --autoclipped/bool -> none: if background is int: if autoclipped: - canvas.set_all_pixels background + canvas.set-all-pixels background else: canvas.rectangle x y --w=w --h=h --color=background else if background != null: (background as Background).draw canvas x y w h --autoclipped=autoclipped - static check_valid background -> none: + static check-valid background -> none: if background != null and background is not int and background is not Background: throw "INVALID_ARGUMENT" @@ -63,12 +63,12 @@ interface Border: redrawn if the container with this border moves. For example for drop shadows this will include the shadow. */ - invalidation_area x/int y/int w/int h/int [block] -> none + invalidation-area x/int y/int w/int h/int [block] -> none /** Calls the block with the w and h after the border has been subtracted. */ - inner_dimensions w/int h/int [block] -> none + inner-dimensions w/int h/int [block] -> none /** Calls the block with the width of the left and top edges, indicating how much @@ -82,13 +82,13 @@ interface Border: We don't need to carve out the window content, there is assumed to be a different alpha map for that. */ - frame_map canvas/Canvas w/int h/int + frame-map canvas/Canvas w/int h/int /** Draws 100% opacity for the window content. In the simplest case this is a filled rectangle. */ - content_map canvas/Canvas w/int h/int + content-map canvas/Canvas w/int h/int /** Borders that are not actually drawn, but you can see where they are by the @@ -98,110 +98,110 @@ abstract class InvisibleBorder implements Border: draw canvas x y w h: // Nothing to draw. - invalidation_area x/int y/int w/int h/int [block]: + invalidation-area x/int y/int w/int h/int [block]: block.call x y w h - inner_dimensions w h [block] -> none: + inner-dimensions w h [block] -> none: block.call w h offsets [block] -> none: block.call 0 0 - frame_map canvas w h: - return Canvas.ALL_TRANSPARENT + frame-map canvas w h: + return Canvas.ALL-TRANSPARENT - abstract content_map canvas/Canvas w/int h/int + abstract content-map canvas/Canvas w/int h/int class NoBorder extends InvisibleBorder: - content_map canvas/Canvas w/int h/int: - transparency_map := canvas.make_alpha_map - transparency_map.rectangle 0 0 --w=w --h=h --color=0xff - return transparency_map + content-map canvas/Canvas w/int h/int: + transparency-map := canvas.make-alpha-map + transparency-map.rectangle 0 0 --w=w --h=h --color=0xff + return transparency-map -NO_BORDER_/Border ::= NoBorder +NO-BORDER_/Border ::= NoBorder /// A rectangular border inside the window's area, with a solid color. class SolidBorder implements Border: - border_width_/BorderWidth + border-width_/BorderWidth color_/int constructor --width/int --color/int: color_ = color - border_width_ = BorderWidth width + border-width_ = BorderWidth width - constructor --border_width/BorderWidth --color/int: + constructor --border-width/BorderWidth --color/int: color_ = color - border_width_ = border_width + border-width_ = border-width - invalidation_area x/int y/int w/int h/int [block]: + invalidation-area x/int y/int w/int h/int [block]: block.call x y w h - inner_dimensions w/int h/int [block] -> none: - border_width_.inner_dimensions w h block + inner-dimensions w/int h/int [block] -> none: + border-width_.inner-dimensions w h block offsets [block] -> none: - border_width_.offsets block + border-width_.offsets block draw canvas/Canvas x/int y/int w/int h/int -> none: - if border_width_.left != 0: - canvas.rectangle x y --w=border_width_.left --h=h --color=color_ - if border_width_.right != 0: - canvas.rectangle (x + w - border_width_.right) y --w=border_width_.right --h=h --color=color_ - if border_width_.top != 0: - canvas.rectangle x y --w=w --h=border_width_.top --color=color_ - if border_width_.bottom != 0: - canvas.rectangle x (y + h - border_width_.bottom) --w=w --h=border_width_.bottom --color=color_ + if border-width_.left != 0: + canvas.rectangle x y --w=border-width_.left --h=h --color=color_ + if border-width_.right != 0: + canvas.rectangle (x + w - border-width_.right) y --w=border-width_.right --h=h --color=color_ + if border-width_.top != 0: + canvas.rectangle x y --w=w --h=border-width_.top --color=color_ + if border-width_.bottom != 0: + canvas.rectangle x (y + h - border-width_.bottom) --w=w --h=border-width_.bottom --color=color_ // Draws 100% opacity for the border and frame shape. We don't need to carve // out the window content, there is assumed to be a different alpha map for // that. - frame_map canvas/Canvas w/int h/int: - if border_width_ == 0: return Canvas.ALL_TRANSPARENT // The frame is not visible anywhere. + frame-map canvas/Canvas w/int h/int: + if border-width_ == 0: return Canvas.ALL-TRANSPARENT // The frame is not visible anywhere. // Transform inner dimensions not including border - border_widths := border_width_.left + border_width_.right - border_heights := border_width_.top + border_width_.bottom - canvas.transform.xywh border_width_.left border_width_.top (w - border_widths) (h - border_heights): | x2 y2 w2 h2 | + border-widths := border-width_.left + border-width_.right + border-heights := border-width_.top + border-width_.bottom + canvas.transform.xywh border-width_.left border-width_.top (w - border-widths) (h - border-heights): | x2 y2 w2 h2 | if x2 <= 0 and y2 <= 0 and x2 + w2 >= canvas.width_ and y2 + h2 >= canvas.height_: // In the middle, the window content is 100% opaque and draw on top of the // frame. There is no need to provide a frame alpha map, so for efficiency we // just return 0 which indicates the frame is 100% transparent. - return Canvas.ALL_TRANSPARENT + return Canvas.ALL-TRANSPARENT canvas.transform.xywh 0 0 w h: | x2 y2 w2 h2 | right := x2 + w2 bottom := y2 + h2 if right <= 0 or bottom <= 0 or x2 >= canvas.width_ or y2 >= canvas.height_: // The frame is completely outside the window, so it is 100% transparent. - return Canvas.ALL_TRANSPARENT + return Canvas.ALL-TRANSPARENT // We need to create a bitmap to describe the frame's extent. - transparency_map := canvas.make_alpha_map + transparency-map := canvas.make-alpha-map // Declare the whole area inside the frame's extent opaque. The window content will // draw on top of this as needed. - transparency_map.rectangle 0 0 + transparency-map.rectangle 0 0 --w = w --h = h --color = 0xff - return transparency_map + return transparency-map // Draws 100% opacity for the window content, a filled rectangle. - content_map canvas/Canvas w/int h/int: - border_widths := border_width_.left + border_width_.right - border_heights := border_width_.top + border_width_.bottom - canvas.transform.xywh border_width_.left border_width_.top (w - border_widths) (h - border_heights): | x2 y2 w2 h2 | + content-map canvas/Canvas w/int h/int: + border-widths := border-width_.left + border-width_.right + border-heights := border-width_.top + border-width_.bottom + canvas.transform.xywh border-width_.left border-width_.top (w - border-widths) (h - border-heights): | x2 y2 w2 h2 | if x2 <= 0 and y2 <= 0 and x2 + w2 >= canvas.width_ and y2 + h2 >= canvas.height_: - return Canvas.ALL_OPAQUE // The content is 100% opaque in the middle. + return Canvas.ALL-OPAQUE // The content is 100% opaque in the middle. right := x2 + w2 bottom := y2 + h2 if right <= 0 or bottom <= 0 or x2 >= canvas.width_ or y2 >= canvas.height_: - return Canvas.ALL_TRANSPARENT // The content is 100% transparent outside the window. + return Canvas.ALL-TRANSPARENT // The content is 100% transparent outside the window. // We need to create a bitmap to describe the content's extent. - transparency_map := canvas.make_alpha_map + transparency-map := canvas.make-alpha-map // Declare the whole area inside the content's extent opaque. The window content will // draw on top of this as needed. - transparency_map.rectangle border_width_.left border_width_.top - --w = w - border_widths - --h = h - border_heights + transparency-map.rectangle border-width_.left border-width_.top + --w = w - border-widths + --h = h - border-heights --color = 0xff - return transparency_map + return transparency-map /// For use with $SolidBorder. class BorderWidth: @@ -215,14 +215,14 @@ class BorderWidth: left = top = right = bottom = width /// A constructor with a different thickness on the top and bottom vs. the sides. - constructor --top_and_bottom/int --left_and_right/int: - top = bottom = top_and_bottom - left = right = left_and_right + constructor --top-and-bottom/int --left-and-right/int: + top = bottom = top-and-bottom + left = right = left-and-right /// A constructor with arbitrary thickness on all sides and zero on all unmentioned sides. constructor --.top/int=0 --.right/int=0 --.bottom/int=0 --.left/int=0: - inner_dimensions w/int h/int [block]: + inner-dimensions w/int h/int [block]: block.call (w - left - right) (h - top - bottom) offsets [block]: @@ -232,40 +232,40 @@ class BorderWidth: class RoundedCornerBorder extends InvisibleBorder: radius_/int := ? opacities_/RoundedCornerOpacity_? := null - shadow_palette_/ByteArray := #[] + shadow-palette_/ByteArray := #[] constructor --radius/int=5: - if not 0 <= radius <= RoundedCornerOpacity_.TABLE_SIZE_: throw "OUT_OF_RANGE" + if not 0 <= radius <= RoundedCornerOpacity_.TABLE-SIZE_: throw "OUT_OF_RANGE" radius_ = radius radius -> int: return radius_ - ensure_opacities_: + ensure-opacities_: if opacities_: return opacities_ = RoundedCornerOpacity_.get radius_ // Draws 100% opacity for the window content, a filled rounded-corner rectangle. - content_map canvas/Canvas w/int h/int: + content-map canvas/Canvas w/int h/int: canvas.transform.xywh 0 0 w h: | x2 y2 w2 h2 | right := x2 + w2 bottom := y2 + h2 if x2 >= canvas.width_ or y2 >= canvas.height_ or right <= 0 or bottom <= 0: - return Canvas.ALL_TRANSPARENT // The content is 100% transparent outside the window. + return Canvas.ALL-TRANSPARENT // The content is 100% transparent outside the window. if x2 <= 0 and y2 + radius_ <= 0 and right >= canvas.width_ and bottom - radius_ >= canvas.height_ or x2 + radius_ <= 0 and y2 <= 0 and right - radius_ >= canvas.width_ and bottom >= canvas.height_: - return Canvas.ALL_OPAQUE // The content is 100% opaque in the cross in the middle where there are no corners. + return Canvas.ALL-OPAQUE // The content is 100% opaque in the cross in the middle where there are no corners. // We need to create a bitmap to describe the content's extent. - transparency_map := canvas.make_alpha_map - draw_rounded_corners_ transparency_map 0 0 w h 0xff - return transparency_map + transparency-map := canvas.make-alpha-map + draw-rounded-corners_ transparency-map 0 0 w h 0xff + return transparency-map - draw_rounded_corners_ transparency_map x2/int y2/int w2/int h2/int opacity/int -> none: + draw-rounded-corners_ transparency-map x2/int y2/int w2/int h2/int opacity/int -> none: // Part 1 of a cross of opacity (the rounded rectangle minus its corners). - transparency_map.rectangle (x2 + radius_) y2 --w=(w2 - 2 * radius_) --h=h2 --color=opacity + transparency-map.rectangle (x2 + radius_) y2 --w=(w2 - 2 * radius_) --h=h2 --color=opacity if radius_ == 0: return - ensure_opacities_ + ensure-opacities_ // Part 2 of the cross. - transparency_map.rectangle x2 (y2 + radius_) --w=w2 --h=(h2 - 2 * radius_) --color=opacity + transparency-map.rectangle x2 (y2 + radius_) --w=w2 --h=(h2 - 2 * radius_) --color=opacity // The rounded corners. // opacity_ has an alpha map shaped like this (only rounder). // ______ @@ -277,83 +277,83 @@ class RoundedCornerBorder extends InvisibleBorder: right := x2 + w2 - radius_ top := y2 + radius_ - 1 bottom := y2 + h2 - radius_ - if transparency_map is one_byte.OneByteCanvas_: - palette := opacity == 0xff ? #[] : shadow_palette_ - draw_corners_ x2 y2 right bottom radius_: | x y orientation | - transparency_map.pixmap x y - --pixels = opacities_.byte_opacity + if transparency-map is one-byte.OneByteCanvas_: + palette := opacity == 0xff ? #[] : shadow-palette_ + draw-corners_ x2 y2 right bottom radius_: | x y orientation | + transparency-map.pixmap x y + --pixels = opacities_.byte-opacity --palette = palette - --source_width = radius_ + --source-width = radius_ --orientation = orientation else: - draw_corners_ x2 y2 right bottom radius_: | x y orientation | - stride := (round_up radius_ 8) >> 3 - transparency_map.bitmap x y - --pixels = opacities_.bit_opacity - --alpha = ONE_ZERO_ALPHA_ - --palette = ONE_ZERO_PALETTE_ - --source_width = radius_ - --source_line_stride = stride + draw-corners_ x2 y2 right bottom radius_: | x y orientation | + stride := (round-up radius_ 8) >> 3 + transparency-map.bitmap x y + --pixels = opacities_.bit-opacity + --alpha = ONE-ZERO-ALPHA_ + --palette = ONE-ZERO-PALETTE_ + --source-width = radius_ + --source-line-stride = stride --orientation = orientation - static ONE_ZERO_PALETTE_ ::= #[0, 0, 0, 1, 1, 1] - static ONE_ZERO_ALPHA_ ::= #[0, 0xff] + static ONE-ZERO-PALETTE_ ::= #[0, 0, 0, 1, 1, 1] + static ONE-ZERO-ALPHA_ ::= #[0, 0xff] - draw_corners_ left/int top/int right/int bottom/int corner_radius/int [block]: + draw-corners_ left/int top/int right/int bottom/int corner-radius/int [block]: // Top left corner: - block.call (left + corner_radius) (top + corner_radius) ORIENTATION_180 + block.call (left + corner-radius) (top + corner-radius) ORIENTATION-180 // Top right corner: - block.call right (top + corner_radius) ORIENTATION_90 + block.call right (top + corner-radius) ORIENTATION-90 // Bottom left corner: - block.call (left + corner_radius) bottom ORIENTATION_270 + block.call (left + corner-radius) bottom ORIENTATION-270 // Bottom right corner: - block.call right bottom ORIENTATION_0 + block.call right bottom ORIENTATION-0 class ShadowRoundedCornerBorder extends RoundedCornerBorder: - blur_radius_/int := ? - drop_distance_x_/int := ? - drop_distance_y_/int := ? - shadow_opacity_percent_/int := ? - - constructor --radius/int=5 --blur_radius/int=5 --drop_distance_x/int=10 --drop_distance_y/int=10 --shadow_opacity_percent/int=25: - if not 0 <= blur_radius <= 6: throw "OUT_OF_RANGE" - blur_radius_ = blur_radius - drop_distance_x_ = drop_distance_x - drop_distance_y_ = drop_distance_y - shadow_opacity_percent_ = shadow_opacity_percent + blur-radius_/int := ? + drop-distance-x_/int := ? + drop-distance-y_/int := ? + shadow-opacity-percent_/int := ? + + constructor --radius/int=5 --blur-radius/int=5 --drop-distance-x/int=10 --drop-distance-y/int=10 --shadow-opacity-percent/int=25: + if not 0 <= blur-radius <= 6: throw "OUT_OF_RANGE" + blur-radius_ = blur-radius + drop-distance-x_ = drop-distance-x + drop-distance-y_ = drop-distance-y + shadow-opacity-percent_ = shadow-opacity-percent super --radius=radius - update_shadow_palette_ + update-shadow-palette_ - extent_helper_ [block]: - extension_left := blur_radius_ > drop_distance_x_ ? blur_radius_ - drop_distance_x_ : 0 - extension_top := blur_radius_ > drop_distance_y_ ? blur_radius_ - drop_distance_y_ : 0 - extension_right := blur_radius_ > -drop_distance_x_ ? blur_radius_ + drop_distance_x_ : 0 - extension_bottom := blur_radius_ > -drop_distance_y_ ? blur_radius_ + drop_distance_y_ : 0 - block.call extension_left extension_top extension_right extension_bottom + extent-helper_ [block]: + extension-left := blur-radius_ > drop-distance-x_ ? blur-radius_ - drop-distance-x_ : 0 + extension-top := blur-radius_ > drop-distance-y_ ? blur-radius_ - drop-distance-y_ : 0 + extension-right := blur-radius_ > -drop-distance-x_ ? blur-radius_ + drop-distance-x_ : 0 + extension-bottom := blur-radius_ > -drop-distance-y_ ? blur-radius_ + drop-distance-y_ : 0 + block.call extension-left extension-top extension-right extension-bottom - invalidation_area x/int y/int w/int h/int [block]: - extent_helper_: | left top right bottom | + invalidation-area x/int y/int w/int h/int [block]: + extent-helper_: | left top right bottom | block.call x - left y - top w + left + right h + top + bottom - blur_radius -> int: return blur_radius_ + blur-radius -> int: return blur-radius_ - drop_distance_x -> int: return drop_distance_x_ + drop-distance-x -> int: return drop-distance-x_ - drop_distance_y -> int: return drop_distance_y_ + drop-distance-y -> int: return drop-distance-y_ - shadow_opacity_percent -> int: return shadow_opacity_percent_ + shadow-opacity-percent -> int: return shadow-opacity-percent_ - update_shadow_palette_ -> none: - max_shadow_opacity := (shadow_opacity_percent_ * 2.5500001).to_int - shadow_palette_ = #[] - if max_shadow_opacity != 0xff: - shadow_palette_ = ByteArray 0x300: ((it / 3) * max_shadow_opacity) / 0xff + update-shadow-palette_ -> none: + max-shadow-opacity := (shadow-opacity-percent_ * 2.5500001).to-int + shadow-palette_ = #[] + if max-shadow-opacity != 0xff: + shadow-palette_ = ByteArray 0x300: ((it / 3) * max-shadow-opacity) / 0xff - frame_map canvas/Canvas w/int h/int: + frame-map canvas/Canvas w/int h/int: // Transform inner dimensions excluding shadow to determine if the canvas // is wholly inside the window. canvas.transform.xywh 0 0 w h: | x2 y2 w2 h2 | @@ -364,73 +364,73 @@ class ShadowRoundedCornerBorder extends RoundedCornerBorder: // In the middle, the window content is 100% opaque and draw on top of the // frame. There is no need to provide a frame alpha map, so for efficiency we // just return 0 which indicates the frame is 100% transparent. - return Canvas.ALL_TRANSPARENT + return Canvas.ALL-TRANSPARENT // Transform outer dimensions including border to determine if the canvas // is wholly outside the window and its shadow. - extent_helper_: | left top right bottom | + extent-helper_: | left top right bottom | canvas.transform.xywh -left -top (w + left + right) (h + top + bottom): | x2 y2 w2 h2 | if x2 + w2 <= 0 or y2 + h2 <= 0 or x2 >= canvas.width_ or y2 >= canvas.height_: - return Canvas.ALL_TRANSPARENT // The frame is not opaque outside the shadow + return Canvas.ALL-TRANSPARENT // The frame is not opaque outside the shadow // Create a bitmap to describe the frame's extent. It needs to be padded // relative to the canvas size so we can use the Gaussian blur. - transparency_map := canvas.make_alpha_map --padding=(blur_radius * 2) - transparency_map.transform = (canvas.transform.invert.translate -blur_radius -blur_radius).invert + transparency-map := canvas.make-alpha-map --padding=(blur-radius * 2) + transparency-map.transform = (canvas.transform.invert.translate -blur-radius -blur-radius).invert - max_shadow_opacity := (shadow_opacity_percent * 2.5500001).to_int - draw_rounded_corners_ transparency_map drop_distance_x_ drop_distance_y_ w h max_shadow_opacity + max-shadow-opacity := (shadow-opacity-percent * 2.5500001).to-int + draw-rounded-corners_ transparency-map drop-distance-x_ drop-distance-y_ w h max-shadow-opacity - if blur_radius == 0 or transparency_map is not one_byte.OneByteCanvas_: - return transparency_map + if blur-radius == 0 or transparency-map is not one-byte.OneByteCanvas_: + return transparency-map - one_byte_map := transparency_map as one_byte.OneByteCanvas_ + one-byte-map := transparency-map as one-byte.OneByteCanvas_ // Blur the shadow. - bitmap.bytemap_blur one_byte_map.pixels_ transparency_map.width_ blur_radius + bitmap.bytemap-blur one-byte-map.pixels_ transparency-map.width_ blur-radius // Crop off the extra that was added to blur. - transparency_map_unpadded := canvas.make_alpha_map + transparency-map-unpadded := canvas.make-alpha-map bitmap.blit - one_byte_map.pixels_[blur_radius + blur_radius * one_byte_map.width_..] // Source. - (transparency_map_unpadded as one_byte.OneByteCanvas_).pixels_ // Destination. - transparency_map_unpadded.width_ // Bytes per line. - --source_line_stride = transparency_map.width_ - return transparency_map_unpadded + one-byte-map.pixels_[blur-radius + blur-radius * one-byte-map.width_..] // Source. + (transparency-map-unpadded as one-byte.OneByteCanvas_).pixels_ // Destination. + transparency-map-unpadded.width_ // Bytes per line. + --source-line-stride = transparency-map.width_ + return transparency-map-unpadded - draw_frame canvas/Canvas: - canvas.set_all_pixels 0 + draw-frame canvas/Canvas: + canvas.set-all-pixels 0 class RoundedCornerOpacity_: - byte_opacity/ByteArray - bit_opacity/ByteArray + byte-opacity/ByteArray + bit-opacity/ByteArray radius/int - bitmap_width/int + bitmap-width/int static cache_ := Map.weak - static get corner_radius/int -> RoundedCornerOpacity_: - cached := cache_.get corner_radius + static get corner-radius/int -> RoundedCornerOpacity_: + cached := cache_.get corner-radius if cached: return cached - new := RoundedCornerOpacity_.private_ corner_radius - cache_[corner_radius] = new + new := RoundedCornerOpacity_.private_ corner-radius + cache_[corner-radius] = new return new - static TABLE_SIZE_/int ::= 256 + static TABLE-SIZE_/int ::= 256 // The heights of a top-right quarter circle of radius [TABLE_SIZE_]. - static QUARTER_CIRCLE_/ByteArray ::= create_quarter_circle_array_ TABLE_SIZE_ + static QUARTER-CIRCLE_/ByteArray ::= create-quarter-circle-array_ TABLE-SIZE_ - static create_quarter_circle_array_ size -> ByteArray: + static create-quarter-circle-array_ size -> ByteArray: array := ByteArray size hypotenuse := (size - 1) * (size - 1) size.repeat: - array[it] = (hypotenuse - it * it).sqrt.to_int + array[it] = (hypotenuse - it * it).sqrt.to-int return array constructor.private_ .radius: - byte_opacity = ByteArray radius * radius - downsample := TABLE_SIZE_ / radius // For example 81 for a radius of 3. + byte-opacity = ByteArray radius * radius + downsample := TABLE-SIZE_ / radius // For example 81 for a radius of 3. steps := List radius: - (it * TABLE_SIZE_) / radius + (it * TABLE-SIZE_) / radius radius.repeat: | j | b := steps[j] radius.repeat: | i | @@ -439,30 +439,30 @@ class RoundedCornerOpacity_: // Set the opacity according to whether the downsample x downsample // square is fully outside the circle, fully inside the circle or on // the edge. - if QUARTER_CIRCLE_[b + downsample - 1] >= a + downsample: - byte_opacity[idx] = 0xff // Inside quarter circle. - else if QUARTER_CIRCLE_[b] < a: - byte_opacity[idx] = 0 // Outside quarter circle. + if QUARTER-CIRCLE_[b + downsample - 1] >= a + downsample: + byte-opacity[idx] = 0xff // Inside quarter circle. + else if QUARTER-CIRCLE_[b] < a: + byte-opacity[idx] = 0 // Outside quarter circle. else: // Edge of quarter circle. total := 0 - downsample.repeat: | small_y | - extent := QUARTER_CIRCLE_[b + small_y] + downsample.repeat: | small-y | + extent := QUARTER-CIRCLE_[b + small-y] if extent >= a + downsample: total += downsample else if extent > a: total += extent - a - byte_opacity[idx] = (0xff * total) / (downsample * downsample) + byte-opacity[idx] = (0xff * total) / (downsample * downsample) // Generate a bit version of the opacities in case we have to use it on a // 2-color or 3-color display. - bitmap_width = round_up radius 8 - bit_opacity = ByteArray (byte_opacity.size / radius) * (bitmap_width >> 3) - destination_line_stride := bitmap_width >> 3 + bitmap-width = round-up radius 8 + bit-opacity = ByteArray (byte-opacity.size / radius) * (bitmap-width >> 3) + destination-line-stride := bitmap-width >> 3 8.repeat: | bit | - bitmap.blit byte_opacity[bit..] bit_opacity ((radius + 7 - bit) >> 3) - --source_pixel_stride = 8 - --source_line_stride = radius - --destination_line_stride = destination_line_stride + bitmap.blit byte-opacity[bit..] bit-opacity ((radius + 7 - bit) >> 3) + --source-pixel-stride = 8 + --source-line-stride = radius + --destination-line-stride = destination-line-stride --shift = bit --mask = (0x80 >> bit) --operation = bitmap.OR @@ -567,46 +567,46 @@ style := Style */ class Style: map_/Map - id_map_/Map? := ? - class_map_/Map? := ? - type_map_/Map? := ? + id-map_/Map? := ? + class-map_/Map? := ? + type-map_/Map? := ? - constructor.empty: return EMPTY_STYLE_ + constructor.empty: return EMPTY-STYLE_ constructor --color/int?=null --font/Font?=null --background=null --border/Border?=null - --class_map/Map?=null - --id_map/Map?=null - --type_map/Map?=null + --class-map/Map?=null + --id-map/Map?=null + --type-map/Map?=null .map_={:}: if color != null: map_["color"] = color if font != null: map_["font"] = font if border != null: map_["border"] = border - Background.check_valid background + Background.check-valid background if background: map_["background"] = background - class_map_ = class_map - id_map_ = id_map - type_map_ = type_map + class-map_ = class-map + id-map_ = id-map + type-map_ = type-map - iterate_properties [block]: + iterate-properties [block]: map_.do: | key/string value | block.call key value - matching_styles --type/string? --classes/List? --id/string? [block]: - if type_map_ and type: - type_map_.get type --if_present=: | style/Style | + matching-styles --type/string? --classes/List? --id/string? [block]: + if type-map_ and type: + type-map_.get type --if-present=: | style/Style | block.call style - if class_map_ and classes and classes.size != 0: + if class-map_ and classes and classes.size != 0: if classes.size == 1: - class_map_.get classes[0] --if_present=: | style/Style | + class-map_.get classes[0] --if-present=: | style/Style | block.call style else: - class_map_.do: | key/string style/Style | + class-map_.do: | key/string style/Style | if classes.contains key: block.call style - if id_map_ and id: - id_map_.get id --if_present=: | style/Style | + if id-map_ and id: + id-map_.get id --if-present=: | style/Style | block.call style diff --git a/src/three_color.toit b/src/three_color.toit index 89bbed6..89eb1b5 100644 --- a/src/three_color.toit +++ b/src/three_color.toit @@ -3,15 +3,15 @@ // found in the LICENSE file. /** -Constants useful for $PixelDisplay.three_color. +Constants useful for $PixelDisplay.three-color. For use with e-paper black, white, and red displays. */ import font show Font import icons show Icon -import .pixel_display show PixelDisplay // For the doc comment. -import .two_bit_texture -import .two_bit_texture as two_bit +import .pixel-display show PixelDisplay // For the doc comment. +import .two-bit-texture +import .two-bit-texture as two-bit WHITE ::= 0 BLACK ::= 1 @@ -24,24 +24,24 @@ RED ::= 2 // 0 1 Red // 1 1 Invalid // Starts off with all pixels white. -class Canvas_ extends two_bit.Canvas_: +class Canvas_ extends two-bit.Canvas_: constructor width height: super width height - supports_8_bit -> bool: return false - gray_scale -> bool: return false + supports-8-bit -> bool: return false + gray-scale -> bool: return false /** Creates a blank texture with the same dimensions as this one. */ - create_similar: + create-similar: result := Canvas_ width_ height_ result.transform = transform return result // Convert from a PNG color (0 = black, 255 = white) to a 2-bit // red-white-black color. - nearest_color_ palette/ByteArray offset/int -> int: + nearest-color_ palette/ByteArray offset/int -> int: r := palette[offset] g := palette[offset + 1] b := palette[offset + 2] diff --git a/src/true_color.toit b/src/true_color.toit index 82bee45..355ad0b 100644 --- a/src/true_color.toit +++ b/src/true_color.toit @@ -3,22 +3,22 @@ // found in the LICENSE file. /** -Functions and constants useful for the RGB $PixelDisplay.true_color display. +Functions and constants useful for the RGB $PixelDisplay.true-color display. */ -import binary show BIG_ENDIAN +import binary show BIG-ENDIAN import bitmap show * import font show Font import icons show Icon import .common -import .gray_scale as gray_scale_ -import .pixel_display show PixelDisplay // For the doc comment. +import .gray-scale as gray-scale_ +import .pixel-display show PixelDisplay // For the doc comment. /** Create a 24 bit color from three components in the 0-255 range. As an alternative, you can use the web-similar syntax, 0xrrggbb. */ -get_rgb r/int g/int b/int -> int: +get-rgb r/int g/int b/int -> int: return (r << 16) | (g << 8) | b WHITE ::= 0xff_ff_ff @@ -27,19 +27,19 @@ BLACK ::= 0 /** Extract the red component in the 0-255 range from a color. */ -red_component pixel/int -> int: +red-component pixel/int -> int: return pixel >> 16 /** Extract the green component in the 0-255 range from a color. */ -green_component pixel/int -> int: +green-component pixel/int -> int: return (pixel >> 8) & 0xff /** Extract the blue component in the 0-255 range from a color. */ -blue_component pixel/int -> int: +blue-component pixel/int -> int: return pixel & 0xff // The canvas contains three ByteArrays, red, green, and blue. @@ -50,8 +50,8 @@ class Canvas_ extends Canvas: blue_/ByteArray := ? components_/List := ? - supports_8_bit -> bool: return true - gray_scale -> bool: return false + supports-8-bit -> bool: return true + gray-scale -> bool: return false constructor width/int height/int: size := width * height @@ -64,144 +64,144 @@ class Canvas_ extends Canvas: stringify: return "true_color.Canvas_ $(width_)x$height_" - set_all_pixels color/int -> none: - bytemap_zap red_ (red_component color) - bytemap_zap green_ (green_component color) - bytemap_zap blue_ (blue_component color) + set-all-pixels color/int -> none: + bytemap-zap red_ (red-component color) + bytemap-zap green_ (green-component color) + bytemap-zap blue_ (blue-component color) - get_pixel_ x y: + get-pixel_ x y: idx := x + width_ * y - return get_rgb red_[idx] green_[idx] blue_[idx] + return get-rgb red_[idx] green_[idx] blue_[idx] /** Creates a blank canvas with the same dimensions as this one. */ - create_similar: + create-similar: result := Canvas_ width_ height_ result.transform = transform return result - make_alpha_map --padding/int=0 -> Canvas: - result := gray_scale_.Canvas_ (width_ + padding) (height_ + padding) + make-alpha-map --padding/int=0 -> Canvas: + result := gray-scale_.Canvas_ (width_ + padding) (height_ + padding) result.transform = transform return result - composit frame_opacity frame_canvas/Canvas_? painting_opacity painting_canvas/Canvas_: - fo := frame_opacity is ByteArray ? frame_opacity : frame_opacity.pixels_ - po := painting_opacity is ByteArray ? painting_opacity : painting_opacity.pixels_ + composit frame-opacity frame-canvas/Canvas_? painting-opacity painting-canvas/Canvas_: + fo := frame-opacity is ByteArray ? frame-opacity : frame-opacity.pixels_ + po := painting-opacity is ByteArray ? painting-opacity : painting-opacity.pixels_ for i := 0; i < 3; i++: - composit_bytes components_[i] fo (frame_canvas ? frame_canvas.components_[i] : null) po painting_canvas.components_[i] false + composit-bytes components_[i] fo (frame-canvas ? frame-canvas.components_[i] : null) po painting-canvas.components_[i] false rectangle x/int y/int --w/int --h/int --color/int: transform.xywh x y w h: | x2 y2 w2 h2 | r := color >> 16 g := (color >> 8) & 0xff b := color & 0xff - bytemap_rectangle x2 y2 r w2 h2 red_ width_ - bytemap_rectangle x2 y2 g w2 h2 green_ width_ - bytemap_rectangle x2 y2 b w2 h2 blue_ width_ + bytemap-rectangle x2 y2 r w2 h2 red_ width_ + bytemap-rectangle x2 y2 g w2 h2 green_ width_ + bytemap-rectangle x2 y2 b w2 h2 blue_ width_ - text x/int y/int --text/string --color/int --font/Font --orientation/int=ORIENTATION_0: + text x/int y/int --text/string --color/int --font/Font --orientation/int=ORIENTATION-0: transform.xyo x y orientation: | x2 y2 o2 | r := color >> 16 g := (color >> 8) & 0xff b := color & 0xff - bytemap_draw_text x2 y2 r o2 text font red_ width_ - bytemap_draw_text x2 y2 g o2 text font green_ width_ - bytemap_draw_text x2 y2 b o2 text font blue_ width_ + bytemap-draw-text x2 y2 r o2 text font red_ width_ + bytemap-draw-text x2 y2 g o2 text font green_ width_ + bytemap-draw-text x2 y2 b o2 text font blue_ width_ bitmap x/int y/int -> none --pixels/ByteArray --alpha/ByteArray // 2-element byte array. --palette/ByteArray // 6-element byte array. - --source_width/int // In pixels. - --source_line_stride/int // In bytes. - --orientation/int=ORIENTATION_0: - source_byte_width := (source_width + 7) >> 3 - zero_alpha := alpha[0] + --source-width/int // In pixels. + --source-line-stride/int // In bytes. + --orientation/int=ORIENTATION-0: + source-byte-width := (source-width + 7) >> 3 + zero-alpha := alpha[0] // Fast case if the alpha is either 0 or 0xff, because we can use the // primitives that paint 1's with a particular color and leave the zeros // transparent. We don't check for the case where 0 is opaque and 1 is // transparent, because pngunzip fixes that for us. - if alpha[1] == 0xff and (zero_alpha == 0xff or zero_alpha == 0): - if zero_alpha == 0xff: - h := (pixels.size + source_line_stride - source_byte_width) / source_line_stride + if alpha[1] == 0xff and (zero-alpha == 0xff or zero-alpha == 0): + if zero-alpha == 0xff: + h := (pixels.size + source-line-stride - source-byte-width) / source-line-stride // Draw the zeros. - rectangle x y --w=source_width --h=h --color=(BIG_ENDIAN.uint24 palette 0) + rectangle x y --w=source-width --h=h --color=(BIG-ENDIAN.uint24 palette 0) // Draw the ones. transform.xyo x y 0: | x2 y2 o2 | for i := 0; i < 3; i++: - bitmap_draw_bitmap x2 y2 + bitmap-draw-bitmap x2 y2 --color = palette[3 + i] --orientation = o2 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride + --source-width = source-width + --source-line-stride = source-line-stride --destination = components_[i] - --destination_width = width_ + --destination-width = width_ --bytewise return // Unfortunately one of the alpha values is not 0 or 0xff, so we can't use // the bitmap draw primitive. We can blow it up to bytes, then use the // bitmap_draw_bytemap. - h := (pixels.size + source_line_stride - source_byte_width) / source_line_stride - bytemap := ByteArray source_width * h - bitmap_draw_bitmap 0 0 + h := (pixels.size + source-line-stride - source-byte-width) / source-line-stride + bytemap := ByteArray source-width * h + bitmap-draw-bitmap 0 0 --color = 1 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride + --source-width = source-width + --source-line-stride = source-line-stride --destination = bytemap - --destination_width = source_width + --destination-width = source-width --bytewise transform.xyo x y 0: | x2 y2 o2 | for i := 0; i < 3; i++: - bitmap_draw_bytemap x2 y2 + bitmap-draw-bytemap x2 y2 --alpha = alpha --orientation = o2 --source = bytemap - --source_width = source_width + --source-width = source-width --palette = palette[i..] --destination = components_[i] - --destination_width = width_ + --destination-width = width_ pixmap x/int y/int --pixels/ByteArray --alpha/ByteArray=#[] --palette/ByteArray=#[] - --source_width/int - --orientation/int=ORIENTATION_0 - --source_line_stride/int=source_width: + --source-width/int + --orientation/int=ORIENTATION-0 + --source-line-stride/int=source-width: transform.xyo x y orientation: | x2 y2 o2 | for i := 0; i < 3; i++: - component_palette := palette.size > i ? palette[i..] : #[] - bitmap_draw_bytemap x2 y2 + component-palette := palette.size > i ? palette[i..] : #[] + bitmap-draw-bytemap x2 y2 --alpha = alpha --orientation = o2 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride - --palette = component_palette + --source-width = source-width + --source-line-stride = source-line-stride + --palette = component-palette --destination = components_[i] - --destination_width = width_ + --destination-width = width_ - rgb_pixmap x/int y/int --r/ByteArray --g/ByteArray --b/ByteArray + rgb-pixmap x/int y/int --r/ByteArray --g/ByteArray --b/ByteArray --alpha/ByteArray=#[] --palette/ByteArray?=null - --source_width/int - --orientation/int=ORIENTATION_0 - --source_line_stride/int=source_width: + --source-width/int + --orientation/int=ORIENTATION-0 + --source-line-stride/int=source-width: components := [r, g, b] transform.xyo x y orientation: | x2 y2 o2 | 3.repeat: | i | - component_palette := (palette and palette.size > i) ? palette[i..] : #[] - bitmap_draw_bytemap x2 y2 + component-palette := (palette and palette.size > i) ? palette[i..] : #[] + bitmap-draw-bytemap x2 y2 --alpha = alpha --orientation = o2 --source = components[i] - --source_width = source_width - --source_line_stride = source_line_stride - --palette = component_palette + --source-width = source-width + --source-line-stride = source-line-stride + --palette = component-palette --destination = components_[i] - --destination_width = width_ + --destination-width = width_ diff --git a/src/two_bit_texture.toit b/src/two_bit_texture.toit index 7c6e0f6..cb42b77 100644 --- a/src/two_bit_texture.toit +++ b/src/two_bit_texture.toit @@ -10,95 +10,95 @@ import bitmap show * import font show Font import .common import .common as common -import .two_color as two_color +import .two-color as two-color // The canvas contains two bitmapped ByteArrays, for up to 4 colors or gray // scales per pixel. Starts off with all pixels 0, 0. abstract class Canvas_ extends Canvas: - plane_0_ := ? - plane_1_ := ? + plane-0_ := ? + plane-1_ := ? constructor width/int height/int: assert: height & 7 == 0 size := (width * height) >> 3 assert: size <= 4000 - plane_0_ = ByteArray size - plane_1_ = ByteArray size + plane-0_ = ByteArray size + plane-1_ = ByteArray size super width height - set_all_pixels color/int -> none: - bitmap_zap plane_0_ (color & 1) - bitmap_zap plane_1_ ((color & 2) >> 1) + set-all-pixels color/int -> none: + bitmap-zap plane-0_ (color & 1) + bitmap-zap plane-1_ ((color & 2) >> 1) - get_pixel_ x y: + get-pixel_ x y: bit := 1 << (y & 7) idx := x + width_ * (y >> 3) - bit0 := (plane_0_[idx] & bit) == 0 ? 0 : 1 - bit1 := (plane_1_[idx] & bit) == 0 ? 0 : 1 + bit0 := (plane-0_[idx] & bit) == 0 ? 0 : 1 + bit1 := (plane-1_[idx] & bit) == 0 ? 0 : 1 return bit0 + (bit1 << 1) - make_alpha_map --padding/int=0 -> Canvas: - result := two_color.Canvas_ (width_ + padding) (height_ + padding) + make-alpha-map --padding/int=0 -> Canvas: + result := two-color.Canvas_ (width_ + padding) (height_ + padding) result.transform = transform return result - composit frame_opacity frame_canvas painting_opacity painting_canvas/Canvas_: - fo := frame_opacity is ByteArray ? frame_opacity : frame_opacity.pixels_ - po := painting_opacity is ByteArray ? painting_opacity : painting_opacity.pixels_ - composit_bytes plane_0_ fo (frame_canvas ? frame_canvas.plane_0_ : null) po painting_canvas.plane_0_ true - composit_bytes plane_1_ fo (frame_canvas ? frame_canvas.plane_1_ : null) po painting_canvas.plane_1_ true + composit frame-opacity frame-canvas painting-opacity painting-canvas/Canvas_: + fo := frame-opacity is ByteArray ? frame-opacity : frame-opacity.pixels_ + po := painting-opacity is ByteArray ? painting-opacity : painting-opacity.pixels_ + composit-bytes plane-0_ fo (frame-canvas ? frame-canvas.plane-0_ : null) po painting-canvas.plane-0_ true + composit-bytes plane-1_ fo (frame-canvas ? frame-canvas.plane-1_ : null) po painting-canvas.plane-1_ true rectangle x/int y/int --w/int --h/int --color/int: transform.xywh x y w h: | x2 y2 w2 h2 | c2 := (color & 2) >> 1 - bitmap_rectangle x2 y2 (color & 1) w2 h2 plane_0_ width_ - bitmap_rectangle x2 y2 c2 w2 h2 plane_1_ width_ + bitmap-rectangle x2 y2 (color & 1) w2 h2 plane-0_ width_ + bitmap-rectangle x2 y2 c2 w2 h2 plane-1_ width_ - text x/int y/int --text/string --color/int --font/Font --orientation/int=ORIENTATION_0: + text x/int y/int --text/string --color/int --font/Font --orientation/int=ORIENTATION-0: transform.xyo x y orientation: | x2 y2 o2 | b0 := color & 1 b1 := (color >> 1) & 1 - bitmap_draw_text x2 y2 b0 o2 text font plane_0_ width_ - bitmap_draw_text x2 y2 b1 o2 text font plane_1_ width_ + bitmap-draw-text x2 y2 b0 o2 text font plane-0_ width_ + bitmap-draw-text x2 y2 b1 o2 text font plane-1_ width_ - abstract nearest_color_ palette/ByteArray offset/int -> int + abstract nearest-color_ palette/ByteArray offset/int -> int bitmap x/int y/int -> none --pixels/ByteArray --alpha/ByteArray // 2-element byte array. --palette/ByteArray // 4 element byte array. - --source_width/int // In pixels. - --source_line_stride/int // In bytes. - --orientation/int=ORIENTATION_0: - source_byte_width := (source_width + 7) >> 3 - zero_alpha := alpha[0] + --source-width/int // In pixels. + --source-line-stride/int // In bytes. + --orientation/int=ORIENTATION-0: + source-byte-width := (source-width + 7) >> 3 + zero-alpha := alpha[0] // Fast case if the alpha is either 0 or 0xff, because we can use the // primitives that paint 1's with a particular color and leave the zeros // transparent. We don't check for the case where 0 is opaque and 1 is // transparent, because pngunzip fixes that for us. - if alpha[1] == 0xff and (zero_alpha == 0xff or zero_alpha == 0): - if zero_alpha == 0xff: - h := (pixels.size + source_line_stride - source_byte_width ) / source_line_stride + if alpha[1] == 0xff and (zero-alpha == 0xff or zero-alpha == 0): + if zero-alpha == 0xff: + h := (pixels.size + source-line-stride - source-byte-width ) / source-line-stride // Draw the zeros. - rectangle x y --w=source_width --h=h --color=(nearest_color_ palette 0) + rectangle x y --w=source-width --h=h --color=(nearest-color_ palette 0) // Draw the ones. transform.xyo x y orientation: | x2 y2 o2 | - color := nearest_color_ palette 3 - bitmap_draw_bitmap x2 y2 + color := nearest-color_ palette 3 + bitmap-draw-bitmap x2 y2 --color = (color & 1) --orientation = o2 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride - --destination = plane_0_ - --destination_width = width_ - bitmap_draw_bitmap x2 y2 + --source-width = source-width + --source-line-stride = source-line-stride + --destination = plane-0_ + --destination-width = width_ + bitmap-draw-bitmap x2 y2 --color = (color >> 1) --orientation = o2 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride - --destination = plane_1_ - --destination_width = width_ + --source-width = source-width + --source-line-stride = source-line-stride + --destination = plane-1_ + --destination-width = width_ return throw "No partially transparent PNGs on 3-color displays." diff --git a/src/two_color.toit b/src/two_color.toit index 0fb7e55..5c83026 100644 --- a/src/two_color.toit +++ b/src/two_color.toit @@ -3,7 +3,7 @@ // found in the LICENSE file. /** -Constants useful for black-and-white $PixelDisplay.two_color. +Constants useful for black-and-white $PixelDisplay.two-color. For use with e-paper displays and the SSD1306 128x64 display (driver at https://pkg.toit.io/package/ssd1306&url=github.com%2Ftoitware%2Ftoit-ssd1306&index=latest) */ @@ -12,7 +12,7 @@ import bitmap show * import font show Font import icons show Icon import .common -import .pixel_display show PixelDisplay // For the doc comment. +import .pixel-display show PixelDisplay // For the doc comment. WHITE ::= 0 BLACK ::= 1 @@ -23,8 +23,8 @@ TRANSPARENT ::= 3 class Canvas_ extends Canvas: pixels_ := ? - supports_8_bit -> bool: return false - gray_scale -> bool: return true + supports-8-bit -> bool: return false + gray-scale -> bool: return true constructor width/int height/int: assert: height & 7 == 0 @@ -33,10 +33,10 @@ class Canvas_ extends Canvas: pixels_ = ByteArray size super width height - set_all_pixels color/int -> none: - bitmap_zap pixels_ (color & 1) + set-all-pixels color/int -> none: + bitmap-zap pixels_ (color & 1) - get_pixel_ x y: + get-pixel_ x y: bit := 1 << (y & 7) idx := x + width_ * (y >> 3) return (pixels_[idx] & bit) == 0 ? 0 : 1 @@ -44,61 +44,61 @@ class Canvas_ extends Canvas: /** Creates a blank canvas with the same dimensions as this one. */ - create_similar -> Canvas_: + create-similar -> Canvas_: result := Canvas_ width_ height_ result.transform = transform return result - make_alpha_map --padding/int=0 -> Canvas: + make-alpha-map --padding/int=0 -> Canvas: result := Canvas_ (width_ + padding) (height_ + padding) result.transform = transform return result - composit frame_opacity frame_canvas/Canvas_? painting_opacity painting_canvas/Canvas_: - fo := frame_opacity is ByteArray ? frame_opacity : frame_opacity.pixels_ - po := painting_opacity is ByteArray ? painting_opacity : painting_opacity.pixels_ - composit_bytes pixels_ fo (frame_canvas ? frame_canvas.pixels_ : null) po painting_canvas.pixels_ true + composit frame-opacity frame-canvas/Canvas_? painting-opacity painting-canvas/Canvas_: + fo := frame-opacity is ByteArray ? frame-opacity : frame-opacity.pixels_ + po := painting-opacity is ByteArray ? painting-opacity : painting-opacity.pixels_ + composit-bytes pixels_ fo (frame-canvas ? frame-canvas.pixels_ : null) po painting-canvas.pixels_ true rectangle x/int y/int --w/int --h/int --color/int: transform.xywh x y w h: | x2 y2 w2 h2 | - bitmap_rectangle x2 y2 color w2 h2 pixels_ width_ + bitmap-rectangle x2 y2 color w2 h2 pixels_ width_ - text x/int y/int --text/string --color/int --font/Font --orientation/int=ORIENTATION_0: + text x/int y/int --text/string --color/int --font/Font --orientation/int=ORIENTATION-0: transform.xyo x y orientation: | x2 y2 o2 | - bitmap_draw_text x2 y2 color o2 text font pixels_ width_ + bitmap-draw-text x2 y2 color o2 text font pixels_ width_ // Convert from a PNG color (0 = black, 255 = white) to white or black. - nearest_color_ palette/ByteArray offset/int -> int: + nearest-color_ palette/ByteArray offset/int -> int: return palette[offset] < 128 ? BLACK : WHITE bitmap x/int y/int -> none --pixels/ByteArray --alpha/ByteArray // 2-element byte array. --palette/ByteArray // 4 element byte array. - --source_width/int // In pixels. - --source_line_stride/int // In bytes. - --orientation/int=ORIENTATION_0: - source_byte_width := (source_width + 7) >> 3 - zero_alpha := alpha[0] + --source-width/int // In pixels. + --source-line-stride/int // In bytes. + --orientation/int=ORIENTATION-0: + source-byte-width := (source-width + 7) >> 3 + zero-alpha := alpha[0] // Fast case if the alpha is either 0 or 0xff, because we can use the // primitives that paint 1's with a particular color and leave the zeros // transparent. We don't check for the case where 0 is opaque and 1 is // transparent, because pngunzip fixes that for us. - if alpha[1] == 0xff and (zero_alpha == 0xff or zero_alpha == 0): - if zero_alpha == 0xff: - h := (pixels.size + source_line_stride - source_byte_width ) / source_line_stride + if alpha[1] == 0xff and (zero-alpha == 0xff or zero-alpha == 0): + if zero-alpha == 0xff: + h := (pixels.size + source-line-stride - source-byte-width ) / source-line-stride // Draw the zeros. - rectangle x y --w=source_width --h=h --color=(nearest_color_ palette 0) + rectangle x y --w=source-width --h=h --color=(nearest-color_ palette 0) // Draw the ones. transform.xyo x y orientation: | x2 y2 o2 | - color := nearest_color_ palette 3 - bitmap_draw_bitmap x2 y2 + color := nearest-color_ palette 3 + bitmap-draw-bitmap x2 y2 --color = (color & 1) --orientation = o2 --source = pixels - --source_width = source_width - --source_line_stride = source_line_stride + --source-width = source-width + --source-line-stride = source-line-stride --destination = pixels_ - --destination_width = width_ + --destination-width = width_ return throw "No partially transparent PNGs on 2-color displays." diff --git a/tests/barcode_visualized.toit b/tests/barcode_visualized.toit index 83b9259..24b9ce7 100644 --- a/tests/barcode_visualized.toit +++ b/tests/barcode_visualized.toit @@ -5,33 +5,33 @@ // Tests drawing a supermarket-style bar code on a pixel display. import expect show * -import pixel_display show * -import pixel_display.bar_code show * -import pixel_display.element show * -import pixel_display.style show Style -import .png_visualizer +import pixel-display show * +import pixel-display.bar-code show * +import pixel-display.element show * +import pixel-display.style show Style +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 - driver := SeveralColorPngVisualizer 120 160 args[0] --outline=SEVERAL_BLUE - display := PixelDisplay.several_color driver --portrait=false - display.background = SEVERAL_GRAY + driver := SeveralColorPngVisualizer 120 160 args[0] --outline=SEVERAL-BLUE + display := PixelDisplay.several-color driver --portrait=false + display.background = SEVERAL-GRAY - style := Style --type_map={ - "bar-code-ean": Style --color=SEVERAL_BLACK --background=SEVERAL_WHITE, + style := Style --type-map={ + "bar-code-ean": Style --color=SEVERAL-BLACK --background=SEVERAL-WHITE, } barcode := BarCodeEanElement --x=15 --y=15 --code="4035999001512" display.add barcode - display.set_styles [style] + display.set-styles [style] display.draw - barcode.move_to 20 20 + barcode.move-to 20 20 display.draw barcode.code = "4000417020000" display.draw - driver.write_png + driver.write-png diff --git a/tests/bitmap_2_visualized.toit b/tests/bitmap_2_visualized.toit index 956cdc9..97c3627 100644 --- a/tests/bitmap_2_visualized.toit +++ b/tests/bitmap_2_visualized.toit @@ -9,10 +9,10 @@ import expect show * import font import host.file -import pixel_display show * -import pixel_display.element show * -import pixel_display.png show Png -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.png show Png +import .png-visualizer SANS := font.Font.get "sans10" @@ -24,36 +24,36 @@ main args: basename := args[0] driver := TrueColorPngVisualizer 524 240 basename --outline=0xffffff - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver display.background = 0xe0e080 - heater := file.read_content "tests/third_party/pictogrammers/heater.png" - heater-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-uncompressed.png" - heater-4-bit := file.read_content "tests/third_party/pictogrammers/heater-4-bit.png" - heater-4-bit-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-4-bit-uncompressed.png" - heater-2-bit := file.read_content "tests/third_party/pictogrammers/heater-2-bit.png" - heater-2-bit-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" - heater-bw := file.read_content "tests/third_party/pictogrammers/heater-bw.png" - heater-bw-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" - heater-white-bg := file.read_content "tests/third_party/pictogrammers/heater-white-bg.png" - heater-white-bg-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" - heater-translucent := file.read_content "tests/third_party/pictogrammers/heater-translucent.png" - heater-translucent-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-translucent-uncompressed.png" - - display.add (Png --x=16 --y=32 --png_file=heater) - display.add (Png --x=100 --y=32 --png_file=heater-4-bit) - display.add (Png --x=184 --y=32 --png_file=heater-2-bit) - display.add (Png --x=268 --y=32 --png_file=heater-bw) - display.add (Png --x=352 --y=32 --png_file=heater-white-bg) - display.add (Png --x=436 --y=32 --png_file=heater-translucent) - - display.add (Png --x=16 --y=120 --png_file=heater-uncompressed) - display.add (Png --x=100 --y=120 --png_file=heater-4-bit-uncompressed) - display.add (Png --x=184 --y=120 --png_file=heater-2-bit-uncompressed) - display.add (Png --x=268 --y=120 --png_file=heater-bw-uncompressed) - display.add (Png --x=352 --y=120 --png_file=heater-white-bg-uncompressed) - display.add (Png --x=436 --y=120 --png_file=heater-translucent-uncompressed) + heater := file.read-content "tests/third_party/pictogrammers/heater.png" + heater-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-uncompressed.png" + heater-4-bit := file.read-content "tests/third_party/pictogrammers/heater-4-bit.png" + heater-4-bit-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-4-bit-uncompressed.png" + heater-2-bit := file.read-content "tests/third_party/pictogrammers/heater-2-bit.png" + heater-2-bit-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" + heater-bw := file.read-content "tests/third_party/pictogrammers/heater-bw.png" + heater-bw-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" + heater-white-bg := file.read-content "tests/third_party/pictogrammers/heater-white-bg.png" + heater-white-bg-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" + heater-translucent := file.read-content "tests/third_party/pictogrammers/heater-translucent.png" + heater-translucent-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-translucent-uncompressed.png" + + display.add (Png --x=16 --y=32 --png-file=heater) + display.add (Png --x=100 --y=32 --png-file=heater-4-bit) + display.add (Png --x=184 --y=32 --png-file=heater-2-bit) + display.add (Png --x=268 --y=32 --png-file=heater-bw) + display.add (Png --x=352 --y=32 --png-file=heater-white-bg) + display.add (Png --x=436 --y=32 --png-file=heater-translucent) + + display.add (Png --x=16 --y=120 --png-file=heater-uncompressed) + display.add (Png --x=100 --y=120 --png-file=heater-4-bit-uncompressed) + display.add (Png --x=184 --y=120 --png-file=heater-2-bit-uncompressed) + display.add (Png --x=268 --y=120 --png-file=heater-bw-uncompressed) + display.add (Png --x=352 --y=120 --png-file=heater-white-bg-uncompressed) + display.add (Png --x=436 --y=120 --png-file=heater-translucent-uncompressed) display.draw - driver.write_png + driver.write-png diff --git a/tests/bitmap_visualized.toit b/tests/bitmap_visualized.toit index 4de21c9..979ce61 100644 --- a/tests/bitmap_visualized.toit +++ b/tests/bitmap_visualized.toit @@ -9,11 +9,11 @@ import expect show * import font import host.file -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import pixel_display.png show Png -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import pixel-display.png show Png +import .png-visualizer SANS := font.Font.get "sans10" @@ -27,36 +27,36 @@ main args: do basename/string w/int h/int: driver := TrueColorPngVisualizer w h basename --outline=0xc0c0ff - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver display.background = 0x808080 // A 1-bit PNG file that is uncompressed, so we can use the PngRandomAccess // class to display it straight from flash. - purifier := file.read_content "tests/third_party/pictogrammers/air-purifier-bit-unzip.png" + purifier := file.read-content "tests/third_party/pictogrammers/air-purifier-bit-unzip.png" // A 1-bit PNG file that is compressed, so it takes less flash, but we have // to decompress it to display it. This file also has an almost-transparent // background, so we test the code path where we display a 1-bit image with // a real alpha channel (and it has a gray background in the output). - purifier_compressed := file.read_content "tests/third_party/pictogrammers/air-purifier-bit.png" + purifier-compressed := file.read-content "tests/third_party/pictogrammers/air-purifier-bit.png" gradient := GradientBackground --angle=160 --specifiers=[ GradientSpecifier --color=0xe0e0ff 10, GradientSpecifier --color=0x8080c0 90, ] - gradient_element := Div --x=0 --y=0 --w=340 --h=320 --background=gradient - display.add gradient_element + gradient-element := Div --x=0 --y=0 --w=340 --h=320 --background=gradient + display.add gradient-element display.draw label := Label --x=44 --y=44 --label="UP ^" --font=SANS --color=0 display.add label - png_element := Png --x=36 --y=32 --png_file=purifier - display.add png_element + png-element := Png --x=36 --y=32 --png-file=purifier + display.add png-element display.draw - display.remove png_element - png_element = Png --x=36 --y=32 --png_file=purifier_compressed - display.add png_element + display.remove png-element + png-element = Png --x=36 --y=32 --png-file=purifier-compressed + display.add png-element display.draw - driver.write_png + driver.write-png diff --git a/tests/drop_shadow_gray_window_visualized.toit b/tests/drop_shadow_gray_window_visualized.toit index 98c2e56..3adb310 100644 --- a/tests/drop_shadow_gray_window_visualized.toit +++ b/tests/drop_shadow_gray_window_visualized.toit @@ -4,11 +4,11 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import pixel-display.style show * +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -17,16 +17,16 @@ main args: print "Usage: script.toit png-basename" exit 1 driver := GrayScalePngVisualizer 160 240 args[0] --outline=0x10 - display := PixelDisplay.gray_scale driver + display := PixelDisplay.gray-scale driver display.background = 160 - background_gradient := GradientBackground --angle=180 + background-gradient := GradientBackground --angle=180 --specifiers=[ GradientSpecifier --color=0x20 10, GradientSpecifier --color=0x60 90, ] - background_gradient_element := Div --x=0 --y=0 --w=240 --h=160 --background=background_gradient - display.add background_gradient_element + background-gradient-element := Div --x=0 --y=0 --w=240 --h=160 --background=background-gradient + display.add background-gradient-element win := Div.clipping --x=30 --y=30 --w=180 --h=100 --border=(ShadowRoundedCornerBorder --radius=15) display.add win @@ -36,22 +36,22 @@ main args: GradientSpecifier --color=0x90 10, GradientSpecifier --color=0xe0 90, ] - gradient_element := Div --x=0 --y=0 --w=180 --h=100 --background=gradient - win.add gradient_element + gradient-element := Div --x=0 --y=0 --w=180 --h=100 --background=gradient + win.add gradient-element text := Label --x=90 --y=55 --label="Hello, World!" --font=sans10 --color=0x10 win.add text display.draw - text.move_to 120 65 + text.move-to 120 65 display.draw // Window-relative coordinates. - text.move_to -10 7 - win.border = ShadowRoundedCornerBorder --radius=15 --shadow_opacity_percent=50 + text.move-to -10 7 + win.border = ShadowRoundedCornerBorder --radius=15 --shadow-opacity-percent=50 display.draw - driver.write_png + driver.write-png diff --git a/tests/drop_shadow_window_visualized.toit b/tests/drop_shadow_window_visualized.toit index f77055a..0826657 100644 --- a/tests/drop_shadow_window_visualized.toit +++ b/tests/drop_shadow_window_visualized.toit @@ -4,11 +4,11 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import pixel-display.style show * +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -17,16 +17,16 @@ main args: print "Usage: script.toit png-basename" exit 1 driver := TrueColorPngVisualizer 240 160 args[0] --outline=0x101010 - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver display.background = 0x78aac8 - background_gradient := GradientBackground --angle=135 + background-gradient := GradientBackground --angle=135 --specifiers=[ GradientSpecifier --color=0x80ddff 10, GradientSpecifier --color=0x80ffdd 90, ] - background_gradient_element := Div --x=0 --y=0 --w=240 --h=160 --background=background_gradient - display.add background_gradient_element + background-gradient-element := Div --x=0 --y=0 --w=240 --h=160 --background=background-gradient + display.add background-gradient-element win := Div.clipping --x=30 --y=30 --w=180 --h=100 --border=(ShadowRoundedCornerBorder --radius=15) display.add win @@ -36,23 +36,23 @@ main args: GradientSpecifier --color=0xffdd80 10, GradientSpecifier --color=0xddff80 90, ] - gradient_element := Div --x=0 --y=0 --w=180 --h=100 --background=gradient - win.add gradient_element + gradient-element := Div --x=0 --y=0 --w=180 --h=100 --background=gradient + win.add gradient-element text := Label --x=90 --y=55 --label="Hello, World!" --font=sans10 --color=0x101040 win.add text display.draw - text.move_to 120 65 + text.move-to 120 65 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 display.draw - driver.write_png + driver.write-png - driver.write_png + driver.write-png diff --git a/tests/four_gray_bitmap_2_visualized.toit b/tests/four_gray_bitmap_2_visualized.toit index 083b0c6..ccffcf3 100644 --- a/tests/four_gray_bitmap_2_visualized.toit +++ b/tests/four_gray_bitmap_2_visualized.toit @@ -9,11 +9,11 @@ import expect show * import font import host.file -import pixel_display show * -import pixel_display.element show * -import pixel_display.four_gray show WHITE LIGHT_GRAY -import pixel_display.png show Png -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.four-gray show WHITE LIGHT-GRAY +import pixel-display.png show Png +import .png-visualizer SANS := font.Font.get "sans10" @@ -25,28 +25,28 @@ main args: basename := args[0] driver := FourGrayPngVisualizer 440 240 basename --outline=WHITE - display := PixelDisplay.four_gray driver - display.background = LIGHT_GRAY - - heater-red := file.read_content "tests/third_party/pictogrammers/heater-red.png" - heater-red-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-red-uncompressed.png" - heater-2-bit := file.read_content "tests/third_party/pictogrammers/heater-2-bit.png" - heater-2-bit-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" - heater-bw := file.read_content "tests/third_party/pictogrammers/heater-bw.png" - heater-bw-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" - heater-white-bg := file.read_content "tests/third_party/pictogrammers/heater-white-bg.png" - heater-white-bg-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" - - display.add (Png --x=100 --y=32 --png_file=heater-red) - display.add (Png --x=184 --y=32 --png_file=heater-2-bit) - display.add (Png --x=268 --y=32 --png_file=heater-bw) - display.add (Png --x=352 --y=32 --png_file=heater-white-bg) - - display.add (Png --x=100 --y=120 --png_file=heater-red-uncompressed) - display.add (Png --x=184 --y=120 --png_file=heater-2-bit-uncompressed) - display.add (Png --x=268 --y=120 --png_file=heater-bw-uncompressed) - display.add (Png --x=352 --y=120 --png_file=heater-white-bg-uncompressed) + display := PixelDisplay.four-gray driver + display.background = LIGHT-GRAY + + heater-red := file.read-content "tests/third_party/pictogrammers/heater-red.png" + heater-red-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-red-uncompressed.png" + heater-2-bit := file.read-content "tests/third_party/pictogrammers/heater-2-bit.png" + heater-2-bit-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" + heater-bw := file.read-content "tests/third_party/pictogrammers/heater-bw.png" + heater-bw-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" + heater-white-bg := file.read-content "tests/third_party/pictogrammers/heater-white-bg.png" + heater-white-bg-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" + + display.add (Png --x=100 --y=32 --png-file=heater-red) + display.add (Png --x=184 --y=32 --png-file=heater-2-bit) + display.add (Png --x=268 --y=32 --png-file=heater-bw) + display.add (Png --x=352 --y=32 --png-file=heater-white-bg) + + display.add (Png --x=100 --y=120 --png-file=heater-red-uncompressed) + display.add (Png --x=184 --y=120 --png-file=heater-2-bit-uncompressed) + display.add (Png --x=268 --y=120 --png-file=heater-bw-uncompressed) + display.add (Png --x=352 --y=120 --png-file=heater-white-bg-uncompressed) display.draw - driver.write_png + driver.write-png diff --git a/tests/gradient_bounds_visualized.toit b/tests/gradient_bounds_visualized.toit index 578dbcf..85db80c 100644 --- a/tests/gradient_bounds_visualized.toit +++ b/tests/gradient_bounds_visualized.toit @@ -8,20 +8,20 @@ import bitmap show * import expect show * import font show * -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 driver := TrueColorPngVisualizer 240 220 args[0] --outline=0x4040ff - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver display.background = 0x808080 - gradient_elements := [] + gradient-elements := [] 16.repeat: angle := it * 45 @@ -39,9 +39,9 @@ main args: GradientSpecifier --color=0xff0000 0, GradientSpecifier --color=0x00ff00 100, ] - gradient_element := Div --x=x --y=y --w=w --h=h --background=gradient - display.add gradient_element - gradient_elements.add gradient_element + gradient-element := Div --x=x --y=y --w=w --h=h --background=gradient + display.add gradient-element + gradient-elements.add gradient-element dot1 := Div --x=(x - 1) --y=(y - 1) --w=1 --h=1 --background=0xffffff display.add dot1 dot2 := Div --x=(x + w) --y=(y + h) --w=1 --h=1 --background=0xffffff @@ -55,10 +55,10 @@ main args: // Rotate all gradient_elements 30 degrees. angle := 30 - gradient_elements.do: + gradient-elements.do: it.background = GradientBackground --angle=angle --specifiers=it.background.specifiers angle = (angle + 45) % 360 display.draw - driver.write_png + driver.write-png diff --git a/tests/gradient_style_visualized.toit b/tests/gradient_style_visualized.toit index 4f605ca..61d7f5d 100644 --- a/tests/gradient_style_visualized.toit +++ b/tests/gradient_style_visualized.toit @@ -8,11 +8,11 @@ import bitmap show * import expect show * import font show * -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import pixel-display.style show * +import .png-visualizer main args: if args.size != 1: @@ -21,7 +21,7 @@ main args: WIDTH ::= 192 HEIGHT ::= 120 driver := TrueColorPngVisualizer WIDTH HEIGHT args[0] --outline=0x4040ff - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver display.background = 0x808080 gradient1 := GradientBackground --angle=120 --specifiers=[ @@ -68,10 +68,10 @@ main args: "round": Style --border=(RoundedCornerBorder --radius=10), } - content.set_styles [style] + content.set-styles [style] display.draw - driver.write_png + driver.write-png content.background = GradientBackground --angle=0 --specifiers=[ GradientSpecifier --color=0xffffff 0, @@ -80,13 +80,13 @@ main args: ] display.draw - driver.write_png + driver.write-png - shadow_style := Style --class_map={ + shadow-style := Style --class-map={ "round": Style --border=(ShadowRoundedCornerBorder --radius=10) } - content.set_styles [shadow_style] + content.set-styles [shadow-style] display.draw - driver.write_png + driver.write-png diff --git a/tests/gradient_visualized.toit b/tests/gradient_visualized.toit index 32bff58..24d825a 100644 --- a/tests/gradient_visualized.toit +++ b/tests/gradient_visualized.toit @@ -8,17 +8,17 @@ import bitmap show * import expect show * import font show * -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 driver := TrueColorPngVisualizer 192 80 args[0] --outline=0x4040ff - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver display.background = 0x808080 gradient := GradientBackground --angle=0 --specifiers=[ @@ -26,28 +26,28 @@ main args: GradientSpecifier --color=0xffc000 50, GradientSpecifier --color=0x808000 90, ] - gradient_element := Div --x=20 --y=10 --w=100 --h=60 --background=gradient - display.add gradient_element + gradient-element := Div --x=20 --y=10 --w=100 --h=60 --background=gradient + display.add gradient-element display.draw - gradient_2 := GradientBackground --angle=180 --specifiers=[ + gradient-2 := GradientBackground --angle=180 --specifiers=[ GradientSpecifier --color=0x00ff00 10, GradientSpecifier --color=0x00ffc0 50, GradientSpecifier --color=0xc0ffff 90, ] - gradient_2_element := Div --x=50 --y=20 --w=100 --h=40 --background=gradient_2 - display.add gradient_2_element + gradient-2-element := Div --x=50 --y=20 --w=100 --h=40 --background=gradient-2 + display.add gradient-2-element display.draw - gradient_element.background = GradientBackground --angle=90 --specifiers=gradient.specifiers - gradient_element.h = 10 - gradient_element.w = 30 - gradient_2_element.background = GradientBackground --angle=270 --specifiers=gradient_2.specifiers - gradient_2_element.h = 10 - gradient_2_element.w = 30 + gradient-element.background = GradientBackground --angle=90 --specifiers=gradient.specifiers + gradient-element.h = 10 + gradient-element.w = 30 + gradient-2-element.background = GradientBackground --angle=270 --specifiers=gradient-2.specifiers + gradient-2-element.h = 10 + gradient-2-element.w = 30 display.draw - driver.write_png + driver.write-png diff --git a/tests/gray_scale.toit b/tests/gray_scale.toit index d974722..7da7c08 100644 --- a/tests/gray_scale.toit +++ b/tests/gray_scale.toit @@ -4,34 +4,34 @@ import expect show * import font show Font -import pixel_display show * -import pixel_display.gray_scale show * +import pixel-display show * +import pixel-display.gray-scale show * class TestDriver extends AbstractDriver: buffer := ByteArray 64 * 128 width ::= 128 height ::= 64 - flags ::= FLAG_GRAY_SCALE | FLAG_PARTIAL_UPDATES - draw_gray_scale left/int top/int right/int bottom/int pixels/ByteArray -> none: + flags ::= FLAG-GRAY-SCALE | FLAG-PARTIAL-UPDATES + draw-gray-scale left/int top/int right/int bottom/int pixels/ByteArray -> none: w := right - left (bottom - top).repeat: | iy | w.repeat: | ix | buffer[left + ix + (top + iy) * width] = pixels[ix + iy * w] - pixel_at x y: + pixel-at x y: return buffer[x + y * width] main: driver := TestDriver - display := PixelDisplay.gray_scale driver + display := PixelDisplay.gray-scale driver display.background = 1 sans10 := Font.get "sans10" ctx := display.context --landscape --color=250 --font=sans10 - display.filled_rectangle ctx 10 20 30 40 + display.filled-rectangle ctx 10 20 30 40 display.text ctx 50 20 "Testing" display.text ctx 50 40 "the display" display.draw @@ -42,14 +42,14 @@ main: for y := 0; y < driver.height; y += 2: line := "" driver.width.repeat: | x | - top_half := (driver.pixel_at x y) < 128 - bottom_half := (driver.pixel_at x y + 1) < 128 - line += "$(top_half ? (bottom_half ? " " : "▄") : (bottom_half ? "▀" : "█"))" + top-half := (driver.pixel-at x y) < 128 + bottom-half := (driver.pixel-at x y + 1) < 128 + line += "$(top-half ? (bottom-half ? " " : "▄") : (bottom-half ? "▀" : "█"))" print line 50.repeat: | x | driver.height.repeat: | y | if x < 10 or y < 20 or x >= 40 or y >= 60: - expect_equals 1 (driver.pixel_at x y) + expect-equals 1 (driver.pixel-at x y) else: - expect_equals 250 (driver.pixel_at x y) + expect-equals 250 (driver.pixel-at x y) diff --git a/tests/gray_scale_bitmap_2_visualized.toit b/tests/gray_scale_bitmap_2_visualized.toit index 62d30f9..6814c84 100644 --- a/tests/gray_scale_bitmap_2_visualized.toit +++ b/tests/gray_scale_bitmap_2_visualized.toit @@ -9,10 +9,10 @@ import expect show * import font import host.file -import pixel_display show * -import pixel_display.element show * -import pixel_display.png show Png -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.png show Png +import .png-visualizer SANS := font.Font.get "sans10" @@ -24,36 +24,36 @@ main args: basename := args[0] driver := GrayScalePngVisualizer 524 240 basename --outline=0xffffff - display := PixelDisplay.gray_scale driver + display := PixelDisplay.gray-scale driver display.background = 0xe0 - heater := file.read_content "tests/third_party/pictogrammers/heater.png" - heater-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-uncompressed.png" - heater-4-bit := file.read_content "tests/third_party/pictogrammers/heater-4-bit.png" - heater-4-bit-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-4-bit-uncompressed.png" - heater-2-bit := file.read_content "tests/third_party/pictogrammers/heater-2-bit.png" - heater-2-bit-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" - heater-bw := file.read_content "tests/third_party/pictogrammers/heater-bw.png" - heater-bw-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" - heater-white-bg := file.read_content "tests/third_party/pictogrammers/heater-white-bg.png" - heater-white-bg-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" - heater-translucent := file.read_content "tests/third_party/pictogrammers/heater-translucent.png" - heater-translucent-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-translucent-uncompressed.png" - - display.add (Png --x=16 --y=32 --png_file=heater) - display.add (Png --x=100 --y=32 --png_file=heater-4-bit) - display.add (Png --x=184 --y=32 --png_file=heater-2-bit) - display.add (Png --x=268 --y=32 --png_file=heater-bw) - display.add (Png --x=352 --y=32 --png_file=heater-white-bg) - display.add (Png --x=436 --y=32 --png_file=heater-translucent) - - display.add (Png --x=16 --y=120 --png_file=heater-uncompressed) - display.add (Png --x=100 --y=120 --png_file=heater-4-bit-uncompressed) - display.add (Png --x=184 --y=120 --png_file=heater-2-bit-uncompressed) - display.add (Png --x=268 --y=120 --png_file=heater-bw-uncompressed) - display.add (Png --x=352 --y=120 --png_file=heater-white-bg-uncompressed) - display.add (Png --x=436 --y=120 --png_file=heater-translucent-uncompressed) + heater := file.read-content "tests/third_party/pictogrammers/heater.png" + heater-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-uncompressed.png" + heater-4-bit := file.read-content "tests/third_party/pictogrammers/heater-4-bit.png" + heater-4-bit-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-4-bit-uncompressed.png" + heater-2-bit := file.read-content "tests/third_party/pictogrammers/heater-2-bit.png" + heater-2-bit-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" + heater-bw := file.read-content "tests/third_party/pictogrammers/heater-bw.png" + heater-bw-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" + heater-white-bg := file.read-content "tests/third_party/pictogrammers/heater-white-bg.png" + heater-white-bg-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" + heater-translucent := file.read-content "tests/third_party/pictogrammers/heater-translucent.png" + heater-translucent-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-translucent-uncompressed.png" + + display.add (Png --x=16 --y=32 --png-file=heater) + display.add (Png --x=100 --y=32 --png-file=heater-4-bit) + display.add (Png --x=184 --y=32 --png-file=heater-2-bit) + display.add (Png --x=268 --y=32 --png-file=heater-bw) + display.add (Png --x=352 --y=32 --png-file=heater-white-bg) + display.add (Png --x=436 --y=32 --png-file=heater-translucent) + + display.add (Png --x=16 --y=120 --png-file=heater-uncompressed) + display.add (Png --x=100 --y=120 --png-file=heater-4-bit-uncompressed) + display.add (Png --x=184 --y=120 --png-file=heater-2-bit-uncompressed) + display.add (Png --x=268 --y=120 --png-file=heater-bw-uncompressed) + display.add (Png --x=352 --y=120 --png-file=heater-white-bg-uncompressed) + display.add (Png --x=436 --y=120 --png-file=heater-translucent-uncompressed) display.draw - driver.write_png + driver.write-png diff --git a/tests/gray_scale_visualized.toit b/tests/gray_scale_visualized.toit index d9e36b1..f4ae679 100644 --- a/tests/gray_scale_visualized.toit +++ b/tests/gray_scale_visualized.toit @@ -4,17 +4,17 @@ import expect show * import font show Font -import pixel_display show * -import pixel_display.gray_scale show * -import pixel_display.element show * -import .png_visualizer +import pixel-display show * +import pixel-display.gray-scale show * +import pixel-display.element show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 driver := GrayScalePngVisualizer 160 64 args[0] --outline=0xff - display := PixelDisplay.gray_scale driver + display := PixelDisplay.gray-scale driver display.background = 0x40 sans10 := Font.get "sans10" @@ -24,8 +24,8 @@ main args: display.add Label --x=50 --y=20 --label="Testing" --font=sans10 --color=0xc0 - middle_line := Label --x=50 --y=40 --label="the display" --font=sans10 --color=0xc0 - display.add middle_line + middle-line := Label --x=50 --y=40 --label="the display" --font=sans10 --color=0xc0 + display.add middle-line display.draw display.add @@ -33,10 +33,10 @@ main args: display.draw - middle_line.move_to 60 40 + middle-line.move-to 60 40 display.draw - middle_line.label = "the DISPLAY" + middle-line.label = "the DISPLAY" display.draw - driver.write_png + driver.write-png diff --git a/tests/invalidate.toit b/tests/invalidate.toit index b38539c..ca511f6 100644 --- a/tests/invalidate.toit +++ b/tests/invalidate.toit @@ -3,8 +3,8 @@ // be found in the TESTS_LICENSE file. import expect show * -import pixel_display show * -import pixel_display.true_color show * +import pixel-display show * +import pixel-display.true-color show * // Check that the minimal area is redrawn. // All redraws are rounded to 8 pixels boundaries. @@ -12,103 +12,103 @@ import pixel_display.true_color show * class AreaRememberingDriver extends AbstractDriver: width/int height/int - flags ::= FLAG_TRUE_COLOR | FLAG_PARTIAL_UPDATES + flags ::= FLAG-TRUE-COLOR | FLAG-PARTIAL-UPDATES constructor .width .height: - static NOT_VALID_PLUS_ ::= 1000000 - static NOT_VALID_MINUS_ ::= -1000000 + static NOT-VALID-PLUS_ ::= 1000000 + static NOT-VALID-MINUS_ ::= -1000000 - last_left := NOT_VALID_PLUS_ - last_top := NOT_VALID_PLUS_ - last_right := NOT_VALID_MINUS_ - last_bottom := NOT_VALID_MINUS_ + last-left := NOT-VALID-PLUS_ + last-top := NOT-VALID-PLUS_ + last-right := NOT-VALID-MINUS_ + last-bottom := NOT-VALID-MINUS_ reset: - last_left = NOT_VALID_PLUS_ - last_top = NOT_VALID_PLUS_ - last_right = NOT_VALID_MINUS_ - last_bottom = NOT_VALID_MINUS_ + last-left = NOT-VALID-PLUS_ + last-top = NOT-VALID-PLUS_ + last-right = NOT-VALID-MINUS_ + last-bottom = NOT-VALID-MINUS_ - draw_true_color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: - last_left = min left last_left - last_top = min top last_top - last_right = max right last_right - last_bottom = max bottom last_bottom + draw-true-color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: + last-left = min left last-left + last-top = min top last-top + last-right = max right last-right + last-bottom = max bottom last-bottom main: - small_test - large_test 56 500 - large_test 1280 640 + small-test + large-test 56 500 + large-test 1280 640 -small_test: +small-test: driver := AreaRememberingDriver 128 64 - display := PixelDisplay.true_color driver - display.background = get_rgb 0 1 2 + display := PixelDisplay.true-color driver + display.background = get-rgb 0 1 2 display.draw - expect_equals 0 driver.last_left - expect_equals 0 driver.last_top - expect_equals driver.width driver.last_right - expect_equals driver.height driver.last_bottom + expect-equals 0 driver.last-left + expect-equals 0 driver.last-top + expect-equals driver.width driver.last-right + expect-equals driver.height driver.last-bottom driver.reset - ctx := display.context --landscape --color=(get_rgb 255 120 0) + ctx := display.context --landscape --color=(get-rgb 255 120 0) - display.filled_rectangle ctx 16 24 32 40 + display.filled-rectangle ctx 16 24 32 40 display.draw - expect_equals 16 driver.last_left - expect_equals 24 driver.last_top - expect_equals 48 driver.last_right - expect_equals 64 driver.last_bottom + expect-equals 16 driver.last-left + expect-equals 24 driver.last-top + expect-equals 48 driver.last-right + expect-equals 64 driver.last-bottom driver.reset - display.filled_rectangle ctx 7 15 8 16 + display.filled-rectangle ctx 7 15 8 16 display.draw - expect_equals 0 driver.last_left - expect_equals 8 driver.last_top - expect_equals 16 driver.last_right - expect_equals 32 driver.last_bottom + expect-equals 0 driver.last-left + expect-equals 8 driver.last-top + expect-equals 16 driver.last-right + expect-equals 32 driver.last-bottom driver.reset - display.filled_rectangle ctx 9 17 8 16 + display.filled-rectangle ctx 9 17 8 16 display.draw - expect_equals 8 driver.last_left - expect_equals 16 driver.last_top - expect_equals 24 driver.last_right - expect_equals 40 driver.last_bottom + expect-equals 8 driver.last-left + expect-equals 16 driver.last-top + expect-equals 24 driver.last-right + expect-equals 40 driver.last-bottom driver.reset - display.filled_rectangle ctx 7 15 9 17 + display.filled-rectangle ctx 7 15 9 17 display.draw - expect_equals 0 driver.last_left - expect_equals 8 driver.last_top - expect_equals 16 driver.last_right - expect_equals 32 driver.last_bottom + expect-equals 0 driver.last-left + expect-equals 8 driver.last-top + expect-equals 16 driver.last-right + expect-equals 32 driver.last-bottom -large_test w h: +large-test w h: driver := AreaRememberingDriver w h - display := PixelDisplay.true_color driver - display.background = get_rgb 0 1 2 + display := PixelDisplay.true-color driver + display.background = get-rgb 0 1 2 display.draw - expect_equals 0 driver.last_left - expect_equals 0 driver.last_top - expect_equals driver.width driver.last_right - expect_equals (round_up driver.height 8) driver.last_bottom + expect-equals 0 driver.last-left + expect-equals 0 driver.last-top + expect-equals driver.width driver.last-right + expect-equals (round-up driver.height 8) driver.last-bottom - ctx := display.context --color=(get_rgb 255 120 0) + ctx := display.context --color=(get-rgb 255 120 0) - set_random_seed "FORTY TWO" + set-random-seed "FORTY TWO" 100.repeat: left := random driver.width top := random driver.height @@ -116,15 +116,15 @@ large_test w h: height := 1 + (random 200) right := left + width bottom := top + height - display.filled_rectangle ctx left top width height + display.filled-rectangle ctx left top width height driver.reset display.draw right = min right driver.width - bottom = min bottom (round_up driver.height 8) + bottom = min bottom (round-up driver.height 8) - expect_equals (round_down left 8) driver.last_left - expect_equals (round_down top 8) driver.last_top - expect_equals (round_up right 8) driver.last_right - expect_equals (round_up bottom 8) driver.last_bottom + expect-equals (round-down left 8) driver.last-left + expect-equals (round-down top 8) driver.last-top + expect-equals (round-up right 8) driver.last-right + expect-equals (round-up bottom 8) driver.last-bottom diff --git a/tests/mixed_text_rotated_visualized.toit b/tests/mixed_text_rotated_visualized.toit index 7bde235..e5e0abd 100644 --- a/tests/mixed_text_rotated_visualized.toit +++ b/tests/mixed_text_rotated_visualized.toit @@ -8,49 +8,49 @@ import bitmap show * import expect show * import font show * -import pixel_display show * -import pixel_display.element show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.style show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 - driver := SeveralColorPngVisualizer 160 96 args[0] --outline=SEVERAL_WHITE - display := PixelDisplay.several_color driver --portrait - display.background = SEVERAL_DARK_GRAY + driver := SeveralColorPngVisualizer 160 96 args[0] --outline=SEVERAL-WHITE + display := PixelDisplay.several-color driver --portrait + display.background = SEVERAL-DARK-GRAY sans10 := Font.get "sans10" // Element-based text. - element_text := Label --x=10 --y=30 --color=SEVERAL_GREEN --font=sans10 --label="Element 1" - element_text_2 := Label --x=10 --y=110 --color=SEVERAL_GREEN --font=sans10 --label="Element 2" - display.add element_text - display.add element_text_2 + element-text := Label --x=10 --y=30 --color=SEVERAL-GREEN --font=sans10 --label="Element 1" + element-text-2 := Label --x=10 --y=110 --color=SEVERAL-GREEN --font=sans10 --label="Element 2" + display.add element-text + display.add element-text-2 display.draw - element_text.move_to 20 30 + element-text.move-to 20 30 display.draw display.draw - element_text_2.move_to 20 110 + element-text-2.move-to 20 110 display.draw - element_text.alignment = ALIGN_RIGHT + element-text.alignment = ALIGN-RIGHT display.draw - element_text.orientation = ORIENTATION_90 - element_text_2.orientation = ORIENTATION_90 + element-text.orientation = ORIENTATION-90 + element-text-2.orientation = ORIENTATION-90 display.draw - element_text.orientation = ORIENTATION_180 - element_text_2.orientation = ORIENTATION_180 + element-text.orientation = ORIENTATION-180 + element-text-2.orientation = ORIENTATION-180 display.draw - element_text.orientation = ORIENTATION_270 - element_text_2.orientation = ORIENTATION_270 + element-text.orientation = ORIENTATION-270 + element-text-2.orientation = ORIENTATION-270 display.draw - driver.write_png + driver.write-png diff --git a/tests/mixed_text_visualized.toit b/tests/mixed_text_visualized.toit index 6213a66..f5a95e4 100644 --- a/tests/mixed_text_visualized.toit +++ b/tests/mixed_text_visualized.toit @@ -7,61 +7,61 @@ import bitmap show * import expect show * import font show * -import pixel_display show * -import pixel_display.element show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.style show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 - driver := SeveralColorPngVisualizer 192 96 args[0] --outline=SEVERAL_WHITE - display := PixelDisplay.several_color driver - display.background = SEVERAL_DARK_GRAY + driver := SeveralColorPngVisualizer 192 96 args[0] --outline=SEVERAL-WHITE + display := PixelDisplay.several-color driver + display.background = SEVERAL-DARK-GRAY sans10 := Font.get "sans10" // Element-based rectangles. - element_text := Label --x=30 --y=30 --color=SEVERAL_ORANGE --label="joo%" --font=sans10 - element_text_2 := Label --x=130 --y=20 --color=SEVERAL_ORANGE --label="joo%" --font=sans10 - display.add element_text - display.add element_text_2 + element-text := Label --x=30 --y=30 --color=SEVERAL-ORANGE --label="joo%" --font=sans10 + element-text-2 := Label --x=130 --y=20 --color=SEVERAL-ORANGE --label="joo%" --font=sans10 + display.add element-text + display.add element-text-2 display.draw - element_text.move_to 31 40 + element-text.move-to 31 40 display.draw display.draw - element_text_2.move_to 130 30 + element-text-2.move-to 130 30 display.draw - element_text.orientation = ORIENTATION_90 + element-text.orientation = ORIENTATION-90 display.draw - element_text.orientation = ORIENTATION_180 + element-text.orientation = ORIENTATION-180 display.draw - element_text.orientation = ORIENTATION_270 + element-text.orientation = ORIENTATION-270 display.draw - element_text.orientation = ORIENTATION_0 + element-text.orientation = ORIENTATION-0 display.draw - element_text.alignment = ALIGN_CENTER + element-text.alignment = ALIGN-CENTER display.draw - element_text.alignment = ALIGN_RIGHT + element-text.alignment = ALIGN-RIGHT display.draw - element_text.orientation = ORIENTATION_90 + element-text.orientation = ORIENTATION-90 display.draw - element_text.orientation = ORIENTATION_180 + element-text.orientation = ORIENTATION-180 display.draw - element_text.orientation = ORIENTATION_270 + element-text.orientation = ORIENTATION-270 display.draw - driver.write_png + driver.write-png diff --git a/tests/mixed_texture_rotated_visualized.toit b/tests/mixed_texture_rotated_visualized.toit index 41c3bb1..b56b79d 100644 --- a/tests/mixed_texture_rotated_visualized.toit +++ b/tests/mixed_texture_rotated_visualized.toit @@ -7,31 +7,31 @@ // Uses a rotated frame (portrait mode). import expect show * -import pixel_display show * -import pixel_display.element show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 - driver := SeveralColorPngVisualizer 160 64 args[0] --outline=SEVERAL_WHITE - display := PixelDisplay.several_color driver --inverted --portrait - display.background = SEVERAL_DARK_GRAY + driver := SeveralColorPngVisualizer 160 64 args[0] --outline=SEVERAL-WHITE + display := PixelDisplay.several-color driver --inverted --portrait + display.background = SEVERAL-DARK-GRAY // Element-based rectangle. - element_rect := Div --x=11 --y=21 --w=28 --h=18 --background=SEVERAL_BLACK - element_rect_2 := Div --x=10 --y=110 --w=30 --h=20 --background=SEVERAL_GREEN - display.add element_rect - display.add element_rect_2 + element-rect := Div --x=11 --y=21 --w=28 --h=18 --background=SEVERAL-BLACK + element-rect-2 := Div --x=10 --y=110 --w=30 --h=20 --background=SEVERAL-GREEN + display.add element-rect + display.add element-rect-2 display.draw - element_rect.move_to 21 21 + element-rect.move-to 21 21 display.draw display.draw - element_rect_2.move_to 20 110 + element-rect-2.move-to 20 110 display.draw - driver.write_png + driver.write-png diff --git a/tests/mixed_texture_visualized.toit b/tests/mixed_texture_visualized.toit index 37028cc..e337482 100644 --- a/tests/mixed_texture_visualized.toit +++ b/tests/mixed_texture_visualized.toit @@ -5,44 +5,44 @@ // Element-based rectangles with simple borders. import expect show * -import pixel_display show * -import pixel_display.element show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.style show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 - driver := SeveralColorPngVisualizer 200 64 args[0] --outline=SEVERAL_WHITE - display := PixelDisplay.several_color driver - display.background = SEVERAL_DARK_GRAY + driver := SeveralColorPngVisualizer 200 64 args[0] --outline=SEVERAL-WHITE + display := PixelDisplay.several-color driver + display.background = SEVERAL-DARK-GRAY // Slightlly smaller element-based rectangle. - element_rect := Div --x=11 --y=21 --w=28 --h=18 --background=SEVERAL_BLACK - element_rect_2 := Div --x=110 --y=20 --w=30 --h=20 --background=SEVERAL_GREEN - element_rect_3 := Div --x=160 --y=10 --w=30 --h=30 --border=(SolidBorder --color=SEVERAL_BLUE --width=5) - display.add element_rect - display.add element_rect_2 - display.add element_rect_3 + element-rect := Div --x=11 --y=21 --w=28 --h=18 --background=SEVERAL-BLACK + element-rect-2 := Div --x=110 --y=20 --w=30 --h=20 --background=SEVERAL-GREEN + element-rect-3 := Div --x=160 --y=10 --w=30 --h=30 --border=(SolidBorder --color=SEVERAL-BLUE --width=5) + display.add element-rect + display.add element-rect-2 + display.add element-rect-3 display.draw - element_rect.move_to 11 31 + element-rect.move-to 11 31 display.draw - element_rect_2.move_to 110 30 + element-rect-2.move-to 110 30 display.draw - display.remove element_rect - display.remove element_rect_2 + display.remove element-rect + display.remove element-rect-2 - element_rect_3.move_to 160 20 + element-rect-3.move-to 160 20 display.draw - element_rect_3.border = SolidBorder --color=SEVERAL_BLUE --width=2 + element-rect-3.border = SolidBorder --color=SEVERAL-BLUE --width=2 display.draw - element_rect_3.border = SolidBorder --color=SEVERAL_BLUE --width=7 + element-rect-3.border = SolidBorder --color=SEVERAL-BLUE --width=7 display.draw - driver.write_png + driver.write-png diff --git a/tests/png-visualizer.toit b/tests/png-visualizer.toit index 5b7d06a..41b1509 100644 --- a/tests/png-visualizer.toit +++ b/tests/png-visualizer.toit @@ -2,146 +2,146 @@ // Use of this source code is governed by an MIT-style license that can be // found in the LICENSE file. -import binary show BIG_ENDIAN byte_swap_32 +import binary show BIG-ENDIAN byte-swap-32 import bitmap show * import bytes show Buffer import crypto.crc show * import host.file import monitor show Latch -import pixel_display show * -import png_tools.png_writer -import png_tools.png_reader show * +import pixel-display show * +import png-tools.png-writer +import png-tools.png-reader show * import zlib class TwoColorPngVisualizer extends PngVisualizingDriver_: - flags ::= FLAG_2_COLOR | FLAG_PARTIAL_UPDATES + flags ::= FLAG-2-COLOR | FLAG-PARTIAL-UPDATES constructor width height basename --outline/int?=null: super width height basename --outline=outline - width_to_byte_width w: return (round_up w 8) >> 3 - x_rounding := 8 // 8 pixels per byte in PNG. - y_rounding := 8 // 8 pixels per byte in canvas. + width-to-byte-width w: return (round-up w 8) >> 3 + x-rounding := 8 // 8 pixels per byte in PNG. + y-rounding := 8 // 8 pixels per byte in canvas. class ThreeColorPngVisualizer extends PngVisualizingDriver_: - flags ::= FLAG_3_COLOR | FLAG_PARTIAL_UPDATES + flags ::= FLAG-3-COLOR | FLAG-PARTIAL-UPDATES constructor width height basename --outline/int?=null: super width height basename --outline=outline - width_to_byte_width w: return (round_up w 4) >> 2 - x_rounding := 4 // 4 pixels per byte. - y_rounding := 8 // 8 pixels per byte in canvas. + width-to-byte-width w: return (round-up w 4) >> 2 + x-rounding := 4 // 4 pixels per byte. + y-rounding := 8 // 8 pixels per byte in canvas. class FourGrayPngVisualizer extends PngVisualizingDriver_: - flags ::= FLAG_4_COLOR | FLAG_PARTIAL_UPDATES + flags ::= FLAG-4-COLOR | FLAG-PARTIAL-UPDATES constructor width height basename --outline/int?=null: super width height basename --outline=outline - width_to_byte_width w: return (round_up w 4) >> 2 - x_rounding := 4 // 4 pixels per byte. - y_rounding := 8 // 8 pixels per byte in canvas. + width-to-byte-width w: return (round-up w 4) >> 2 + x-rounding := 4 // 4 pixels per byte. + y-rounding := 8 // 8 pixels per byte in canvas. class TrueColorPngVisualizer extends PngVisualizingDriver_: - flags ::= FLAG_TRUE_COLOR | FLAG_PARTIAL_UPDATES + flags ::= FLAG-TRUE-COLOR | FLAG-PARTIAL-UPDATES constructor width height basename --outline/int?=null: super width height basename --outline=outline - width_to_byte_width w: return w * 3 - x_rounding := 1 - y_rounding := 1 + width-to-byte-width w: return w * 3 + x-rounding := 1 + y-rounding := 1 class GrayScalePngVisualizer extends PngVisualizingDriver_: - flags ::= FLAG_GRAY_SCALE | FLAG_PARTIAL_UPDATES + flags ::= FLAG-GRAY-SCALE | FLAG-PARTIAL-UPDATES constructor width height basename --outline/int?=null: super width height basename --outline=outline - width_to_byte_width w: return w - x_rounding := 1 - y_rounding := 1 + width-to-byte-width w: return w + x-rounding := 1 + y-rounding := 1 class SeveralColorPngVisualizer extends PngVisualizingDriver_: - flags ::= FLAG_SEVERAL_COLOR | FLAG_PARTIAL_UPDATES + flags ::= FLAG-SEVERAL-COLOR | FLAG-PARTIAL-UPDATES constructor width height basename --outline/int?=null: super width height basename --outline=outline - width_to_byte_width w: return w - x_rounding := 1 - y_rounding := 1 + width-to-byte-width w: return w + x-rounding := 1 + y-rounding := 1 abstract class PngVisualizingDriver_ extends AbstractDriver: width /int ::= ? height /int ::= ? width_ := 0 // Rounded up depending on the bit depth. height_ := 0 // Rounded up depending on the bit depth. - outline_buffer_ /ByteArray? := null + outline-buffer_ /ByteArray? := null buffer_ /ByteArray := #[] - temp_buffer_/ByteArray := #[] + temp-buffer_/ByteArray := #[] temps_ := List 8 // Optional outliner to see update locations. outline/int? := null // How many bytes make up one strip of image data. - abstract width_to_byte_width w/int -> int + abstract width-to-byte-width w/int -> int static INVERT_ := ByteArray 0x100: 0xff - it constructor .width .height basename/string --.outline/int?=null: - png_basename_ = basename - width_ = round_up width x_rounding - height_ = round_up height y_rounding + png-basename_ = basename + width_ = round-up width x-rounding + height_ = round-up height y-rounding buffer_ = ByteArray - (width_to_byte_width width_) * height_ + (width-to-byte-width width_) * height_ if outline: - outline_buffer_ = buffer_.copy + outline-buffer_ = buffer_.copy snapshots_ := [] - draw_true_color left/int top/int right/int bottom/int red/ByteArray green/ByteArray blue/ByteArray -> none: - patch_width := right - left - top_left := min buffer_.size (3 * (left + width_ * top)) + draw-true-color left/int top/int right/int bottom/int red/ByteArray green/ByteArray blue/ByteArray -> none: + patch-width := right - left + top-left := min buffer_.size (3 * (left + width_ * top)) if outline: red2 := red.copy green2 := green.copy blue2 := blue.copy - draw_byte_outline_ (outline >> 16) red2 patch_width - draw_byte_outline_ ((outline >> 16) & 0xff) green2 patch_width - draw_byte_outline_ (outline & 0xff) blue2 patch_width + draw-byte-outline_ (outline >> 16) red2 patch-width + draw-byte-outline_ ((outline >> 16) & 0xff) green2 patch-width + draw-byte-outline_ (outline & 0xff) blue2 patch-width // Pack 3 pixels in three consecutive bytes. Since we receive the data in // three one-byte-per-pixel buffers we have to shuffle the bytes. - blit red2 outline_buffer_[top_left..] patch_width --destination_pixel_stride=3 --destination_line_stride=(width_ * 3) - blit green2 outline_buffer_[top_left + 1..] patch_width --destination_pixel_stride=3 --destination_line_stride=(width_ * 3) - blit blue2 outline_buffer_[top_left + 2..] patch_width --destination_pixel_stride=3 --destination_line_stride=(width_ * 3) + blit red2 outline-buffer_[top-left..] patch-width --destination-pixel-stride=3 --destination-line-stride=(width_ * 3) + blit green2 outline-buffer_[top-left + 1..] patch-width --destination-pixel-stride=3 --destination-line-stride=(width_ * 3) + blit blue2 outline-buffer_[top-left + 2..] patch-width --destination-pixel-stride=3 --destination-line-stride=(width_ * 3) // Pack 3 pixels in three consecutive bytes. Since we receive the data in // three one-byte-per-pixel buffers we have to shuffle the bytes. - blit red buffer_[top_left..] patch_width --destination_pixel_stride=3 --destination_line_stride=(width_ * 3) - blit green buffer_[top_left + 1..] patch_width --destination_pixel_stride=3 --destination_line_stride=(width_ * 3) - blit blue buffer_[top_left + 2..] patch_width --destination_pixel_stride=3 --destination_line_stride=(width_ * 3) + blit red buffer_[top-left..] patch-width --destination-pixel-stride=3 --destination-line-stride=(width_ * 3) + blit green buffer_[top-left + 1..] patch-width --destination-pixel-stride=3 --destination-line-stride=(width_ * 3) + blit blue buffer_[top-left + 2..] patch-width --destination-pixel-stride=3 --destination-line-stride=(width_ * 3) - draw_gray_scale left/int top/int right/int bottom/int pixels/ByteArray -> none: - patch_width := right - left - top_left := min buffer_.size (left + width_ * top) + draw-gray-scale left/int top/int right/int bottom/int pixels/ByteArray -> none: + patch-width := right - left + top-left := min buffer_.size (left + width_ * top) if outline: pixels2 := pixels.copy - draw_byte_outline_ outline pixels2 patch_width --dotted + draw-byte-outline_ outline pixels2 patch-width --dotted - blit pixels2 outline_buffer_[top_left..] patch_width --destination_line_stride=width_ + blit pixels2 outline-buffer_[top-left..] patch-width --destination-line-stride=width_ - blit pixels buffer_[top_left..] patch_width --destination_line_stride=width_ + blit pixels buffer_[top-left..] patch-width --destination-line-stride=width_ - draw_several_color left/int top/int right/int bottom/int pixels/ByteArray -> none: - draw_gray_scale left top right bottom pixels + draw-several-color left/int top/int right/int bottom/int pixels/ByteArray -> none: + draw-gray-scale left top right bottom pixels - draw_two_color left/int top/int right/int bottom/int pixels/ByteArray -> none: + draw-two-color left/int top/int right/int bottom/int pixels/ByteArray -> none: if outline: - patch_width := right - left + patch-width := right - left pixels2 := pixels.copy - draw_bit_outline_ outline pixels2 patch_width - write_png_two_color outline_buffer_ left top right bottom pixels2 + draw-bit-outline_ outline pixels2 patch-width + write-png-two-color outline-buffer_ left top right bottom pixels2 - write_png_two_color buffer_ left top right bottom pixels + write-png-two-color buffer_ left top right bottom pixels - write_png_two_color buffer/ByteArray left/int top/int right/int bottom/int pixels/ByteArray -> none: - if temp_buffer_.size < pixels.size: - temp_buffer_ = ByteArray pixels.size + write-png-two-color buffer/ByteArray left/int top/int right/int bottom/int pixels/ByteArray -> none: + if temp-buffer_.size < pixels.size: + temp-buffer_ = ByteArray pixels.size 8.repeat: - temps_[it] = temp_buffer_[it..pixels.size] + temps_[it] = temp-buffer_[it..pixels.size] - assert: left == (round_up left 8) - assert: top == (round_up top 8) - assert: right == (round_up right 8) - assert: bottom == (round_up bottom 8) + assert: left == (round-up left 8) + assert: top == (round-up top 8) + assert: right == (round-up right 8) + assert: bottom == (round-up bottom 8) - patch_width := right - left - patch_height := bottom - top + patch-width := right - left + patch-height := bottom - top // Writes the patch to the buffer. The patch is arranged as height/8 // strips of width bytes, where each byte represents 8 vertically stacked @@ -149,83 +149,83 @@ abstract class PngVisualizingDriver_ extends AbstractDriver: // line is represented by consecutive bytes, from top to bottom, msbit on // the left. - pixels_0 := pixels[0..] - pixels_1 := pixels[1..] - pixels_2 := pixels[2..] - pixels_4 := pixels[4..] + pixels-0 := pixels[0..] + pixels-1 := pixels[1..] + pixels-2 := pixels[2..] + pixels-4 := pixels[4..] // We start by reflecting each 8x8 block. // Reflect each 2x2 pixel block. - blit pixels_0 temps_[0] patch_width/2 --source_pixel_stride=2 --destination_pixel_stride=2 --mask=0xaa - blit pixels_1 temps_[1] patch_width/2 --source_pixel_stride=2 --destination_pixel_stride=2 --mask=0x55 - blit pixels_0 temps_[1] patch_width/2 --source_pixel_stride=2 --destination_pixel_stride=2 --shift=-1 --mask=0xaa --operation=OR - blit pixels_1 temps_[0] patch_width/2 --source_pixel_stride=2 --destination_pixel_stride=2 --shift=1 --mask=0x55 --operation=OR + blit pixels-0 temps_[0] patch-width/2 --source-pixel-stride=2 --destination-pixel-stride=2 --mask=0xaa + blit pixels-1 temps_[1] patch-width/2 --source-pixel-stride=2 --destination-pixel-stride=2 --mask=0x55 + blit pixels-0 temps_[1] patch-width/2 --source-pixel-stride=2 --destination-pixel-stride=2 --shift=-1 --mask=0xaa --operation=OR + blit pixels-1 temps_[0] patch-width/2 --source-pixel-stride=2 --destination-pixel-stride=2 --shift=1 --mask=0x55 --operation=OR // Reflect each 4x4 pixel block. Blit is treating each 4x8 block as a line for this operation. - blit temps_[0] pixels_0 2 --source_line_stride=4 --destination_line_stride=4 --mask=0xcc - blit temps_[2] pixels_2 2 --source_line_stride=4 --destination_line_stride=4 --mask=0x33 - blit temps_[0] pixels_2 2 --source_line_stride=4 --destination_line_stride=4 --shift=-2 --mask=0xcc --operation=OR - blit temps_[2] pixels_0 2 --source_line_stride=4 --destination_line_stride=4 --shift=2 --mask=0x33 --operation=OR + blit temps_[0] pixels-0 2 --source-line-stride=4 --destination-line-stride=4 --mask=0xcc + blit temps_[2] pixels-2 2 --source-line-stride=4 --destination-line-stride=4 --mask=0x33 + blit temps_[0] pixels-2 2 --source-line-stride=4 --destination-line-stride=4 --shift=-2 --mask=0xcc --operation=OR + blit temps_[2] pixels-0 2 --source-line-stride=4 --destination-line-stride=4 --shift=2 --mask=0x33 --operation=OR // Reflect each 8x8 pixel block. Blit is treating each 8x8 block as a line for this operation. - blit pixels_0 temps_[0] 4 --source_line_stride=8 --destination_line_stride=8 --mask=0xf0 - blit pixels_4 temps_[4] 4 --source_line_stride=8 --destination_line_stride=8 --mask=0x0f - blit pixels_0 temps_[4] 4 --source_line_stride=8 --destination_line_stride=8 --shift=-4 --mask=0xf0 --operation=OR - blit pixels_4 temps_[0] 4 --source_line_stride=8 --destination_line_stride=8 --shift=4 --mask=0x0f --operation=OR + blit pixels-0 temps_[0] 4 --source-line-stride=8 --destination-line-stride=8 --mask=0xf0 + blit pixels-4 temps_[4] 4 --source-line-stride=8 --destination-line-stride=8 --mask=0x0f + blit pixels-0 temps_[4] 4 --source-line-stride=8 --destination-line-stride=8 --shift=-4 --mask=0xf0 --operation=OR + blit pixels-4 temps_[0] 4 --source-line-stride=8 --destination-line-stride=8 --shift=4 --mask=0x0f --operation=OR // Now we need to spread the 8x8 blocks out over the lines they belong on. // First line is bytes 0, 8, 16..., next line is bytes 1, 9, 17... etc. 8.repeat: index := left + (width_ * (top + 7 - it)) >> 3 - blit temps_[it] buffer[index..] (patch_width >> 3) --source_pixel_stride=8 --destination_line_stride=width_ --lookup_table=INVERT_ + blit temps_[it] buffer[index..] (patch-width >> 3) --source-pixel-stride=8 --destination-line-stride=width_ --lookup-table=INVERT_ - draw_bit_outline_ outline/int pixels/ByteArray patch_width/int -> none: - bottom_left := pixels.size - patch_width + draw-bit-outline_ outline/int pixels/ByteArray patch-width/int -> none: + bottom-left := pixels.size - patch-width // Dotted line along top and bottom. - for x := 0; x < patch_width; x += 2: + for x := 0; x < patch-width; x += 2: if outline == 0: pixels[x] &= ~1 - pixels[bottom_left + x] &= ~0x80 + pixels[bottom-left + x] &= ~0x80 else: pixels[x] |= 1 - pixels[bottom_left + x] |= 0x80 + pixels[bottom-left + x] |= 0x80 // Dotted line along left and right. - for y := 0; y < pixels.size; y += patch_width: + for y := 0; y < pixels.size; y += patch-width: if outline == 0: pixels[y] &= ~0b01010101 - pixels[y + patch_width - 1] &= ~0b01010101 + pixels[y + patch-width - 1] &= ~0b01010101 else: pixels[y] |= 0b01010101 - pixels[y + patch_width - 1] |= 0b01010101 + pixels[y + patch-width - 1] |= 0b01010101 - draw_byte_outline_ outline/int pixels/ByteArray patch_width/int --dotted=false -> none: - bottom_left := pixels.size - patch_width + 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. - x_step := dotted ? 2 : 1 - for x := 0; x < patch_width; x += x_step: + x-step := dotted ? 2 : 1 + for x := 0; x < patch-width; x += x-step: pixels[x] = outline - pixels[bottom_left + x] = outline + pixels[bottom-left + x] = outline // Dotted line along left and right. - y_step := patch_width * (dotted ? 2 : 1) - for y := 0; y < pixels.size; y += y_step: + 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 + pixels[y + patch-width - 1] = outline - draw_two_bit left/int top/int right/int bottom/int plane_0/ByteArray plane_1/ByteArray -> none: + draw-two-bit left/int top/int right/int bottom/int plane-0/ByteArray plane-1/ByteArray -> none: if outline: - patch_width := right - left - plane_0_2 := plane_0.copy - plane_1_2 := plane_1.copy - draw_bit_outline_ (outline & 1) plane_0_2 patch_width - draw_bit_outline_ (outline >> 1) plane_1_2 patch_width - write_png_two_bit outline_buffer_ left top right bottom plane_0_2 plane_1_2 - write_png_two_bit buffer_ left top right bottom plane_0 plane_1 - - write_png_two_bit buffer/ByteArray left/int top/int right/int bottom/int plane_0/ByteArray plane_1/ByteArray -> none: - patch_width := right - left - assert: patch_width == (round_up patch_width 4) - patch_height := bottom - top - assert: patch_height == (round_up patch_height 8) - - byte_width := width_to_byte_width width_ + patch-width := right - left + plane-0-2 := plane-0.copy + plane-1-2 := plane-1.copy + draw-bit-outline_ (outline & 1) plane-0-2 patch-width + draw-bit-outline_ (outline >> 1) plane-1-2 patch-width + write-png-two-bit outline-buffer_ left top right bottom plane-0-2 plane-1-2 + write-png-two-bit buffer_ left top right bottom plane-0 plane-1 + + write-png-two-bit buffer/ByteArray left/int top/int right/int bottom/int plane-0/ByteArray plane-1/ByteArray -> none: + patch-width := right - left + assert: patch-width == (round-up patch-width 4) + patch-height := bottom - top + assert: patch-height == (round-up patch-height 8) + + byte-width := width-to-byte-width width_ // Writes part of the patch to the compressor. The patch is arranged as // height/8 strips of width bytes, where each byte represents 8 vertically @@ -235,26 +235,26 @@ abstract class PngVisualizingDriver_ extends AbstractDriver: // This implementation is not as optimized as the two-color version. row := 0 ppb := 4 // Pixels per byte. - for y := 0; y < patch_height; y += 8: - for in_bit := 0; in_bit < 8 and y + top + in_bit < height; in_bit++: - out_index := (left >> 2) + (top + y + in_bit) * byte_width - for x := 0; x < patch_width; x += ppb: + for y := 0; y < patch-height; y += 8: + for in-bit := 0; in-bit < 8 and y + top + in-bit < height; in-bit++: + out-index := (left >> 2) + (top + y + in-bit) * byte-width + for x := 0; x < patch-width; x += ppb: out := 0 - byte_pos := row + x + ppb - 1 - for out_bit := ppb - 1; out_bit >= 0; out_bit--: - out |= ((plane_0[byte_pos - out_bit] >> in_bit) & 1) << (out_bit * 2) - out |= ((plane_1[byte_pos - out_bit] >> in_bit) & 1) << (out_bit * 2 + 1) - buffer[out_index + (width_to_byte_width x)] = out - row += patch_width + byte-pos := row + x + ppb - 1 + for out-bit := ppb - 1; out-bit >= 0; out-bit--: + out |= ((plane-0[byte-pos - out-bit] >> in-bit) & 1) << (out-bit * 2) + out |= ((plane-1[byte-pos - out-bit] >> in-bit) & 1) << (out-bit * 2 + 1) + buffer[out-index + (width-to-byte-width x)] = out + row += patch-width - png_basename_/string + png-basename_/string static HEADER ::= #[0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n'] - static write_chunk stream name/string data/ByteArray -> none: + static write-chunk stream name/string data/ByteArray -> none: length := ByteArray 4 if name.size != 4: throw "invalid name" - BIG_ENDIAN.put_uint32 length 0 data.size + BIG-ENDIAN.put-uint32 length 0 data.size write_ stream length write_ stream name write_ stream data @@ -262,102 +262,102 @@ abstract class PngVisualizingDriver_ extends AbstractDriver: crc.add name crc.add data write_ stream - byte_swap_ + byte-swap_ crc.get - static write_ stream byte_array -> none: + static write_ stream byte-array -> none: done := 0 - while done != byte_array.size: - done += stream.write byte_array[done..] + while done != byte-array.size: + done += stream.write byte-array[done..] commit left/int top/int right/int bottom/int -> none: if outline: - write_snapshot outline_buffer_ - outline_buffer_.replace 0 buffer_ - write_snapshot buffer_ + write-snapshot outline-buffer_ + outline-buffer_.replace 0 buffer_ + write-snapshot buffer_ - write_snapshot buffer/ByteArray -> none: + write-snapshot buffer/ByteArray -> none: snapshots_.add buffer.copy - write_png -> none: - true_color := flags & FLAG_TRUE_COLOR != 0 - gray := flags & FLAG_4_COLOR != 0 - three_color := flags & FLAG_3_COLOR != 0 - gray_scale := flags & FLAG_GRAY_SCALE != 0 - several_color := flags & FLAG_SEVERAL_COLOR != 0 + write-png -> none: + true-color := flags & FLAG-TRUE-COLOR != 0 + gray := flags & FLAG-4-COLOR != 0 + three-color := flags & FLAG-3-COLOR != 0 + gray-scale := flags & FLAG-GRAY-SCALE != 0 + several-color := flags & FLAG-SEVERAL-COLOR != 0 - writeable := file.Stream.for_write "$(png_basename_).png" + writeable := file.Stream.for-write "$(png-basename_).png" - frames_across := 2 - frames_down := snapshots_.size / frames_across + frames-across := 2 + frames-down := snapshots_.size / frames-across padding := 32 - mega_width := frames_across * width_ + (frames_across + 1) * padding - mega_height := frames_down * height_ + (frames_down + 1) * padding - - mega_buffer := ByteArray - (width_to_byte_width mega_width) * mega_height - - bit_depth := ? - color_type := ? - if true_color: - bit_depth = 8 - color_type = COLOR-TYPE-TRUECOLOR - else if gray_scale: - bit_depth = 8 - color_type = COLOR-TYPE-GRAYSCALE - else if three_color: - bit_depth = 2 - color_type = COLOR-TYPE-INDEXED - else if several_color: - bit_depth = 8 - color_type = COLOR-TYPE-INDEXED + mega-width := frames-across * width_ + (frames-across + 1) * padding + mega-height := frames-down * height_ + (frames-down + 1) * padding + + mega-buffer := ByteArray + (width-to-byte-width mega-width) * mega-height + + bit-depth := ? + color-type := ? + if true-color: + bit-depth = 8 + color-type = COLOR-TYPE-TRUECOLOR + else if gray-scale: + bit-depth = 8 + color-type = COLOR-TYPE-GRAYSCALE + else if three-color: + bit-depth = 2 + color-type = COLOR-TYPE-INDEXED + else if several-color: + bit-depth = 8 + color-type = COLOR-TYPE-INDEXED else if gray: - bit_depth = 2 - color_type = COLOR-TYPE-GRAYSCALE + bit-depth = 2 + color-type = COLOR-TYPE-GRAYSCALE else: - bit_depth = 1 - color_type = COLOR-TYPE-GRAYSCALE - - for y := 0; y < frames_down; y++: - for x := 0; x < frames_across; x++: - snapshot_index := y * frames_across + x - if snapshot_index >= snapshots_.size: continue - snapshot/ByteArray := snapshots_[snapshot_index] - bits_per_line_raw := bit_depth * width_ - bits_per_line_rounded := round_up bits_per_line_raw 8 - if bits_per_line_rounded != bits_per_line_raw: + bit-depth = 1 + color-type = COLOR-TYPE-GRAYSCALE + + for y := 0; y < frames-down; y++: + for x := 0; x < frames-across; x++: + snapshot-index := y * frames-across + x + if snapshot-index >= snapshots_.size: continue + snapshot/ByteArray := snapshots_[snapshot-index] + bits-per-line-raw := bit-depth * width_ + bits-per-line-rounded := round-up bits-per-line-raw 8 + if bits-per-line-rounded != bits-per-line-raw: // Zap the bits at the end of each line. for y2 := 0; y2 < height_; y2++: // Index of last byte of the line. - index := (y2 + 1) * (width_to_byte_width width_) - 1 + index := (y2 + 1) * (width-to-byte-width width_) - 1 // Mask out the bits that are beyond the last real pixel. - snapshot[index] &= 0xff << (bits_per_line_rounded - bits_per_line_raw) - pixel_index := (y * (height_ + padding) + padding) * (width_to_byte_width mega_width) + (width_to_byte_width (x * (width_ + padding) + padding)) + snapshot[index] &= 0xff << (bits-per-line-rounded - bits-per-line-raw) + pixel-index := (y * (height_ + padding) + padding) * (width-to-byte-width mega-width) + (width-to-byte-width (x * (width_ + padding) + padding)) blit snapshot // Source. - mega_buffer[pixel_index..] // Destination. - width_to_byte_width width_ // Bytes per line - --destination_line_stride=(width_to_byte_width mega_width) - --source_line_stride=(width_to_byte_width width_) + mega-buffer[pixel-index..] // Destination. + width-to-byte-width width_ // Bytes per line + --destination-line-stride=(width-to-byte-width mega-width) + --source-line-stride=(width-to-byte-width width_) - png_writer := png_writer.PngWriter + png-writer := png-writer.PngWriter writeable - mega_width - mega_height - --bit_depth=bit_depth - --color_type=color_type + mega-width + mega-height + --bit-depth=bit-depth + --color-type=color-type - if three_color: - png_writer.write_chunk "PLTE" #[ // Palette. + if three-color: + png-writer.write-chunk "PLTE" #[ // Palette. 0xff, 0xff, 0xff, // 0 is white. 0, 0, 0, // 1 is black. 0xff, 0, 0, // 2 is red. ] - else if several_color: + else if several-color: // Use color palette of 7-color epaper display. - png_writer.write_chunk "PLTE" #[ // Palette. + png-writer.write-chunk "PLTE" #[ // Palette. 0xff, 0xff, 0xff, // 0 is white. 0, 0, 0, // 1 is black. 0xff, 0, 0, // 2 is red. @@ -371,35 +371,35 @@ abstract class PngVisualizingDriver_ extends AbstractDriver: 0xc0, 0xc0, 0xc0, // 9 is light gray. ] - zero_byte := #[0] - line_size := width_to_byte_width mega_width - line_step := width_to_byte_width mega_width - mega_height.repeat: | y | - png_writer.write_uncompressed zero_byte // Adaptive scheme. - index := y * line_step - line := mega_buffer[index..index + line_size] + zero-byte := #[0] + line-size := width-to-byte-width mega-width + line-step := width-to-byte-width mega-width + mega-height.repeat: | y | + png-writer.write-uncompressed zero-byte // Adaptive scheme. + index := y * line-step + line := mega-buffer[index..index + line-size] if gray: line = ByteArray line.size: line[it] ^ 0xff - else if several_color: - line = ByteArray line.size: min SEVERAL_MAX_COLOR_ line[it] - png_writer.write_uncompressed line + else if several-color: + line = ByteArray line.size: min SEVERAL-MAX-COLOR_ line[it] + png-writer.write-uncompressed line - png_writer.close + png-writer.close writeable.close -SEVERAL_WHITE ::= 0 -SEVERAL_BLACK ::= 1 -SEVERAL_RED ::= 2 -SEVERAL_GREEN ::= 3 -SEVERAL_BLUE ::= 4 -SEVERAL_YELLOW ::= 5 -SEVERAL_ORANGE ::= 6 -SEVERAL_DARK_GRAY ::= 7 -SEVERAL_GRAY ::= 8 -SEVERAL_LIGHT_GRAY ::= 9 -SEVERAL_MAX_COLOR_ ::= 9 - -byte_swap_ ba/ByteArray -> ByteArray: +SEVERAL-WHITE ::= 0 +SEVERAL-BLACK ::= 1 +SEVERAL-RED ::= 2 +SEVERAL-GREEN ::= 3 +SEVERAL-BLUE ::= 4 +SEVERAL-YELLOW ::= 5 +SEVERAL-ORANGE ::= 6 +SEVERAL-DARK-GRAY ::= 7 +SEVERAL-GRAY ::= 8 +SEVERAL-LIGHT-GRAY ::= 9 +SEVERAL-MAX-COLOR_ ::= 9 + +byte-swap_ ba/ByteArray -> ByteArray: result := ba.copy - byte_swap_32 result + byte-swap-32 result return result diff --git a/tests/rounded_gray_window_visualized.toit b/tests/rounded_gray_window_visualized.toit index b6e9a76..60cf1ed 100644 --- a/tests/rounded_gray_window_visualized.toit +++ b/tests/rounded_gray_window_visualized.toit @@ -4,11 +4,11 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import pixel-display.style show * +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -17,16 +17,16 @@ main args: print "Usage: script.toit png-basename" exit 1 driver := GrayScalePngVisualizer 240 160 args[0] --outline=0x10 - display := PixelDisplay.gray_scale driver + display := PixelDisplay.gray-scale driver display.background = 160 - background_gradient := GradientBackground --angle=180 + background-gradient := GradientBackground --angle=180 --specifiers=[ GradientSpecifier --color=0x20 10, GradientSpecifier --color=0x60 90, ] - background_gradient_element := Div --x=0 --y=0 --w=240 --h=160 --background=background_gradient - display.add background_gradient_element + background-gradient-element := Div --x=0 --y=0 --w=240 --h=160 --background=background-gradient + display.add background-gradient-element win := Div.clipping --x=30 --y=30 --w=180 --h=100 --border=(RoundedCornerBorder --radius=15) display.add win @@ -36,21 +36,21 @@ main args: GradientSpecifier --color=0x90 10, GradientSpecifier --color=0xe0 90, ] - gradient_element := Div --x=0 --y=0 --w=180 --h=100 --background=gradient - win.add gradient_element + gradient-element := Div --x=0 --y=0 --w=180 --h=100 --background=gradient + win.add gradient-element text := Label --x=90 --y=55 --label="Hello, World!" --font=sans10 --color=0x10 win.add text display.draw - text.move_to 120 65 + text.move-to 120 65 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 display.draw - driver.write_png + driver.write-png diff --git a/tests/rounded_several_window_visualized.toit b/tests/rounded_several_window_visualized.toit index eec9683..dc60faf 100644 --- a/tests/rounded_several_window_visualized.toit +++ b/tests/rounded_several_window_visualized.toit @@ -4,10 +4,10 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.style show * +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -15,25 +15,25 @@ main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 - driver := SeveralColorPngVisualizer 240 160 args[0] --outline=SEVERAL_BLUE - display := PixelDisplay.several_color driver - display.background = SEVERAL_BLUE + driver := SeveralColorPngVisualizer 240 160 args[0] --outline=SEVERAL-BLUE + display := PixelDisplay.several-color driver + display.background = SEVERAL-BLUE - win := Div.clipping --x=30 --y=30 --w=180 --h=100 --background=SEVERAL_LIGHT_GRAY --border=(RoundedCornerBorder --radius=15) + win := Div.clipping --x=30 --y=30 --w=180 --h=100 --background=SEVERAL-LIGHT-GRAY --border=(RoundedCornerBorder --radius=15) display.add win - text := Label --x=90 --y=55 --label="Hello, World!" --font=sans10 --color=SEVERAL_BLACK + text := Label --x=90 --y=55 --label="Hello, World!" --font=sans10 --color=SEVERAL-BLACK win.add text display.draw - text.move_to 120 65 + text.move-to 120 65 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 display.draw - driver.write_png + driver.write-png diff --git a/tests/rounded_three_color_window_visualized.toit b/tests/rounded_three_color_window_visualized.toit index f46ee09..61884d4 100644 --- a/tests/rounded_three_color_window_visualized.toit +++ b/tests/rounded_three_color_window_visualized.toit @@ -4,11 +4,11 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.style show * -import pixel_display.three_color show BLACK WHITE RED -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.style show * +import pixel-display.three-color show BLACK WHITE RED +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -17,7 +17,7 @@ main args: print "Usage: script.toit png-basename" exit 1 driver := ThreeColorPngVisualizer 240 160 args[0] --outline=RED - display := PixelDisplay.three_color driver + display := PixelDisplay.three-color driver display.background = WHITE win := Div.clipping --x=30 --y=30 --w=180 --h=100 --background=RED --border=(RoundedCornerBorder --radius=17) @@ -28,15 +28,15 @@ main args: display.draw - text.move_to 120 65 + text.move-to 120 65 win.border = RoundedCornerBorder --radius=16 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 win.border = RoundedCornerBorder --radius=15 display.draw - driver.write_png + driver.write-png diff --git a/tests/rounded_two_color_window_visualized.toit b/tests/rounded_two_color_window_visualized.toit index 9f64122..e716aea 100644 --- a/tests/rounded_two_color_window_visualized.toit +++ b/tests/rounded_two_color_window_visualized.toit @@ -4,11 +4,11 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.style show * -import pixel_display.two_color show BLACK WHITE -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.style show * +import pixel-display.two-color show BLACK WHITE +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -17,7 +17,7 @@ main args: print "Usage: script.toit png-basename" exit 1 driver := TwoColorPngVisualizer 240 160 args[0] --outline=BLACK - display := PixelDisplay.two_color driver + display := PixelDisplay.two-color driver display.background = BLACK win := Div.clipping --x=30 --y=30 --w=180 --h=100 --background=WHITE --border=(RoundedCornerBorder --radius=17) @@ -28,15 +28,15 @@ main args: display.draw - text.move_to 120 65 + text.move-to 120 65 win.border = RoundedCornerBorder --radius=16 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 win.border = RoundedCornerBorder --radius=15 display.draw - driver.write_png + driver.write-png diff --git a/tests/rounded_window_visualized.toit b/tests/rounded_window_visualized.toit index dc5c302..0384aef 100644 --- a/tests/rounded_window_visualized.toit +++ b/tests/rounded_window_visualized.toit @@ -4,11 +4,11 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import pixel-display.style show * +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -17,16 +17,16 @@ main args: print "Usage: script.toit png-basename" exit 1 driver := TrueColorPngVisualizer 240 160 args[0] --outline=0x101010 - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver display.background = 0x78aac8 - background_gradient := GradientBackground --angle=180 + background-gradient := GradientBackground --angle=180 --specifiers=[ GradientSpecifier --color=0x80ddff 10, GradientSpecifier --color=0x80ffdd 90, ] - background_gradient_element := Div --x=0 --y=0 --w=240 --h=160 --background=background_gradient - display.add background_gradient_element + background-gradient-element := Div --x=0 --y=0 --w=240 --h=160 --background=background-gradient + display.add background-gradient-element win := Div.clipping --x=30 --y=30 --w=180 --h=100 --border=(RoundedCornerBorder --radius=15) display.add win @@ -36,21 +36,21 @@ main args: GradientSpecifier --color=0xffdd80 10, GradientSpecifier --color=0xddff80 90, ] - gradient_element := Div --x=0 --y=0 --w=180 --h=100 --background=gradient - win.add gradient_element + gradient-element := Div --x=0 --y=0 --w=180 --h=100 --background=gradient + win.add gradient-element text := Label --x=90 --y=55 --label="Hello, World!" --font=sans10 --color=0x101040 win.add text display.draw - text.move_to 120 65 + text.move-to 120 65 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 display.draw - driver.write_png + driver.write-png diff --git a/tests/several_color.toit b/tests/several_color.toit index c7e6375..23cd432 100644 --- a/tests/several_color.toit +++ b/tests/several_color.toit @@ -4,34 +4,34 @@ import expect show * import font show Font -import pixel_display show * -import pixel_display.several_color show * +import pixel-display show * +import pixel-display.several-color show * class TestDriver extends AbstractDriver: buffer := ByteArray 64 * 128 width ::= 128 height ::= 64 - flags ::= FLAG_SEVERAL_COLOR | FLAG_PARTIAL_UPDATES - draw_several_color left/int top/int right/int bottom/int pixels/ByteArray -> none: + flags ::= FLAG-SEVERAL-COLOR | FLAG-PARTIAL-UPDATES + draw-several-color left/int top/int right/int bottom/int pixels/ByteArray -> none: w := right - left (bottom - top).repeat: | iy | w.repeat: | ix | buffer[left + ix + (top + iy) * width] = pixels[ix + iy * w] - pixel_at x y: + pixel-at x y: return buffer[x + y * width] main: driver := TestDriver - display := PixelDisplay.several_color driver + display := PixelDisplay.several-color driver display.background = 1 sans10 := Font.get "sans10" ctx := display.context --landscape --color=250 --font=sans10 - display.filled_rectangle ctx 10 20 30 40 + display.filled-rectangle ctx 10 20 30 40 display.text ctx 50 20 "Testing" display.text ctx 50 40 "the display" display.draw @@ -42,14 +42,14 @@ main: for y := 0; y < driver.height; y += 2: line := "" driver.width.repeat: | x | - top_half := (driver.pixel_at x y) < 128 - bottom_half := (driver.pixel_at x y + 1) < 128 - line += "$(top_half ? (bottom_half ? " " : "▄") : (bottom_half ? "▀" : "█"))" + top-half := (driver.pixel-at x y) < 128 + bottom-half := (driver.pixel-at x y + 1) < 128 + line += "$(top-half ? (bottom-half ? " " : "▄") : (bottom-half ? "▀" : "█"))" print line 50.repeat: | x | driver.height.repeat: | y | if x < 10 or y < 20 or x >= 40 or y >= 60: - expect_equals 1 (driver.pixel_at x y) + expect-equals 1 (driver.pixel-at x y) else: - expect_equals 250 (driver.pixel_at x y) + expect-equals 250 (driver.pixel-at x y) diff --git a/tests/simple.toit b/tests/simple.toit index 07cf260..74ea021 100644 --- a/tests/simple.toit +++ b/tests/simple.toit @@ -4,77 +4,77 @@ import expect show * import font show Font -import pixel_display show * -import pixel_display.two_color -import pixel_display.true_color +import pixel-display show * +import pixel-display.two-color +import pixel-display.true-color class TwoColorDriver extends AbstractDriver: width ::= 128 height ::= 64 - flags ::= FLAG_2_COLOR - draw_two_color left/int top/int right/int bottom/int pixels/ByteArray -> none: + flags ::= FLAG-2-COLOR + draw-two-color left/int top/int right/int bottom/int pixels/ByteArray -> none: class ThreeColorDriver extends AbstractDriver: width ::= 128 height ::= 64 - flags ::= FLAG_3_COLOR - draw_two_bit left/int top/int right/int bottom/int plane0/ByteArray plane1/ByteArray -> none: + flags ::= FLAG-3-COLOR + draw-two-bit left/int top/int right/int bottom/int plane0/ByteArray plane1/ByteArray -> none: class FourGrayDriver extends AbstractDriver: width ::= 128 height ::= 64 - flags ::= FLAG_4_COLOR - draw_two_bit left/int top/int right/int bottom/int plane0/ByteArray plane1/ByteArray -> none: + flags ::= FLAG-4-COLOR + draw-two-bit left/int top/int right/int bottom/int plane0/ByteArray plane1/ByteArray -> none: class TrueColorDriver extends AbstractDriver: width ::= 128 height ::= 64 - flags ::= FLAG_TRUE_COLOR - draw_true_color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: + flags ::= FLAG-TRUE-COLOR + draw-true-color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: class GrayScaleDriver extends AbstractDriver: width ::= 128 height ::= 64 - flags ::= FLAG_GRAY_SCALE - draw_gray_scale left/int top/int right/int bottom/int pixels/ByteArray -> none: + flags ::= FLAG-GRAY-SCALE + draw-gray-scale left/int top/int right/int bottom/int pixels/ByteArray -> none: class SeveralColorDriver extends AbstractDriver: width ::= 128 height ::= 64 - flags ::= FLAG_SEVERAL_COLOR - draw_several_color left/int top/int right/int bottom/int pixels/ByteArray -> none: + flags ::= FLAG-SEVERAL-COLOR + draw-several-color left/int top/int right/int bottom/int pixels/ByteArray -> none: class DrawRecordingDriver extends AbstractDriver: width ::= 128 height ::= 64 - flags ::= FLAG_TRUE_COLOR | FLAG_PARTIAL_UPDATES - r_left := 0 - r_top := 0 - r_right := 0 - r_bottom := 0 + flags ::= FLAG-TRUE-COLOR | FLAG-PARTIAL-UPDATES + r-left := 0 + r-top := 0 + r-right := 0 + r-bottom := 0 constructor: reset reset -> none: - r_left = 1_000_000 - r_top = 1_000_000 - r_right = -1 - r_bottom = -1 + r-left = 1_000_000 + r-top = 1_000_000 + r-right = -1 + r-bottom = -1 - draw_true_color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: - r_left = min r_left left - r_top = min r_top top - r_right = max r_right right - r_bottom = max r_bottom bottom + draw-true-color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: + r-left = min r-left left + r-top = min r-top top + r-right = max r-right right + r-bottom = max r-bottom bottom main: - for_the_win_test - invalidate_test + for-the-win-test + invalidate-test -invalidate_test: +invalidate-test: driver := DrawRecordingDriver - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver context := display.context @@ -82,19 +82,19 @@ invalidate_test: driver.reset print "Rectangle" - display.filled_rectangle context 42 23 12 10 + display.filled-rectangle context 42 23 12 10 display.draw - expect_equals driver.r_left 40 // 42 rounded down. - expect_equals driver.r_right 56 // 42 + 12 rounded up. - expect_equals driver.r_top 16 // 23 rounded down. - expect_equals driver.r_bottom 40 // 23 + 10 rounded up. + expect-equals driver.r-left 40 // 42 rounded down. + expect-equals driver.r-right 56 // 42 + 12 rounded up. + expect-equals driver.r-top 16 // 23 rounded down. + expect-equals driver.r-bottom 40 // 23 + 10 rounded up. driver.reset print "Window" - window := true_color.SimpleWindow 42 23 22 20 context.transform + window := true-color.SimpleWindow 42 23 22 20 context.transform 0 // Border width. 0 // Border color. 0 // Background color. @@ -103,15 +103,15 @@ invalidate_test: display.draw - expect_equals driver.r_left 40 // 42 rounded down. - expect_equals driver.r_right 64 // 42 + 22 rounded up. - expect_equals driver.r_top 16 // 23 rounded down. - expect_equals driver.r_bottom 48 // 23 + 20 rounded up. + expect-equals driver.r-left 40 // 42 rounded down. + expect-equals driver.r-right 64 // 42 + 22 rounded up. + expect-equals driver.r-top 16 // 23 rounded down. + expect-equals driver.r-bottom 48 // 23 + 20 rounded up. driver.reset // Place rectangle at window-relative coordinates. - rect_in_window := true_color.FilledRectangle + rect-in-window := true-color.FilledRectangle 0 // Color. 8 // x. 0 // y. @@ -119,39 +119,39 @@ invalidate_test: 1 // h. window.transform - window.add rect_in_window + window.add rect-in-window display.draw - expect_equals driver.r_left 48 // 42 + 8 rounded down. - expect_equals driver.r_right 64 // 42 + 8 + 10 rounded up. - expect_equals driver.r_top 16 // 23 + 0 rounded down. - expect_equals driver.r_bottom 24 // 23 + 0 + 1 rounded up. + expect-equals driver.r-left 48 // 42 + 8 rounded down. + expect-equals driver.r-right 64 // 42 + 8 + 10 rounded up. + expect-equals driver.r-top 16 // 23 + 0 rounded down. + expect-equals driver.r-bottom 24 // 23 + 0 + 1 rounded up. -for_the_win_test: +for-the-win-test: driver2 := TwoColorDriver - display2 := PixelDisplay.two_color driver2 + display2 := PixelDisplay.two-color driver2 driver3 := ThreeColorDriver - display3 := PixelDisplay.three_color driver3 + display3 := PixelDisplay.three-color driver3 driver4 := FourGrayDriver - display4 := PixelDisplay.four_gray driver4 + display4 := PixelDisplay.four-gray driver4 - driver_true := TrueColorDriver - display_true := PixelDisplay.true_color driver_true + driver-true := TrueColorDriver + display-true := PixelDisplay.true-color driver-true - driver_gray := GrayScaleDriver - display_gray := PixelDisplay.gray_scale driver_gray + driver-gray := GrayScaleDriver + display-gray := PixelDisplay.gray-scale driver-gray - driver_several := SeveralColorDriver - display_several := PixelDisplay.several_color driver_several + driver-several := SeveralColorDriver + display-several := PixelDisplay.several-color driver-several sans10 := Font.get "sans10" - [display2, display3, display4, display_true, display_gray, display_several].do: | display | + [display2, display3, display4, display-true, display-gray, display-several].do: | display | ctx := display.context --landscape --font=sans10 - display.filled_rectangle ctx 10 20 30 40 + display.filled-rectangle ctx 10 20 30 40 display.text ctx 50 20 "Testing" display.text ctx 50 40 "the display" display.text ctx 50 60 "for the win" diff --git a/tests/simple_several_window_visualized.toit b/tests/simple_several_window_visualized.toit index 8a6a8fb..f8db13f 100644 --- a/tests/simple_several_window_visualized.toit +++ b/tests/simple_several_window_visualized.toit @@ -4,9 +4,9 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -14,25 +14,25 @@ main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 - driver := SeveralColorPngVisualizer 240 160 args[0] --outline=SEVERAL_BLUE - display := PixelDisplay.several_color driver - display.background = SEVERAL_BLUE + driver := SeveralColorPngVisualizer 240 160 args[0] --outline=SEVERAL-BLUE + display := PixelDisplay.several-color driver + display.background = SEVERAL-BLUE - win := Div.clipping --x=30 --y=30 --w=180 --h=100 --background=SEVERAL_LIGHT_GRAY + win := Div.clipping --x=30 --y=30 --w=180 --h=100 --background=SEVERAL-LIGHT-GRAY display.add win - text := Label --x=90 --y=55 --label="Hello, World!" --font=sans10 --color=SEVERAL_BLACK + text := Label --x=90 --y=55 --label="Hello, World!" --font=sans10 --color=SEVERAL-BLACK win.add text display.draw - text.move_to 120 65 + text.move-to 120 65 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 display.draw - driver.write_png + driver.write-png diff --git a/tests/simple_three_color_window_visualized.toit b/tests/simple_three_color_window_visualized.toit index 54437c2..cbdefc0 100644 --- a/tests/simple_three_color_window_visualized.toit +++ b/tests/simple_three_color_window_visualized.toit @@ -4,10 +4,10 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.three_color show BLACK WHITE RED -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.three-color show BLACK WHITE RED +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -16,7 +16,7 @@ main args: print "Usage: script.toit png-basename" exit 1 driver := ThreeColorPngVisualizer 240 160 args[0] --outline=RED - display := PixelDisplay.three_color driver + display := PixelDisplay.three-color driver display.background = WHITE win := Div.clipping --x=30 --y=30 --w=180 --h=100 --background=RED @@ -27,13 +27,13 @@ main args: display.draw - text.move_to 120 65 + text.move-to 120 65 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 display.draw - driver.write_png + driver.write-png diff --git a/tests/simple_two_color_window_visualized.toit b/tests/simple_two_color_window_visualized.toit index d54a9c7..3ebdc89 100644 --- a/tests/simple_two_color_window_visualized.toit +++ b/tests/simple_two_color_window_visualized.toit @@ -4,10 +4,10 @@ import bitmap show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.two_color show BLACK WHITE -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.two-color show BLACK WHITE +import .png-visualizer main args: sans10 := Font.get "sans10" @@ -16,7 +16,7 @@ main args: print "Usage: script.toit png-basename" exit 1 driver := TwoColorPngVisualizer 240 160 args[0] --outline=BLACK - display := PixelDisplay.two_color driver + display := PixelDisplay.two-color driver display.background = BLACK win := Div.clipping --x=30 --y=30 --w=180 --h=100 @@ -27,13 +27,13 @@ main args: display.draw - text.move_to 120 65 + text.move-to 120 65 display.draw // Window-relative coordinates. - text.move_to -10 7 + text.move-to -10 7 display.draw - driver.write_png + driver.write-png diff --git a/tests/slider_visualized.toit b/tests/slider_visualized.toit index 3057527..bf694e8 100644 --- a/tests/slider_visualized.toit +++ b/tests/slider_visualized.toit @@ -8,12 +8,12 @@ import bitmap show * import expect show * import font show * -import pixel_display show * -import pixel_display.element show * -import pixel_display.gradient show * -import pixel_display.slider show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.gradient show * +import pixel-display.slider show * +import pixel-display.style show * +import .png-visualizer main args: if args.size != 1: @@ -22,7 +22,7 @@ main args: WIDTH ::= 220 HEIGHT ::= 140 driver := TrueColorPngVisualizer WIDTH HEIGHT args[0] --outline=0x4040ff - display := PixelDisplay.true_color driver + display := PixelDisplay.true-color driver display.background = 0x808080 heat := GradientBackground --angle=0 --specifiers=[ @@ -40,7 +40,7 @@ main args: sliders := List 5: Slider --x=(20 + 40 * it) --y=10 --value=(10 + it * 20) labels := List 5: - Label --x=(30 + 40 * it) --y=125 --label="$(%c 'A' + it)" --alignment=ALIGN_CENTER + Label --x=(30 + 40 * it) --y=125 --label="$(%c 'A' + it)" --alignment=ALIGN-CENTER content := Div --x=0 --y=0 --w=WIDTH --h=HEIGHT --background=0x202020 (sliders + labels) @@ -59,10 +59,10 @@ main args: "label": Style --font=sans10 --color=0xffffff, } - content.set_styles [style] + content.set-styles [style] display.draw - driver.write_png + driver.write-png sliders[0].value = 50 sliders[1].value = 70 @@ -71,4 +71,4 @@ main args: sliders[4].value = 30 display.draw - driver.write_png + driver.write-png diff --git a/tests/style_test.toit b/tests/style_test.toit index d5315aa..da7b144 100644 --- a/tests/style_test.toit +++ b/tests/style_test.toit @@ -4,58 +4,58 @@ import expect show * -import pixel_display.common show Canvas -import pixel_display.element show Element -import pixel_display.style show * +import pixel-display.common show Canvas +import pixel-display.element show Element +import pixel-display.style show * /// Test that the examples from style.toit are well-formed. -toit_doc_examples_test: +toit-doc-examples-test: style := Style - --type_map={ + --type-map={ "button": Style --color=0xffffff --background=0x606060, } - --class_map={ + --class-map={ "box": Style --border=(SolidBorder --color=0xff0000 --width=2) } - --id_map={ + --id-map={ "fish": Style --color=0x00ff00, } style2 := Style - --class_map={ + --class-map={ "box": Style - --type_map={ + --type-map={ "p": Style --color=0xffffff, }, } - FISH_OR_FOWL_STYLE ::= Style --color=0xffffff --background=0x606060 + FISH-OR-FOWL-STYLE ::= Style --color=0xffffff --background=0x606060 style3 := Style - --class_map={ - "fish": FISH_OR_FOWL_STYLE, - "fowl": FISH_OR_FOWL_STYLE, + --class-map={ + "fish": FISH-OR-FOWL-STYLE, + "fowl": FISH-OR-FOWL-STYLE, } style4 := Style - --class_map={ + --class-map={ "fish-or-fowl": Style --color=0xffffff --background=0x606060, } /// Test a literal element tree can be constructed and get_element_by_id can be /// used to find a named element. -element_tree_test: +element-tree-test: elements := Div [ Square --id="first-square", Square --classes=["fish"], ] - first := elements.get_element_by_id "first-square" + first := elements.get-element-by-id "first-square" expect first.id == "first-square" /// Test that we can use set_styles to distribute the styles to all the /// elements. -combine_test: +combine-test: elements := Div [ Div --id="special" [ Square --id="first-square", @@ -66,34 +66,34 @@ combine_test: ] style := Style - --class_map={ + --class-map={ "fish": Style --color=0xffffff --background=0x606060, "fowl": Style --color=0x123456 --background=0x606060, } - --id_map={ + --id-map={ // The special div gets a different color and its children // get a different background if they are squares. - "special": Style --color=424242 --type_map={ + "special": Style --color=424242 --type-map={ // Squares inside the special div get a different backgorund. "square": Style --background=0xabcdef, }, } - elements.set_styles [style] + elements.set-styles [style] - special := elements.get_element_by_id "special" - first/Square := elements.get_element_by_id "first-square" - second/Square := elements.get_element_by_id "second-square" - expect_equals 0 first.color - expect_equals 0xffffff second.color - expect_equals 0xabcdef first.background + special := elements.get-element-by-id "special" + first/Square := elements.get-element-by-id "first-square" + second/Square := elements.get-element-by-id "second-square" + expect-equals 0 first.color + expect-equals 0xffffff second.color + expect-equals 0xabcdef first.background /// Test that we can attach an overriding style to a single element. -single_element_style_test: - first_style := Style --color=0x8090a0 --background=0x403020 +single-element-style-test: + first-style := Style --color=0x8090a0 --background=0x403020 elements := Div [ Div --id="special" [ - Square --id="first-square" --style=first_style, + Square --id="first-square" --style=first-style, Square --id="second-square", ], Square --id="third-square", @@ -101,22 +101,22 @@ single_element_style_test: ] style := Style - --type_map={ + --type-map={ "square": Style --color=0xffffff --background=0x606060, } - elements.set_styles [style] + elements.set-styles [style] - expect_equals 0xffffff - (elements.get_element_by_id "second-square").color - expect_equals 0x8090a0 - (elements.get_element_by_id "first-square").color + expect-equals 0xffffff + (elements.get-element-by-id "second-square").color + expect-equals 0x8090a0 + (elements.get-element-by-id "first-square").color /// Test that we can add custom properties to a style and use them /// from an element with the same custom property name. -extra_properties_test: +extra-properties-test: style := Style - --type_map={ + --type-map={ "foo-haver": Style { "foo": "bar" }, } @@ -124,10 +124,10 @@ extra_properties_test: FooHaver --id="first-foo-haver", ] - elements.set_styles [style] + elements.set-styles [style] expect-equals "bar" - (elements.get_element_by_id "first-foo-haver").foo + (elements.get-element-by-id "first-foo-haver").foo /// A class that stubs out the display methods we don't need /// for test purposes. @@ -150,7 +150,7 @@ class Square extends TestElement: constructor --style/Style?=null --classes/List?=null --id/string?=null children/List?=null: super --style=style --classes=classes --id=id children - set_attribute_ key/string value -> none: + set-attribute_ key/string value -> none: if key == "width": w = value else if key == "height": @@ -168,7 +168,7 @@ class Div extends TestElement: constructor --style/Style?=null --classes/List?=null --id/string?=null children/List?=null: super --style=style --classes=classes --id=id children - set_attribute_ key/string value -> none: + set-attribute_ key/string value -> none: if key == "width": w = value else if key == "height": @@ -184,13 +184,13 @@ class FooHaver extends TestElement: constructor --style/Style?=null --classes/List?=null --id/string?=null children/List?=null: super --style=style --classes=classes --id=id children - set_attribute_ key/string value -> none: + set-attribute_ key/string value -> none: if key == "foo": foo = value main: - toit_doc_examples_test - element_tree_test - combine_test - single_element_style_test - extra_properties_test + toit-doc-examples-test + element-tree-test + combine-test + single-element-style-test + extra-properties-test diff --git a/tests/text_visualized.toit b/tests/text_visualized.toit index d387fec..fb995fe 100644 --- a/tests/text_visualized.toit +++ b/tests/text_visualized.toit @@ -8,44 +8,44 @@ import bitmap show * import expect show * import font show * -import pixel_display show * -import pixel_display.element show * -import pixel_display.style show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.style show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 - driver := SeveralColorPngVisualizer 192 96 args[0] --outline=SEVERAL_WHITE - display := PixelDisplay.several_color driver - display.background = SEVERAL_DARK_GRAY + driver := SeveralColorPngVisualizer 192 96 args[0] --outline=SEVERAL-WHITE + display := PixelDisplay.several-color driver + display.background = SEVERAL-DARK-GRAY sans10 := Font.get "sans10" - element_text := Label --x=30 --y=20 --color=SEVERAL_ORANGE --label="Testing 123" --font=sans10 - element_text_2 := Label --x=180 --y=50 --color=SEVERAL_ORANGE --label="123 Testing" --font=sans10 --alignment=ALIGN_RIGHT - element_text_3 := Label --x=96 --y=80 --color=SEVERAL_ORANGE --label="T 123 For the win" --font=sans10 --alignment=ALIGN_CENTER - display.add element_text - display.add element_text_2 - display.add element_text_3 + element-text := Label --x=30 --y=20 --color=SEVERAL-ORANGE --label="Testing 123" --font=sans10 + element-text-2 := Label --x=180 --y=50 --color=SEVERAL-ORANGE --label="123 Testing" --font=sans10 --alignment=ALIGN-RIGHT + element-text-3 := Label --x=96 --y=80 --color=SEVERAL-ORANGE --label="T 123 For the win" --font=sans10 --alignment=ALIGN-CENTER + display.add element-text + display.add element-text-2 + display.add element-text-3 display.draw - element_text.label = "Testing 42" - element_text_2.label = "42 Testing" + element-text.label = "Testing 42" + element-text-2.label = "42 Testing" // The "MM" has the same pixel width as the "123" above, so we can test the // case where the ends are unchanged, but the middle changes. - element_text_3.label = "T MM For the win" + element-text-3.label = "T MM For the win" display.draw - element_text.label = "Test the West" - element_text_2.label = "Test the Folketing" - element_text_3.label = "Test * For the win" + element-text.label = "Test the West" + element-text-2.label = "Test the Folketing" + element-text-3.label = "Test * For the win" display.draw - element_text.label = "Test the West" - element_text_2.label = "Test the Folketlng" - element_text_3.label = "Test * For the win" // Both ends move because its centered. + element-text.label = "Test the West" + element-text-2.label = "Test the Folketlng" + element-text-3.label = "Test * For the win" // Both ends move because its centered. display.draw - driver.write_png + driver.write-png diff --git a/tests/texture_test_slow.toit b/tests/texture_test_slow.toit index cbd0c77..3ccbea9 100644 --- a/tests/texture_test_slow.toit +++ b/tests/texture_test_slow.toit @@ -8,128 +8,128 @@ import bitmap show * import crypto.sha1 as crypto import font show * -import pixel_display.common show Transform -import pixel_display.four_gray -import pixel_display.two_bit_texture as two_bit -import pixel_display.three_color -import pixel_display.true_color -import pixel_display.two_color - -THREE_COLOR ::= 0 -TWO_COLOR ::= 1 -FOUR_GRAY ::= 2 -TRUE_COLOR ::= 3 +import pixel-display.common show Transform +import pixel-display.four-gray +import pixel-display.two-bit-texture as two-bit +import pixel-display.three-color +import pixel-display.true-color +import pixel-display.two-color + +THREE-COLOR ::= 0 +TWO-COLOR ::= 1 +FOUR-GRAY ::= 2 +TRUE-COLOR ::= 3 VERSIONS := 4 -skip_version version/int -> bool: - if bitmap_primitives_present and version < TRUE_COLOR: +skip-version version/int -> bool: + if bitmap-primitives-present and version < TRUE-COLOR: return false - if bytemap_primitives_present and version == TRUE_COLOR: + if bytemap-primitives-present and version == TRUE-COLOR: return false return true main: - feature_detect - test_simple_three_color - test_simple_four_gray - test_simple_two_color - test_simple_true_color + feature-detect + test-simple-three-color + test-simple-four-gray + test-simple-two-color + test-simple-true-color -bitmap_primitives_present := true -bytemap_primitives_present := true +bitmap-primitives-present := true +bytemap-primitives-present := true -feature_detect: +feature-detect: e := catch: ba := ByteArray 25 - bytemap_blur ba 5 2 + bytemap-blur ba 5 2 if e == "UNIMPLEMENTED": - bytemap_primitives_present = false + bytemap-primitives-present = false e = catch: ba := ByteArray 16 - bitmap_rectangle 0 0 0 1 1 ba 16 + bitmap-rectangle 0 0 0 1 1 ba 16 if e == "UNIMPLEMENTED": - bitmap_primitives_present = false + bitmap-primitives-present = false identity ::= Transform.identity -orientation_to_transform x y orientation [block]: +orientation-to-transform x y orientation [block]: transform := null - if orientation == ORIENTATION_0: + if orientation == ORIENTATION-0: transform = identity else: transform = Transform.identity.translate x y x = 0 y = 0 - if orientation == ORIENTATION_90: - transform = transform.rotate_right - else if orientation == ORIENTATION_180: - transform = transform.rotate_right.rotate_right - else if orientation == ORIENTATION_270: - transform = transform.rotate_left + if orientation == ORIENTATION-90: + transform = transform.rotate-right + else if orientation == ORIENTATION-180: + transform = transform.rotate-right.rotate-right + else if orientation == ORIENTATION-270: + transform = transform.rotate-left block.call x y transform -canvas_factory version w h x y: +canvas-factory version w h x y: result := ? - if version == THREE_COLOR: - result = three_color.Canvas_ w h - else if version == TWO_COLOR: - result = two_color.Canvas_ w h - else if version == FOUR_GRAY: - result = four_gray.Canvas_ w h + if version == THREE-COLOR: + result = three-color.Canvas_ w h + else if version == TWO-COLOR: + result = two-color.Canvas_ w h + else if version == FOUR-GRAY: + result = four-gray.Canvas_ w h else: - result = true_color.Canvas_ w h - result.x_offset_ = x - result.y_offset_ = y + result = true-color.Canvas_ w h + result.x-offset_ = x + result.y-offset_ = y return result -test_simple_three_color: - red_bg := three_color.RED +test-simple-three-color: + red-bg := three-color.RED // A little 8x8 canvas to draw on. - canvas := three_color.Canvas_ 8 8 + canvas := three-color.Canvas_ 8 8 // Fill the canvas with red. - canvas.set_all_pixels red_bg + canvas.set-all-pixels red-bg 8.repeat: | x | 8.repeat: | y | - expect (canvas.get_pixel_ x y) == three_color.RED + expect (canvas.get-pixel_ x y) == three-color.RED -test_simple_four_gray: +test-simple-four-gray: // A little 8x8 canvas to draw on. - canvas := four_gray.Canvas_ 8 8 + canvas := four-gray.Canvas_ 8 8 // Fill the canvas with light gray. - canvas.set_all_pixels four_gray.LIGHT_GRAY + canvas.set-all-pixels four-gray.LIGHT-GRAY 8.repeat: | x | 8.repeat: | y | - expect (canvas.get_pixel_ x y) == four_gray.LIGHT_GRAY + expect (canvas.get-pixel_ x y) == four-gray.LIGHT-GRAY -test_simple_two_color: +test-simple-two-color: // A little 8x8 canvas to draw on. - canvas := two_color.Canvas_ 8 8 + canvas := two-color.Canvas_ 8 8 8.repeat: | x | 8.repeat: | y | - expect (canvas.get_pixel_ x y) == two_color.WHITE + expect (canvas.get-pixel_ x y) == two-color.WHITE // Fill the canvas with black. - canvas.set_all_pixels two_color.BLACK + canvas.set-all-pixels two-color.BLACK 8.repeat: | x | 8.repeat: | y | - expect (canvas.get_pixel_ x y) == two_color.BLACK + expect (canvas.get-pixel_ x y) == two-color.BLACK -test_simple_true_color: - bluish := true_color.get_rgb 0x12 0x34 0x56 +test-simple-true-color: + bluish := true-color.get-rgb 0x12 0x34 0x56 // A little 8x8 canvas to draw on. - canvas := true_color.Canvas_ 8 8 + canvas := true-color.Canvas_ 8 8 - black := true_color.get_rgb 0 0 0 + black := true-color.get-rgb 0 0 0 8.repeat: | x | 8.repeat: | y | - expect (canvas.get_pixel_ x y) == black + expect (canvas.get-pixel_ x y) == black // Fill the canvas with red. - canvas.set_all_pixels bluish + canvas.set-all-pixels bluish 8.repeat: | x | 8.repeat: | y | - expect (canvas.get_pixel_ x y) == bluish + expect (canvas.get-pixel_ x y) == bluish diff --git a/tests/three_color_bitmap_2_visualized.toit b/tests/three_color_bitmap_2_visualized.toit index eb31dc6..ab6d418 100644 --- a/tests/three_color_bitmap_2_visualized.toit +++ b/tests/three_color_bitmap_2_visualized.toit @@ -9,11 +9,11 @@ import expect show * import font import host.file -import pixel_display show * -import pixel_display.element show * -import pixel_display.png show Png -import pixel_display.three_color show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.png show Png +import pixel-display.three-color show * +import .png-visualizer SANS := font.Font.get "sans10" @@ -25,28 +25,28 @@ main args: basename := args[0] driver := ThreeColorPngVisualizer 440 240 basename --outline=BLACK - display := PixelDisplay.three_color driver + display := PixelDisplay.three-color driver display.background = WHITE - heater-red := file.read_content "tests/third_party/pictogrammers/heater-red.png" - heater-red-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-red-uncompressed.png" - heater-2-bit := file.read_content "tests/third_party/pictogrammers/heater-2-bit.png" - heater-2-bit-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" - heater-bw := file.read_content "tests/third_party/pictogrammers/heater-bw.png" - heater-bw-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" - heater-white-bg := file.read_content "tests/third_party/pictogrammers/heater-white-bg.png" - heater-white-bg-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" - - display.add (Png --x=100 --y=32 --png_file=heater-red) - display.add (Png --x=184 --y=32 --png_file=heater-2-bit) - display.add (Png --x=268 --y=32 --png_file=heater-bw) - display.add (Png --x=352 --y=32 --png_file=heater-white-bg) - - display.add (Png --x=100 --y=120 --png_file=heater-red-uncompressed) - display.add (Png --x=184 --y=120 --png_file=heater-2-bit-uncompressed) - display.add (Png --x=268 --y=120 --png_file=heater-bw-uncompressed) - display.add (Png --x=352 --y=120 --png_file=heater-white-bg-uncompressed) + heater-red := file.read-content "tests/third_party/pictogrammers/heater-red.png" + heater-red-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-red-uncompressed.png" + heater-2-bit := file.read-content "tests/third_party/pictogrammers/heater-2-bit.png" + heater-2-bit-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" + heater-bw := file.read-content "tests/third_party/pictogrammers/heater-bw.png" + heater-bw-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" + heater-white-bg := file.read-content "tests/third_party/pictogrammers/heater-white-bg.png" + heater-white-bg-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" + + display.add (Png --x=100 --y=32 --png-file=heater-red) + display.add (Png --x=184 --y=32 --png-file=heater-2-bit) + display.add (Png --x=268 --y=32 --png-file=heater-bw) + display.add (Png --x=352 --y=32 --png-file=heater-white-bg) + + display.add (Png --x=100 --y=120 --png-file=heater-red-uncompressed) + display.add (Png --x=184 --y=120 --png-file=heater-2-bit-uncompressed) + display.add (Png --x=268 --y=120 --png-file=heater-bw-uncompressed) + display.add (Png --x=352 --y=120 --png-file=heater-white-bg-uncompressed) display.draw - driver.write_png + driver.write-png diff --git a/tests/transform_test.toit b/tests/transform_test.toit index c85ff30..82236ad 100644 --- a/tests/transform_test.toit +++ b/tests/transform_test.toit @@ -4,77 +4,77 @@ import expect show * -import pixel_display.common show * +import pixel-display.common show * main: - simple_texture_test + simple-texture-test -simple_texture_test: +simple-texture-test: id := Transform.identity - expect_equals 42 (id.x 42 103) - expect_equals 103 (id.y 42 103) - expect_equals 42 (id.width 42 103) - expect_equals 103 (id.height 42 103) + expect-equals 42 (id.x 42 103) + expect-equals 103 (id.y 42 103) + expect-equals 42 (id.width 42 103) + expect-equals 103 (id.height 42 103) - r90 := id.rotate_left - expect_equals 103 (r90.x 42 103) - expect_equals -42 (r90.y 42 103) - expect_equals 103 (r90.width 42 103) - expect_equals -42 (r90.height 42 103) - expect_equals id + r90 := id.rotate-left + expect-equals 103 (r90.x 42 103) + expect-equals -42 (r90.y 42 103) + expect-equals 103 (r90.width 42 103) + expect-equals -42 (r90.height 42 103) + expect-equals id r90.invert.apply r90 - expect_equals id + expect-equals id r90.apply r90.invert - r180 := r90.rotate_left - expect_equals -42 (r180.x 42 103) - expect_equals -103 (r180.y 42 103) - expect_equals -42 (r180.width 42 103) - expect_equals -103 (r180.height 42 103) - expect_equals id + r180 := r90.rotate-left + expect-equals -42 (r180.x 42 103) + expect-equals -103 (r180.y 42 103) + expect-equals -42 (r180.width 42 103) + expect-equals -103 (r180.height 42 103) + expect-equals id r180.invert.apply r180 - expect_equals id + expect-equals id r180.apply r180.invert - r270 := r180.rotate_left - expect_equals -103 (r270.x 42 103) - expect_equals 42 (r270.y 42 103) - expect_equals -103 (r270.width 42 103) - expect_equals 42 (r270.height 42 103) - expect_equals id + r270 := r180.rotate-left + expect-equals -103 (r270.x 42 103) + expect-equals 42 (r270.y 42 103) + expect-equals -103 (r270.width 42 103) + expect-equals 42 (r270.height 42 103) + expect-equals id r270.invert.apply r270 - expect_equals id + expect-equals id r270.apply r270.invert - r270b := id.rotate_right - expect_equals -103 (r270b.x 42 103) - expect_equals 42 (r270b.y 42 103) - expect_equals -103 (r270b.width 42 103) - expect_equals 42 (r270b.height 42 103) + r270b := id.rotate-right + expect-equals -103 (r270b.x 42 103) + expect-equals 42 (r270b.y 42 103) + expect-equals -103 (r270b.width 42 103) + expect-equals 42 (r270b.height 42 103) idb := r90.apply r270 - expect_equals 42 (idb.x 42 103) - expect_equals 103 (idb.y 42 103) - expect_equals 42 (idb.width 42 103) - expect_equals 103 (idb.height 42 103) + expect-equals 42 (idb.x 42 103) + expect-equals 103 (idb.y 42 103) + expect-equals 42 (idb.width 42 103) + expect-equals 103 (idb.height 42 103) idc := r180.apply r180 - expect_equals 42 (idc.x 42 103) - expect_equals 103 (idc.y 42 103) - expect_equals 42 (idc.width 42 103) - expect_equals 103 (idc.height 42 103) + expect-equals 42 (idc.x 42 103) + expect-equals 103 (idc.y 42 103) + expect-equals 42 (idc.width 42 103) + expect-equals 103 (idc.height 42 103) x10 := id.translate 10 0 - x10l := x10.rotate_left - expect_equals 113 (x10l.x 42 103) - expect_equals -42 (x10l.y 42 103) - expect_equals 103 (x10l.width 42 103) - expect_equals -42 (x10l.height 42 103) - expect_equals id + x10l := x10.rotate-left + expect-equals 113 (x10l.x 42 103) + expect-equals -42 (x10l.y 42 103) + expect-equals 103 (x10l.width 42 103) + expect-equals -42 (x10l.height 42 103) + expect-equals id x10.invert.apply x10 - expect_equals id + expect-equals id x10.apply x10.invert - expect_equals id + expect-equals id x10l.invert.apply x10l - expect_equals id + expect-equals id x10l.apply x10l.invert diff --git a/tests/true_color.toit b/tests/true_color.toit index 52c566b..abd9dab 100644 --- a/tests/true_color.toit +++ b/tests/true_color.toit @@ -4,16 +4,16 @@ import expect show * import font show Font -import pixel_display show * -import pixel_display.true_color show * +import pixel-display show * +import pixel-display.true-color show * class TestDriver extends AbstractDriver: buffer := ByteArray 3 * 64 * 128 width ::= 128 height ::= 64 - flags ::= FLAG_TRUE_COLOR | FLAG_PARTIAL_UPDATES - draw_true_color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: + flags ::= FLAG-TRUE-COLOR | FLAG-PARTIAL-UPDATES + draw-true-color left/int top/int right/int bottom/int r/ByteArray g/ByteArray b/ByteArray -> none: w := right - left (bottom - top).repeat: | iy | w.repeat: | ix | @@ -21,25 +21,25 @@ class TestDriver extends AbstractDriver: buffer[1 + 3 * (left + ix + (top + iy) * width)] = g[ix + iy * w] buffer[2 + 3 * (left + ix + (top + iy) * width)] = b[ix + iy * w] - red_at x y: + red-at x y: return buffer[0 + 3 * (x + y * width)] - green_at x y: + green-at x y: return buffer[1 + 3 * (x + y * width)] - blue_at x y: + blue-at x y: return buffer[2 + 3 * (x + y * width)] main: driver := TestDriver - display := PixelDisplay.true_color driver - display.background = get_rgb 0 1 2 + display := PixelDisplay.true-color driver + display.background = get-rgb 0 1 2 sans10 := Font.get "sans10" - ctx := display.context --landscape --color=(get_rgb 255 120 0) --font=sans10 + ctx := display.context --landscape --color=(get-rgb 255 120 0) --font=sans10 - display.filled_rectangle ctx 10 20 30 40 + display.filled-rectangle ctx 10 20 30 40 display.text ctx 50 20 "Testing" display.text ctx 50 40 "the display" display.draw @@ -50,18 +50,18 @@ main: for y := 0; y < driver.height; y += 2: line := "" driver.width.repeat: | x | - top_half := (driver.red_at x y) < 128 - bottom_half := (driver.red_at x y + 1) < 128 - line += "$(top_half ? (bottom_half ? " " : "▄") : (bottom_half ? "▀" : "█"))" + top-half := (driver.red-at x y) < 128 + bottom-half := (driver.red-at x y + 1) < 128 + line += "$(top-half ? (bottom-half ? " " : "▄") : (bottom-half ? "▀" : "█"))" print line 50.repeat: | x | driver.height.repeat: | y | if x < 10 or y < 20 or x >= 40 or y >= 60: - expect_equals 0 (driver.red_at x y) - expect_equals 1 (driver.green_at x y) - expect_equals 2 (driver.blue_at x y) + expect-equals 0 (driver.red-at x y) + expect-equals 1 (driver.green-at x y) + expect-equals 2 (driver.blue-at x y) else: - expect_equals 255 (driver.red_at x y) - expect_equals 120 (driver.green_at x y) - expect_equals 0 (driver.blue_at x y) + expect-equals 255 (driver.red-at x y) + expect-equals 120 (driver.green-at x y) + expect-equals 0 (driver.blue-at x y) diff --git a/tests/true_color_portrait_visualized.toit b/tests/true_color_portrait_visualized.toit index c9f2829..cf65c4b 100644 --- a/tests/true_color_portrait_visualized.toit +++ b/tests/true_color_portrait_visualized.toit @@ -4,22 +4,22 @@ import expect show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.true_color show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.true-color show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 driver := TrueColorPngVisualizer 129 89 args[0] --outline=0xffff00 - display := PixelDisplay.true_color driver --portrait - display.background = get_rgb 0 1 2 + display := PixelDisplay.true-color driver --portrait + display.background = get-rgb 0 1 2 sans10 := Font.get "sans10" - foreground := get_rgb 255 120 0 + foreground := get-rgb 255 120 0 display.add Div --x=10 --y=20 --w=30 --h=40 --background=0x4040ff @@ -27,8 +27,8 @@ main args: Div --x=20 --y=70 --w=30 --h=40 --background=0x4040ff display.add Label --x=5 --y=80 --label="Testing" --font=sans10 --color=foreground - middle_line := Label --x=5 --y=100 --label="the display" --font=sans10 --color=foreground - display.add middle_line + middle-line := Label --x=5 --y=100 --label="the display" --font=sans10 --color=foreground + display.add middle-line display.draw display.add @@ -36,10 +36,10 @@ main args: display.draw - middle_line.move_to 10 100 + middle-line.move-to 10 100 display.draw - middle_line.label = "the DisplaY" + middle-line.label = "the DisplaY" display.draw - driver.write_png + driver.write-png diff --git a/tests/true_color_visualized.toit b/tests/true_color_visualized.toit index f971b9d..e9cca35 100644 --- a/tests/true_color_visualized.toit +++ b/tests/true_color_visualized.toit @@ -4,39 +4,39 @@ import expect show * import font show Font -import pixel_display show * -import pixel_display.element show * -import pixel_display.true_color show * -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.true-color show * +import .png-visualizer main args: if args.size != 1: print "Usage: script.toit png-basename" exit 1 driver := TrueColorPngVisualizer 160 64 args[0] --outline=0xffff00 - display := PixelDisplay.true_color driver - display.background = get_rgb 0 1 2 + display := PixelDisplay.true-color driver + display.background = get-rgb 0 1 2 sans10 := Font.get "sans10" - foreground := get_rgb 255 120 0 + foreground := get-rgb 255 120 0 display.add Div --x=10 --y=20 --w=30 --h=40 --background=0x4040ff display.add Label --x=50 --y=20 --label="Testing" --font=sans10 --color=foreground - middle_line := Label --x=50 --y=40 --label="the display" --font=sans10 --color=foreground - display.add middle_line + middle-line := Label --x=50 --y=40 --label="the display" --font=sans10 --color=foreground + display.add middle-line display.draw display.add Label --x=50 --y=60 --label="for the win" --font=sans10 --color=foreground display.draw - middle_line.move_to 60 40 + middle-line.move-to 60 40 display.draw - middle_line.label = "the DISPLAY" + middle-line.label = "the DISPLAY" display.draw - driver.write_png + driver.write-png diff --git a/tests/two_color_bitmap_2_visualized.toit b/tests/two_color_bitmap_2_visualized.toit index 8ec3b82..1e559d2 100644 --- a/tests/two_color_bitmap_2_visualized.toit +++ b/tests/two_color_bitmap_2_visualized.toit @@ -9,11 +9,11 @@ import expect show * import font import host.file -import pixel_display show * -import pixel_display.element show * -import pixel_display.png show Png -import pixel_display.two_color show WHITE BLACK -import .png_visualizer +import pixel-display show * +import pixel-display.element show * +import pixel-display.png show Png +import pixel-display.two-color show WHITE BLACK +import .png-visualizer SANS := font.Font.get "sans10" @@ -25,28 +25,28 @@ main args: basename := args[0] driver := TwoColorPngVisualizer 440 240 basename --outline=BLACK - display := PixelDisplay.two_color driver + display := PixelDisplay.two-color driver display.background = WHITE - heater-red := file.read_content "tests/third_party/pictogrammers/heater-red.png" - heater-red-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-red-uncompressed.png" - heater-2-bit := file.read_content "tests/third_party/pictogrammers/heater-2-bit.png" - heater-2-bit-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" - heater-bw := file.read_content "tests/third_party/pictogrammers/heater-bw.png" - heater-bw-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" - heater-white-bg := file.read_content "tests/third_party/pictogrammers/heater-white-bg.png" - heater-white-bg-uncompressed := file.read_content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" - - display.add (Png --x=100 --y=32 --png_file=heater-red) - display.add (Png --x=184 --y=32 --png_file=heater-2-bit) - display.add (Png --x=268 --y=32 --png_file=heater-bw) - display.add (Png --x=352 --y=32 --png_file=heater-white-bg) - - display.add (Png --x=100 --y=120 --png_file=heater-red-uncompressed) - display.add (Png --x=184 --y=120 --png_file=heater-2-bit-uncompressed) - display.add (Png --x=268 --y=120 --png_file=heater-bw-uncompressed) - display.add (Png --x=352 --y=120 --png_file=heater-white-bg-uncompressed) + heater-red := file.read-content "tests/third_party/pictogrammers/heater-red.png" + heater-red-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-red-uncompressed.png" + heater-2-bit := file.read-content "tests/third_party/pictogrammers/heater-2-bit.png" + heater-2-bit-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-2-bit-uncompressed.png" + heater-bw := file.read-content "tests/third_party/pictogrammers/heater-bw.png" + heater-bw-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-bw-uncompressed.png" + heater-white-bg := file.read-content "tests/third_party/pictogrammers/heater-white-bg.png" + heater-white-bg-uncompressed := file.read-content "tests/third_party/pictogrammers/heater-white-bg-uncompressed.png" + + display.add (Png --x=100 --y=32 --png-file=heater-red) + display.add (Png --x=184 --y=32 --png-file=heater-2-bit) + display.add (Png --x=268 --y=32 --png-file=heater-bw) + display.add (Png --x=352 --y=32 --png-file=heater-white-bg) + + display.add (Png --x=100 --y=120 --png-file=heater-red-uncompressed) + display.add (Png --x=184 --y=120 --png-file=heater-2-bit-uncompressed) + display.add (Png --x=268 --y=120 --png-file=heater-bw-uncompressed) + display.add (Png --x=352 --y=120 --png-file=heater-white-bg-uncompressed) display.draw - driver.write_png + driver.write-png