-
Notifications
You must be signed in to change notification settings - Fork 2
/
render.ss
85 lines (67 loc) · 2.42 KB
/
render.ss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;; * MIOGUI *
;;
;; Copyright 2016 Aldo Nicolas Bruno
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
(define mi-state (make-parameter 'first))
(define (layout-ready?) (eq? (mi-state) 'ready))
(define (render-prepare)
(define tex (mi-sdl-texture))
(define r0 (make-ftype-pointer sdl-rect-t 0))
(sdl-set-render-draw-color (mi-renderer) 0 0 0 1)
(sdl-render-clear (mi-renderer))
(mi-cairo-surface
(sdl-let-ref-call sdl-lock-texture
(tex r0 (pixels void*) (pitch int))
return
(cairo-image-surface-create-for-data
(make-ftype-pointer unsigned-8 pixels)
(cairo-format 'argb-32) (mi-window-width) (mi-window-height) pitch)))
(mi-cr (cairo-create (mi-cairo-surface)))
(with-cairo (mi-cr)
(set-source-rgb 1 1 1) ; blank scrren
(rectangle 0 0 (mi-window-width) (mi-window-height))
(fill))
(mi-hot-item #f))
(define (render-finish)
(if (not (mi-mouse-down?))
(mi-active-item #f)
(if (not (mi-active-item))
(mi-active-item '())))
(draw-all)
(sdl-unlock-texture (mi-sdl-texture))
(sdl-render-copy (mi-renderer) (mi-sdl-texture)
(make-ftype-pointer sdl-rect-t 0)
(make-ftype-pointer sdl-rect-t 0))
(sdl-render-present (mi-renderer))
(collect)
(sdl-free-garbage))
(define last-frame (current-time))
(define mi-stat-fps 0)
(define (render-stuff user-render-func)
(set! old-element-table element-table)
(set! element-table (make-eq-hashtable))
(render-prepare)
(p10e ([mi-state 'first])
;(printf "LAYOUT PASS: ~d~n" 'first)
(user-render-func))
(layout-element (mi-current-window))
(p10e ([mi-state 'ready])
;(printf "LAYOUT PASS: ~d~n" 'ready)
(user-render-func))
(render-finish)
(let ([d (time-difference (current-time) last-frame)])
;(printf "frame-duration: ~d~n" (time-float d))
;(printf "fps: ~d~n" (/ 1. (time-float d)))
(set! mi-stat-fps (/ 1. (time-float d)))
(set! last-frame (current-time))))