;;; uko-dual-select.el -- scanning modes in UKO-II

;; Copyright (C) 2003 Michael Kuehn, Universität Koblenz-Landau

;; Author: Michael Kuehn <kuehn@uni-koblenz.de>
;; Maintainer: Michael Kuehn <kuehn@uni-koblenz.de>
;; Created: September 2003
;;
;; $Id: uko-dual-select.el,v 1.4 2003/10/10 11:42:17 deee Exp $



;;;; DUAL-SELECT

;;;; Dual-Select allows the use of UKO-II with only two physical switches.
;;;; By default they are set to the keypad numbers 7 and 9.
;;;; they are customizable and can be changed to any other key.
;;;;
;;;; The first button-action selects either the two buttons on the right
;;;; or the two buttons on the left, depending on the button pressed.
;;;; The next button-action makes a selection between the remaining two buttons.
;;;; -----------------------------------------------------------------------


;(defvar uko-dual-select-level 1)

;; define a switch for for left of dual select
(defvar uko-dual-select-physical-switch-a [(kp-4)]
  "Physical switch left for dual select")

;; define a switch for right of dual select
(defvar uko-dual-select-physical-switch-b [(kp-6)]
  "Physical switch right for dual select")

;; default backgound color
(defvar uko-dual-select-default-color "white")

;; default backgound color
(defvar uko-dual-select-default-font-color "black")

;; interactive function to activate dual select mode with the M-x command
(defun uko-dual-select-on ()
  "Interactive function activating scanning."
  (interactive)
  (setq uko-dual-select t)
  (uko-dual-select-initialize)
  )

;; interactive function to deactivate dual select mode with the M-x command
;; sets the customizable variable uko-dual-select to nil
;; deactivates dual select mode
;; turns off the highlighting
(defun uko-dual-select-off ()
  "Interactive function deactivating dual select."
  (interactive)
  (setq uko-dual-select nil)
  (uko-dual-select-hilight-off)
  )

;; initialisation routine for dual-selection mode
;; Set the background colors of the buttons
;; Assign the functions to the buttons
(defun uko-dual-select-initialize ()
  "Perform the necessary initialization steps for dual selection mode."
  (local-set-key uko-dual-select-physical-switch-a 'uko-dual-select-left)
  (local-set-key uko-dual-select-physical-switch-b 'uko-dual-select-right)
   (set-face-background 'default uko-dual-select-hilight-color-left (aref uko-button-windows 1))
   (set-face-foreground 'default uko-dual-select-font-color-left (aref uko-button-windows 1))
   (set-face-background 'default uko-dual-select-hilight-color-left (aref uko-button-windows 2))
   (set-face-foreground 'default uko-dual-select-font-color-left (aref uko-button-windows 2))
   (set-face-background 'default uko-dual-select-hilight-color-right (aref uko-button-windows 3))
   (set-face-foreground 'default uko-dual-select-font-color-right (aref uko-button-windows 3))
   (set-face-background 'default uko-dual-select-hilight-color-right (aref uko-button-windows 0))
   (set-face-foreground 'default uko-dual-select-font-color-right (aref uko-button-windows 0))
   )

;; routine for the case that the two buttons on the left were selected
;; set the background colors of the buttons
;; assign new functions to the buttons to be used in this case
(defun uko-dual-select-left ()
  (interactive)
   (set-face-background 'default uko-dual-select-hilight-color-left (aref uko-button-windows 1))
   (set-face-foreground 'default uko-dual-select-font-color-left (aref uko-button-windows 1))
   (set-face-background 'default uko-dual-select-hilight-color-right (aref uko-button-windows 2))
   (set-face-foreground 'default uko-dual-select-font-color-right (aref uko-button-windows 2))
   (set-face-background 'default uko-dual-select-default-color (aref uko-button-windows 3))
   (set-face-background 'default uko-dual-select-default-color (aref uko-button-windows 0))
  (local-set-key uko-dual-select-physical-switch-a 'uko-dual-select-left-left)
  (local-set-key uko-dual-select-physical-switch-b 'uko-dual-select-left-right)
)

;; routine for the case that the two buttons on the right were selected
;; set the background colors of the buttons
;; assign new functions to the buttons to be used in this case
(defun uko-dual-select-right ()
  (interactive)
   (set-face-background 'default uko-dual-select-hilight-color-left (aref uko-button-windows 3))
   (set-face-foreground 'default uko-dual-select-font-color-left (aref uko-button-windows 3))
   (set-face-background 'default uko-dual-select-hilight-color-right (aref uko-button-windows 0))
   (set-face-foreground 'default uko-dual-select-font-color-right (aref uko-button-windows 0))
   (set-face-background 'default uko-dual-select-default-color (aref uko-button-windows 1))
   (set-face-background 'default uko-dual-select-default-color (aref uko-button-windows 2))
   (set-face-foreground 'default uko-dual-select-default-font-color (aref uko-button-windows 1))
   (set-face-foreground 'default uko-dual-select-default-font-color (aref uko-button-windows 2))
  (local-set-key uko-dual-select-physical-switch-a 'uko-dual-select-right-left)
  (local-set-key uko-dual-select-physical-switch-b 'uko-dual-select-right-right)
)

;; function for the case that the LEFT of the remaining two buttons was selected
;; after the two buttons on the LEFT were selected
(defun uko-dual-select-left-left ()
  (interactive)
  (uko-key-1)
  (uko-dual-select-initialize)
)

;; function for the case that the RIGHT of the remaining two buttons was selected
;; after the two buttons on the LEFT were selected
(defun uko-dual-select-left-right ()
  (interactive)
  (uko-key-2)
  (uko-dual-select-initialize)
)

;; function for the case that the LEFT of the remaining two buttons was selected
;; after the two buttons on the RIGHT were selected
(defun uko-dual-select-right-left ()
  (interactive)
  (uko-key-3)
  (uko-dual-select-initialize)
)

;; function for the case that the RIGHT of the remaining two buttons was selected
;; after the two buttons on the RIGHT were selected
(defun uko-dual-select-right-right ()
  (interactive)
  (uko-key-0)
  (uko-dual-select-initialize)
)

;; turn off all button highlighting. turn on default font color
(defun uko-dual-select-hilight-off ()
   (set-face-background 'default uko-dual-select-default-color (aref uko-button-windows 1))
   (set-face-background 'default uko-dual-select-default-color (aref uko-button-windows 2))
   (set-face-background 'default uko-dual-select-default-color (aref uko-button-windows 3))
   (set-face-background 'default uko-dual-select-default-color (aref uko-button-windows 0))
   (set-face-foreground 'default uko-dual-select-default-font-color (aref uko-button-windows 1))
   (set-face-foreground 'default uko-dual-select-default-font-color (aref uko-button-windows 2))
   (set-face-foreground 'default uko-dual-select-default-font-color (aref uko-button-windows 3))
   (set-face-foreground 'default uko-dual-select-default-font-color (aref uko-button-windows 0))
)
