bitmap.tcl 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # ------------------------------------------------------------------------------
  2. # bitmap.tcl
  3. # This file is part of Unifix BWidget Toolkit
  4. # $Id$
  5. # ------------------------------------------------------------------------------
  6. # Index of commands:
  7. # - Bitmap::get
  8. # - Bitmap::_init
  9. # ------------------------------------------------------------------------------
  10. namespace eval Bitmap {
  11. variable path
  12. variable _bmp
  13. variable _types {
  14. photo .gif
  15. photo .ppm
  16. bitmap .xbm
  17. photo .xpm
  18. }
  19. proc use {} {}
  20. }
  21. # ------------------------------------------------------------------------------
  22. # Command Bitmap::get
  23. # ------------------------------------------------------------------------------
  24. proc Bitmap::get { name } {
  25. variable path
  26. variable _bmp
  27. variable _types
  28. if {[info exists _bmp($name)]} {
  29. return $_bmp($name)
  30. }
  31. # --- Nom de fichier avec extension ------------------------------------------------------
  32. set ext [file extension $name]
  33. if { $ext != "" } {
  34. if { ![info exists _bmp($ext)] } {
  35. error "$ext not supported"
  36. }
  37. if { [file exists $name] } {
  38. if {![string compare $ext ".xpm"]} {
  39. set _bmp($name) [xpm-to-image $name]
  40. return $_bmp($name)
  41. }
  42. if {![catch {set _bmp($name) [image create $_bmp($ext) -file $name]}]} {
  43. return $_bmp($name)
  44. }
  45. }
  46. }
  47. foreach dir $path {
  48. foreach {type ext} $_types {
  49. if { [file exists [file join $dir $name$ext]] } {
  50. if {![string compare $ext ".xpm"]} {
  51. set _bmp($name) [xpm-to-image [file join $dir $name$ext]]
  52. return $_bmp($name)
  53. } else {
  54. if {![catch {set _bmp($name) [image create $type -file [file join $dir $name$ext]]}]} {
  55. return $_bmp($name)
  56. }
  57. }
  58. }
  59. }
  60. }
  61. return -code error "$name not found"
  62. }
  63. # ------------------------------------------------------------------------------
  64. # Command Bitmap::_init
  65. # ------------------------------------------------------------------------------
  66. proc Bitmap::_init { } {
  67. global env
  68. variable path
  69. variable _bmp
  70. variable _types
  71. set path [list "." [file join $env(BWIDGET_LIBRARY) images]]
  72. set supp [image types]
  73. foreach {type ext} $_types {
  74. if { [lsearch $supp $type] != -1} {
  75. set _bmp($ext) $type
  76. }
  77. }
  78. }
  79. Bitmap::_init