Files
plot/tests/plot_widget_host.zi
T

174 lines
4.8 KiB
Ziran

#import "kryon/drawing_props"
#import "kryon/geometry"
backgrounds: s32;
marks: s32;
outlines: s32;
lines: s32;
labels: s32;
failed: bool;
expected_surface: u32;
expected_border: u32;
expected_text: u32;
expected_mark: u32;
#program_export
ExpectPlotColors :: (surface: u32, border: u32, text: u32, mark: u32) {
expected_surface = surface
expected_border = border
expected_text = text
expected_mark = mark
}
ColorMatches :: (color: Color, packed: u32) -> bool {
expected := ColorFromPacked(packed)
return color.r == expected.r && color.g == expected.g &&
color.b == expected.b && color.a == expected.a
}
#program_export
MeasureGlyphWidth :: (value: string, font: s32, typeface: string) -> s32 {
if font != 14 || typeface.count != 0 { failed = true }
return cast(s32)value.count * 8
}
#program_export
RasterRoundedRectangle :: (bounds: Rectangle, radius: float32,
segments: s32, color: Color) {
unused segments
if bounds.x < 10.0 || bounds.y < 10.0 ||
bounds.x + bounds.width > 110.0 ||
bounds.y + bounds.height > 150.0 { failed = true }
if radius == 0.0 {
if !ColorMatches(color, expected_mark) {
failed = true
}
which: s32 = marks % 3
if which == 0 && (bounds.x <= 10.9 || bounds.x >= 11.1 ||
bounds.y != 120.0 || bounds.height != 30.0) { failed = true }
if which == 1 && (bounds.x <= 44.2 || bounds.x >= 44.5 ||
bounds.y != 90.0 || bounds.height != 60.0) { failed = true }
if which == 2 && (bounds.x <= 77.5 || bounds.x >= 77.8 ||
bounds.y != 135.0 || bounds.height != 15.0) { failed = true }
marks += 1
} else {
if radius != 4.0 || !ColorMatches(color, expected_surface) { failed = true }
backgrounds += 1
}
}
#program_export
RasterRoundedRectangleOutline :: (bounds: Rectangle, radius: float32,
segments: s32, width: float32, color: Color) {
unused segments
if bounds.x != 10.0 || bounds.width != 100.0 ||
bounds.height != 60.0 ||
(bounds.y != 10.0 && bounds.y != 90.0) ||
radius != 4.0 || width != 1.0 ||
!ColorMatches(color, expected_border) { failed = true }
outlines += 1
}
#program_export
RasterLine :: (line: Rectangle, color: Color) {
if line.x < 10.0 || line.x + line.width > 110.0 ||
line.y < 10.0 || line.y > 70.0 ||
line.y + line.height < 10.0 || line.y + line.height > 70.0 ||
!ColorMatches(color, expected_mark) { failed = true }
lines += 1
}
#program_export
RasterText :: (value: string, x: s32, y: s32, font: s32,
color: Color) {
unused value
unused x
unused y
unused font
unused color
failed = true
}
#program_export
RasterTextClipped :: (value: string, x: s32, y: s32, font: s32,
color: Color, clip: Rectangle) {
if value.count == 0 || x < 10 || x > 110 || y < 10 || y > 150 ||
font != 14 || clip.x != 10.0 || clip.width != 100.0 ||
(clip.y != 10.0 && clip.y != 90.0) || clip.height != 60.0 ||
!ColorMatches(color, expected_text) { failed = true }
labels += 1
}
#program_export
RasterImage :: (path: string, texture_id: u32,
source: Rectangle, destination: Rectangle, clip: Rectangle,
origin: Vector2, rotation: float32, radius: float32, tint: Color) {
unused path
unused texture_id
unused source
unused destination
unused clip
unused origin
unused rotation
unused radius
unused tint
failed = true
}
#program_export
PlotHostFailed :: () -> bool { return failed }
#program_export
PlotBackgrounds :: () -> s32 { return backgrounds }
#program_export
PlotMarks :: () -> s32 { return marks }
#program_export
PlotOutlines :: () -> s32 { return outlines }
#program_export
PlotLineCount :: () -> s32 { return lines }
#program_export
PlotLabels :: () -> s32 { return labels }
// Required raster capabilities; these charts never queue these operations.
#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 x
unused y
unused font
unused color
unused clip
unused origin
unused rotation
unused outer_clip
unused outer_clipped
unused emphasis
unused italic
failed = true
}
#program_export
RasterImageMesh :: (path: string, texture_id: u32, source: Rectangle, points: []Vector2, columns: s32, rows: s32, clip: Rectangle, tint: Color) {
unused path
unused texture_id
unused source
unused points
unused columns
unused rows
unused clip
unused tint
failed = true
}
#program_export
MeasureGlyphLineHeight :: (font: s32, typeface: string) -> s32 {
unused typeface
return font
}