gg: fix x11 scaling

pull/5221/head
Delyan Angelov 2020-06-04 21:09:46 +03:00
parent e7f52ebed6
commit 2237968ec1
2 changed files with 13 additions and 8 deletions

View File

@ -139,7 +139,7 @@ struct Game {
const ( fpath = os.resource_abs_path('../assets/fonts/RobotoMono-Regular.ttf') )
fn init_gui(mut game Game){
x := ft.new({ font_path: fpath, scale: 2 }) or {panic(err)}
x := ft.new({ font_path: fpath, scale: sapp.dpi_scale() }) or {panic(err)}
game.ft = x
game.font_loaded = true
}
@ -184,7 +184,6 @@ fn main() {
init_fn: init_gui
frame_fn: frame
event_fn: on_event
scale: 2
//wait_events: true
)
game.init_game()

View File

@ -29,7 +29,6 @@ pub:
window_title string
borderless_window bool
always_on_top bool
scale f32 = 1.0
bg_color gx.Color
init_fn FNvoidptr1 = voidptr(0)
frame_fn FNvoidptr1 = voidptr(0)
@ -42,8 +41,8 @@ pub:
}
pub struct Context {
scale f32 = 1.0// retina = 2 , normal = 1
pub mut:
scale f32 = 1.0 // will get set to 2.0 for retina, will remain 1.0 for normal
width int
height int
clear_pass C.sg_pass_action
@ -67,6 +66,16 @@ fn gg_init_sokol_window(user_data voidptr) {
gfx.setup(&desc)
sgl_desc := C.sgl_desc_t{}
sgl.setup(&sgl_desc)
g.scale = sapp.dpi_scale()
// NB: on older X11, `Xft.dpi` from ~/.Xresources, that sokol uses,
// may not be set which leads to sapp.dpi_scale reporting incorrectly 0.0
if g.scale < 0.1 {
g.scale = 1.0
}
is_high_dpi := sapp.high_dpi()
fb_w := sapp.width()
fb_h := sapp.height()
println('g.scale=$g.scale is_high_dpi=$is_high_dpi fb_w=$fb_w fb_h=$fb_h')
if g.config.init_fn != voidptr(0) {
g.config.init_fn( g.config.user_data )
}
@ -111,7 +120,6 @@ pub fn new_context(cfg Config) &Context{
height: cfg.height
clear_pass: gfx.create_clear_pass( f32(cfg.bg_color.r) / 255.0, f32(cfg.bg_color.g) / 255.0,
f32(cfg.bg_color.b) / 255.0, 1.0)
scale: cfg.scale //sapp.dpi_scale()// cfg.scale
config: cfg
}
@ -127,11 +135,9 @@ f32(cfg.bg_color.b) / 255.0, 1.0)
html5_canvas_name: cfg.window_title.str
width: cfg.width
height: cfg.height
high_dpi: cfg.scale > 1
high_dpi: true
fullscreen: cfg.fullscreen
}
//b := sapp.high_dpi()
//println('scale=$g.scale high_dpi=$b')
if cfg.use_ortho {}
else {}
g.window = window