vydd / sketch

A Common Lisp framework for the creation of electronic art, visual design, game prototyping, game making, computer graphics, exploration of human-computer interaction, and more.
MIT License
1.4k stars 67 forks source link

Default window size #71

Closed Gleefre closed 10 months ago

Gleefre commented 1 year ago

Completes https://github.com/vydd/sketch/issues/25. Fixes https://github.com/vydd/sketch/issues/69.

It adds :default-initargs to the class definition generated by defsketch and uses them to set :w and :h initargs in the initialize-instance :around method. Those are used in sdl2:create-window by kit.sdl2.

Thus the window

  1. is not resized immediately after its creation (which probably is the problem with https://github.com/vydd/sketch/issues/69);
  2. is centered during the creation (unless :x or :y are specified).
Gleefre commented 1 year ago

There is a problem: WIDTH and HEIGHT bindings might be expressions depending on other variables, and thus can be set only during the PREPARE method call. But that would be too late, since the window would be already created.

It seems that PREPARE doesn't depend on the window being created (and the sketch's environment being initialized), so it seems possible to transform it into an initialize-instance :around method that calculates slots values before calling next method and set them after. It should also pass :w and :h arguments to create the window with given width/height avoiding the resize.