aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/region.lisp
blob: 4b86aeb30d5048219733c105830d34b57ebf0e8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
;;;; region.lisp

(in-package :wheelwork)

(def:class region ()
  (left bottom top right :prefix :initform 0))

(defmethod width ((region region))
  (- (region-right region) (region-left region)))

(defmethod (setf width) (newval (region region))
  (with-slots (left right) region
    (setf right (+ left newval))))

(defmethod height ((region region))
  (- (region-top region) (region-bottom region)))

(defmethod (setf height) (newval (region region))
  (with-slots (top bottom) region
    (setf top (+ bottom newval))))

(defmethod x ((r region))
  (region-left r))

(defmethod (setf x) (newval (region region))
  (let ((width (width region))) ;;get before change
    (with-slots (left right)
        (setf left newval
              right (+ newval width)))))

(defmethod y ((r region))
  (region-bottom r))

(defmethod (setf y) (newval (region region))
  (let ((height (height region))) ;;get before change
    (with-slots (top bottom) region
      (setf bottom newval
            top (+ newval height)))))