Skip to content

Commit acac759

Browse files
committed
Make window resize event work properly
1 parent 4a0f537 commit acac759

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
system-index.txt
22
release/
33
*.tar*
4+
*.fasl

src/globals.lisp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,15 @@ generateing the map. ")
8686
(defparameter planet-core-radius 3)
8787
(defparameter star-max-amount 1000)
8888

89-
(defparameter screen-rightmost (- world-rightmost screen-width))
90-
(defparameter screen-bottommost (- world-bottommost screen-height))
91-
(defparameter world-width (- world-rightmost world-leftmost))
92-
(defparameter world-height (- world-bottommost world-topmost))
93-
(defparameter margin-bottom (- screen-height 10))
94-
(defparameter margin-right (- screen-width 10))
89+
(defun load-world-limits ()
90+
(defparameter screen-rightmost (- world-rightmost screen-width))
91+
(defparameter screen-bottommost (- world-bottommost screen-height))
92+
(defparameter world-width (- world-rightmost world-leftmost))
93+
(defparameter world-height (- world-bottommost world-topmost))
94+
(defparameter margin-bottom (- screen-height 10))
95+
(defparameter margin-right (- screen-width 10)))
96+
97+
(load-world-limits)
9598

9699
(defun generate-bg-stars (n)
97100
"generate N bg stars and return list"
@@ -196,10 +199,4 @@ INIT-AMOUNT is how many planets one player own at the beginning of game"
196199

197200
;; load all the configure file
198201
(load-file-set-parameters "starwar.conf")
199-
200-
(setq screen-rightmost (- world-rightmost screen-width))
201-
(setq screen-bottommost (- world-bottommost screen-height))
202-
(setq world-width (- world-rightmost world-leftmost))
203-
(setq world-height (- world-bottommost world-topmost))
204-
(setq margin-bottom (- screen-height 10))
205-
(setq margin-right (- screen-width 10)))
202+
(load-world-limits))

src/starwar.lisp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
(setq star-speed speed))
8686
(setq *news* (format nil "Decrease speed to ~ax" star-speed)))
8787

88+
(defun toggle-fullscreen ()
89+
(if fullscreen
90+
(sdl:resize-window screen-width screen-height :sw t :resizable t)
91+
(sdl:resize-window screen-width screen-height :sw t :fullscreen t))
92+
(setf fullscreen (not fullscreen)))
93+
8894
(defun handle-key (key)
8995
(case key
9096
(:sdl-key-escape
@@ -95,6 +101,8 @@
95101
(set-game-running *paused*))
96102
(:sdl-key-r
97103
(clear-global-vars))
104+
(:sdl-key-f11
105+
(toggle-fullscreen))
98106
(:sdl-key-minus
99107
(decrease-star-speed))
100108
(:sdl-key-equals
@@ -104,6 +112,8 @@
104112
(clear-global-vars)
105113
(set-game-running t)))))
106114

115+
116+
107117
;; draw the information line by line
108118
(defun draw-information (&rest infos)
109119
(let ((x 10)
@@ -120,6 +130,7 @@
120130
(:up (decf *screen-pos-y* scroll-speed))
121131
(:down (incf *screen-pos-y* scroll-speed))
122132
(otherwise (error "unknown direction!"))))
133+
123134
(defun fix-screen-pos-overflow ()
124135
(when (> *screen-pos-x* screen-rightmost)
125136
(setq *screen-pos-x* screen-rightmost))
@@ -129,6 +140,7 @@
129140
(setq *screen-pos-y* screen-bottommost))
130141
(when (< *screen-pos-y* screen-topmost)
131142
(setq *screen-pos-y* screen-topmost)))
143+
132144
(defun move-screen-on-worldmap ()
133145
(let ((x (sdl:mouse-x)) (y (sdl:mouse-y)))
134146
(when (or (<= x margin-left)
@@ -265,6 +277,7 @@ the outter rect. the rect is filled by VALUE/FULL-VALUE"
265277
(format t "fullscreen: ~a~%" fullscreen)
266278
(sdl:window screen-width screen-height
267279
:fullscreen fullscreen
280+
:resizable t
268281
:title-caption "Star War"
269282
:icon-caption "Star War")
270283
(set-game-running t)
@@ -285,6 +298,12 @@ the outter rect. the rect is filled by VALUE/FULL-VALUE"
285298
(handle-mouse-button button x y t))
286299
(:mouse-button-up-event (:button button :x x :y y)
287300
(handle-mouse-button button x y nil))
301+
302+
(:video-resize-event (:w w :h h)
303+
(setq screen-width w)
304+
(setq screen-height h)
305+
(sdl:resize-window w h)
306+
(load-world-limits))
288307
(:idle ()
289308
(unless *game-over*
290309
(sdl:clear-display bg-color)

0 commit comments

Comments
 (0)