mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
gtk/ui: Introduce helper gd_update_scale
The code snippet updating scale_x/scale_y is general and will be used in next patch. Make it a function. Signed-off-by: Weifeng Liu <weifeng.liu.z@gmail.com> Message-ID: <20250511073337.876650-4-weifeng.liu.z@gmail.com> Acked-by: Gerd Hoffmann <kraxel@redhat.com> Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
parent
3a6b314409
commit
a196654481
2 changed files with 21 additions and 11 deletions
|
@ -224,4 +224,6 @@ int gd_gl_area_make_current(DisplayGLCtx *dgc,
|
|||
/* gtk-clipboard.c */
|
||||
void gd_clipboard_init(GtkDisplayState *gd);
|
||||
|
||||
void gd_update_scale(VirtualConsole *vc, int ww, int wh, int fbw, int fbh);
|
||||
|
||||
#endif /* UI_GTK_H */
|
||||
|
|
30
ui/gtk.c
30
ui/gtk.c
|
@ -801,6 +801,24 @@ void gd_update_monitor_refresh_rate(VirtualConsole *vc, GtkWidget *widget)
|
|||
#endif
|
||||
}
|
||||
|
||||
void gd_update_scale(VirtualConsole *vc, int ww, int wh, int fbw, int fbh)
|
||||
{
|
||||
if (!vc) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (vc->s->full_screen) {
|
||||
vc->gfx.scale_x = (double)ww / fbw;
|
||||
vc->gfx.scale_y = (double)wh / fbh;
|
||||
} else if (vc->s->free_scale) {
|
||||
double sx, sy;
|
||||
|
||||
sx = (double)ww / fbw;
|
||||
sy = (double)wh / fbh;
|
||||
|
||||
vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* DOC: Coordinate handling.
|
||||
*
|
||||
|
@ -908,17 +926,7 @@ static gboolean gd_draw_event(GtkWidget *widget, cairo_t *cr, void *opaque)
|
|||
ww_widget = gdk_window_get_width(gtk_widget_get_window(widget));
|
||||
wh_widget = gdk_window_get_height(gtk_widget_get_window(widget));
|
||||
|
||||
if (s->full_screen) {
|
||||
vc->gfx.scale_x = (double)ww_widget / fbw;
|
||||
vc->gfx.scale_y = (double)wh_widget / fbh;
|
||||
} else if (s->free_scale) {
|
||||
double sx, sy;
|
||||
|
||||
sx = (double)ww_widget / fbw;
|
||||
sy = (double)wh_widget / fbh;
|
||||
|
||||
vc->gfx.scale_x = vc->gfx.scale_y = MIN(sx, sy);
|
||||
}
|
||||
gd_update_scale(vc, ww_widget, wh_widget, fbw, fbh);
|
||||
|
||||
ww_surface = fbw * vc->gfx.scale_x;
|
||||
wh_surface = fbh * vc->gfx.scale_y;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue