Skip to content

Commit

Permalink
Added more wrapper functions to the Objc 'bridge'.
Browse files Browse the repository at this point in the history
  • Loading branch information
jtza8 authored and patzy committed Oct 31, 2011
1 parent bbd665a commit 2b55e02
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 21 deletions.
1 change: 1 addition & 0 deletions glop.asd
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
:components ((:file "package")
(:file "bridge")
(:file "foundation")
(:file "appkit")
(:file "quartz")
(:file "glop-osx")))
#+(or win32 windows)
Expand Down
40 changes: 40 additions & 0 deletions src/osx/appkit.lisp
Original file line number Diff line number Diff line change
@@ -1,10 +1,50 @@
(in-package #:glop-bridge)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; NSColor ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defcfun ("NSColorBlackColor" ns-black-color) :pointer)
(defcfun ("NSColorBlueColor" ns-blue-color) :pointer)
(defcfun ("NSColorBrownColor" ns-brown-color) :pointer)
(defcfun ("NSColorCyanColor" ns-cyan-color) :pointer)
(defcfun ("NSColorDarkGrayColor" ns-dark-gray-color) :pointer)
(defcfun ("NSColorGrayColor" ns-gray-color) :pointer)
(defcfun ("NSColorGreenColor" ns-green-color) :pointer)
(defcfun ("NSColorLightGrayColor" ns-light-gray-color) :pointer)
(defcfun ("NSColorMagentaColor" ns-magenta-color) :pointer)
(defcfun ("NSColorOrangeColor" ns-orange-color) :pointer)
(defcfun ("NSColorPurpleColor" ns-purple-color) :pointer)
(defcfun ("NSColorWhiteColor" ns-white-color) :pointer)
(defcfun ("NSColorYellowColor" ns-yellow-color) :pointer)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; NSApplication ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defcfun ("NSApplicationSharedApplication" ns-application-shared-application)
:void)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; NSWindow ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defcfun ("NSWindowAllocInit" ns-window-alloc-init) :pointer
(x :int)
(y :int)
(width :int)
(height :int))

(defcfun ("NSWindowSetBackgroundColor" ns-window-set-background-color) :void
(window :pointer)
(color :pointer))

(defcfun ("NSWindowMakeKeyAndOrderFront" ns-window-make-key-and-order-front)
:void
(window :pointer))
47 changes: 47 additions & 0 deletions src/osx/bridge/appkit.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
#include <AppKit/AppKit.h>


/******************************************************************************/
/*** NSColor ***/
/******************************************************************************/


NSColor *NSColorBlackColor () { return [NSColor blackColor]; }
NSColor *NSColorBlueColor () { return [NSColor blueColor]; }
NSColor *NSColorBrownColor () { return [NSColor brownColor]; }
NSColor *NSColorCyanColor () { return [NSColor cyanColor]; }
NSColor *NSColorDarkGrayColor () { return [NSColor darkGrayColor]; }
NSColor *NSColorGrayColor () { return [NSColor grayColor]; }
NSColor *NSColorGreenColor () { return [NSColor greenColor]; }
NSColor *NSColorLightGrayColor () { return [NSColor lightGrayColor]; }
NSColor *NSColorMagentaColor () { return [NSColor magentaColor]; }
NSColor *NSColorOrangeColor () { return [NSColor orangeColor]; }
NSColor *NSColorPurpleColor () { return [NSColor purpleColor]; }
NSColor *NSColorWhiteColor () { return [NSColor whiteColor]; }
NSColor *NSColorYellowColor () { return [NSColor yellowColor]; }


/******************************************************************************/
/*** NSApplication ***/
/******************************************************************************/
Expand All @@ -10,3 +30,30 @@ void NSApplicationSharedApplication ()
{
[NSApplication sharedApplication];
}


/******************************************************************************/
/*** NSWindow ***/
/******************************************************************************/


NSWindow *NSWindowAllocInit (int x, int y, int width, int height)
{
NSWindow *window =
[[[NSWindow alloc]
initWithContentRect:NSMakeRect(x, y, width, height)
styleMask:NSClosableWindowMask | NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO] autorelease];
return window;
}

void NSWindowSetBackgroundColor (NSWindow *window, NSColor *color)
{
[window setBackgroundColor:color];
}

void NSWindowMakeKeyAndOrderFront (NSWindow *window, id sender)
{
[window makeKeyAndOrderFront:sender];
}
Binary file modified src/osx/bridge/glop-bridge.dylib
Binary file not shown.
19 changes: 18 additions & 1 deletion src/osx/glop-osx.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,21 @@
(loop for i below (glop-bridge:ns-array-count display-modes)
collect (display-to-video-mode
(glop-bridge:ns-array-object-at-index
display-modes i)))))
display-modes i)))))

(defmethod open-window (window title width height
&key (x 0) (y 0) (rgba t) (double-buffer t) stereo
(red-size 4) (green-size 4) (blue-size 4) (alpha-size 4)
(depth-size 16) accum-buffer (accum-red-size 0)
(accum-green-size 0) (accum-blue-size 0) stencil-buffer
(stencil-size 0))
(declare (ignorable
x y rgba double-buffer stereo red-size green-size blue-size
alpha-size depth-size accum-buffer accum-red-size
accum-green-size accum-blue-size stencil-buffer
stencil-size))
(glop-bridge:with-ns-autorelease-pool
(let ((window (glop-bridge:ns-window-alloc-init x y width height)))
(glop-bridge:ns-window-set-background-color
window (glop-bridge:ns-blue-color))
(glop-bridge:ns-window-make-key-and-order-front window))))
23 changes: 22 additions & 1 deletion src/osx/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,25 @@
#:ns-array-count
#:ns-array-object-at-index
#:ns-string-to-lisp
#:ns-application-shared-application))
#:ns-application-shared-application
#:ns-black-color
#:ns-blue-color
#:ns-brown-color
#:ns-cyan-color
#:ns-dark-gray-color
#:ns-gray-color
#:ns-green-color
#:ns-light-gray-color
#:ns-magenta-color
#:ns-orange-color
#:ns-purple-color
#:ns-white-color
#:ns-yellow-color
#:ns-window-alloc-init
#:ns-window-set-background-color
#:ns-window-make-key-and-order-front
#:ns-autorelease-pool-alloc-init
#:ns-autorelease-pool-release
#:with-ns-autorelease-pool
#:ns-string-c-string-using-encoding
#:ns-string-to-lisp-string))
40 changes: 22 additions & 18 deletions src/utils.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,27 @@ Otherwise, only one key-press event will be triggered.")

;; misc.
(defun load-libraries ()
#+(and unix (not darwin))(progn (cffi:define-foreign-library xlib
(t (:default "libX11")))
(cffi:use-foreign-library xlib)
(cffi:define-foreign-library opengl
(t (:default "libGL")))
(cffi:use-foreign-library opengl))
#+(or win32 windows)(progn (cffi:define-foreign-library user32
(t (:default "user32")))
(cffi:use-foreign-library user32)
(cffi:define-foreign-library kernel32
(t (:default "kernel32")))
(cffi:use-foreign-library kernel32)
(cffi:define-foreign-library opengl
(t (:default "opengl32")))
(cffi:use-foreign-library opengl)
(cffi:define-foreign-library gdi32
(t (:default "gdi32")))
(cffi:use-foreign-library gdi32)))
#+(and unix (not darwin))
(progn (cffi:define-foreign-library xlib
(t (:default "libX11")))
(cffi:use-foreign-library xlib)
(cffi:define-foreign-library opengl
(t (:or (:default "libGL")
"libGL.so.1"
"libGL.so.2")))
(cffi:use-foreign-library opengl))
#+(or win32 windows)
(progn (cffi:define-foreign-library user32
(t (:default "user32")))
(cffi:use-foreign-library user32)
(cffi:define-foreign-library kernel32
(t (:default "kernel32")))
(cffi:use-foreign-library kernel32)
(cffi:define-foreign-library opengl
(t (:default "opengl32")))
(cffi:use-foreign-library opengl)
(cffi:define-foreign-library gdi32
(t (:default "gdi32")))
(cffi:use-foreign-library gdi32)))


4 changes: 3 additions & 1 deletion src/x11/glx.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@
(:bad-enum))

(define-foreign-library opengl
(t (:default "libGL")))
(t (:or (:default "libGL")
"libGL.so.1"
"libGL.so.2")))
(use-foreign-library opengl)

(defctype fb-config :pointer)
Expand Down

0 comments on commit 2b55e02

Please sign in to comment.