-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathMMovieOSD.m
711 lines (619 loc) · 20.9 KB
/
MMovieOSD.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
//
// Movist
//
// Copyright 2006 ~ 2008 Yong-Hoe Kim. All rights reserved.
// Yong-Hoe Kim <[email protected]>
//
// This file is part of Movist.
//
// Movist is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
//
// Movist is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#import "MMovieOSD.h"
#import <OpenGL/CGLContext.h>
@interface MMovieOSD (Private)
- (void)updateShadow;
- (void)updateFont;
- (void)renderString:(NSMutableAttributedString*)string inRect:(NSRect)rect;
- (void)renderImage:(NSImage*)image inRect:(NSRect)rect;
- (void)updateDrawingRect;
@end
////////////////////////////////////////////////////////////////////////////////
@implementation MMovieOSD
- (id)init
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (self = [super init]) {
// shadow
_shadow = [[NSShadow alloc] init];
_shadowNone = [[NSShadow alloc] init];
_shadowColor = [[NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:1] retain];
_shadowBlur = 1.0;
_shadowOffset = 0.0;
_shadowDarkness = 1;
// position & align
_hPosition = OSD_HPOSITION_CENTER;
_vPosition = OSD_VPOSITION_CENTER;
_vPositionPrefs = OSD_VPOSITION_CENTER;
_hMargin = _vMargin = 0.0;
_updateMask = 0;
_lock = [[NSRecursiveLock alloc] init];
}
return self;
}
- (void)dealloc
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
[_lock release];
[_texImage release];
[_font release];
[_fontName release];
[_textColor release];
[_strokeWidth release];
[_strokeWidth2 release];
[_strokeColor release];
[_paragraphStyle release];
[_shadowColor release];
[_shadow release];
[_shadowNone release];
[super dealloc];
}
enum { // for _updateMask
UPDATE_SHADOW = 1 << 0,
UPDATE_FONT = 1 << 1,
UPDATE_TEX_IMAGE = 1 << 2,
UPDATE_TEXTURE = 1 << 3,
UPDATE_DRAWING_RECT = 1 << 4,
};
#define AUTO_SIZE(size, movieWidth) ((size) * (movieWidth) / 640.0)
#define LT_MARGIN(movieWidth) AUTO_SIZE(10, movieWidth) // left/top
#define RB_MARGIN(movieWidth) AUTO_SIZE(15, movieWidth) // right/bottom (larger for shadow-offset)
////////////////////////////////////////////////////////////////////////////////
#pragma mark shadow
- (NSColor*)shadowColor { return _shadowColor; }
- (float)shadowBlur { return _shadowBlur; }
- (float)shadowOffset { return _shadowOffset; }
- (int)shadowDarkness { return _shadowDarkness; }
- (BOOL)setShadowColor:(NSColor*)shadowColor
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (![_shadowColor isEqualTo:shadowColor]) {
[_lock lock];
[_shadowColor release];
_shadowColor = [shadowColor retain];
_updateMask |= UPDATE_SHADOW | UPDATE_TEXTURE;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setShadowBlur:(float)shadowBlur
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (_shadowBlur != shadowBlur) {
[_lock lock];
_shadowBlur = shadowBlur;
_updateMask |= UPDATE_SHADOW | UPDATE_TEXTURE;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setShadowOffset:(float)shadowOffset
{
//TRACE(@"%s", __PRETTY_FUNCTION__);
if (_shadowOffset != shadowOffset) {
[_lock lock];
_shadowOffset = shadowOffset;
_updateMask |= UPDATE_SHADOW | UPDATE_TEXTURE;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setShadowDarkness:(int)darkness
{
assert(0 < darkness);
if (_shadowDarkness != darkness) {
[_lock lock];
_shadowDarkness = darkness;
_updateMask |= UPDATE_SHADOW | UPDATE_TEXTURE;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (void)updateShadow
{
float blur = AUTO_SIZE(_shadowBlur, _autoSizeWidth);
float offset = AUTO_SIZE(_shadowOffset, _autoSizeWidth);
[_shadow setShadowOffset:NSMakeSize(offset, -offset)];
[_shadow setShadowBlurRadius:blur];
[_shadow setShadowColor:_shadowColor];
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark text
- (void)initTextRendering
{
_textColor = [[NSColor colorWithCalibratedRed:1 green:1 blue:1 alpha:1] retain];
_strokeColor = [[NSColor colorWithCalibratedRed:0 green:0 blue:0 alpha:1] retain];
_strokeWidth = [[NSNumber alloc] initWithFloat:10.0];
_strokeWidth2= [[NSNumber alloc] initWithFloat:-0.01];
_paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[_paragraphStyle setLineBreakMode:NSLineBreakByWordWrapping];
[_paragraphStyle setAlignment:NSCenterTextAlignment];
_lineSpacing = 0;
}
- (NSString*)fontName { return _fontName; }
- (float)fontSize { return _fontSize; }
- (NSTextAlignment)textAlignment { return [_paragraphStyle alignment]; }
- (NSColor*)textColor { return _textColor; }
- (NSColor*)strokeColor { return _strokeColor; }
- (float)strokeWidth { return [_strokeWidth floatValue]; }
- (float)lineSpacing { return _lineSpacing; }
- (BOOL)setFontName:(NSString*)name size:(float)size
{
if (![_fontName isEqualToString:name] || _fontSize != size) {
[_lock lock];
[_fontName release];
_fontName = [name retain];
_fontSize = size;
_updateMask |= UPDATE_FONT | UPDATE_TEXTURE | UPDATE_DRAWING_RECT;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (void)updateFont
{
[_font release];
float size = AUTO_SIZE(_fontSize, _autoSizeWidth);
_font = [[NSFont fontWithName:_fontName size:MAX(10.0, size)] retain];
}
- (BOOL)setTextAlignment:(NSTextAlignment)alignment
{
if ([_paragraphStyle alignment] != alignment) {
[_lock lock];
[_paragraphStyle setAlignment:alignment];
_updateMask |= UPDATE_TEXTURE;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setTextColor:(NSColor*)textColor
{
if (![_textColor isEqualTo:textColor]) {
[_lock lock];
[_textColor release];
_textColor = [textColor retain];
_updateMask |= UPDATE_TEXTURE;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setStrokeColor:(NSColor*)strokeColor
{
if (![_strokeColor isEqualTo:strokeColor]) {
[_lock lock];
[_strokeColor release];
_strokeColor = [strokeColor retain];
_updateMask |= UPDATE_TEXTURE;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setStrokeWidth:(float)strokeWidth
{
if ([_strokeWidth floatValue] != -strokeWidth) {
[_lock lock];
[_strokeWidth release];
_strokeWidth = [[NSNumber alloc] initWithFloat:-strokeWidth];
_updateMask |= UPDATE_TEXTURE;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setLineSpacing:(float)lineSpacing
{
if (_lineSpacing != lineSpacing) {
[_lock lock];
_lineSpacing = lineSpacing;
_updateMask |= UPDATE_TEXTURE | UPDATE_DRAWING_RECT;
[_lock unlock];
return TRUE;
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark position
- (unsigned int)hPosition { return _hPosition; }
- (unsigned int)vPosition { return _vPosition; }
- (BOOL)setHPosition:(unsigned int)hPosition
{
if (_hPosition != hPosition) {
[_lock lock];
_hPosition = hPosition;
_updateMask |= UPDATE_DRAWING_RECT;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setVPosition:(unsigned int)vPosition
{
if (_vPosition != vPosition) {
[_lock lock];
_vPosition = vPosition;
_vPositionPrefs = vPosition;
_updateMask |= UPDATE_DRAWING_RECT;
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (void)updateVPosition:(BOOL)displayOnLetterBox
{
if (_vPositionPrefs == OSD_VPOSITION_UBOX) {
_vPosition = (displayOnLetterBox) ? OSD_VPOSITION_UBOX : OSD_VPOSITION_TOP;
_updateMask |= UPDATE_DRAWING_RECT;
}
else if (_vPositionPrefs == OSD_VPOSITION_LBOX) {
// _vPositionPrefs is OSD_VPOSITION_BOTTOM or OSD_VPOSITION_LBOX.
_vPosition = (displayOnLetterBox) ? OSD_VPOSITION_LBOX : OSD_VPOSITION_BOTTOM;
_updateMask |= UPDATE_DRAWING_RECT;
}
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark margin
- (float)hMargin { return _hMargin * 100; }
- (float)vMargin { return _vMargin * 100; }
- (BOOL)setHMargin:(float)hMargin
{
if (_hMargin != hMargin) {
[_lock lock];
_hMargin = hMargin / 100.0f; // percentage
_updateMask |= UPDATE_TEXTURE | UPDATE_DRAWING_RECT; // for line wrapping
[_lock unlock];
return TRUE;
}
return FALSE;
}
- (BOOL)setVMargin:(float)vMargin
{
if (_vMargin != vMargin) {
[_lock lock];
_vMargin = vMargin / 100.0f; // percentage
_updateMask |= UPDATE_DRAWING_RECT;
[_lock unlock];
return TRUE;
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark subtitle sync
- (float)subtitleSync { return _subtitleSync; }
- (void)setSubtitleSync:(float)sync { _subtitleSync = sync; }
////////////////////////////////////////////////////////////////////////////////
#pragma mark making tex-image
- (float)adjustedLineHeight:(float)movieWidth
{
float fontSize = AUTO_SIZE(_fontSize, movieWidth);
//fontSize = MAX(15.0, fontSize);
NSFont* font = [NSFont fontWithName:_fontName size:fontSize];
NSMutableAttributedString* s = [[[NSMutableAttributedString alloc]
initWithString:NSLocalizedString(@"SubtitleTestChar", nil)] autorelease];
[s addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, 1)];
NSSize maxSize = NSMakeSize(1000, 1000);
NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading |
NSStringDrawingUsesDeviceMetrics;
return [s boundingRectWithSize:maxSize options:options].size.height;
}
- (float)adjustedLineSpacing:(float)movieWidth
{
return AUTO_SIZE(_lineSpacing, movieWidth);
}
- (void)renderString:(NSMutableAttributedString*)string inRect:(NSRect)rect
{
//[[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:1.0 alpha:1.0] set];
//NSFrameRect(rect);
float ltMargin = LT_MARGIN(_autoSizeWidth);
float rbMargin = RB_MARGIN(_autoSizeWidth);
rect.origin.x += ltMargin;
rect.origin.y += rbMargin;
rect.size.width -= ltMargin + rbMargin;
rect.size.height -= ltMargin + rbMargin;
// at first, draw with outline & shadow
[_shadow set];
int i, darkness = (0 < [_shadow shadowBlurRadius]) ? _shadowDarkness : 1;
for (i = 0; i < darkness; i++) {
[string drawInRect:rect];
}
// redraw with new-outline & no-shadow for sharpness
[_shadowNone set];
NSRange range = NSMakeRange(0, [string length]);
[string addAttribute:NSStrokeWidthAttributeName
value:_strokeWidth2 range:range];
[string fixAttributesInRange:range];
[string drawInRect:rect];
//[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0] set];
//NSFrameRect(rect);
}
- (void)renderImage:(NSImage*)image inRect:(NSRect)rect
{
//[[NSColor colorWithCalibratedRed:0.0 green:0.0 blue:1.0 alpha:1.0] set];
//NSFrameRect(rect);
float ltMargin = LT_MARGIN(_autoSizeWidth);
float rbMargin = RB_MARGIN(_autoSizeWidth);
rect.origin.x += ltMargin;
rect.origin.y += rbMargin;
rect.size.width -= ltMargin + rbMargin;
rect.size.height -= ltMargin + rbMargin;
[_shadow set];
int i, darkness = (0 < [_shadow shadowBlurRadius]) ? _shadowDarkness : 1;
for (i = 0; i < darkness; i++) {
[image drawInRect:rect fromRect:NSZeroRect
operation:NSCompositeSourceOver fraction:1.0];
}
//[[NSColor colorWithCalibratedRed:1.0 green:0.0 blue:0.0 alpha:1.0] set];
//NSFrameRect(rect);
}
- (NSImage*)makeTexImageForString:(NSAttributedString*)string
{
if (!string || [[string string] isEqualToString:@""]) {
return nil;
}
[_lock lock];
if (_updateMask & UPDATE_SHADOW) {
_updateMask &= ~UPDATE_SHADOW;
[self updateShadow];
}
if (_updateMask & UPDATE_FONT) {
_updateMask &= ~UPDATE_FONT;
[self updateFont];
}
// set attributes : font & shadow should be applied before calculating size
NSMutableAttributedString* s = [[string mutableCopy] autorelease];
[_paragraphStyle setLineSpacing:AUTO_SIZE(_lineSpacing, _autoSizeWidth)];
[s applyFont:_font textColor:_textColor strokeColor:_strokeColor
strokeWidth:_strokeWidth paragraphStyle:_paragraphStyle];
NSSize maxSize = _movieRect.size;
maxSize.width -= (maxSize.width * _hMargin) * 2;
NSStringDrawingOptions options = NSStringDrawingUsesLineFragmentOrigin |
NSStringDrawingUsesFontLeading |
NSStringDrawingUsesDeviceMetrics;
NSSize size = [s boundingRectWithSize:maxSize options:options].size;
// add margins for outline & shadow
float ltMargin = LT_MARGIN(_autoSizeWidth);
float rbMargin = RB_MARGIN(_autoSizeWidth);
size.width += ltMargin + rbMargin;
size.height += ltMargin + rbMargin;
NSImage* img = [[NSImage alloc] initWithSize:size];
[img setCacheMode:NSImageCacheNever];
[img lockFocus];
[self renderString:s inRect:NSMakeRect(0, 0, size.width, size.height)];
[img unlockFocus];
[_lock unlock];
return [img autorelease];
}
- (NSImage*)makeTexImageForImage:(NSImage*)image
{
if (!image) {
return nil;
}
[_lock lock];
if (_updateMask & UPDATE_SHADOW) {
_updateMask &= ~UPDATE_SHADOW;
[self updateShadow];
}
NSSize size;
NSSize imageSize = [image size];
if (0 < _imageBaseWidth) {
size.width = imageSize.width * _movieRect.size.width / _imageBaseWidth;
size.width *= MAX(10.0, _fontSize) / 24.0;
size.height = imageSize.height * size.width / imageSize.width;
}
else if (imageSize.width < _movieRect.size.width &&
imageSize.height< _movieRect.size.height) {
size = imageSize;
}
else {
float minSize = MIN(_movieRect.size.width, _movieRect.size.height);
if (imageSize.width < imageSize.height) {
size.width = imageSize.width * minSize / imageSize.height;
size.height = imageSize.height * minSize / imageSize.width;
}
else {
size.width = imageSize.width * minSize / imageSize.height;
size.height = imageSize.height * minSize / imageSize.width;
}
}
// add margins for outline & shadow
float ltMargin = LT_MARGIN(_autoSizeWidth);
float rbMargin = RB_MARGIN(_autoSizeWidth);
size.width += ltMargin + rbMargin;
size.height += ltMargin + rbMargin;
NSImage* img = [[NSImage alloc] initWithSize:size];
[img setCacheMode:NSImageCacheNever];
[img lockFocus];
[self renderImage:image inRect:NSMakeRect(0, 0, size.width, size.height)];
[img unlockFocus];
[_lock unlock];
return [img autorelease];
}
- (BOOL)setString:(NSAttributedString*)string
{
if (![_string isEqualToAttributedString:string]) {
[string retain], [_string release], _string = string;
_updateMask |= UPDATE_TEX_IMAGE;
return TRUE;
}
return FALSE;
}
- (BOOL)setImage:(NSImage*)image
{
if (![_image isEqualTo:image]) {
[image retain], [_image release], _image = image;
_updateMask |= UPDATE_TEX_IMAGE;
return TRUE;
}
return FALSE;
}
- (BOOL)setImageBaseWidth:(float)baseWidth
{
if (_imageBaseWidth != baseWidth) {
_imageBaseWidth = baseWidth;
_updateMask |= UPDATE_TEX_IMAGE;
return TRUE;
}
return FALSE;
}
- (void)clearContent
{
[_texImage release], _texImage = nil;
[_string release], _string = nil;
[_image release], _image = nil;
_updateMask &= ~UPDATE_TEX_IMAGE;
_updateMask &= ~UPDATE_TEXTURE;
_updateMask &= ~UPDATE_DRAWING_RECT;
}
////////////////////////////////////////////////////////////////////////////////
#pragma mark drawing
- (BOOL)hasContent { return _texImage || (_updateMask & UPDATE_TEX_IMAGE); }
- (NSImage*)texImage { return _texImage; }
- (BOOL)setTexImage:(NSImage*)texImage
{
if (_texImage != texImage) {
[texImage retain], [_texImage release], _texImage = texImage;
_updateMask |= UPDATE_TEXTURE | UPDATE_DRAWING_RECT;
_updateMask &= ~UPDATE_TEX_IMAGE;
return TRUE;
}
return FALSE;
}
- (void)updateDrawingRect
{
float hmargin = _movieRect.size.width * _hMargin;
float vmargin = _movieRect.size.height* _vMargin;
float ltMargin = LT_MARGIN(_autoSizeWidth);
float rbMargin = RB_MARGIN(_autoSizeWidth);
NSRect mr = _movieRect;
mr.origin.x += hmargin;
mr.size.width -= hmargin * 2;
if (mr.origin.x < _viewBounds.origin.x) {
mr.origin.x = _viewBounds.origin.x;
mr.size.width = _viewBounds.size.width;
}
if (mr.origin.y < _viewBounds.origin.y) {
mr.origin.y = _viewBounds.origin.y;
mr.size.height = _viewBounds.size.height;
}
NSRect rect;
rect.size = [_texImage size];
// horizontal position
switch (_hPosition) {
case OSD_HPOSITION_LEFT :
rect.origin.x = mr.origin.x;
rect.origin.x -= ltMargin;
break;
case OSD_HPOSITION_CENTER :
rect.origin.x = mr.origin.x + (mr.size.width - rect.size.width) / 2;
rect.origin.x += (rbMargin - ltMargin) / 2;
break;
case OSD_HPOSITION_RIGHT :
rect.origin.x = mr.origin.x + mr.size.width - rect.size.width;
rect.origin.x += rbMargin;
break;
}
// vertical position : rect is flipped
float tm = NSMinY(_viewBounds) + NSMaxY(_viewBounds) - NSMaxY(mr);
switch (_vPosition) {
case OSD_VPOSITION_UBOX :
rect.origin.y = tm - vmargin - rect.size.height;
rect.origin.y += rbMargin;
float minContentY = NSMinY(rect) + ltMargin;
float minBoundsY = NSMinY(_viewBounds);
if (minContentY < minBoundsY) {
rect.origin.y += minBoundsY - minContentY;
}
break;
case OSD_VPOSITION_TOP :
rect.origin.y = tm + vmargin;
rect.origin.y -= ltMargin;
break;
case OSD_VPOSITION_CENTER :
rect.origin.y = tm + (mr.size.height - rect.size.height) / 2;
rect.origin.y += (rbMargin - ltMargin) / 2;
break;
case OSD_VPOSITION_BOTTOM :
rect.origin.y = (tm + mr.size.height) - vmargin - rect.size.height;
rect.origin.y += rbMargin;
break;
case OSD_VPOSITION_LBOX :
rect.origin.y = (tm + mr.size.height) + vmargin;
rect.origin.y -= ltMargin;
float maxContentY = NSMaxY(rect) - rbMargin;
float maxBoundsY = NSMaxY(_viewBounds);
if (maxBoundsY < maxContentY) {
rect.origin.y -= maxContentY - maxBoundsY;
}
break;
}
_drawingRect = rect;
}
- (BOOL)setViewBounds:(NSRect)viewBounds movieRect:(NSRect)movieRect
autoSizeWidth:(float)autoSizeWidth
{
if (!NSEqualRects(_viewBounds, viewBounds) ||
!NSEqualRects(_movieRect, movieRect) ||
_autoSizeWidth != autoSizeWidth) {
_viewBounds = viewBounds;
_movieRect = movieRect;
_autoSizeWidth = MAX(autoSizeWidth, _movieRect.size.width);
if (_string || _image) {
_updateMask |= UPDATE_TEX_IMAGE;
}
_updateMask |= UPDATE_SHADOW | UPDATE_FONT | UPDATE_TEXTURE | UPDATE_DRAWING_RECT;
return TRUE;
}
return FALSE;
}
- (void)drawOnScreen
{
//TRACE(@"%s %@", __PRETTY_FUNCTION__, NSStringFromRect(viewBounds));
if (_updateMask & UPDATE_TEX_IMAGE) {
_updateMask &= ~UPDATE_TEX_IMAGE;
if (_string) {
[self setTexImage:[self makeTexImageForString:_string]];
}
else if (_image) {
[self setTexImage:[self makeTexImageForImage:_image]];
}
else {
[self setTexImage:nil];
}
}
if (_updateMask & UPDATE_TEXTURE) {
_updateMask &= ~UPDATE_TEXTURE;
// We're not using OpenGL for display anymore
}
if (_updateMask & UPDATE_DRAWING_RECT) {
_updateMask &= ~UPDATE_DRAWING_RECT;
[self updateDrawingRect];
}
}
@end