~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Open Mash Cross Reference
mash/tcl/vic/ui-visualframe.tcl

Component: ~ [ mash ] ~ [ apps ] ~ [ gsm ] ~ [ lib ] ~ [ otcl ] ~ [ srm ] ~ [ tcl8.3 ] ~ [ tclcl ] ~ [ tk8.3 ] ~ [ tutorials ] ~

  1 # ui-visualframe.tcl --
  2 #
  3 #       FIXME: This file needs a description here.
  4 #
  5 # Copyright (c) 1998-2002 The Regents of the University of California.
  6 # All rights reserved.
  7 #
  8 # Redistribution and use in source and binary forms, with or without
  9 # modification, are permitted provided that the following conditions are met:
 10 #
 11 # A. Redistributions of source code must retain the above copyright notice,
 12 #    this list of conditions and the following disclaimer.
 13 # B. Redistributions in binary form must reproduce the above copyright notice,
 14 #    this list of conditions and the following disclaimer in the documentation
 15 #    and/or other materials provided with the distribution.
 16 # C. Neither the names of the copyright holders nor the names of its
 17 #    contributors may be used to endorse or promote products derived from this
 18 #    software without specific prior written permission.
 19 #
 20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
 21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 23 # ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
 24 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 26 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 27 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 28 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 29 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 30 #
 31 #  @(#) $Header: /usr/mash/src/repository/mash/mash-1/tcl/vic/ui-visualframe.tcl,v 1.10 2003/08/19 19:55:57 aswan Exp $
 32 
 33 
 34 import ErrorWindow Configuration
 35 
 36 #-------------------------------------------------------------------------
 37 # Class:
 38 #   VisualFrame
 39 # Description:
 40 #   This is a tk frame that offers some methods for initializing the
 41 #   visual and colormap and selecting dithering algorithms.
 42 #-------------------------------------------------------------------------
 43 Class VisualFrame -superclass Observable -configuration {
 44         dither Dither
 45         gamma 0.7
 46 }
 47 
 48 
 49 #-------------------------------------------------------------------------
 50 # Method:
 51 #   VisualFrame init
 52 # Description:
 53 #   Initialize the visual, colormap, and dither global variables
 54 #   based on  X resources, available visuals, etc.  Create the
 55 #   specified window as a frame widget and set its visual.  We pick
 56 #   the visual only once and startup -- the user cannot change it
 57 #   interactively.  But the user can change the dithering algorithms
 58 #   interactively constrained to the selected visual
 59 #   Sets the colormap global variable to <i>w</i> since this window
 60 #   will always have the reference colormap.
 61 # Arguments:
 62 #   w -- Tk pathname to the frame to be created.
 63 #-------------------------------------------------------------------------
 64 VisualFrame instproc init {w} {
 65         global V
 66 
 67         $self instvar gamma_ dither_
 68 
 69         Application set colormap_ $w
 70         set dither [$self get_option dither]
 71         if { $dither == "best" } {
 72                 set dither ED
 73         }
 74         if { $dither == "dither" } {
 75                 set dither Dither
 76         }
 77         if { $dither == "gray" } {
 78                 set dither Gray
 79         }
 80         if { $dither == "quantize" } {
 81                 set dither Quant
 82         }
 83         set gamma_ [$self get_option gamma]
 84         if { [lsearch -exact "Dither ED Gray Quant" $dither] < 0 } {
 85                 #FIXME
 86                 puts stderr "[$self get_option appname]: unknown dither: $dither"
 87                 exit 1
 88         }
 89         set visual [$self get_option visual]
 90         if { $visual == "" } {
 91                 set visual [$self lookup_visual]
 92         } elseif { $visual == "pseudocolor" } {
 93                 set visual "pseudocolor 8"
 94         }
 95         set cmap ""
 96         if [$self yesno privateColormap] {
 97                 set cmap "-colormap new"
 98         }
 99         if [catch "frame $w -visual {$visual} $cmap"] {
100                 $self fatal "bad visual: $visual"
101         }
102         if { [winfo depth $w] == 8 } {
103                 set dither_ $dither
104         } else {
105                 set dither_ ""
106         }
107         Application set visual_ $visual
108 
109         if ![$self init_color] {
110                 if { [winfo depth $w] != 8 } {
111                         puts stderr "[$self get_option appname]: internal error: no colors"
112                         exit 2
113                 }
114                 puts stderr \
115                     "[$self get_option appname]: warning: ran out of colors; using private colormap"
116                 destroy $w
117                 frame $w -visual [Application set visual_] -colormap new
118                 if ![$self init_color] {
119                         puts stderr "[$self get_option appname]: internal error: no colors"
120                         exit 2
121                 }
122         }
123 }
124 
125 
126 #-------------------------------------------------------------------------
127 # Method:
128 #   VisualFrame lookup_visual
129 # Description:
130 #   Look through the list of available visuals, and choose
131 #   the best one that vic supports.
132 #-------------------------------------------------------------------------
133 VisualFrame instproc lookup_visual {} {
134         set vlist [winfo visualsavailable .]
135         if { [lsearch -exact $vlist "truecolor 24"] >= 0 || \
136                  [lsearch -exact $vlist "truecolor 32"] >= 0 } {
137                 set visual "truecolor 24"
138         } elseif { [lsearch -exact $vlist "truecolor 16"] >= 0 } {
139                 set visual "truecolor 16"
140         } elseif { [lsearch -exact $vlist "pseudocolor 8"] >= 0 } {
141                 set visual "pseudocolor 8"
142         } elseif { [lsearch -exact $vlist "staticgray 1"] >= 0 } {
143                 set visual "staticgray 1"
144         } else {
145                 puts stderr "[$self get_option appname]: no support for your display type {$vlist}"
146                 exit 1
147         }
148 }
149 
150 #FIXME
151 set vmap(truecolor) TrueColor
152 set vmap(pseudocolor) PseudoColor
153 
154 #-------------------------------------------------------------------------
155 # Method:
156 #   VisualFrame init_color
157 # Description:
158 #   Initialize the colormodel based on the visual, dither, and colormap
159 #   global variables.  If we run out of colors, free the colormodel
160 #   and return false (leaving it up to the caller to fix things);
161 #   otherwise, return true.  Set the global variable colorModel
162 #   to the corresponding tcl object.
163 #-------------------------------------------------------------------------
164 VisualFrame instproc init_color {} {
165         #FIXME
166         global vmap
167 
168         $self instvar dither_ gamma_ colorModel_
169         if [info exists colorModel_] {
170                 delete $colorModel_
171                 unset colorModel_
172         }
173         set colormap [Application set colormap_]
174         set v [winfo visual $colormap]
175         set v $vmap($v)
176         set d [winfo depth $colormap]
177         if { $d == 8 } {
178                 set id $v/$d/$dither_
179         } else {
180                 set id $v/$d
181         }
182         if { $id == "TrueColor/32" } {
183                 set id TrueColor/24
184         }
185         set cm [new Colormodel/$id]
186         if { $cm == "" } {
187                 puts stderr "[$self get_option appname]: unsupported visual type: $v"
188                 exit 1
189         }
190         $cm visual $colormap
191         $cm gamma $gamma_
192         #FIXME revert to gray?
193         if ![$cm alloc-colors] {
194                 delete $cm
195                 return 0
196         }
197         set colorModel_ $cm
198         return 1
199 }
200 
201 
202 #-------------------------------------------------------------------------
203 # Method:
204 #   VisualFrame revert_to_gray
205 # Description:
206 #   Set the dither to gray.
207 #-------------------------------------------------------------------------
208 VisualFrame instproc revert_to_gray {} {
209         $self instvar dither_
210         if { $dither_ == "Gray" } {
211                 #FIXME
212                 puts stderr "[$self get_option appname]: out of colors"
213                 exit 1
214         }
215         new ErrorWindow "ran out of colors; reverting to gray"
216         $self set-dither Gray
217 }
218 
219 
220 #-------------------------------------------------------------------------
221 # Method:
222 #   VisualFrame set-dither
223 # Description:
224 #   Set the dither to <i>d</i>, initialize the colormodel, and reallocate 
225 #   all renderers.
226 #-------------------------------------------------------------------------
227 VisualFrame instproc set-dither {d} {
228         $self instvar dither_
229         set dither_ $d
230         if ![$self init_color] {
231                 $self revert_to_gray
232         }
233         # FIXME crufty way to reallocate all renderers
234         $self notify_observers trigger_format_all
235 }
236 
237 
238 VisualFrame instproc set-gamma {s} {
239         $self instvar colorModel_ gamma_
240         global win_src
241         set cm $colorModel_
242         if ![$cm gamma $s] {
243                 return -1
244         }
245         set gamma_ $s
246         $cm free-colors
247         if ![$cm alloc-colors] {
248                 $self revert_to_gray
249         }
250         #
251         # Need to update all the windows.  Can't just do a redraw
252         # on all the windows because that won't cause the renderer's
253         # to update their copy of the image (which has the old colormap
254         # installed).  Instead, go through all the active decoders and
255         # force them to update all the windows.
256         #
257         foreach src [session active] {
258                 set d [$src handler]
259                 if { $d != "" } {
260                         $d redraw
261                 }
262         }
263 
264         return 0
265 }
266 
267 
268 #-------------------------------------------------------------------------
269 # Method:
270 #   VisualFrame frame
271 # Description:
272 #   Return the pathname to the frame associated with this object.
273 #-------------------------------------------------------------------------
274 VisualFrame instproc frame {} {
275     return [Application set colormap_]
276 }
277 
278 #-------------------------------------------------------------------------
279 # Method:
280 #   VisualFrame colormodel
281 # Description:
282 #   Return the color model.
283 #-------------------------------------------------------------------------
284 VisualFrame instproc colormodel {} {
285     return [$self set colorModel_]
286 }
287 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.