Recent

Author Topic: The problem with the window scaling  (Read 171 times)

yyttyy

  • New Member
  • *
  • Posts: 18
The problem with the window scaling
« on: October 28, 2020, 08:31:20 pm »
I coding window. My window should be with strict aspect ratio. With help of gtk_window_set_geometry_hints() I  did this. But my window is now resizing very jerky and unflustered. Can I fix it? Or its only WM problem?
Code: Pascal  [Select][+][-]
  1. unit OutputWindow;
  2. interface
  3.  
  4. procedure CreateWindow();
  5.  
  6. implementation
  7.  
  8. uses glib2, gdk2pixbuf, gdk2, gtk2;
  9.  
  10. procedure BackgroundInit(var Pixbuf : PGdkPixbuf);
  11. var
  12.     PathToBackG : array [0..100] of char;
  13.     error : PGError;
  14. begin
  15.     PathToBackG := '/home/yarik/Desktop/Zhuzhculator/GUIZhuzh/Testing_Background.bmp';
  16.     error := nil;
  17.     Pixbuf :=  gdk_pixbuf_new_from_file(@PathToBackG , @error);
  18.     // Pixbuf := gdk_pixbuf_scale_simple(Pixbuf, 344, 531, GDK_INTERP_HYPER);
  19.     if error <> nil then
  20.     begin
  21.         if error^.domain = GDK_PIXBUF_ERROR then
  22.         begin
  23.             g_print('Pixbuf Related Error'#10);
  24.             halt(1)
  25.         end;
  26.         if error^.domain = G_FILE_ERROR then
  27.         begin
  28.             g_print('File Error: Check file permissions and state'#10);
  29.             halt(1)
  30.         end;
  31.     end;
  32. end;
  33.  
  34. procedure SetStyle(var Style : PGtkStyle; Pixbuf : PGdkPixbuf);
  35. var
  36.     Background : PGdkPixmap;
  37.     MaskReturn : PGdkBitmap;
  38. begin
  39.     MaskReturn := nil;
  40.     gdk_pixbuf_render_pixmap_and_mask (Pixbuf, Background, MaskReturn, 0);
  41.     Style := gtk_style_new();
  42.     Style^.bg_pixmap[0] := Background;
  43. end;
  44.  
  45. procedure destroy (widget : pGtkWidget ; data : pgpointer); cdecl ;
  46. begin
  47. gtk_main_quit()
  48. end;
  49.  
  50. procedure SetGeometry(var Geometry : TGdkGeometry);
  51. begin
  52.     Geometry.min_width := 321;
  53.     Geometry.min_height := 480;
  54.     Geometry.min_aspect := 321 / 480;
  55.     Geometry.max_aspect := 321 / 480;
  56. end;
  57.  
  58. procedure CreateWindow();
  59. var
  60.     Window : PGtkWidget;
  61.     Style : PGtkStyle;
  62.     Pixbuf : PGdkPixbuf;
  63.     Geometry : TGdkGeometry;
  64. begin
  65.     gtk_init(@argc, @argv);
  66.     Window := gtk_window_new(GTK_WINDOW_TOPLEVEL);
  67.     gtk_window_set_title(GTK_WINDOW(Window), 'Zhuzhculator');
  68.     SetGeometry(Geometry);
  69.     gtk_window_set_geometry_hints(GTK_WINDOW(Window), Window,
  70.                                   @Geometry, GDK_HINT_ASPECT
  71.                                   or GDK_HINT_MIN_SIZE);
  72.     gtk_window_set_gravity(GTK_WINDOW(Window), GDK_GRAVITY_CENTER);
  73.     // gtk_widget_set_size_request(Window, 321, 480);
  74.     gtk_window_set_default_size(GTK_WINDOW(Window), 321, 480);
  75.     BackgroundInit(Pixbuf);
  76.     SetStyle(Style, Pixbuf);
  77.     gtk_widget_set_style(Window, GTK_STYLE(Style));
  78.     gtk_widget_show(Window);
  79.     gtk_signal_connect(PGtkObject(Window), 'destroy',
  80.                        GTK_SIGNAL_FUNC (@destroy), NULL);
  81.     gtk_main();
  82. end;
  83. end.

 

TinyPortal © 2005-2018