transform takes translate(), scale() and rotate() and their X and Y forms in any order that does not shear, kept as one translation, turn and x and y scale; scale, rotate and transform-origin are read too, and a transition that names transform (or all) sets how a change eases. They are box fields Kryon's paint transform pass applies on every host. Skew, matrix(), 3D functions, translate() percentages and shearing lists fail a plain native parse with the reason; a shared sheet leaves them to the browser. Transforms are opt-in paint code in Kryon: CssSheetInstall refuses a sheet that sets one until the app has called PaintTransformInstall(), and says so. The browser-only transform message this replaces is gone. The pack format is 116 words a rule. Pins Kryon fdd70c4b.
145 lines
4.1 KiB
Ziran
145 lines
4.1 KiB
Ziran
#import "kryon/drawing_props"
|
|
#import "kryon/geometry"
|
|
|
|
CssButtonRasterState :: struct {
|
|
fill_count: s32
|
|
outline_count: s32
|
|
text_count: s32
|
|
fill_color: Color
|
|
text_color: Color
|
|
fill_bounds: Rectangle
|
|
radius: float32
|
|
font: s32
|
|
failed: bool
|
|
// Transformed paint: triangle calls with the box of the last one's
|
|
// points, and rotated text with its last anchor, size and turn.
|
|
triangle_count: s32
|
|
triangle_bounds: Rectangle
|
|
rotated_count: s32
|
|
rotated_x: s32
|
|
rotated_y: s32
|
|
rotated_font: s32
|
|
rotation: float32
|
|
}
|
|
|
|
sample: CssButtonRasterState;
|
|
|
|
#program_export
|
|
MeasureGlyphWidth :: (value: string, font: s32, typeface: string) -> s32 {
|
|
unused typeface
|
|
if value != "Save" || font <= 0 { sample.failed = true }
|
|
return 30
|
|
}
|
|
|
|
#program_export
|
|
MeasureGlyphLineHeight :: (font: s32, typeface: string) -> s32 {
|
|
unused typeface
|
|
if font <= 0 { sample.failed = true }
|
|
return font
|
|
}
|
|
|
|
#program_export
|
|
RasterTextClipped :: (value: string, x: s32, y: s32, font: s32,
|
|
color: Color, clip: Rectangle) {
|
|
unused x; unused y; unused clip
|
|
if value != "Save" { sample.failed = true }
|
|
sample.text_count += 1; sample.text_color = color; sample.font = font
|
|
}
|
|
|
|
#program_export
|
|
RasterText :: (value: string, x: s32, y: s32, font: s32,
|
|
color: Color) {
|
|
unused value; unused x; unused y; unused font; unused color
|
|
sample.failed = true
|
|
}
|
|
|
|
#program_export
|
|
RasterTextRotated :: (value: string, x: s32, y: s32, font: s32, color: Color,
|
|
clip: Rectangle, origin: Vector2, rotation: float32, outer_clip: Rectangle,
|
|
outer_clipped: bool, emphasis: bool, italic: bool) {
|
|
unused value; unused color; unused clip
|
|
unused origin; unused outer_clip; unused outer_clipped
|
|
unused emphasis; unused italic
|
|
sample.rotated_count += 1
|
|
sample.rotated_x = x
|
|
sample.rotated_y = y
|
|
sample.rotated_font = font
|
|
sample.rotation = rotation
|
|
}
|
|
|
|
#program_export
|
|
RasterRoundedRectangle :: (bounds: Rectangle, radius: float32,
|
|
segments: s32, color: Color) {
|
|
unused segments
|
|
sample.fill_count += 1; sample.fill_bounds = bounds
|
|
sample.radius = radius; sample.fill_color = color
|
|
}
|
|
|
|
#program_export
|
|
RasterRoundedRectangleOutline :: (bounds: Rectangle, radius: float32,
|
|
segments: s32, width: float32, color: Color) {
|
|
unused bounds; unused radius; unused segments; unused width
|
|
sample.outline_count += 1; sample.text_color = color
|
|
}
|
|
|
|
#program_export
|
|
ImageWidth :: (asset_path: string) -> s32 {
|
|
unused asset_path
|
|
return 0
|
|
}
|
|
|
|
#program_export
|
|
ImageHeight :: (asset_path: string) -> s32 {
|
|
unused asset_path
|
|
return 0
|
|
}
|
|
|
|
#program_export
|
|
RasterTriangles :: (points: []Vector2, color: Color) {
|
|
unused color
|
|
if points.count == 0 { return }
|
|
left := points[0].x
|
|
right := points[0].x
|
|
top := points[0].y
|
|
bottom := points[0].y
|
|
for point: points {
|
|
if point.x < left { left = point.x }
|
|
if point.x > right { right = point.x }
|
|
if point.y < top { top = point.y }
|
|
if point.y > bottom { bottom = point.y }
|
|
}
|
|
sample.triangle_count += 1
|
|
sample.triangle_bounds = .{left, top, right - left, bottom - top}
|
|
}
|
|
|
|
#program_export
|
|
RasterLine :: (line: Rectangle, color: Color) {
|
|
unused line; unused color
|
|
}
|
|
|
|
#program_export
|
|
RasterImage :: (asset_path: string, texture_id: u32,
|
|
source: Rectangle, destination: Rectangle, clip: Rectangle,
|
|
origin: Vector2, rotation: float32, radius: float32, tint: Color) {
|
|
unused asset_path; unused texture_id; unused source; unused destination
|
|
unused clip; unused origin; unused rotation; unused radius; unused tint
|
|
}
|
|
|
|
#program_export
|
|
RasterImageMesh :: (asset_path: string, texture_id: u32,
|
|
source: Rectangle, points: []Vector2, columns: s32, rows: s32,
|
|
clip: Rectangle, tint: Color) {
|
|
unused asset_path; unused texture_id; unused source; unused points
|
|
unused columns; unused rows; unused clip; unused tint
|
|
sample.failed = true
|
|
}
|
|
|
|
#program_export
|
|
CssButtonRasterReset :: () -> CssButtonRasterState {
|
|
sample = CssButtonRasterState.{}
|
|
return sample
|
|
}
|
|
|
|
#program_export
|
|
CssButtonRasterSample :: () -> CssButtonRasterState { return sample }
|