blob: 06cc3a1ebd8429616b8b2f07c89d0b594e2c872b (
plain)
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
|
//
// PlaylistTableCellView.m
// VKPC
//
// Created by Eugene on 12/2/13.
// Copyright (c) 2013-2014 Eugene Z. All rights reserved.
//
// TODO maybe remove lastDrawed
#import "PlaylistTableCellView.h"
#import "VibrantTextField.h"
static const int kTextFieldNormalX = 17;
static const int kTextFieldPlayingX = 46;
static const int kTitleNormalWidth = 315;
static const int kArtistNormalWidth = 283;
static const int kTitlePlayingWidth = 285;
static const int kArtistPlayingWidth = 253;
@implementation PlaylistTableCellView {
PlayingStatus lastDrawed;
}
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
_playingStatus = PlayingStatusNotPlaying;
lastDrawed = PlayingStatusUndefined;
[self updateStyle];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
_playingStatus = PlayingStatusNotPlaying;
lastDrawed = PlayingStatusUndefined;
[self updateStyle];
}
return self;
}
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
[self drawMode];
}
- (void)setPlayingStatus:(PlayingStatus)playingStatus {
// NSLog(@"view setplayingstatus");
lastDrawed = PlayingStatusUndefined;
_playingStatus = playingStatus;
[self drawMode];
}
- (NSImageView *)playIconImageView {
return [self viewWithTag:0];
}
- (NSTextField *)artistTextField {
return [self viewWithTag:1];
}
- (VibrantTextField *)titleTextField {
return [self viewWithTag:2];
}
- (VibrantTextField *)durationTextField {
return [self viewWithTag:3];
}
- (void)setPlay {
[self.playIconImageView setImage:VKPCGetImagesDictionary()[[[NSUserDefaults standardUserDefaults] boolForKey:VKPCPreferencesInvertPlaylistIcons] == YES ? VKPCImagePause : VKPCImagePlay]];
[self moveTextFields];
}
- (void)setPause {
[self.playIconImageView setImage:VKPCGetImagesDictionary()[[[NSUserDefaults standardUserDefaults] boolForKey:VKPCPreferencesInvertPlaylistIcons] == YES ? VKPCImagePlay : VKPCImagePause]];
[self moveTextFields];
}
- (void)unsetPlay {
[self.playIconImageView setImage:VKPCGetImagesDictionary()[VKPCImageEmpty]];
[self moveTextFields];
}
- (void)moveTextFields {
// NSLog(@"[cellview movetextfields]");
int x, artistWidth, titleWidth;
if (_playingStatus <= PlayingStatusNotPlaying) {
x = kTextFieldNormalX;
artistWidth = kArtistNormalWidth;
titleWidth = kTitleNormalWidth;
} else {
x = kTextFieldPlayingX;
artistWidth = kArtistPlayingWidth;
titleWidth = kTitlePlayingWidth;
}
NSTextField *artist = [self artistTextField];
NSTextField *title = [self titleTextField];
NSRect artistRect = artist.frame;
NSRect titleRect = title.frame;
NSRect newArtistRect = NSMakeRect(x, artistRect.origin.y, artistWidth, artistRect.size.height);
NSRect newTitleRect = NSMakeRect(x, titleRect.origin.y, titleWidth, titleRect.size.height);
[artist setFrame:newArtistRect];
[title setFrame:newTitleRect];
[self setNeedsDisplay:YES];
}
- (void)updateStyle {
switch (GetInterfaceStyle()) {
case InterfaceStyleLegacy:
[self.titleTextField setTextColor:[NSColor colorWithSRGBRed:0.529 green:0.537 blue:0.549 alpha:1]];
[self.durationTextField setTextColor:[NSColor colorWithSRGBRed:0.71 green:0.714 blue:0.718 alpha:1]];
break;
case InterfaceStyleYosemite:
[self.titleTextField setTextColor:[NSColor colorWithSRGBRed:0.0 green:0.0 blue:0.0 alpha:0.35]];
[self.durationTextField setTextColor:[NSColor colorWithSRGBRed:0.0 green:0.0 blue:0.0 alpha:0.17]];
break;
case InterfaceStyleYosemiteDark:
[self.titleTextField setTextColor:[NSColor colorWithSRGBRed:1.0 green:1.0 blue:1.0 alpha:0.28]];
[self.durationTextField setTextColor:[NSColor colorWithSRGBRed:1.0 green:1.0 blue:1.0 alpha:0.15]];
break;
}
}
- (void)drawMode {
// if (lastDrawed != _playingStatus) {
switch (_playingStatus) {
case PlayingStatusNotPlaying:
[self unsetPlay];
break;
case PlayingStatusPaused:
[self setPause];
break;
case PlayingStatusPlaying:
[self setPlay];
break;
default:
break;
}
// }
lastDrawed = _playingStatus;
}
@end
|