Changeset 7353


Ignore:
Timestamp:
Oct 5, 2007, 12:41:57 PM (12 years ago)
Author:
af
Message:

Implement a drawing view, add a demo (tiny.lisp)

Also, fix a few things:

  • Titles in windows weren't correct.
  • Extract the content-view functions from window into a mixin.
Location:
branches/easygui/ccl/examples/cocoa/easygui
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • branches/easygui/ccl/examples/cocoa/easygui/easygui.asd

    r7325 r7353  
    2828                 (:file "action-targets" :depends-on ("views"))
    2929                 ;;; example:
    30                  (:file "currency-converter" :depends-on ("new-cocoa-bindings"))))
     30                 (:file "tiny" :depends-on ("action-targets"))
     31                 (:file "currency-converter" :depends-on ("action-targets"))))
  • branches/easygui/ccl/examples/cocoa/easygui/new-cocoa-bindings.lisp

    r7347 r7353  
    11(in-package :easygui)
     2
     3;;; Helper types:
    24
    35(defclass eg-point ()
     
    2123  (ns:make-ns-range (range-start range) (range-end range)))
    2224
     25(defclass eg-rectangle ()
     26     ((x :initarg :x :reader rectangle-x)
     27      (y :initarg :y :reader rectangle-y)
     28      (width :initarg :width :reader rectangle-width)
     29      (height :initarg :height :reader rectangle-height)))
     30
     31(defun rectangle (x y width height)
     32  (assert (>= x 0))
     33  (assert (>= y 0))
     34  (assert (>= width 0))
     35  (assert (>= height 0))
     36  (make-instance 'eg-rectangle :x x :y y :width width :height height))
     37
     38(defun rectangle-nsrect (r)
     39  (ns:make-ns-rect (rectangle-x r) (rectangle-y r)
     40                   (rectangle-width r) (rectangle-height r)))
     41
     42(defun nsrect-rectangle (r)
     43  (rectangle (ns:ns-rect-x r) (ns:ns-rect-y r)
     44             (ns:ns-rect-width r) (ns:ns-rect-height r)))
     45
     46;;;
    2347(defclass easy-cocoa-object ()
    24      ((ref :accessor cocoa-ref)))
     48     ((ref :initarg :cocoa-ref :accessor cocoa-ref)))
    2549
    2650(defvar *window-position-default-x* 200)
  • branches/easygui/ccl/examples/cocoa/easygui/package.lisp

    r7347 r7353  
    22  (:use :cl)
    33  (:import-from :ccl with-autorelease-pool @selector lisp-string-from-nsstring +null-ptr+)
    4   (:export #:point #:range #:window
     4  (:export #:point #:range #:rectangle #:window
     5           #:point-x #:point-y #:rectangle-x #:rectangle-y #:rectangle-width
     6           #:rectangle-height
    57           ;; view classes
    68           #:view #:static-text-view #:text-input-view #:password-input-view
    79           #:push-button-view
    8            #:form-view #:form-cell-view #:box-view
     10           #:form-view #:form-cell-view #:box-view #:drawing-view
    911           ;; operators
     12           #:cocoa-ref
    1013           #:add-subviews #:window-show #:set-window-title
     14           #:content-view
    1115           #:initialize-view #:action #:view-text
    1216           #:add-entry #:add-entries #:editable-p
     17           #:draw-view-rectangle
    1318           #:entry-text #:nth-cell #:selection))
    1419
  • branches/easygui/ccl/examples/cocoa/easygui/views.lisp

    r7347 r7353  
    1818     ((text :initarg :text)))
    1919(defclass view-text-via-stringvalue-mixin (view-text-mixin) ())
    20 (defclass view-text-via-title-mixin (view-text-mixin) ())
     20(defclass view-text-via-title-mixin (view-text-mixin)
     21     ((text :initarg :title)))
    2122
    2223(defmethod view-text ((view view-text-via-stringvalue-mixin))
     
    5758               (ns:ns-range-length range)))))
    5859
    59 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    60 ;;; the actual views (when adding one,
     60(defclass content-view-mixin ()
     61     (content-view))
     62
     63(defmethod initialize-view :after ((view content-view-mixin))
     64  (setf (slot-value view 'content-view)
     65        (make-instance 'view
     66           :cocoa-ref (dcc (#/contentView (cocoa-ref view))))))
     67
     68(defmethod content-view ((view content-view-mixin))
     69  (assert (eql (cocoa-ref (slot-value view 'content-view))
     70               (dcc (#/contentView (cocoa-ref view)))))
     71  (slot-value view 'content-view))
     72
     73(defmethod (setf content-view) (new-content-view (view content-view-mixin))
     74  (setf (slot-value view 'content-view) new-content-view)
     75  (dcc (#/setContentView: (cocoa-ref view) (cocoa-ref new-content-view))))
     76
     77;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     78;;; the actual views (when adding a new class,
    6179;;; consider *view-class-to-ns-class-map*):
    6280
     
    6684      (frame-inited-p :initform nil)))
    6785
    68 (defclass window (view)
     86(defclass window (content-view-mixin view-text-via-title-mixin view)
    6987     ((text :initarg :title :initform "" :reader window-title)
    7088      (zoomable-p :initarg :zoomable-p :initform t :reader window-zoomable-p)
     
    7391      (resizable-p :initarg :resizable-p :initform t
    7492                   :reader window-resizable-p)
    75       (closable-p :initarg :closable-p :initform t :reader window-closable-p)
    76       (content-view :initform nil :reader window-content-view)))
     93      (closable-p :initarg :closable-p :initform t :reader window-closable-p)))
    7794
    7895(defclass static-text-view (view view-text-via-stringvalue-mixin) ())
     
    99116
    100117(defclass form-cell-view (view editable-mixin view-text-via-stringvalue-mixin)
    101      ((ref :initarg :cocoa-ref)))
    102 
    103 (defclass box-view (view) ())
     118     ())
     119
     120(defclass box-view (content-view-mixin view) ())
     121
     122(defclass drawing-view (view) ())
    104123
    105124(defparameter *view-class-to-ns-class-map*
     
    110129                (form-view . ns:ns-form)
    111130                (form-cell-view . ns:ns-form-cell)
    112                 (box-view . ns:ns-box)))
     131                (box-view . ns:ns-box)
     132                (drawing-view . cocoa-drawing-view)))
    113133
    114134;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     
    124144  "Initializes the view via the class-to-ns-class map."
    125145  (when (slot-boundp view 'ref)
    126     (format *trace-output* "hey, it's bound! (on ~A)~%" view)
    127146    (return-from initialize-view nil))
    128147  (let ((ns-view-class (cdr (assoc (class-name (class-of view))
    129                                    *view-class-to-ns-class-map*))))
     148                                   *view-class-to-ns-class-map*
     149                                   :test #'subtypep))))
    130150    (when ns-view-class
    131151      (setf (cocoa-ref view)
     
    165185                                :style-mask style-mask
    166186                                :backing #$NSBackingStoreBuffered ; TODO?
    167                                 :defer nil))
    168        ;; initialize the content-view proxy object
    169        (setf (slot-value win 'content-view)
    170              (make-instance 'view))
    171        (setf (cocoa-ref (window-content-view win))
    172              (dcc (#/contentView (cocoa-ref win)))))))
     187                                :defer nil)))))
    173188
    174189(defmethod initialize-view :after ((view text-input-view))
     
    206221;;; view hierarchies:
    207222
    208 (defmethod add-1-subview :around ((view view) (window window))
    209   (add-1-subview view (window-content-view window)))
     223(defmethod add-1-subview :around ((view view) (cw-view content-view-mixin))
     224  (add-1-subview view (content-view cw-view)))
    210225
    211226(defmethod add-1-subview :around ((view view) (super-view view))
     
    262277  (view-text (nth-cell index view)))
    263278
     279;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
     280;;; Drawing:
     281
     282(defclass cocoa-drawing-view (ns:ns-view)
     283     ((easygui-view :initarg :eg-view :reader easygui-view-of))
     284  (:metaclass ns:+ns-view))
     285
     286(defmethod initialize-view :after ((view drawing-view))
     287  (setf (slot-value (cocoa-ref view) 'easygui-view) view))
     288
     289(objc:defmethod (#/drawRect: :void) ((self cocoa-drawing-view)
     290                                     (rect :<NSR>ect))
     291  (draw-view-rectangle (easygui-view-of self) (nsrect-rectangle rect)))
     292
     293(defgeneric draw-view-rectangle (view rectangle)
     294  (:method ((view drawing-view) rectangle)
     295    (declare (ignore view rectangle))
     296    nil))
Note: See TracChangeset for help on using the changeset viewer.