Skip to content

Commit

Permalink
Move ALL_* constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Corry committed Dec 7, 2023
1 parent f5d5bb6 commit f6f016f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
12 changes: 8 additions & 4 deletions src/common.toit
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import font show Font
import bitmap show ORIENTATION_0 ORIENTATION_90 ORIENTATION_180 ORIENTATION_270

import .element as element
import .element show Element
import .style

Expand Down Expand Up @@ -126,13 +125,18 @@ abstract class Canvas:
if x2 <= 0 and y2 <= 0 and right >= width_ and bottom >= height_: return CANVAS_IN_AREA
return OVERLAP

/// For use with $composit.
static ALL_TRANSPARENT ::= #[0]
/// For use with $composit.
static ALL_OPAQUE ::= #[0xff]

/**
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 $Element.ALL_OPAQUE or
$Element.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

Expand Down Expand Up @@ -206,7 +210,7 @@ abstract class Canvas:
/**
Draws the given 8-bit pixmap on the canvas.
The source pixmap has one byte per pixel, which is an index into the
$palette and $argument arguments. The order of the pixmap is as in
$palette and $alpha arguments. The order of the pixmap is as in
PNG, so the lines are ordered from top to bottom, and within each
line the bytes are ordered from left to right.
The $alpha argument controls which pixel indexes are transparent. A
Expand Down
5 changes: 1 addition & 4 deletions src/element.toit
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,6 @@ class ClippingDiv extends Div:
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 ALL_TRANSPARENT ::= #[0]
static ALL_OPAQUE ::= #[0xff]

static is_all_transparent opacity -> bool:
if opacity is not ByteArray: return false
return opacity.size == 1 and opacity[0] == 0
Expand Down Expand Up @@ -526,7 +523,7 @@ class ClippingDiv extends Div:
the top and left edges may be plotted at negative coordinates.
*/
frame_map canvas/Canvas:
if not border_: return ClippingDiv.ALL_TRANSPARENT // No border visible.
if not border_: return Canvas.ALL_TRANSPARENT // No border visible.
return border_.frame_map canvas w h

/**
Expand Down
4 changes: 2 additions & 2 deletions src/slider.toit
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class Slider extends CustomElement:
blend = true
if not blend: return

lo_alpha := background_lo_ ? canvas.make_alpha_map : ClippingDiv.ALL_TRANSPARENT
hi_alpha := background_hi_ ? canvas.make_alpha_map : ClippingDiv.ALL_TRANSPARENT
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

Expand Down
20 changes: 10 additions & 10 deletions src/style.toit
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ abstract class InvisibleBorder implements Border:
block.call 0 0

frame_map canvas w h:
return element.ClippingDiv.ALL_TRANSPARENT
return Canvas.ALL_TRANSPARENT

abstract content_map canvas/Canvas w/int h/int

Expand Down Expand Up @@ -156,7 +156,7 @@ class SolidBorder implements Border:
// 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 element.ClippingDiv.ALL_TRANSPARENT // The frame is not visible anywhere.
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
Expand All @@ -165,13 +165,13 @@ class SolidBorder implements Border:
// 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 element.ClippingDiv.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 element.ClippingDiv.ALL_TRANSPARENT
return Canvas.ALL_TRANSPARENT
// We need to create a bitmap to describe the frame's extent.
transparency_map := canvas.make_alpha_map
// Declare the whole area inside the frame's extent opaque. The window content will
Expand All @@ -188,11 +188,11 @@ class SolidBorder implements Border:
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 element.ClippingDiv.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 element.ClippingDiv.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
// Declare the whole area inside the content's extent opaque. The window content will
Expand Down Expand Up @@ -250,10 +250,10 @@ class RoundedCornerBorder extends InvisibleBorder:
right := x2 + w2
bottom := y2 + h2
if x2 >= canvas.width_ or y2 >= canvas.height_ or right <= 0 or bottom <= 0:
return element.ClippingDiv.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 element.ClippingDiv.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
Expand Down Expand Up @@ -364,14 +364,14 @@ 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 element.ClippingDiv.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 |
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 element.ClippingDiv.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.
Expand Down

0 comments on commit f6f016f

Please sign in to comment.