macOS: Add VLCHUDTableView
[vlc.git] / modules / gui / macosx / VLCHUDTableHeaderCell.m
blob1161ef575ec8aad82059099a39f317dd78a69379
1 //
2 //  VLCHUDTableHeaderCell.m
3 //  BGHUDAppKit
4 //
5 //  Created by BinaryGod on 6/17/08.
6 //
7 //  Copyright (c) 2008, Tim Davis (BinaryMethod.com, binary.god@gmail.com)
8 //  All rights reserved.
9 //
10 //  Redistribution and use in source and binary forms, with or without modification,
11 //  are permitted provided that the following conditions are met:
13 //              Redistributions of source code must retain the above copyright notice, this
14 //      list of conditions and the following disclaimer.
16 //              Redistributions in binary form must reproduce the above copyright notice,
17 //      this list of conditions and the following disclaimer in the documentation and/or
18 //      other materials provided with the distribution.
20 //              Neither the name of the BinaryMethod.com nor the names of its contributors
21 //      may be used to endorse or promote products derived from this software without
22 //      specific prior written permission.
24 //      THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS AND
25 //      ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 //      WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 //      IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 //      INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 //      BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
30 //      OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 //      WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 //      ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 //      POSSIBILITY OF SUCH DAMAGE.
35 #import "VLCHUDTableHeaderCell.h"
37 @interface NSTableHeaderCell (AppKitPrivate)
38 - (void)_drawSortIndicatorIfNecessaryWithFrame:(NSRect)arg1 inView:(id)arg2;
39 @end
41 @implementation VLCHUDTableHeaderCell
43 #pragma mark Drawing Functions
45 - (instancetype)initWithCoder:(NSCoder *)coder
47     self = [super initWithCoder:coder];
48     if (self) {
49         _cellTextColor = [NSColor whiteColor];
50         _disabledCellTextColor = [NSColor colorWithDeviceRed:1 green:1 blue:1 alpha:0.2f];
51         _tableHeaderCellBorderColor = [NSColor colorWithDeviceRed:0.349f green:0.361f blue:0.388f alpha:1.0f];
52         _tableHeaderCellNormalFill = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.251f green:0.251f blue:0.255f alpha:1.0f]
53                                                                    endingColor:[NSColor colorWithDeviceRed:0.118f green:0.118f blue:0.118f alpha:1.0f]];
54         _tableHeaderCellSelectedFill = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithDeviceRed:0.651f green:0.651f blue:0.655f alpha:1.0f]
55                                                                      endingColor:[NSColor colorWithDeviceRed:0.518f green:0.518f blue:0.518f alpha:1.0f]];
56     }
57     return self;
60 - (id)textColor {
62     return _textColor;
65 - (void)_drawThemeContents:(NSRect)frame highlighted:(BOOL)flag inView:(id)view {
67     // Draw base layer
68     [_tableHeaderCellBorderColor set];
69     NSRectFill(frame);
71     // Adjust fill layer
72     // frame.origin.x += 1;     - Removed to fix Issue #31
73     frame.size.width -= 1;
74     frame.origin.y +=1;
75     frame.size.height -= 2;
77     if(flag) {
78         [_tableHeaderCellSelectedFill drawInRect: frame angle: 90];
79     } else {
80         [_tableHeaderCellNormalFill drawInRect: frame angle: 90];
81     }
83     // Adjust so text aligns correctly
84     frame.origin.x -= 1;
85     frame.size.width += 1;
86     frame.origin.y -= 1;
87     frame.size.height += 2;
89     // REMOVED - Enabling this line draws two sort arrows, frame alignment issue here.
90     //                   Not needed since the Apple drawing routines seem to be updating sort
91     //                   arrows fine.
92     /*if ([self respondsToSelector:@selector(_drawSortIndicatorIfNecessaryWithFrame:inView:)])
93      [super _drawSortIndicatorIfNecessaryWithFrame: frame inView: view];*/
95     frame.origin.y += (NSMidY(frame) - ([[self font] pointSize] /2)) - 2;
96     frame.origin.x += 3;
100     [super drawInteriorWithFrame: frame inView: view];
103 - (void)drawSortIndicatorWithFrame:(NSRect) frame inView:(id) controlView ascending:(BOOL) ascFlag priority:(NSInteger) priInt {
105     frame.origin.y -=1;
106     frame.size.height += 2;
108     if (priInt == 0) {
110         NSRect arrowRect = [self sortIndicatorRectForBounds: frame];
112         // Adjust Arrow rect
113         arrowRect.size.width -= 2;
114         arrowRect.size.height -= 1;
116         NSBezierPath *arrow = [[NSBezierPath alloc] init];
117         NSPoint points[3];
119         if (ascFlag == NO) {
120             // Re-center arrow
121             arrowRect.origin.y -= 2;
122             points[0] = NSMakePoint(NSMinX(arrowRect), NSMinY(arrowRect) +2);
123             points[1] = NSMakePoint(NSMaxX(arrowRect), NSMinY(arrowRect) +2);
124             points[2] = NSMakePoint(NSMidX(arrowRect), NSMaxY(arrowRect));
125         } else {
126             points[0] = NSMakePoint(NSMinX(arrowRect), NSMaxY(arrowRect) -2);
127             points[1] = NSMakePoint(NSMaxX(arrowRect), NSMaxY(arrowRect) -2);
128             points[2] = NSMakePoint(NSMidX(arrowRect), NSMinY(arrowRect));
129         }
131         [arrow appendBezierPathWithPoints: points count: 3];
133         if ([self isEnabled]) {
134             [_cellTextColor set];
135         } else {
136             [_disabledCellTextColor set];
137         }
138         
139         [arrow fill];
140     }
141     
142     frame.origin.y += 1;
143     frame.size.height -= 2;
146 @end