Changeset 7472


Ignore:
Timestamp:
Oct 18, 2007, 3:19:32 PM (13 years ago)
Author:
af
Message:

Add mouse event handling methods to drawing-view.

Allows overriding mouse-up, mouse-down and mouse-dragged, each receiving
sensible keyword arguments.

Location:
branches/easygui/ccl/examples/cocoa/easygui
Files:
1 added
5 edited

Legend:

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

    r7353 r7472  
    2525    :components ((:file "package")
    2626                 (:file "new-cocoa-bindings" :depends-on ("package"))
    27                  (:file "views" :depends-on ("new-cocoa-bindings"))
     27                 (:file "events" :depends-on ("new-cocoa-bindings"))
     28                 (:file "views" :depends-on ("events"))
    2829                 (:file "action-targets" :depends-on ("views"))
    2930                 ;;; example:
  • branches/easygui/ccl/examples/cocoa/easygui/new-cocoa-bindings.lisp

    r7353 r7472  
    33;;; Helper types:
    44
     5;;; point:
    56(defclass eg-point ()
    67     ((x :initarg :x :reader point-x)
     
    1213  (make-instance 'eg-point :x x :y y))
    1314
     15(defmethod print-object ((o eg-point) s)
     16  (print-unreadable-object (o s :identity nil :type t)
     17    (format s "(~,2,F/~,2,F)" (point-x o) (point-y o))))
     18
     19;;; range:
    1420(defclass eg-range ()
    1521     ((start :initarg :start :reader range-start)
     
    107113(defmacro running-on-main-thread ((&key (waitp t)) &body body)
    108114  `(run-on-main-thread ,waitp (lambda () ,@body)))
     115
     116;;; Getting views from objc objects:
     117
     118(defgeneric easygui-view-of (cocoa-view))
  • branches/easygui/ccl/examples/cocoa/easygui/package.lisp

    r7353 r7472  
    99           #:push-button-view
    1010           #:form-view #:form-cell-view #:box-view #:drawing-view
     11           ;; event methods
     12           #:mouse-down #:mouse-dragged #:mouse-up
    1113           ;; operators
    1214           #:cocoa-ref
     
    1618           #:add-entry #:add-entries #:editable-p
    1719           #:draw-view-rectangle
    18            #:entry-text #:nth-cell #:selection))
     20           #:entry-text #:nth-cell #:selection #:redisplay))
    1921
    2022(cl:defpackage :easygui-user
  • branches/easygui/ccl/examples/cocoa/easygui/tiny.lisp

    r7353 r7472  
    55(in-package :easygui-user)
    66
    7 (defclass tiny-demo-drawing-view (drawing-view) ())
     7(defclass tiny-demo-drawing-view (drawing-view) ()
     8  (:default-initargs :accept-key-events-p t))
    89
    910(defconstant short-pi (coerce pi 'short-float))
    10 (defconstant numsides 12)
     11(defparameter numsides 12)
    1112
    1213(defmethod draw-view-rectangle ((view tiny-demo-drawing-view) rectangle)
    1314  (declare (ignore rectangle))
    14   (format *trace-output* "hallo test!~%")
    1515  (let* ((view (cocoa-ref view))
    1616         (bounds (#/bounds view))
     
    3535(defclass tiny-demo-window (window) ()
    3636  (:default-initargs :size (point 400 400)
    37      :position (point 100 350)
    38      :title "Tiny rectangle drawing demo"
    39      :resizable-p nil
    40      :minimizable-p t))
     37    :position (point 100 350)
     38    :title "Tiny rectangle drawing demo"
     39    :resizable-p nil
     40    :minimizable-p t))
    4141
    4242(defmethod initialize-view :after ((window tiny-demo-window))
     
    4444    (setf (content-view window) draw-view)
    4545    (window-show window)))
     46
     47;;; Mouse handling:
     48;;; (Drag up to increase number of points, down to decrease)
     49(defvar *original-point* nil)
     50
     51(defmethod mouse-down ((view tiny-demo-drawing-view) &key location
     52                       &allow-other-keys)
     53  (setf *original-point* location))
     54
     55(defmethod mouse-up ((view tiny-demo-drawing-view) &key location
     56                     &allow-other-keys)
     57  (when *original-point*
     58    (cond ((> (point-y location) (point-y *original-point*))
     59           (incf numsides))
     60          ((< (point-y location) (point-y *original-point*))
     61           (decf numsides)))
     62    (redisplay view)))
  • branches/easygui/ccl/examples/cocoa/easygui/views.lisp

    r7353 r7472  
    120120(defclass box-view (content-view-mixin view) ())
    121121
    122 (defclass drawing-view (view) ())
     122(defclass drawing-view (view)
     123     (
     124      ;; TODO: make this a mixin
     125      (accept-key-events-p :initform nil :initarg :accept-key-events-p
     126                           :accessor accept-key-events-p)))
    123127
    124128(defparameter *view-class-to-ns-class-map*
     
    291295  (draw-view-rectangle (easygui-view-of self) (nsrect-rectangle rect)))
    292296
     297(objc:defmethod (#/acceptsFirstReponder: :boolean) ((view cocoa-drawing-view))
     298  (accept-key-events-p (easygui-view-of view)))
     299
    293300(defgeneric draw-view-rectangle (view rectangle)
    294301  (:method ((view drawing-view) rectangle)
    295302    (declare (ignore view rectangle))
    296303    nil))
     304
     305(defmethod redisplay ((view drawing-view)
     306                      &key rect)
     307  (setf rect (if rect
     308                 (rectangle-nsrect rect)
     309                 (#/bounds (cocoa-ref view))))
     310  (#/setNeedsDisplayInRect: (cocoa-ref view) rect))
     311
     312(define-useful-mouse-event-handling-routines cocoa-drawing-view)
Note: See TracChangeset for help on using the changeset viewer.