Skip to content

Commit

Permalink
Some major refactoring. Key events fully implemented.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtza8 committed Oct 10, 2011
1 parent 5d37822 commit 2fdec80
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 240 deletions.
5 changes: 2 additions & 3 deletions glop.asd
Expand Up @@ -27,13 +27,12 @@
:serial t
:components ((:file "package")
(:file "carbon")
(:file "quartz")
(:file "bridge")
(:file "foundation")
(:file "appkit")
(:file "quartz")
(:file "glop-app")
(:file "glop-window-responder")
(:file "glop-gl-view")
(:file "glop-view")
(:file "glop-osx")))
#+(or win32 windows)
(:module "win32"
Expand Down
14 changes: 14 additions & 0 deletions src/glop.lisp
Expand Up @@ -199,6 +199,13 @@ set window fullscreen state."
"Swaps GL buffers."))

;;; Events handling
(defmacro define-simple-print-object (type &rest attribs)
`(defmethod print-object ((event ,type) stream)
(with-slots ,attribs event
(format stream
,(format nil "#<~~s~{ ~s ~~s~}>" attribs)
(type-of event) ,@attribs))))

(defclass event () ()
(:documentation "Common ancestor for all events."))

Expand All @@ -208,6 +215,7 @@ set window fullscreen state."
(text :initarg :text :reader text)
(pressed :initarg :pressed :reader pressed))
(:documentation "Keyboard key press or release."))
(define-simple-print-object key-event keycode keysym text pressed)

(defclass key-press-event (key-event)
()
Expand All @@ -223,6 +231,7 @@ set window fullscreen state."
((button :initarg :button :reader button)
(pressed :initarg :pressed :reader pressed))
(:documentation "Mouse button press or release."))
(define-simple-print-object button-event button pressed)

(defclass button-press-event (button-event)
()
Expand All @@ -240,23 +249,27 @@ set window fullscreen state."
(dx :initarg :dx :reader dx)
(dy :initarg :dy :reader dy))
(:documentation "Mouse motion."))
(define-simple-print-object mouse-motion-event x y dx dy)

(defclass expose-event (event)
((width :initarg :width :reader width)
(height :initarg :height :reader height))
(:documentation "Window expose."))
(define-simple-print-object expose-event width height)

(defclass resize-event (event)
((width :initarg :width :reader width)
(height :initarg :height :reader height))
(:documentation "Window resized."))
(define-simple-print-object resize-event width height)

(defclass close-event (event) ()
(:documentation "Window closed."))

(defclass visibility-event (event)
((visible :initarg :visible :reader visible))
(:documentation "Window visibility changed."))
(define-simple-print-object visibility-event visible)

(defclass visibility-obscured-event (visibility-event)
()
Expand All @@ -271,6 +284,7 @@ set window fullscreen state."
(defclass focus-event (event)
((focused :initarg :focused :reader focused))
(:documentation "Window focus state changed."))
(define-simple-print-object focus-event focused)

(defclass focus-in-event (focus-event)
()
Expand Down
133 changes: 64 additions & 69 deletions src/osx/appkit.lisp
Expand Up @@ -65,23 +65,23 @@
(foreign-enum-keyword 'ns-event-type (%ns-event-type event)))

(defcenum ns-key-code
:A
:S
:D
:F
:H
:G
:Z
:X
:C
:V
(:B 11)
:Q
:W
:E
:R
:Y
:T
:a
:s
:d
:f
:h
:g
:z
:x
:c
:v
(:b 11)
:q
:w
:e
:r
:y
:t
:1
:2
:3
Expand All @@ -95,38 +95,39 @@
:8
:0
:|]|
:O
:U
:o
:u
:|[|
:I
:P
:enter
:L
:J
:i
:p
:return
:l
:j
:|'|
:K
:k
(:|;| 41)
:|\\|
:|,|
:|/|
:N
:M
:n
:m
:|.|
:tab
:space
:|`|
(:backspace 51)
:esc
(:rsuper 54)
:lsuper
:lshift
(:escape 53)
:super-r
:super-l
:shift-l
:caps-lock
:lalt
:lctrl
:rshift
:ralt
:rctrl
(:f17 64)
:alt-l
:ctrl-l
:shift-r
:alt-r
:ctrl-r
(:function 63)
:f17
:kp-decimal
(:kp-multiply 67)
(:kp-add 69)
Expand Down Expand Up @@ -162,24 +163,23 @@
(:f15 113)
:insert
:home
:pageup
:del
:page-up
:delete
:f4
:end
:f2
:pagedown
:page-down
:f1
:left
:right
:down
:up)

(defcfun ("NSEventKeyCode" %ns-event-key-code) :uint16
(defcfun ("NSEventKeyCode" ns-event-key-code) :uint16
(event :pointer))

(defun ns-event-key-code (event)
(let* ((code (%ns-event-key-code event))
(key (foreign-enum-keyword 'ns-key-code code :errorp nil)))
(defun keysym (code)
(let* ((key (foreign-enum-keyword 'ns-key-code code :errorp nil)))
(if key key :unknown)))

(defbitfield ns-modifier-flags
Expand Down Expand Up @@ -219,6 +219,8 @@
(defcfun ("NSEventDeltaY" ns-event-delta-y) cg-float
(event :pointer))

(defcfun ("NSEventCharacters" ns-event-characters) ns-string
(event :pointer))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; NSApplication ;;;
Expand All @@ -240,12 +242,9 @@
(width :int)
(height :int))

(defcfun ("NSWindowSetTitle" %ns-window-set-title) :pointer
(defcfun ("NSWindowSetTitle" ns-window-set-title) :void
(window :pointer)
(title :pointer))
(defun ns-window-set-title (window title)
(with-ns-strings ((ns-title title))
(%ns-window-set-title window ns-title)))
(title ns-string))

(defcfun ("NSWindowSetBackgroundColor" ns-window-set-background-color) :void
(window :pointer)
Expand Down Expand Up @@ -298,34 +297,23 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defcfun ("NSMenuAllocInit" %ns-menu-alloc-init) :pointer
(title :pointer))
(defun ns-menu-alloc-init (title)
(with-ns-strings ((ns-str-title title))
(%ns-menu-alloc-init ns-str-title)))
(defcfun ("NSMenuAllocInit" ns-menu-alloc-init) :pointer
(title ns-string))

(defcfun ("NSMenuAddItem" ns-menu-add-item) :void
(menu :pointer)
(item :pointer))

(defcfun ("NSMenuAddItemWithTitle" %ns-menu-add-item-with-title) :void
(defcfun ("NSMenuAddItemWithTitle" ns-menu-add-item-with-title) :void
(menu :pointer)
(title :pointer)
(title ns-string)
(selector :pointer)
(key-equiv :pointer))
(defun ns-menu-add-item-with-title (menu title selector key-equiv)
(with-ns-strings ((ns-str-title title)
(ns-str-key-equiv key-equiv))
(%ns-menu-add-item-with-title menu ns-str-title selector ns-str-key-equiv)))

(defcfun ("NSMenuItemAllocInit" %ns-menu-item-alloc-init) :void
(title :pointer)
(key-equiv ns-string))

(defcfun ("NSMenuItemAllocInit" ns-menu-item-alloc-init) :void
(title ns-string)
(selector :pointer)
(key-equiv :pointer))
(defun ns-menu-item-alloc-init (title selector key-equiv)
(with-ns-strings ((ns-str-title title)
(ns-str-key-equiv key-equiv))
(%ns-menu-item-alloc-init ns-str-title selector ns-str-key-equiv)))
(key-equiv ns-string))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down Expand Up @@ -408,6 +396,13 @@
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defcfun ("NSOpenGLContextInit" ns-opengl-context-init) :pointer
(format :pointer))

(defcfun ("NSOpenGLContextSetView" ns-opengl-context-set-view) :void
(context :pointer)
(view :pointer))

(defcfun ("NSOpenGLContextClearDrawable" ns-opengl-context-clear-drawable) :void
(context :pointer))

Expand Down
4 changes: 0 additions & 4 deletions src/osx/bridge/GlopGLView.h

This file was deleted.

37 changes: 0 additions & 37 deletions src/osx/bridge/GlopGLView.m

This file was deleted.

@@ -1,9 +1,9 @@
#import <Appkit/Appkit.h>
#import <Cocoa/Cocoa.h>

typedef void(*GlopEventCallback)(NSEvent*);


@interface GlopWindowResponder : NSResponder <NSWindowDelegate>
@interface GlopView : NSView <NSWindowDelegate>
{
GlopEventCallback eventCallback;
}
Expand Down

0 comments on commit 2fdec80

Please sign in to comment.