From: <va...@us...> - 2010-06-24 23:12:24
|
Revision: 11551 http://openmsx.svn.sourceforge.net/openmsx/?rev=11551&view=rev Author: vampier Date: 2010-06-24 23:12:17 +0000 (Thu, 24 Jun 2010) Log Message: ----------- Fully implemented text_box function. - removed the line restrictions (previous 10 lines) - added textcolor textsize - minimal text size is automatically set to 9 (scale factor 1) Expanded display_osd_text in osd_menu.tcl: usage: display_osd_text message category {info warning error} Info is the default when no category is given. Modified Paths: -------------- openmsx/trunk/share/scripts/osd_menu.tcl openmsx/trunk/share/scripts/osd_widgets.tcl Modified: openmsx/trunk/share/scripts/osd_menu.tcl =================================================================== --- openmsx/trunk/share/scripts/osd_menu.tcl 2010-06-24 22:07:38 UTC (rev 11550) +++ openmsx/trunk/share/scripts/osd_menu.tcl 2010-06-24 23:12:17 UTC (rev 11551) @@ -10,6 +10,8 @@ variable default_text_color 0x000000ff variable default_select_color "0x0044aa80 0x2266dd80 0x0055cc80 0x44aaff80" variable default_header_text_color 0xff9020ff +variable error_color "0xaa0000e8 0xdd0000e8 0xcc0000e8 0xff0000e8" +variable warning_color "0xaa6600e8 0xdd9900e8 0xcc8800e8 0xffaa00e8" variable is_dingoo [string match *-dingux* $::tcl_platform(osVersion)] @@ -614,7 +616,7 @@ proc menu_load_machine_exec_replace { item } { if { [catch "machine $item" errorText] } { - display_osd_text $errorText + display_osd_text $errorText error } else { menu_close_all } @@ -625,7 +627,7 @@ set err [catch { ${id}::load_machine $item } error_result ] if {$err} { delete_machine $id - display_osd_text "Error starting [utils::get_machine_display_name_by_config_name $item]: $error_result" + display_osd_text "Error starting [utils::get_machine_display_name_by_config_name $item]: $error_result" error } else { menu_close_top activate_machine $id @@ -658,7 +660,7 @@ proc menu_add_extension_exec { item } { if { [catch "ext $item" errorText] } { - display_osd_text $errorText + display_osd_text $errorText error } else { menu_close_all } @@ -739,9 +741,33 @@ return [concat ".." [lsort $dirs2] [lsort $roms]] } -proc display_osd_text { message } { +proc display_osd_text { message {category info} } { + + set category [string tolower $category] + variable default_bg_color - osd_widgets::text_box display_osd_text $message $default_bg_color + variable error_color + variable warning_color + + set bg_color $default_bg_color + + if {$category=="error"} {set bg_color $error_color} + if {$category=="warning"} {set bg_color $warning_color} + + osd_widgets::text_box display_osd_text \ + -text $message \ + -textcolor 0xffffffff \ + -textsize 6 \ + -fill $bg_color \ + -x 3 -y 12 -z 5 -w 314 \ + -scaled true \ + -border 0.5 \ + -clip true \ + -scaled true \ + -rgba 0x000000ff \ + -fadeCurrent 1 \ + -fadeTarget 0 \ + -fadePeriod 5 \ } proc menu_create_ROM_list { path } { Modified: openmsx/trunk/share/scripts/osd_widgets.tcl =================================================================== --- openmsx/trunk/share/scripts/osd_widgets.tcl 2010-06-24 22:07:38 UTC (rev 11550) +++ openmsx/trunk/share/scripts/osd_widgets.tcl 2010-06-24 23:12:17 UTC (rev 11551) @@ -164,40 +164,54 @@ return "" } -proc text_box {name message bg_color} { +set_help_text osd_widgets::box\ +{The command 'osd_widgets::text_box' supports the same parameters as an 'osd_widgets::box' command. +With the following exception: +-text: defines the text to be printer, the text can be 10 lines in height and need to be separate by 'new line' characters. +-textcolor: definses the color of the text +-textsize: defines the font size of the text} + +proc text_box {name args} { + + #default values in case nothing is given + set txt_color 0xffffffff + set txt_size 6 + + # process arguments + set child_props [list] + set parent_props [list] + foreach {key val} $args { + switch -- $key { + -text + {set message $val} + -textcolor + {set txt_color $val} + -textsize + {set txt_size $val} + default + {lappend parent_props $key $val} + } + } + + #for handheld devices set minimal text size to 9 + if {$::scale_factor==1} {set txt_size 9} + if {$message==""} {return "nothing to display"} set message_list [split $message "\n"] set lines [llength $message_list] - if {$lines>10} {return "Text box can hold Max of 10 lines"} - #If widget doesn't exist create it - if {[catch {osd info $name}]} { - osd_widgets::box $name \ - -x 3 -y 12 -z 5 -w 314 \ - -scaled true -rgba 0x000000ff -border 0.5 \ - -clip true -fill $bg_color -scaled true + #If widget exist destroy it + if {![catch {osd info $name}]} {osd destroy $name} + + #todo: adjust calculations to textsize given + eval "osd_widgets::box \{$name\} $parent_props -h [expr 4+(($txt_size+1)*$lines)]" - #create 10 lines - for { set i 0 } { $i <= 10 } { incr i } { - osd create text $name.$i -y 999 -x 2 -size 6 -rgb 0xffffff - } - } - osd configure $name -h [expr 4+(9*$lines)] - - #use the lines which are needed set line 0 foreach message $message_list { - osd configure $name.$line -text "$message" -y [expr 2+($line*9)] + osd create text $name.$line -x 2 -size $txt_size -rgb $txt_color -text "$message" -y [expr 2+($line*($txt_size+1))] incr line } - - #hide the others - for { set i $line } { $i <= 10 } { incr i } { - osd configure $name.$line -y 999 - } - - osd configure display_osd_text -fadeCurrent 1 -fadeTarget 0 -fadePeriod 5 } # only export stuff that is useful in other scripts or for the console user @@ -214,3 +228,4 @@ # only import stuff to global that is useful outside of scripts (i.e. for the console user) namespace import osd_widgets::toggle_fps + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |