/usr/share/openmsx/scripts/load_icons.tcl is in openmsx-data 0.8.2-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | namespace eval load_icons {
set_help_text load_icons \
{Load a different set of OSD icons.
usage: load_icons [<name> [<position>]]
<name> is the name of a directory (share/skins/<name>) that
contains the icon images. If this parameter is not given,
a list of available skins will be printed.
<position> can be one of the following 'bottom', 'top', 'left'
or 'right'. The default depends on the selected skin.
example: load_icons set1 top
}
set_tabcompletion_proc load_icons [namespace code tab_load_icons]
proc tab_load_icons {args} {
set num [llength $args]
if {$num == 2} {
set r1 [glob -nocomplain -tails -type d -directory $::env(OPENMSX_USER_DATA)/skins *]
set r2 [glob -nocomplain -tails -type d -directory $::env(OPENMSX_SYSTEM_DATA)/skins *]
concat $r1 $r2
} elseif {$num == 3} {
list "top" "bottom" "left" "right"
}
}
variable icon_list
variable last_change
variable current_osd_leds_set
variable current_osd_leds_pos
variable current_fade_delay_active
variable current_fade_delay_non_active
variable fade_id
proc trace_icon_status {name1 name2 op} {
variable last_change
global $name1
set icon [string trimleft $name1 ":"]
set last_change($icon) [openmsx_info realtime]
redraw_osd_icons $icon
}
proc redraw_osd_icons {icon} {
variable last_change
variable current_fade_delay_active
variable current_fade_delay_non_active
variable fade_id
global $icon
# handle 'unset' variables (when current msx machine got deleted)
if {[catch {set value [set $icon]}]} {set value false}
if {$value} {
set widget osd_icons.${icon}_on
set widget2 osd_icons.${icon}_off
set fade_delay $current_fade_delay_active($icon)
} else {
set widget osd_icons.${icon}_off
set widget2 osd_icons.${icon}_on
set fade_delay $current_fade_delay_non_active($icon)
}
osd configure $widget2 -fadeCurrent 0 -fadeTarget 0
if {$fade_delay == 0} {
# no fading yet
osd configure $widget -fadeCurrent 1 -fadeTarget 1
} else {
set diff [expr {[openmsx_info realtime] - $last_change($icon)}]
if {$diff < $fade_delay} {
# no fading yet
osd configure $widget -fadeCurrent 1 -fadeTarget 1
catch {
after cancel $fade_id($icon)
}
set fade_id($icon) [after realtime [expr {$fade_delay - $diff}] "load_icons::redraw_osd_icons $icon"]
} else {
# fading out
osd configure $widget -fadeTarget 0
}
}
}
proc load_icons {{set_name "-show"} {position_param "default"}} {
variable icon_list
variable current_osd_leds_set
variable current_osd_leds_pos
variable current_fade_delay_active
variable current_fade_delay_non_active
if {$set_name eq "-show"} {
# Show list of available skins
set user_skins \
[glob -tails -types d -directory $::env(OPENMSX_USER_DATA)/skins *]
set system_skins \
[glob -tails -types d -directory $::env(OPENMSX_SYSTEM_DATA)/skins *]
return [lsort -unique [concat $user_skins $system_skins]]
}
# Check skin directory
# All files belonging to this skin must come from this directory.
# So we don't allow mixing individual files for one skin from the
# system and from the user directory. Though fallback images are
# again searched in both system and user dirs.
set skin_set_dir [data_file "skins/$set_name"]
if {![file isdirectory $skin_set_dir]} {
error "No such icon skin: $set_name"
}
# Check position
if {$position_param ni [list "top" "bottom" "left" "right" "default"]} {
error "Invalid position: $position_param"
}
# Defaut icon positions
set xbase 0
set ybase 0
set xwidth 50
set yheight 30
set xspacing 60
set yspacing 35
set horizontal 1
set fade_delay 5
set fade_duration 5
set scale 2
set position $position_param
# but allow to override these values by the skin script
set icons $icon_list ;# the 'none' skin needs this
set script $skin_set_dir/skin.tcl
if {[file isfile $script]} {source $script}
set invscale [expr {1.0 / $scale}]
set xbase [expr {$xbase * $invscale}]
set ybase [expr {$ybase * $invscale}]
set xwidth [expr {$xwidth * $invscale}]
set yheight [expr {$yheight * $invscale}]
set xspacing [expr {$xspacing * $invscale}]
set yspacing [expr {$yspacing * $invscale}]
# change according to <position> parameter
if {$position eq "default"} {
# script didn't set a default, so we choose a "default default"
set position "bottom"
}
if {$position eq "left"} {
set horizontal 0
} elseif {$position eq "right"} {
set horizontal 0
set xbase [expr {320 - $xwidth}]
} elseif {$position eq "bottom"} {
set ybase [expr {240 - $yheight}]
}
set vertical [expr {!$horizontal}]
proc __try_dirs {skin_set_dir file fallback} {
# don't touch already resolved pathnames
if {[file normalize $file] eq $file} {return $file}
# first look in specified skin-set directory
set f1 [file normalize $skin_set_dir/$file]
if {[file isfile $f1]} {return $f1}
# look for the falback image in the skin directory
set f2 [file normalize $skin_set_dir/$fallback]
if {[file isfile $f2]} {return $f2}
# if it's not there look in the root skin directory
# (system or user directory)
set f3 [file normalize [data_file "skins/$file"]]
if {[file isfile $f3]} {return $f3}
# still not found, look for the fallback image in system and
# user root skin dir
set f4 [file normalize [data_file "skins/$fallback"]]
if {[file isfile $f4]} {return $f4}
return ""
}
# Calculate default parameter values ...
for {set i 0} {$i < [llength $icons]} {incr i} {
set icon [lindex $icons $i]
set xcoord($icon) [expr {$i * $xspacing * $horizontal}]
set ycoord($icon) [expr {$i * $yspacing * $vertical}]
set fade_delay_active($icon) $fade_delay
set fade_delay_non_active($icon) $fade_delay
set fade_duration_active($icon) $fade_duration
set fade_duration_non_active($icon) $fade_duration
switch -glob $icon {
led_* {
set base [string tolower [string range $icon 4 end]]
set image_on "${base}-on.png"
set image_off "${base}-off.png"
set fallback_on "led-on.png"
set fallback_off "led-off.png"
}
throttle {
set image_on ""
set image_off "${icon}.png"
set fallback_on ""
set fallback_off ""
set current_fade_delay_non_active($icon) 0
}
default {
set image_on "${icon}.png"
set image_off ""
set fallback_on ""
set fallback_off ""
set fade_delay_active($icon) 0
}
}
set active_image($icon) [__try_dirs $skin_set_dir $image_on $fallback_on ]
set non_active_image($icon) [__try_dirs $skin_set_dir $image_off $fallback_off]
}
# ... but allow to override these calculated values (again) by the skin script
if {[file isfile $script]} {source $script}
osd configure osd_icons -x $xbase -y $ybase
foreach icon $icon_list {
osd configure osd_icons.${icon}_on \
-x $xcoord($icon) \
-y $ycoord($icon) \
-fadePeriod $fade_duration_active($icon) \
-image [__try_dirs $skin_set_dir $active_image($icon) ""] \
-scale $invscale
osd configure osd_icons.${icon}_off \
-x $xcoord($icon) \
-y $ycoord($icon) \
-fadePeriod $fade_duration_non_active($icon) \
-image [__try_dirs $skin_set_dir $non_active_image($icon) ""] \
-scale $invscale
}
# Also try to load "frame.png"
osd destroy osd_frame
set framefile "$skin_set_dir/frame.png"
if {[file isfile $framefile]} {
osd create rectangle osd_frame -z 0 -x 0 -y 0 -w 320 -h 240 \
-scaled true -image $framefile
}
# If successful, store in settings (order of assignments is important!)
set current_osd_leds_set $set_name
set ::osd_leds_set $set_name
set current_osd_leds_pos $position_param
set ::osd_leds_pos $position_param
foreach icon $icon_list {
set current_fade_delay_active($icon) $fade_delay_active($icon)
set current_fade_delay_non_active($icon) $fade_delay_non_active($icon)
}
# Force redrawing of all icons
foreach icon $icon_list {
redraw_osd_icons $icon
}
return ""
}
proc trace_osd_icon_vars {name1 name2 op} {
variable current_osd_leds_set
variable current_osd_leds_pos
# avoid executing load_icons multiple times
# (because of the assignments to the settings in that proc)
if {($::osd_leds_set eq $current_osd_leds_set) &&
($::osd_leds_pos eq $current_osd_leds_pos)} {
return
}
load_icons $::osd_leds_set $::osd_leds_pos
}
proc machine_switch_osd_icons {} {
variable icon_list
foreach icon $icon_list {
trace remove variable ::$icon "write unset" [namespace code trace_icon_status]
trace add variable ::$icon "write unset" [namespace code trace_icon_status]
redraw_osd_icons $icon
}
after machine_switch [namespace code machine_switch_osd_icons]
}
# Available icons. Icons are also drawn in this order (by default)
set icon_list [list "led_power" "led_caps" "led_kana" "led_pause" "led_turbo" "led_FDD" \
"pause" "throttle" "mute" "breaked"]
# create OSD widgets
osd create rectangle osd_icons -scaled true -alpha 0 -z 1
foreach icon $icon_list {
variable last_change
osd create rectangle osd_icons.${icon}_on -fadeCurrent 0 -fadeTarget 0 -fadePeriod 5.0
osd create rectangle osd_icons.${icon}_off -fadeCurrent 0 -fadeTarget 0 -fadePeriod 5.0
trace add variable ::$icon "write unset" load_icons::trace_icon_status
set last_change($icon) [openmsx_info realtime]
}
namespace export load_icons
} ;# namespace load_icons
namespace import load_icons::*
# Restore settings from previous session
# default is set1, but if only scale_factor 1 is supported, use handheld
if {[lindex [lindex [openmsx_info setting scale_factor] 2] 1] == 1} {
user_setting create string osd_leds_set "Name of the OSD icon set" "handheld"
} else {
user_setting create string osd_leds_set "Name of the OSD icon set" "set1"
}
user_setting create string osd_leds_pos "Position of the OSD icons" "default"
set load_icons::current_osd_leds_set $osd_leds_set
set load_icons::current_osd_leds_pos $osd_leds_pos
trace add variable osd_leds_set write load_icons::trace_osd_icon_vars
trace add variable osd_leds_pos write load_icons::trace_osd_icon_vars
after machine_switch load_icons::machine_switch_osd_icons
load_icons $osd_leds_set $osd_leds_pos
|