]> git.sesse.net Git - vlc/blob - modules/gui/macosx/misc.m
* ./modules/gui/macosx/aout.m: output more debug info
[vlc] / modules / gui / macosx / misc.m
1 /*****************************************************************************
2  * misc.m: code not specific to vlc
3  *****************************************************************************
4  * Copyright (C) 2003 VideoLAN
5  * $Id: misc.m,v 1.1 2003/01/21 00:47:43 jlj Exp $
6  *
7  * Authors: Jon Lech Johansen <jon-vl@nanocrew.net>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 #include <Cocoa/Cocoa.h>
25
26 #include "misc.h"
27
28 /*****************************************************************************
29  * MPSlider
30  *****************************************************************************/
31
32 @implementation MPSlider
33
34 + (Class)cellClass
35 {
36     return( [MPSliderCell class] );
37 }
38
39 @end
40
41 /*****************************************************************************
42  * MPSliderCell
43  *****************************************************************************/
44
45 @implementation MPSliderCell
46
47 - (id)init
48 {
49     self = [super init];
50
51     if( self != nil )
52     {
53         _bgColor = [[NSColor colorWithDeviceRed: 0.8627451
54                                           green: 0.8784314
55                                            blue: 0.7725490
56                                           alpha: 1.0] retain];
57         _knobColor = [[NSColor blackColor] retain];
58     }
59
60     return( self );
61 }
62
63 - (void)dealloc
64 {
65     [_bgColor release];
66     [_knobColor release];
67     [super dealloc];
68 }
69
70 - (void)setBackgroundColor:(NSColor *)newColor
71 {
72     [_bgColor release];  
73     _bgColor = [newColor retain];
74 }
75
76 - (NSColor *)backgroundColor
77 {
78     return( _bgColor );
79 }
80
81 - (void)setKnobColor:(NSColor *)newColor
82 {
83     [_knobColor release];  
84     _knobColor = [newColor retain];
85 }
86
87 - (NSColor *)knobColor
88 {
89     return( _knobColor );
90 }
91
92 - (void)setKnobThickness:(float)f_value
93 {
94     _knobThickness = f_value;
95 }
96
97 - (float)knobThickness
98 {
99     return( _knobThickness );
100 }
101
102 - (NSSize)cellSizeForBounds:(NSRect)s_rc
103 {
104     return( s_rc.size );
105 }
106
107 - (void)drawWithFrame:(NSRect)s_rc inView:(NSView *)o_view
108 {
109     if( _scFlags.weAreVertical )
110     {
111         s_rc.origin.x = 1; s_rc.size.width -= 3;
112         s_rc.origin.y = 2; s_rc.size.height -= 5;    
113     }
114     else
115     {
116         s_rc.origin.x = 2; s_rc.size.width -= 5;
117         s_rc.origin.y = 1; s_rc.size.height -= 3;
118     }
119
120     [super drawWithFrame: s_rc inView: o_view]; 
121 }
122
123 - (void)drawBarInside:(NSRect)s_rc flipped:(BOOL)b_flipped
124 {
125     NSRect s_arc;
126  
127     s_rc.size.width += (s_rc.origin.x * 2) + 1;
128     s_rc.size.height += (s_rc.origin.y * 2) + 1;
129     s_rc.origin.x = s_rc.origin.y = 0;
130
131     [[NSGraphicsContext currentContext] setShouldAntialias: NO];
132
133     [_bgColor set];
134     NSRectFill( s_rc );
135
136     s_arc = s_rc;
137     s_arc.origin.x += 1.5;
138     s_arc.origin.y += 1.5;
139     s_arc.size.width -= s_arc.origin.x;
140     s_arc.size.height -= s_arc.origin.y;
141     [[_bgColor shadowWithLevel: 0.1] set];
142     [NSBezierPath strokeRect: s_arc];
143
144     s_arc.origin = s_rc.origin;
145     [[NSColor blackColor] set];
146     [NSBezierPath strokeRect: s_arc];
147
148     [[NSGraphicsContext currentContext] setShouldAntialias: YES];
149 }
150
151 - (NSRect)knobRectFlipped:(BOOL)b_flipped
152 {
153     NSSize s_size;
154     NSPoint s_pto;
155     float floatValue;
156
157     floatValue = [self floatValue];
158
159     if( _scFlags.weAreVertical && b_flipped )
160     {
161         floatValue = _maxValue + _minValue - floatValue;
162     }
163
164     floatValue = (floatValue - _minValue) / (_maxValue - _minValue);
165
166     if( _scFlags.weAreVertical )
167     {   
168         s_size = NSMakeSize( _trackRect.size.width, _knobThickness ?
169                              _knobThickness : _trackRect.size.width );
170         s_pto = _trackRect.origin;
171         s_pto.y += (_trackRect.size.height - s_size.height) * floatValue;
172     }
173     else
174     {   
175         s_size = NSMakeSize( _knobThickness ? _knobThickness :
176                              _trackRect.size.height, _trackRect.size.height );
177         s_pto = _trackRect.origin;
178         s_pto.x += (_trackRect.size.width - s_size.width) * floatValue;
179     }
180
181     return NSMakeRect( s_pto.x, s_pto.y, s_size.width, s_size.height );
182 }
183
184 - (void)drawKnob:(NSRect)s_rc
185 {
186     [[NSGraphicsContext currentContext] setShouldAntialias: NO];
187
188     [_knobColor set];
189     NSRectFill( s_rc );
190
191     [[NSGraphicsContext currentContext] setShouldAntialias: YES];
192 }
193
194 @end