gg: some stuff required to have svg and png screenshots working on v ui (#14180)
parent
be513b4c27
commit
c26b7666c7
|
@ -0,0 +1,24 @@
|
||||||
|
module gg
|
||||||
|
|
||||||
|
import gx
|
||||||
|
import sokol.sgl
|
||||||
|
|
||||||
|
// Stuff for ui from now for screenshot (that would be interesting for gg if screenshot is implemented also for gg)
|
||||||
|
|
||||||
|
// required for ui.DrawDevice interface (with &gg.Context as an instance)
|
||||||
|
pub fn (ctx &Context) scissor_rect(x int, y int, w int, h int) {
|
||||||
|
sgl.scissor_rect(int(dpi_scale() * x), int(dpi_scale() * y), int(dpi_scale() * w),
|
||||||
|
int(dpi_scale() * h), true)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (ctx &Context) has_text_style() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn (ctx &Context) set_text_style(font_name string, font_path string, size int, color gx.Color, align int, vertical_align int) {}
|
||||||
|
|
||||||
|
// default draw_text (draw_text_def but without set_cfg)
|
||||||
|
pub fn (ctx &Context) draw_text_default(x int, y int, text string) {
|
||||||
|
scale := if ctx.ft.scale == 0 { f32(1) } else { ctx.ft.scale }
|
||||||
|
ctx.ft.fons.draw_text(x * scale, y * scale, text) // TODO: check offsets/alignment
|
||||||
|
}
|
|
@ -59,13 +59,13 @@ pub fn (mut bmp BitMap) clear() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// transform matrix applied to the text
|
// transform matrix applied to the text
|
||||||
fn (bmp &BitMap) trf_txt(p &Point) (int, int) {
|
pub fn (bmp &BitMap) trf_txt(p &Point) (int, int) {
|
||||||
return int(p.x * bmp.tr_matrix[0] + p.y * bmp.tr_matrix[3] + bmp.tr_matrix[6]), int(
|
return int(p.x * bmp.tr_matrix[0] + p.y * bmp.tr_matrix[3] + bmp.tr_matrix[6]), int(
|
||||||
p.x * bmp.tr_matrix[1] + p.y * bmp.tr_matrix[4] + bmp.tr_matrix[7])
|
p.x * bmp.tr_matrix[1] + p.y * bmp.tr_matrix[4] + bmp.tr_matrix[7])
|
||||||
}
|
}
|
||||||
|
|
||||||
// transform matrix applied to the char
|
// transform matrix applied to the char
|
||||||
fn (bmp &BitMap) trf_ch(p &Point) (int, int) {
|
pub fn (bmp &BitMap) trf_ch(p &Point) (int, int) {
|
||||||
return int(p.x * bmp.ch_matrix[0] + p.y * bmp.ch_matrix[3] + bmp.ch_matrix[6]), int(
|
return int(p.x * bmp.ch_matrix[0] + p.y * bmp.ch_matrix[3] + bmp.ch_matrix[6]), int(
|
||||||
p.x * bmp.ch_matrix[1] + p.y * bmp.ch_matrix[4] + bmp.ch_matrix[7])
|
p.x * bmp.ch_matrix[1] + p.y * bmp.ch_matrix[4] + bmp.ch_matrix[7])
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub struct Text_block {
|
||||||
cut_lines bool = true // force to cut the line if the length is over the text block width
|
cut_lines bool = true // force to cut the line if the length is over the text block width
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut dev BitMap) get_justify_space_cw(txt string, w int, block_w int, space_cw int) f32 {
|
pub fn (mut dev BitMap) get_justify_space_cw(txt string, w int, block_w int, space_cw int) f32 {
|
||||||
num_spaces := txt.count(' ')
|
num_spaces := txt.count(' ')
|
||||||
if num_spaces < 1 {
|
if num_spaces < 1 {
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -771,7 +771,7 @@ fn (mut tf TTF_File) read_cmap(offset u32) {
|
||||||
* CMAPS 0/4
|
* CMAPS 0/4
|
||||||
*
|
*
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
fn (mut tf TTF_File) map_code(char_code int) u16 {
|
pub fn (mut tf TTF_File) map_code(char_code int) u16 {
|
||||||
mut index := 0
|
mut index := 0
|
||||||
for i in 0 .. tf.cmaps.len {
|
for i in 0 .. tf.cmaps.len {
|
||||||
mut cmap := tf.cmaps[i]
|
mut cmap := tf.cmaps[i]
|
||||||
|
@ -1006,13 +1006,13 @@ fn (mut tf TTF_File) read_kern_table() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut tf TTF_File) reset_kern() {
|
pub fn (mut tf TTF_File) reset_kern() {
|
||||||
for i in 0 .. tf.kern.len {
|
for i in 0 .. tf.kern.len {
|
||||||
tf.kern[i].reset()
|
tf.kern[i].reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut tf TTF_File) next_kern(glyph_index int) (int, int) {
|
pub fn (mut tf TTF_File) next_kern(glyph_index int) (int, int) {
|
||||||
mut x := 0
|
mut x := 0
|
||||||
mut y := 0
|
mut y := 0
|
||||||
for i in 0 .. tf.kern.len {
|
for i in 0 .. tf.kern.len {
|
||||||
|
|
Loading…
Reference in New Issue