~eda-qa/dhlib/main

« back to all changes in this revision

Viewing changes to lib/ui/Dialog.mhx

  • Committer: edA-qa mort-ora-y
  • Date: 2010-04-03 14:56:55 UTC
  • Revision ID: eda-qa@disemia.com-20100403145655-0tfwdswbw3uctiay
improvingĀ appearance

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 */
6
6
package ui;
7
7
 
 
8
import DrawBasicTypes;
 
9
 
8
10
import flash.display.Sprite;
9
11
import flash.display.DisplayObject;
10
12
 
12
14
 * Implements a standard dialog class.  This is meant to be subclasses to create
13
15
 * the real dialog items.
14
16
 */
15
 
class Dialog extends Sprite, implements Window, implements Widget
 
17
class Dialog extends SpriteWidget, implements Window
16
18
{
17
19
        var mainLayout : LinearLayout;
18
20
        var actionLayout : LinearLayout;
21
23
        var fillColor : draw.Color;
22
24
        var rounding : Int;
23
25
        
24
 
        private function new( title : String, body : Widget, ?color : draw.Color )
 
26
        var title : ui.StaticText;
 
27
        private function new( titleStr : String, body : Widget, ?color : draw.Color )
25
28
        {
26
29
                super();
27
 
                MixinWidget();
28
30
                
29
31
                mainBody = body;
30
32
                
31
33
                this.fillColor = if( color == null ) Theme.current.dialogColor else color;
32
 
                rounding = 5;
 
34
                rounding = 4;
33
35
                
34
36
                mainLayout = LinearLayout.vertical();
35
37
                mainLayout.collapseMargin = true;
36
 
                var tf = StaticText.singleLine( title );
37
 
                tf.bold = true;
38
 
                tf.fillColor = fillColor.brighten();
 
38
                title = StaticText.singleLine( titleStr );
 
39
                title.bold = true;
39
40
                
40
 
                mainLayout.add( tf, ui.SizeType.FixedFunc1( FontManager.getDefault().byLines, 1.1  ) );
 
41
                mainLayout.add( title, ui.SizeType.FixedFunc1( FontManager.getDefault().byLines, 1.1  ) );
41
42
                mainLayout.add( body, SizeType.Fill( 0 ) );
42
43
                addChild( mainLayout );
43
44
                
44
45
                actionLayout = LinearLayout.horizontal();
 
46
                actionLayout.spacing =5;
45
47
                actionLayout.collapseMargin = true;
46
48
                actionLayout.add( Box.empty(), SizeType.Fill( 1 ) );
47
49
                mainLayout.add( actionLayout, ui.SizeType.FixedFunc1( FontManager.getDefault().byLines, 1.2 ) );
108
110
                        Action.handle( this, __closeListener );
109
111
        }
110
112
        
111
 
        function _resize( w : Float, h : Float )
 
113
        override function _resize( w : Float, h : Float )
112
114
        {
113
 
                graphics.clear();
114
 
                graphics.beginFill( fillColor.asInt() );
115
 
                graphics.lineStyle( 1, 0 );
116
 
                graphics.drawRoundRect( 0, 0, w, h, 4*rounding );
 
115
                //var l = Math.sqrt( (w*w) + (h*h) );
 
116
                var l = w; //FLASH: distance is along x it seems, not along angle
 
117
                var b = Brush.linearGradient(
 
118
                        Math.PI/4,
 
119
                        [ fillColor, fillColor.adjustBrightness(1.11), 
 
120
                                fillColor, fillColor.adjustBrightness(1.08), 
 
121
                                fillColor, fillColor.adjustBrightness(0.9) ],
 
122
                        [ l*0.05, l*0.25, l*0.45, l * 0.65, l*0.85, l ]
 
123
                        );      
 
124
                gfx.clear();
 
125
                gfx.use( b );
 
126
                gfx.use( Pen.solid( 1, Color.rgb(0,0,0) ) );
 
127
                gfx.drawRoundRect( 0, 0, w, h, 2*rounding, 2*rounding );
117
128
                
118
129
                mainLayout.move( rounding, rounding );
119
130
                mainLayout.resize( w- 2*rounding, h- 2*rounding );
 
131
                
 
132
                var r = Rect2.fromULSizePt( title.getPos(), title.getSize() ).fromWindowToWindow( mainLayout, this );
 
133
                r.height += 2; //TODO: I don't know why this is needed (the text box also exceeds the above size)
 
134
                l = r.height;
 
135
                b = Brush.linearGradient(
 
136
                        Math.PI/2,
 
137
                        [ fillColor.adjustBrightness(1.5), 
 
138
                                fillColor.adjustBrightness(1.2), 
 
139
                        ],
 
140
                        [ 0, l ],
 
141
                        [ 1.0, 0.6 ]
 
142
                        );      
 
143
                gfx.use( b );
 
144
                gfx.use( Pen.empty() );
 
145
                gfx.drawRoundRectPt( r.upperLeft, r.size, Point2.at( rounding, rounding )  );
120
146
        }
121
147
 
122
148
        //with which action did we finish...?
178
204
                resize( sw, sh );       
179
205
        }
180
206
        
181
 
        /*final*/ public function getPrefWidth() : ui.SizeType
 
207
        override public function getPrefWidth() : ui.SizeType
182
208
        {
183
209
                return SizeType.Sum(
184
210
                        SizeType.Fixed( 2 * rounding ),         //for borders
186
212
                        );
187
213
        }
188
214
        
189
 
        /*final*/ public function getPrefHeight() : ui.SizeType
 
215
        override public function getPrefHeight() : ui.SizeType
190
216
        {
191
217
                return 
192
218
                        SizeType.Sum(
199
225
        {
200
226
                return this;
201
227
        }
202
 
 
203
 
        define(`NoSizing',`')
204
 
        include(`MixinWidget.ihx')
205
228
}
 
 
b'\\ No newline at end of file'