Check-in [bcc0c5730e]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:added basic keyboard support
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:bcc0c5730e43f9610e52d607b2c3670aa9be34b8
User & Date: aldo 2016-09-12 17:28:28
Context
2016-09-12
22:09
added textline editor, added text-align css support check-in: a2511885ee user: aldo tags: trunk
17:28
added basic keyboard support check-in: bcc0c5730e user: aldo tags: trunk
17:27
added multiline text to label in demo2.ss check-in: 543f2597d0 user: aldo tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to element.ss.

74
75
76
77
78
79
80



















81
82
83
84

85
86
87
88
89
90
91
92
93
94
95
...
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
    (set! id (mi-id id)))
  (let-values ([(last-x last-y last-w last-h) (get-last-coords id)])
    (let ([old-style (widget-old-style id)]
	  [element #f] 
	  [td #f] 
	  [style #f] 
	  [pseudo #f])



















      (when (and (number? last-w) (number? last-h) (region-hit? last-x last-y last-w last-h))
	(mi-hot-item id)
	(when (and activable (not (mi-active-item)) (mi-mouse-down?))
	  (mi-active-item id))

	(if (eq? (mi-active-item) id)
	    (set! pseudo 'pressed)
	    (set! pseudo 'hover)))

      (set! element (make-mi-element el id (mi-class) pseudo (mi-el)))
      
      (set! style (stylesheet-resolve element))
      (hashtable-set! style-table id style)
      (mi-element-style-set! element style)
      
      (set! td (mi-style-query element 'transition-duration 0 #f))
................................................................................

(define-css-element flex 1 #f i-t number?)

(define-css-element min-width 0 #f i-t number? list?)

(define-css-element min-height 0 #f i-t number? list?)

(define-css-element text-align 0 #f i-t number? list?)

(define-css-element box-sizing 'border-box #f i-t
  (eq-transformer 'border-box))

(define-css-element order 0 #f i-t
  number?)








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



|
>



|







 







|







74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
...
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
    (set! id (mi-id id)))
  (let-values ([(last-x last-y last-w last-h) (get-last-coords id)])
    (let ([old-style (widget-old-style id)]
	  [element #f] 
	  [td #f] 
	  [style #f] 
	  [pseudo #f])
      (when activable
	(when (not (mi-kbd-item))
	  (mi-kbd-item id)
	  (printf "KBD ITEM: ~d~n" id))
	(when (eq? (mi-kbd-item) id)
	  (when (mi-key)
	    (case (mi-key)
	      #;['(shift tab) 
	       (mi-kbd-item (mi-last-activable))
	       (mi-keys-pop) (mi-keys-pop)]
	      [tab
	       (mi-kbd-item #f)(printf "TAB~n")
	       (mi-key #f)]
	      [return
	       (mi-hot-item id) (mi-active-item id)
	       (mi-key #f)
	       ])))
	  (mi-last-activable id))

      (when (and (number? last-w) (number? last-h) (region-hit? last-x last-y last-w last-h))
	(mi-hot-item id)
	(when (and activable (not (mi-active-item)) (mi-mouse-down?))
	  (mi-active-item id)
	  (mi-kbd-item id))
	(if (eq? (mi-active-item) id)
	    (set! pseudo 'pressed)
	    (set! pseudo 'hover)))
      
      (set! element (make-mi-element el id (mi-class) pseudo (mi-el)))
      
      (set! style (stylesheet-resolve element))
      (hashtable-set! style-table id style)
      (mi-element-style-set! element style)
      
      (set! td (mi-style-query element 'transition-duration 0 #f))
................................................................................

(define-css-element flex 1 #f i-t number?)

(define-css-element min-width 0 #f i-t number? list?)

(define-css-element min-height 0 #f i-t number? list?)

(define-css-element text-align 'left #f i-t number? (in-list-validator 'left 'center 'right))

(define-css-element box-sizing 'border-box #f i-t
  (eq-transformer 'border-box))

(define-css-element order 0 #f i-t
  number?)

Changes to event-loop.ss.

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
85
86
87
88
89
90
	  sdl-poll-event ((e sdl-event-t &)) result
	  ;(printf "~d ~d\n" e result)
	  (when (not (zero? result))
		(let-struct 
		 e sdl-event-t (type)
		 (case (sdl-event-type-ref type)
		   [quit (printf "quit\n") (quit)]
		   [keydown (let* ([sym (event-keyboard-keysym-sym e)]

				   [sym-name (sdl-keycode-ref sym)])



			      (printf "keydown ~x ~d\n" sym (sdl-keycode-ref sym))

			      (if (eq? sym-name 'q) (quit)))]



		   [textinput (let* ([ti (ftype-&ref sdl-event-t (text) e)]
				     [text (char*-array->string
					    (ftype-&ref sdl-text-input-event-t (text) ti) 32)])
				(printf "text input \"~d\"\n" text )
				(if (string=? text "q") (quit)))]
		   [mousemotion (let* ([mousemotion (ftype-&ref sdl-event-t (motion) e)])
				  (let-struct mousemotion sdl-mouse-motion-event-t
					      (x y xrel yrel state)
					      (mi-mouse-x x) (mi-mouse-y y)
					      (if (region-hit? 0 0 (mi-window-width) (mi-window-height))
						  (sdl-capture-mouse #t)
						  (sdl-capture-mouse #f))
					      ;(printf "mouse moved ~d ~d ~d ~d ~d" x y xrel yrel state)
					      ))]
		   [mousewheel (let* ([wheel (ftype-&ref sdl-event-t (wheel) e)])
				 (let-struct wheel sdl-mouse-wheel-event-t (x y window-id)
					     (printf "mouse wheel ~d ~d\n" x y)))]
		   
		   [mousebuttondown (let* ([button (event-mouse-button e)]
					   [button-name (sdl-button-ref button)])
				      (printf "mouse down ~d ~d\n" button button-name)
				      (when (eq? button-name 'left)
					    (mi-mouse-down? #t)))]
		   [mousebuttonup (let* ([button (event-mouse-button e)]
					 [button-name (sdl-button-ref button)])
				    (printf "mouse up ~d ~d\n" button button-name)
				    (when (eq? button-name 'left)
					  (mi-mouse-down? #f)))]
		   [windowevent 
		    (let-struct (ftype-&ref sdl-event-t (window) e) sdl-window-event-t (event)
				(let ([we (sdl-window-event-enum-ref event)])







|
>

>
>
>
|
>

>
>
>



|
<













|




|







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
85
86
87
88
89
90
91
92
93
94
95
96
97
	  sdl-poll-event ((e sdl-event-t &)) result
	  ;(printf "~d ~d\n" e result)
	  (when (not (zero? result))
		(let-struct 
		 e sdl-event-t (type)
		 (case (sdl-event-type-ref type)
		   [quit (printf "quit\n") (quit)]
		   [keydown (let* ([sym (sdl-event-keyboard-keysym-sym e)]
				   [mod (sdl-event-keyboard-keysym-mod e)]
				   [sym-name (sdl-keycode-ref sym)])
			      (printf "keydown ~x ~x ~d ~d\n" sym mod (sdl-keycode-ref sym) 
				      (sdl-keymod-decode mod))
			      (mi-keymod (sdl-keymod-decode mod))
			      (mi-key (sdl-keycode-ref sym))
			      
			      (if (eq? sym-name 'q) (quit)))]
		   [keyup (let* ([sym (sdl-event-keyboard-keysym-sym e)]
				   [sym-name (sdl-keycode-ref sym)])
			      (printf "keyup ~x ~d\n" sym (sdl-keycode-ref sym)))]
		   [textinput (let* ([ti (ftype-&ref sdl-event-t (text) e)]
				     [text (char*-array->string
					    (ftype-&ref sdl-text-input-event-t (text) ti) 32)])
				(printf "text input \"~d\"\n" text ))]

		   [mousemotion (let* ([mousemotion (ftype-&ref sdl-event-t (motion) e)])
				  (let-struct mousemotion sdl-mouse-motion-event-t
					      (x y xrel yrel state)
					      (mi-mouse-x x) (mi-mouse-y y)
					      (if (region-hit? 0 0 (mi-window-width) (mi-window-height))
						  (sdl-capture-mouse #t)
						  (sdl-capture-mouse #f))
					      ;(printf "mouse moved ~d ~d ~d ~d ~d" x y xrel yrel state)
					      ))]
		   [mousewheel (let* ([wheel (ftype-&ref sdl-event-t (wheel) e)])
				 (let-struct wheel sdl-mouse-wheel-event-t (x y window-id)
					     (printf "mouse wheel ~d ~d\n" x y)))]
		   
		   [mousebuttondown (let* ([button (sdl-event-mouse-button e)]
					   [button-name (sdl-button-ref button)])
				      (printf "mouse down ~d ~d\n" button button-name)
				      (when (eq? button-name 'left)
					    (mi-mouse-down? #t)))]
		   [mousebuttonup (let* ([button (sdl-event-mouse-button e)]
					 [button-name (sdl-button-ref button)])
				    (printf "mouse up ~d ~d\n" button button-name)
				    (when (eq? button-name 'left)
					  (mi-mouse-down? #f)))]
		   [windowevent 
		    (let-struct (ftype-&ref sdl-event-t (window) e) sdl-window-event-t (event)
				(let ([we (sdl-window-event-enum-ref event)])

Changes to miogui.ss.

51
52
53
54
55
56
57

























58
59
60
61
62
63
64

(define mi-mouse-x (make-parameter 0))
(define mi-mouse-y (make-parameter 0))
(define mi-mouse-down? (make-parameter #f))
(define mi-hot-item (make-parameter #f))
(define mi-active-item (make-parameter #f))
(define mi-active-window 'none)

























(define mi-cr (make-parameter #f))
(define mi-cairo-surface (make-parameter #f))

(define fps (make-parameter 25))
(define mi-frame-number (make-parameter 0))

(import (srfi s26 cut)) 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
85
86
87
88
89

(define mi-mouse-x (make-parameter 0))
(define mi-mouse-y (make-parameter 0))
(define mi-mouse-down? (make-parameter #f))
(define mi-hot-item (make-parameter #f))
(define mi-active-item (make-parameter #f))
(define mi-active-window 'none)
(define mi-last-activable (make-parameter #f))

(define mi-kbd-item (make-parameter #f))

;; (define mi-keys (make-parameter '()))

;; (define (mi-keys-add k)
;;   (mi-keys (append (mi-keys) (list k))))

;; (define (mi-keys-rm k)
;;   (mi-keys (remove k (mi-keys))))

;; (define (mi-keys-available)
;;   (pair? (mi-keys)))

;; (define (mi-keys-pop)
;;   (if (pair? (mi-keys))
;;       (let ([k (car (mi-keys))])
;; 	(mi-keys (cdr (mi-keys)))
;; 	k)
;;       #f))

(define mi-key (make-parameter #f))
(define mi-keymod (make-parameter '()))

(define mi-cr (make-parameter #f))
(define mi-cairo-surface (make-parameter #f))

(define fps (make-parameter 25))
(define mi-frame-number (make-parameter 0))

(import (srfi s26 cut))