mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
test
This commit is contained in:
Vendored
+53
-57
@@ -816,22 +816,20 @@ __getVerticalAlign :: proc(
|
|||||||
pixelSize: i16,
|
pixelSize: i16,
|
||||||
) -> (res: f32) {
|
) -> (res: f32) {
|
||||||
switch ctx.location {
|
switch ctx.location {
|
||||||
case .TOPLEFT: {
|
case .TOPLEFT:
|
||||||
switch av {
|
switch av {
|
||||||
case .TOP: res = font.ascender * f32(pixelSize) / 10
|
case .TOP: res = font.ascender * f32(pixelSize) / 10
|
||||||
case .MIDDLE: res = (font.ascender + font.descender) / 2 * f32(pixelSize) / 10
|
case .MIDDLE: res = (font.ascender + font.descender) / 2 * f32(pixelSize) / 10
|
||||||
case .BASELINE: res = 0
|
case .BASELINE: res = 0
|
||||||
case .BOTTOM: res = font.descender * f32(pixelSize) / 10
|
case .BOTTOM: res = font.descender * f32(pixelSize) / 10
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case .BOTTOMLEFT: {
|
case .BOTTOMLEFT:
|
||||||
switch av {
|
switch av {
|
||||||
case .TOP: res = -font.ascender * f32(pixelSize) / 10
|
case .TOP: res = -font.ascender * f32(pixelSize) / 10
|
||||||
case .MIDDLE: res = -(font.ascender + font.descender) / 2 * f32(pixelSize) / 10
|
case .MIDDLE: res = -(font.ascender + font.descender) / 2 * f32(pixelSize) / 10
|
||||||
case .BASELINE: res = 0
|
case .BASELINE: res = 0
|
||||||
case .BOTTOM: res = -font.descender * f32(pixelSize) / 10
|
case .BOTTOM: res = -font.descender * f32(pixelSize) / 10
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1005,35 +1003,33 @@ __getQuad :: proc(
|
|||||||
y1 = f32(glyph.y1 - 1)
|
y1 = f32(glyph.y1 - 1)
|
||||||
|
|
||||||
switch ctx.location {
|
switch ctx.location {
|
||||||
case .TOPLEFT: {
|
case .TOPLEFT:
|
||||||
rx = math.floor(x^ + xoff)
|
rx = math.floor(x^ + xoff)
|
||||||
ry = math.floor(y^ + yoff)
|
ry = math.floor(y^ + yoff)
|
||||||
|
|
||||||
quad.x0 = rx
|
quad.x0 = rx
|
||||||
quad.y0 = ry
|
quad.y0 = ry
|
||||||
quad.x1 = rx + x1 - x0
|
quad.x1 = rx + x1 - x0
|
||||||
quad.y1 = ry + y1 - y0
|
quad.y1 = ry + y1 - y0
|
||||||
|
|
||||||
quad.s0 = x0 * ctx.itw
|
quad.s0 = x0 * ctx.itw
|
||||||
quad.t0 = y0 * ctx.ith
|
quad.t0 = y0 * ctx.ith
|
||||||
quad.s1 = x1 * ctx.itw
|
quad.s1 = x1 * ctx.itw
|
||||||
quad.t1 = y1 * ctx.ith
|
quad.t1 = y1 * ctx.ith
|
||||||
}
|
|
||||||
|
|
||||||
case .BOTTOMLEFT: {
|
case .BOTTOMLEFT:
|
||||||
rx = math.floor(x^ + xoff)
|
rx = math.floor(x^ + xoff)
|
||||||
ry = math.floor(y^ - yoff)
|
ry = math.floor(y^ - yoff)
|
||||||
|
|
||||||
quad.x0 = rx
|
quad.x0 = rx
|
||||||
quad.y0 = ry
|
quad.y0 = ry
|
||||||
quad.x1 = rx + x1 - x0
|
quad.x1 = rx + x1 - x0
|
||||||
quad.y1 = ry - y1 + y0
|
quad.y1 = ry - y1 + y0
|
||||||
|
|
||||||
quad.s0 = x0 * ctx.itw
|
quad.s0 = x0 * ctx.itw
|
||||||
quad.t0 = y0 * ctx.ith
|
quad.t0 = y0 * ctx.ith
|
||||||
quad.s1 = x1 * ctx.itw
|
quad.s1 = x1 * ctx.itw
|
||||||
quad.t1 = y1 * ctx.ith
|
quad.t1 = y1 * ctx.ith
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x^ += f32(int(f32(glyph.xadvance) / 10 + 0.5))
|
x^ += f32(int(f32(glyph.xadvance) / 10 + 0.5))
|
||||||
@@ -1056,15 +1052,15 @@ TextIterInit :: proc(
|
|||||||
x := x
|
x := x
|
||||||
y := y
|
y := y
|
||||||
switch state.ah {
|
switch state.ah {
|
||||||
case .LEFT: {}
|
case .LEFT: {}
|
||||||
case .CENTER: {
|
|
||||||
width := TextBounds(ctx, text, x, y, nil)
|
case .CENTER:
|
||||||
x = math.round(x - width * 0.5)
|
width := TextBounds(ctx, text, x, y, nil)
|
||||||
}
|
x = math.round(x - width * 0.5)
|
||||||
case .RIGHT: {
|
|
||||||
width := TextBounds(ctx, text, x, y, nil)
|
case .RIGHT:
|
||||||
x -= width
|
width := TextBounds(ctx, text, x, y, nil)
|
||||||
}
|
x -= width
|
||||||
}
|
}
|
||||||
|
|
||||||
// align vertically
|
// align vertically
|
||||||
@@ -1184,15 +1180,15 @@ TextBounds :: proc(
|
|||||||
// horizontal alignment
|
// horizontal alignment
|
||||||
advance := x - start_x
|
advance := x - start_x
|
||||||
switch state.ah {
|
switch state.ah {
|
||||||
case .LEFT: {}
|
case .LEFT: {}
|
||||||
case .CENTER: {
|
|
||||||
minx -= advance * 0.5
|
case .CENTER:
|
||||||
maxx -= advance * 0.5
|
minx -= advance * 0.5
|
||||||
}
|
maxx -= advance * 0.5
|
||||||
case .RIGHT: {
|
|
||||||
minx -= advance
|
case .RIGHT:
|
||||||
maxx -= advance
|
minx -= advance
|
||||||
}
|
maxx -= advance
|
||||||
}
|
}
|
||||||
|
|
||||||
if bounds != nil {
|
if bounds != nil {
|
||||||
|
|||||||
Vendored
+5
-5
@@ -1020,11 +1020,11 @@ __renderFlush :: proc(uptr: rawptr) {
|
|||||||
__blendFuncSeparate(ctx, &call.blendFunc)
|
__blendFuncSeparate(ctx, &call.blendFunc)
|
||||||
|
|
||||||
switch call.type {
|
switch call.type {
|
||||||
case .NONE: {}
|
case .NONE: {}
|
||||||
case .FILL: __fill(ctx, call)
|
case .FILL: __fill(ctx, call)
|
||||||
case .CONVEX_FILL: __convexFill(ctx, call)
|
case .CONVEX_FILL: __convexFill(ctx, call)
|
||||||
case .STROKE: __stroke(ctx, call)
|
case .STROKE: __stroke(ctx, call)
|
||||||
case .TRIANGLES: __triangles(ctx, call)
|
case .TRIANGLES: __triangles(ctx, call)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Vendored
+75
-96
@@ -1302,30 +1302,21 @@ __appendCommands :: proc(ctx: ^Context, values: []f32) {
|
|||||||
cmd := Commands(values[i])
|
cmd := Commands(values[i])
|
||||||
|
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case .MOVE_TO, .LINE_TO: {
|
case .MOVE_TO, .LINE_TO:
|
||||||
TransformPoint(&values[i + 1], &values[i + 2], state.xform, values[i + 1], values[i + 2])
|
TransformPoint(&values[i + 1], &values[i + 2], state.xform, values[i + 1], values[i + 2])
|
||||||
i += 3
|
i += 3
|
||||||
}
|
|
||||||
|
|
||||||
case .BEZIER_TO: {
|
case .BEZIER_TO:
|
||||||
TransformPoint(&values[i + 1], &values[i + 2], state.xform, values[i + 1], values[i + 2])
|
TransformPoint(&values[i + 1], &values[i + 2], state.xform, values[i + 1], values[i + 2])
|
||||||
TransformPoint(&values[i + 3], &values[i + 4], state.xform, values[i + 3], values[i + 4])
|
TransformPoint(&values[i + 3], &values[i + 4], state.xform, values[i + 3], values[i + 4])
|
||||||
TransformPoint(&values[i + 5], &values[i + 6], state.xform, values[i + 5], values[i + 6])
|
TransformPoint(&values[i + 5], &values[i + 6], state.xform, values[i + 5], values[i + 6])
|
||||||
i += 7
|
i += 7
|
||||||
}
|
|
||||||
|
|
||||||
case .CLOSE: {
|
case .CLOSE: i += 1
|
||||||
i += 1
|
case .WINDING: i += 2
|
||||||
}
|
|
||||||
|
|
||||||
case .WINDING: {
|
// default
|
||||||
i += 2
|
case: i += 1
|
||||||
}
|
|
||||||
|
|
||||||
// default
|
|
||||||
case: {
|
|
||||||
i += 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1510,45 +1501,38 @@ __flattenPaths :: proc(ctx: ^Context) {
|
|||||||
cmd := Commands(ctx.commands[i])
|
cmd := Commands(ctx.commands[i])
|
||||||
|
|
||||||
switch cmd {
|
switch cmd {
|
||||||
case .MOVE_TO: {
|
case .MOVE_TO:
|
||||||
__addPath(ctx)
|
__addPath(ctx)
|
||||||
p := ctx.commands[i + 1:]
|
p := ctx.commands[i + 1:]
|
||||||
__addPoint(ctx, p[0], p[1], { .CORNER })
|
__addPoint(ctx, p[0], p[1], { .CORNER })
|
||||||
i += 3
|
i += 3
|
||||||
|
|
||||||
|
case .LINE_TO:
|
||||||
|
p := ctx.commands[i + 1:]
|
||||||
|
__addPoint(ctx, p[0], p[1], { .CORNER })
|
||||||
|
i += 3
|
||||||
|
|
||||||
|
case .BEZIER_TO:
|
||||||
|
last := __lastPoint(ctx)
|
||||||
|
|
||||||
|
if last != nil {
|
||||||
|
cp1 := ctx.commands[i + 1:]
|
||||||
|
cp2 := ctx.commands[i + 3:]
|
||||||
|
p := ctx.commands[i + 5:]
|
||||||
|
__tesselateBezier(ctx, last.x,last.y, cp1[0],cp1[1], cp2[0],cp2[1], p[0],p[1], 0, { .CORNER })
|
||||||
}
|
}
|
||||||
|
|
||||||
case .LINE_TO: {
|
i += 7
|
||||||
p := ctx.commands[i + 1:]
|
|
||||||
__addPoint(ctx, p[0], p[1], { .CORNER })
|
|
||||||
i += 3
|
|
||||||
}
|
|
||||||
|
|
||||||
case .BEZIER_TO: {
|
case .CLOSE:
|
||||||
last := __lastPoint(ctx)
|
__closePath(ctx)
|
||||||
|
i += 1
|
||||||
if last != nil {
|
|
||||||
cp1 := ctx.commands[i + 1:]
|
|
||||||
cp2 := ctx.commands[i + 3:]
|
|
||||||
p := ctx.commands[i + 5:]
|
|
||||||
__tesselateBezier(ctx, last.x,last.y, cp1[0],cp1[1], cp2[0],cp2[1], p[0],p[1], 0, { .CORNER })
|
|
||||||
}
|
|
||||||
|
|
||||||
i += 7
|
case .WINDING:
|
||||||
}
|
__pathWinding(ctx, Winding(ctx.commands[i + 1]))
|
||||||
|
i += 2
|
||||||
|
|
||||||
case .CLOSE: {
|
case: i += 1
|
||||||
__closePath(ctx)
|
|
||||||
i += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
case .WINDING: {
|
|
||||||
__pathWinding(ctx, Winding(ctx.commands[i + 1]))
|
|
||||||
i += 2
|
|
||||||
}
|
|
||||||
|
|
||||||
case: {
|
|
||||||
i += 1
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2520,7 +2504,7 @@ Ellipse :: proc(ctx: ^Context, cx, cy, rx, ry: f32) {
|
|||||||
__cmdf(.BEZIER_TO), cx+rx*KAPPA, cy+ry, cx+rx, cy+ry*KAPPA, cx+rx, cy,
|
__cmdf(.BEZIER_TO), cx+rx*KAPPA, cy+ry, cx+rx, cy+ry*KAPPA, cx+rx, cy,
|
||||||
__cmdf(.BEZIER_TO), cx+rx, cy-ry*KAPPA, cx+rx*KAPPA, cy-ry, cx, cy-ry,
|
__cmdf(.BEZIER_TO), cx+rx, cy-ry*KAPPA, cx+rx*KAPPA, cy-ry, cx, cy-ry,
|
||||||
__cmdf(.BEZIER_TO), cx-rx*KAPPA, cy-ry, cx-rx, cy-ry*KAPPA, cx-rx, cy,
|
__cmdf(.BEZIER_TO), cx-rx*KAPPA, cy-ry, cx-rx, cy-ry*KAPPA, cx-rx, cy,
|
||||||
__cmdf(.CLOSE)
|
__cmdf(.CLOSE),
|
||||||
}
|
}
|
||||||
__appendCommands(ctx, values[:])
|
__appendCommands(ctx, values[:])
|
||||||
}
|
}
|
||||||
@@ -2674,8 +2658,8 @@ CreateFont :: proc(ctx: ^Context, name, filename: string) -> int {
|
|||||||
|
|
||||||
// Creates font by loading it from the specified memory chunk.
|
// Creates font by loading it from the specified memory chunk.
|
||||||
// Returns handle to the font.
|
// Returns handle to the font.
|
||||||
CreateFontMem :: proc(ctx: ^Context, name: string, slice: []byte) -> int {
|
CreateFontMem :: proc(ctx: ^Context, name: string, slice: []byte, free_loaded_data: bool) -> int {
|
||||||
return fontstash.AddFontMem(&ctx.fs, name, slice)
|
return fontstash.AddFontMem(&ctx.fs, name, slice, free_loaded_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
|
// Finds a loaded font of specified name, and returns handle to it, or -1 if the font is not found.
|
||||||
@@ -2890,15 +2874,15 @@ TextIcon :: proc(ctx: ^Context, x, y: f32, codepoint: rune) -> f32 {
|
|||||||
x := x * scale
|
x := x * scale
|
||||||
y := y * scale
|
y := y * scale
|
||||||
switch fstate.ah {
|
switch fstate.ah {
|
||||||
case .LEFT: {}
|
case .LEFT: {}
|
||||||
case .CENTER: {
|
|
||||||
width := fontstash.CodepointWidth(font, codepoint, fscale)
|
case .CENTER:
|
||||||
x = math.round(x - width * 0.5)
|
width := fontstash.CodepointWidth(font, codepoint, fscale)
|
||||||
}
|
x = math.round(x - width * 0.5)
|
||||||
case .RIGHT: {
|
|
||||||
width := fontstash.CodepointWidth(font, codepoint, fscale)
|
case .RIGHT:
|
||||||
x -= width
|
width := fontstash.CodepointWidth(font, codepoint, fscale)
|
||||||
}
|
x -= width
|
||||||
}
|
}
|
||||||
|
|
||||||
// align vertically
|
// align vertically
|
||||||
@@ -3190,35 +3174,30 @@ TextBreakLines :: proc(
|
|||||||
prev_iter = iter
|
prev_iter = iter
|
||||||
|
|
||||||
switch iter.codepoint {
|
switch iter.codepoint {
|
||||||
case '\t', '\v', '\f', ' ', 0x00a0: {
|
case '\t', '\v', '\f', ' ', 0x00a0:
|
||||||
// NBSP
|
// NBSP
|
||||||
type = .Space
|
type = .Space
|
||||||
}
|
|
||||||
|
|
||||||
case '\n': {
|
case '\n':
|
||||||
type = pcodepoint == 13 ? .Space : .Newline
|
type = pcodepoint == 13 ? .Space : .Newline
|
||||||
}
|
|
||||||
|
case '\r':
|
||||||
case '\r': {
|
type = pcodepoint == 10 ? .Space : .Newline
|
||||||
type = pcodepoint == 10 ? .Space : .Newline
|
|
||||||
}
|
|
||||||
|
|
||||||
case 0x0085: {
|
case 0x0085:
|
||||||
// NEL
|
// NEL
|
||||||
type = .Newline
|
type = .Newline
|
||||||
}
|
|
||||||
|
|
||||||
case: {
|
case:
|
||||||
if (iter.codepoint >= 0x4E00 && iter.codepoint <= 0x9FFF) ||
|
if (iter.codepoint >= 0x4E00 && iter.codepoint <= 0x9FFF) ||
|
||||||
(iter.codepoint >= 0x3000 && iter.codepoint <= 0x30FF) ||
|
(iter.codepoint >= 0x3000 && iter.codepoint <= 0x30FF) ||
|
||||||
(iter.codepoint >= 0xFF00 && iter.codepoint <= 0xFFEF) ||
|
(iter.codepoint >= 0xFF00 && iter.codepoint <= 0xFFEF) ||
|
||||||
(iter.codepoint >= 0x1100 && iter.codepoint <= 0x11FF) ||
|
(iter.codepoint >= 0x1100 && iter.codepoint <= 0x11FF) ||
|
||||||
(iter.codepoint >= 0x3130 && iter.codepoint <= 0x318F) ||
|
(iter.codepoint >= 0x3130 && iter.codepoint <= 0x318F) ||
|
||||||
(iter.codepoint >= 0xAC00 && iter.codepoint <= 0xD7AF) {
|
(iter.codepoint >= 0xAC00 && iter.codepoint <= 0xD7AF) {
|
||||||
type = .CJK
|
type = .CJK
|
||||||
} else {
|
} else {
|
||||||
type = .Char
|
type = .Char
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3426,9 +3405,9 @@ TextBoxBounds :: proc(
|
|||||||
|
|
||||||
// Horizontal bounds
|
// Horizontal bounds
|
||||||
switch halign {
|
switch halign {
|
||||||
case .LEFT: dx = 0
|
case .LEFT: dx = 0
|
||||||
case .CENTER: dx = breakRowWidth*0.5 - row.width*0.5
|
case .CENTER: dx = breakRowWidth*0.5 - row.width*0.5
|
||||||
case .RIGHT: dx = breakRowWidth - row.width
|
case .RIGHT: dx = breakRowWidth - row.width
|
||||||
}
|
}
|
||||||
|
|
||||||
rminx = x + row.minx + dx
|
rminx = x + row.minx + dx
|
||||||
|
|||||||
Reference in New Issue
Block a user