]> git.sesse.net Git - vlc/blob - modules/gui/macosx/misc.m
* modules/gui/macosx/misc.?
[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.2 2003/03/13 22:24:17 hartman 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  * VLBrushedMetalImageView
30  *****************************************************************************/
31
32 @implementation VLBrushedMetalImageView
33
34 - (BOOL)mouseDownCanMoveWindow
35 {
36     return YES;
37 }
38
39 @end
40
41
42 /*****************************************************************************
43  * MPSlider
44  *****************************************************************************/
45
46 @implementation MPSlider
47
48 + (Class)cellClass
49 {
50     return( [MPSliderCell class] );
51 }
52
53 @end
54
55 /*****************************************************************************
56  * MPSliderCell
57  *****************************************************************************/
58
59 @implementation MPSliderCell
60
61 - (id)init
62 {
63     self = [super init];
64
65     if( self != nil )
66     {
67         _bgColor = [[NSColor colorWithDeviceRed: 0.8627451
68                                           green: 0.8784314
69                                            blue: 0.7725490
70                                           alpha: 1.0] retain];
71         _knobColor = [[NSColor blackColor] retain];
72     }
73
74     return( self );
75 }
76
77 - (void)dealloc
78 {
79     [_bgColor release];
80     [_knobColor release];
81     [super dealloc];
82 }
83
84 - (void)setBackgroundColor:(NSColor *)newColor
85 {
86     [_bgColor release];  
87     _bgColor = [newColor retain];
88 }
89
90 - (NSColor *)backgroundColor
91 {
92     return( _bgColor );
93 }
94
95 - (void)setKnobColor:(NSColor *)newColor
96 {
97     [_knobColor release];  
98     _knobColor = [newColor retain];
99 }
100
101 - (NSColor *)knobColor
102 {
103     return( _knobColor );
104 }
105
106 - (void)setKnobThickness:(float)f_value
107 {
108     _knobThickness = f_value;
109 }
110
111 - (float)knobThickness
112 {
113     return( _knobThickness );
114 }
115
116 - (NSSize)cellSizeForBounds:(NSRect)s_rc
117 {
118     return( s_rc.size );
119 }
120
121 - (void)drawWithFrame:(NSRect)s_rc inView:(NSView *)o_view
122 {
123     if( _scFlags.weAreVertical )
124     {
125         s_rc.origin.x = 1; s_rc.size.width -= 3;
126         s_rc.origin.y = 2; s_rc.size.height -= 5;    
127     }
128     else
129     {
130         s_rc.origin.x = 2; s_rc.size.width -= 5;
131         s_rc.origin.y = 1; s_rc.size.height -= 3;
132     }
133
134     [super drawWithFrame: s_rc inView: o_view]; 
135 }
136
137 - (void)drawBarInside:(NSRect)s_rc flipped:(BOOL)b_flipped
138 {
139     NSRect s_arc;
140  
141     s_rc.size.width += (s_rc.origin.x * 2) + 1;
142     s_rc.size.height += (s_rc.origin.y * 2) + 1;
143     s_rc.origin.x = s_rc.origin.y = 0;
144
145     [[NSGraphicsContext currentContext] setShouldAntialias: NO];
146
147     [_bgColor set];
148     NSRectFill( s_rc );
149
150     s_arc = s_rc;
151     s_arc.origin.x += 1.5;
152     s_arc.origin.y += 1.5;
153     s_arc.size.width -= s_arc.origin.x;
154     s_arc.size.height -= s_arc.origin.y;
155     [[_bgColor shadowWithLevel: 0.1] set];
156     [NSBezierPath strokeRect: s_arc];
157
158     s_arc.origin = s_rc.origin;
159     [[NSColor blackColor] set];
160     [NSBezierPath strokeRect: s_arc];
161
162     [[NSGraphicsContext currentContext] setShouldAntialias: YES];
163 }
164
165 - (NSRect)knobRectFlipped:(BOOL)b_flipped
166 {
167     NSSize s_size;
168     NSPoint s_pto;
169     float floatValue;
170
171     floatValue = [self floatValue];
172
173     if( _scFlags.weAreVertical && b_flipped )
174     {
175         floatValue = _maxValue + _minValue - floatValue;
176     }
177
178     floatValue = (floatValue - _minValue) / (_maxValue - _minValue);
179
180     if( _scFlags.weAreVertical )
181     {   
182         s_size = NSMakeSize( _trackRect.size.width, _knobThickness ?
183                              _knobThickness : _trackRect.size.width );
184         s_pto = _trackRect.origin;
185         s_pto.y += (_trackRect.size.height - s_size.height) * floatValue;
186     }
187     else
188     {   
189         s_size = NSMakeSize( _knobThickness ? _knobThickness :
190                              _trackRect.size.height, _trackRect.size.height );
191         s_pto = _trackRect.origin;
192         s_pto.x += (_trackRect.size.width - s_size.width) * floatValue;
193     }
194
195     return NSMakeRect( s_pto.x, s_pto.y, s_size.width, s_size.height );
196 }
197
198 - (void)drawKnob:(NSRect)s_rc
199 {
200     [[NSGraphicsContext currentContext] setShouldAntialias: NO];
201
202     [_knobColor set];
203     NSRectFill( s_rc );
204
205     [[NSGraphicsContext currentContext] setShouldAntialias: YES];
206 }
207
208 @end