#|

Cycle Part Color

Note: This is an example file showing concepts of the Integration Kit. The code itself is not supported and will never be supported.
|#


(in-package :EXAMPLES)
(use-package :OLI)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


(defun new-part-color (&rest args)
  (declare (ignore args))
  (let*
   ((color (sd-rgb-to-hsl (sd-inq-default-part-color))))
   (setf (gpnt3d_x color) (+ (gpnt3d_x color) (/ 1.0 6.0)))
   (when (> (gpnt3d_x color) 1.0)
	 (setf (gpnt3d_x color) (- (gpnt3d_x color) 1.0)))
   (when (= (gpnt3d_y color) 0.0)
	 (setf (gpnt3d_y color) 1.0))
   (SET_DEFAULT_PART_COLOR :hsl color :done)))


(sd-defdialog 'cycle_part_color
  :variables
  '((CYCLE :value-type :boolean
	   :initial-value
	   (member
	    (list 'new-part-color)
	    (sd-unsubscribe-event *SD-CHANGE-CURRENT-OBJECT-EVENT* nil)
	    :test #'equal)))
  :local-functions
  '((doit ()
     (if
      cycle
      (sd-subscribe-event *SD-CHANGE-CURRENT-OBJECT-EVENT* 'new-part-color)
      (progn
       (sd-unsubscribe-event *SD-CHANGE-CURRENT-OBJECT-EVENT* 'new-part-color)
       (sd-call-cmds (SET_DEFAULT_PART_COLOR :hsl 0,0,0.6 :done))))))
  :ok-action '(doit))

;;