-
Notifications
You must be signed in to change notification settings - Fork 3
/
color-objects.lisp
90 lines (73 loc) · 3.71 KB
/
color-objects.lisp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
;;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: FM-PLUGIN-TOOLS; Base: 10 -*-
;;; $Header: /usr/local/cvsrep/fm-plugin-tools/color-objects.lisp,v 1.5 2010/07/22 09:38:05 edi Exp $
;;; Copyright (c) 2006-2010, Dr. Edmund Weitz. All rights reserved.
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; * Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; * Redistributions in binary form must reproduce the above
;;; copyright notice, this list of conditions and the following
;;; disclaimer in the documentation and/or other materials
;;; provided with the distribution.
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR 'AS IS' AND ANY EXPRESSED
;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;;; DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
;;; GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;;; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
;;; WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(in-package :fm-plugin-tools)
(defclass color-object (fm-object)
()
(:documentation "A COLOR-OBJECT is a Lisp object which is a proxy
for a FileMaker `Color' object."))
(defmethod fm-delete ((color-object color-object))
"Deletes the Color \(C++) object which is proxied by COLOR-OBJECT."
(fm-color-delete (pointer color-object)))
(defun make-color-object (&key (red 255) (green 255) (blue 255) (alpha 255))
"Creates and returns a COLOR-OBJECT with color channels
corresponding to RED, GREEN, BLUE, and ALPHA."
(let (ptr)
(handler-bind
((error (lambda (cond)
(declare (ignore cond))
;; delete object if something bad happens during
;; creation
(when ptr
(ignore-errors
(fm-color-delete ptr))))))
(setq ptr (fm-color-constructor2 red green blue alpha))
(make-instance 'color-object :pointer ptr))))
(defmethod red ((color-object color-object))
"Returns the red component of COLOR-OBJECT."
(fm-color-get-red (pointer color-object)))
(defmethod (setf red) (new-value (color-object color-object))
"Sets the red component of COLOR-OBJECT to RED."
(fm-color-set-red (pointer color-object) new-value)
new-value)
(defmethod green ((color-object color-object))
"Returns the green component of COLOR-OBJECT."
(fm-color-get-green (pointer color-object)))
(defmethod (setf green) (new-value (color-object color-object))
"Sets the green component of COLOR-OBJECT to GREEN."
(fm-color-set-green (pointer color-object) new-value)
new-value)
(defmethod blue ((color-object color-object))
"Returns the blue component of COLOR-OBJECT."
(fm-color-get-blue (pointer color-object)))
(defmethod (setf blue) (new-value (color-object color-object))
"Sets the blue component of COLOR-OBJECT to BLUE."
(fm-color-set-blue (pointer color-object) new-value)
new-value)
(defmethod alpha ((color-object color-object))
"Returns the alpha component of COLOR-OBJECT."
(fm-color-get-alpha (pointer color-object)))
(defmethod (setf alpha) (new-value (color-object color-object))
"Sets the alpha component of COLOR-OBJECT to ALPHA."
(fm-color-set-alpha (pointer color-object) new-value)
new-value)