~ubuntu-branches/ubuntu/gutsy/amsn/gutsy

« back to all changes in this revision

Viewing changes to utils/scalable-bg/scalable-bg.tcl

  • Committer: Bazaar Package Importer
  • Author(s): Theodore Karkoulis
  • Date: 2006-01-04 15:26:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060104152602-ipe1yg00rl3nlklv
Tags: 0.95-1
New Upstream Release (closes: #345052, #278575).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package require snit
 
2
#package require TkCximage
 
3
package provide scalable-bg 0.1
 
4
 
 
5
snit::type scalable-bg {
 
6
        option -n -configuremethod setOption
 
7
        option -e -configuremethod setOption
 
8
        option -s -configuremethod setOption
 
9
        option -w -configuremethod setOption
 
10
        option -resizemethod
 
11
        option -source -configuremethod setOption
 
12
        option -width -configuremethod setOption -default 1
 
13
        option -height -configuremethod setOption -default 1
 
14
 
 
15
        variable top
 
16
        variable right
 
17
        variable bottom
 
18
        variable left
 
19
        variable centre
 
20
        variable src
 
21
 
 
22
        variable base
 
23
 
 
24
        constructor { args } {
 
25
                $self configurelist $args
 
26
 
 
27
                set base [image create photo -width $options(-width) -height $options(-height)]
 
28
                set left [image create photo -width $options(-w) -height [expr {$options(-height) - $options(-n) - $options(-s)}]]
 
29
                set centre [image create photo -width [expr {$options(-width) - $options(-w) - $options(-e)}] -height [expr {$options(-height) - $options(-n) - $options(-s)}]]
 
30
                set right [image create photo -width $options(-e) -height [expr {$options(-height) - $options(-n) - $options(-s)}]]
 
31
                set top [image create photo -width [expr {$options(-width) - $options(-e)}] -height $options(-n)]
 
32
                set bottom [image create photo -width [expr {$options(-width) - $options(-e)}] -height $options(-n)]
 
33
                set src $options(-source)
 
34
 
 
35
                $self BuildImage
 
36
        }
 
37
 
 
38
        method BuildImage { } {
 
39
                $base configure -width $options(-width) -height $options(-height)
 
40
                #Check if requested size is too small:
 
41
                if {
 
42
                        $options(-width) < [expr {$options(-w) + $options(-e) + 1}] || \
 
43
                        $options(-height) < [expr {$options(-n) + $options(-s) + 1}] || \
 
44
                        [image width $src] < [expr {$options(-w) + $options(-e) + 1}] || \
 
45
                        [image height $src] < [expr {$options(-n) + $options(-s) + 1}]
 
46
                 } {
 
47
                        return
 
48
                } else {
 
49
                        #Resize left section:
 
50
                        $left configure -width $options(-w) \
 
51
                                -height [expr [image height $src] - $options(-n) - $options(-s)]
 
52
                        $left blank
 
53
                        if { [expr {[image height $src] - $options(-s)}] < 0 } { exit }
 
54
                        $left copy $src -from 0 $options(-n) $options(-w) [expr [image height $src] - $options(-s)] -to 0 0
 
55
                        if { $options(-resizemethod) == "scale" } {
 
56
                                ::CxImage::Resize $left $options(-w) [expr {$options(-height) - $options(-n) - $options(-s)}]
 
57
                        }
 
58
                
 
59
                        #Resize middle section:
 
60
                        $centre configure -width [expr {[image width $src] - $options(-w) - $options(-e)}] \
 
61
                                -height [expr {[image height $src] - $options(-n) - $options(-s)}]
 
62
                        $centre blank
 
63
                        $centre copy $src -from $options(-w) $options(-n) [expr {[image width $src] - $options(-e)}] \
 
64
                                [expr {[image height $src] - $options(-s)}] -to 0 0
 
65
                        if { $options(-resizemethod) == "scale" } {
 
66
                                ::CxImage::Resize $centre [expr {$options(-width) - $options(-w) - $options(-e)}] \
 
67
                                        [expr {$options(-height) - $options(-n) - $options(-s)}]
 
68
                        }
 
69
        
 
70
                        #Resize right section:
 
71
                        $right configure -width $options(-e) \
 
72
                                -height [expr {[image height $src] - $options(-n) - $options(-s)}]
 
73
                        $right blank
 
74
                        $right copy $src -from [expr {[image width $src] - $options(-e)}] $options(-n) [image width $src] [expr {[image height $src] - $options(-s)}] -to 0 0
 
75
                        if { $options(-resizemethod) == "scale" } {
 
76
                                ::CxImage::Resize $right $options(-e) [expr {$options(-height) - $options(-n) - $options(-s)}]
 
77
                        }
 
78
        
 
79
                        #Resize top section:
 
80
                        $top configure -width [expr {[image width $src] - $options(-w) - $options(-e)}] -height $options(-n)
 
81
                        $top blank
 
82
                        $top copy $src -from $options(-w) 0 [expr {[image width $src] - $options(-e)}] $options(-n)
 
83
                        if { $options(-resizemethod) == "scale" } {
 
84
                                ::CxImage::Resize $top [expr {$options(-width) - $options(-w) - $options(-e)}] $options(-n)
 
85
                        }
 
86
        
 
87
                        #Resize bottom section:
 
88
                        $bottom configure -width [expr {[image width $src] - $options(-w) - $options(-e)}] -height $options(-s)
 
89
                        $bottom blank
 
90
                        $bottom copy $src -from $options(-w) [expr {[image height $src] - $options(-s)}] \
 
91
                                [expr {[image width $src] - $options(-e)}] [image height $src]
 
92
                        if { $options(-resizemethod) == "scale" } {
 
93
                                ::CxImage::Resize $bottom [expr {$options(-width) - $options(-w) - $options(-e)}] \
 
94
                                        $options(-s)
 
95
                        }
 
96
        
 
97
                        #Build up button image:
 
98
                        $base configure -width $options(-width) -height $options(-height)
 
99
                        $base blank
 
100
                        #NW corner
 
101
                        $base copy $src -from 0 0 $options(-w) $options(-n) -to 0 0
 
102
                        #Top border
 
103
                        $base copy $top -to $options(-w) 0 [expr {$options(-width) - $options(-e)}] $options(-n)
 
104
                        #NE corner
 
105
                        $base copy $src -from [expr {[image width $src] - $options(-e)}] 0 [image width $src] \
 
106
                                $options(-n) -to [expr {$options(-width) - $options(-e)}] 0
 
107
                        #Left border
 
108
                        $base copy $left -to 0 $options(-n) $options(-w) [expr {$options(-height) - $options(-s)}]
 
109
                        #Centre
 
110
                        $base copy $centre -to $options(-w) $options(-n) [expr {$options(-width) - $options(-e)}] \
 
111
                                [expr {$options(-height) - $options(-s)}]
 
112
                        #Right border
 
113
                        $base copy $right -to [expr {$options(-width) - $options(-e)}] $options(-n) $options(-width) \
 
114
                                [expr {$options(-height) - $options(-s)}]
 
115
                        #SW corner
 
116
                        $base copy $src -from 0 [expr {[image height $src] - $options(-s)}] $options(-w) \
 
117
                                [image height $src] -to 0 [expr {$options(-height) - $options(-s)}]
 
118
                        #Bottom border
 
119
                        $base copy $bottom -to $options(-w) [expr {[image height $base] - $options(-s)}] \
 
120
                                [expr {$options(-width) - $options(-e)}] $options(-height)
 
121
                        #SE corner
 
122
                        $base copy $src -from [expr {[image width $src] - $options(-e)}] \
 
123
                                [expr {[image height $src] - $options(-s)}] [image width $src] [image height $src] \
 
124
                                -to [expr {$options(-width) - $options(-e)}] [expr {$options(-height) - $options(-s)}]
 
125
                }
 
126
        }
 
127
 
 
128
        method setOption { option value } {
 
129
                set options($option) $value
 
130
                if {
 
131
                        [info exists top] && \
 
132
                        [info exists right] && \
 
133
                        [info exists bottom] && \
 
134
                        [info exists left] && \
 
135
                        [info exists centre] && \
 
136
                        [info exists src] && \
 
137
                        [info exists base]
 
138
                } {
 
139
                        $self BuildImage
 
140
                }
 
141
        }
 
142
 
 
143
        method name { } {
 
144
                return $base
 
145
        }
 
146
}