# clrpick.tcl --
#
# Color selection dialog for platforms that do not support a
# standard color selection dialog.
#
# SCCS: @(#) clrpick.tcl 1.3 96/09/05 09:59:24
#
# Copyright (c) 1996 Sun Microsystems, Inc.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# ToDo:
#
# (1): Find out how many free colors are left in the colormap and
# don't allocate too many colors.
# (2): Implement HSV color selection.
#
# tkColorDialog --
#
# Create a color dialog and let the user choose a color. This function
# should not be called directly. It is called by the tk_chooseColor
# function when a native color selector widget does not exist
#
global tkPriv
set w .__tk__color
upvar #0 $w data
# The lines variables track the start and end indices of the line
# elements in the colorbar canvases.
# This is the actual number of lines that are drawn in each color strip.
# Note that the bars may be of any width.
# However, NUM_COLORBARS must be a number that evenly divides 256.
# Such as 256, 128, 64, etc.
# BARS_WIDTH is the number of pixels wide the color bar portion of the
# canvas is. This number must be a multiple of NUM_COLORBARS
# PLGN_WIDTH is the number of pixels wide of the triangular selection
# polygon. This also results in the definition of the padding on the
# left and right sides which is half of PLGN_WIDTH. Make this number even.
# PLGN_HEIGHT is the height of the selection polygon and the height of the
# selection rectangle at the bottom of the color bar. No restrictions.
}
# 5. Withdraw the window, then update all the geometry information
# so we know how big it wants to be, then center the window in the
# display and de-iconify it.
update idletasks
# 6. Set a grab and claim the focus too.
set oldFocus [focus]
}
grab $w
# 7. Wait for the user to respond, then restore the focus and
# return the index of the selected button. Restore the focus
# before deleting the window, since otherwise the window manager
# may take the focus away so we can't redirect it. Finally,
# restore any grab that was in effect.
tkwait variable tkPriv(selectColor)
catch {focus $oldFocus}
destroy $w
unset data
grab -global $oldGrab
} else {
grab $oldGrab
}
}
return $tkPriv(selectColor)
}
# tkColorDialog_InitValues --
#
# Get called during initialization or when user resets NUM_COLORBARS
#
upvar #0 $w data
# IntensityIncr is the difference in color intensity between a colorbar
# and its neighbors.
# ColorbarWidth is the width of each colorbar
set data(colorbarWidth) \
# Indent is the width of the space at the left and right side of the
# colorbar. It is always half the selector polygon width, because the
# polygon extends into the space.
#
# minX is the x coordinate of the first colorbar
#
#
# maxX is the x coordinate of the last colorbar
#
#
# canvasWidth is the width of the entire canvas, including the indents
#
$data(PLGN_WIDTH)]
# Set the initial color, specified by -initialcolor, or the
# color chosen by the user the last time.
}
# tkColorDialog_Config --
#
# Parses the command line arguments to tk_chooseColor
#
global tkPriv
upvar #0 $w data
# 1: the configuration specs
#
set specs {
{-initialcolor "" "" ""}
{-parent "" "" "."}
{-title "" "" "Color"}
}
# 2: parse the arguments
#
}
} else {
}
} else {
error $err
}
}
error "bad window path name \"$data(-parent)\""
}
}
# tkColorDialog_BuildDialog --
#
# Build the dialog.
#
upvar #0 $w data
# TopFrame contains the color strips and the color selection
#
# StripsFrame contains the colorstrips and the individual RGB entries
# each f frame contains an [R|G|B] entry and the equiv. color strip.
# The box frame contains the label and entry widget for an [R|G|B]
set height [expr \
"tkColorDialog_DrawColorScale $w $color 1"
"tkColorDialog_EnterColorBar $w $color"
"tkColorDialog_LeaveColorBar $w $color"
"tkColorDialog_EnterColorBar $w $color"
"tkColorDialog_LeaveColorBar $w $color"
}
# The selFrame contains a frame that demonstrates the currently
# selected color
#
# the botFrame frame contains the buttons
#
-command "tkColorDialog_OkCmd $w"
-command "tkColorDialog_CancelCmd $w"
# Accelerator bindings
}
# tkColorDialog_SetRGBValue --
#
# Sets the current selection of the dialog box
#
upvar #0 $w data
# Now compute the new x value of each colorbars pointer polygon
}
}
# tkColorDialog_XToRgb --
#
# Converts a screen coordinate to intensity
#
upvar #0 $w data
}
# tkColorDialog_RgbToX
#
# Converts an intensity to screen coordinate.
#
upvar #0 $w data
}
# tkColorDialog_DrawColorScale --
#
# Draw color scale is called whenever the size of one of the color
# scale canvases is changed.
#
global lines
upvar #0 $w data
# col: color bar canvas
# sel: selector canvas
# First handle the case that we are creating everything for the first time.
if $create {
# First remove all the lines that already exist.
}
}
# Delete the selector if it exists
}
# Draw the selection polygons
"tkColorDialog_StartMove $w $sel $c %x $data(selPad) 1"
"tkColorDialog_MoveSelector $w $sel $c %x $data(selPad)"
"tkColorDialog_ReleaseMouse $w $sel $c %x $data(selPad)"
# Create an invisible region under the colorstrip to catch mouse clicks
# that aren't on the selector.
"tkColorDialog_StartMove $w $sel $c %x $data(colorPad)"
"tkColorDialog_MoveSelector $w $sel $c %x $data(colorPad)"
"tkColorDialog_ReleaseMouse $w $sel $c %x $data(colorPad)"
"tkColorDialog_StartMove $w $sel $c %x $data(selPad)"
"tkColorDialog_MoveSelector $w $sel $c %x $data(selPad)"
"tkColorDialog_ReleaseMouse $w $sel $c %x $data(selPad)"
} else {
# l is the canvas index of the first colorbar.
}
# Draw the color bars.
set highlightW [expr \
set color [format "#%02x%02x%02x" \
$intensity \
set color [format "#%02x%02x%02x" \
$intensity \
} else {
set color [format "#%02x%02x%02x" \
}
if $create {
} else {
incr l
}
}
if $create {
}
}
# tkColorDialog_CreateSelector --
#
# Creates and draws the selector polygon at the position
# $data($c,intensity).
#
upvar #0 $w data
}
# tkColorDialog_RedrawFinalColor
#
# Combines the intensities of the three colors into the final color
#
upvar #0 $w data
}
# tkColorDialog_RedrawColorBars --
#
# Only redraws the colors on the color strips that were not manipulated.
# Params: color of colorstrip that changed. If color is not [red|green|blue]
# Then all colorstrips will be updated
#
upvar #0 $w data
switch $colorChanged {
red {
}
green {
}
blue {
}
default {
}
}
}
#----------------------------------------------------------------------
# Event handlers
#----------------------------------------------------------------------
# tkColorDialog_StartMove --
#
# Handles a mousedown button event over the selector polygon.
# Adds the bindings for moving the mouse while the button is
# pressed. Sets the binding for the button-release event.
#
# Params: sel is the selector canvas window, color is the color of the strip.
#
upvar #0 $w data
if !$dontMove {
}
}
# tkColorDialog_MoveSelector --
#
# Moves the polygon selector so that its middle point has the same
# x value as the specified x. If x is outside the bounds [0,255],
# the selector is set to the closest endpoint.
#
# Params: sel is the selector canvas, c is [red|green|blue]
# x is a x-coordinate.
#
upvar #0 $w data
}
# Return the x value that it was actually set at
return $x
}
# tkColorDialog_ReleaseMouse
#
# Removes mouse tracking bindings, updates the colorbars.
#
# Params: sel is the selector canvas, color is the color of the strip,
# x is the x-coord of the mouse.
#
upvar #0 $w data
# Determine exactly what color we are looking at.
}
# tkColorDialog_ResizeColorbars --
#
# Completely redraws the colorbars, including resizing the
# colorstrips
#
upvar #0 $w data
}
}
}
# tkColorDialog_HandleSelEntry --
#
# Handles the return keypress event in the "Selection:" entry
#
upvar #0 $w data
# Check to make sure that the color is valid
return
}
set data(selection) $text
}
# tkColorDialog_HandleRGBEntry --
#
# Handles the return keypress event in the R, G or B entry
#
upvar #0 $w data
if [catch {
}] {
}
}
}
}
$data(blue,intensity)"
}
# mouse cursor enters a color bar
#
upvar #0 $w data
}
# mouse leaves enters a color bar
#
upvar #0 $w data
}
# user hits OK button
#
global tkPriv
upvar #0 $w data
}
# user hits Cancel button
#
global tkPriv
}