1/* 2 PPToolButtonMatrix.m 3 4 Copyright 2013-2018 Josh Freeman 5 http://www.twilightedge.com 6 7 This file is part of PikoPixel for Mac OS X and GNUstep. 8 PikoPixel is a graphical application for drawing & editing pixel-art images. 9 10 PikoPixel is free software: you can redistribute it and/or modify it under 11 the terms of the GNU Affero General Public License as published by the 12 Free Software Foundation, either version 3 of the License, or (at your 13 option) any later version approved for PikoPixel by its copyright holder (or 14 an authorized proxy). 15 16 PikoPixel is distributed in the hope that it will be useful, but WITHOUT ANY 17 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more 19 details. 20 21 You should have received a copy of the GNU Affero General Public License 22 along with this program. If not, see <http://www.gnu.org/licenses/>. 23*/ 24 25#import "PPToolButtonMatrix.h" 26 27#import "NSColor_PPUtilities.h" 28#import "PPUIColors_Panels.h" 29 30 31@implementation PPToolButtonMatrix 32 33- (void) dealloc 34{ 35 [_activeToolCellColor release]; 36 [_inactiveToolCellColor release]; 37 38 [super dealloc]; 39} 40 41- (void) highlightCellWithToolType: (PPToolType) toolType 42{ 43 NSButtonCell *cellToHighlight; 44 45 if (toolType == kPPToolType_ColorRamp) 46 { 47 toolType = kPPToolType_Line; 48 } 49 50 cellToHighlight = [self cellWithTag: (NSInteger) toolType]; 51 52 if (_highlightedCell != cellToHighlight) 53 { 54 [_highlightedCell setBackgroundColor: _inactiveToolCellColor]; 55 56 [cellToHighlight setBackgroundColor: _activeToolCellColor]; 57 58 [self selectCell: cellToHighlight]; 59 60 _highlightedCell = cellToHighlight; 61 } 62} 63 64- (NSButtonCell *) highlightedCell 65{ 66 return _highlightedCell; 67} 68 69- (PPToolType) toolTypeOfSelectedCell 70{ 71 return [self toolTypeOfCell: [self selectedCell]]; 72} 73 74- (PPToolType) toolTypeOfCellAtRow: (NSInteger) row column: (NSInteger) col 75{ 76 return [self toolTypeOfCell: [self cellAtRow: row column: col]]; 77} 78 79- (PPToolType) toolTypeOfCell: (NSCell *) cell 80{ 81 if (!cell) 82 goto ERROR; 83 84 return (PPToolType) [cell tag]; 85 86ERROR: 87 // return invalid PPToolType value 88 return (PPToolType) -1; 89} 90 91#pragma mark NSMatrix overrides 92 93- (void) awakeFromNib 94{ 95 // check before calling [super awakeFromNib] - before 10.6, some classes didn't implement it 96 if ([[PPToolButtonMatrix superclass] instancesRespondToSelector: @selector(awakeFromNib)]) 97 { 98 [super awakeFromNib]; 99 } 100 101 _activeToolCellColor = 102 [[NSColor ppCenteredVerticalGradientPatternColorWithHeight: [self cellSize].height 103 innerColor: kUIColor_ToolsPanel_ActiveToolCellGradientInnerColor 104 outerColor: kUIColor_ToolsPanel_ActiveToolCellGradientOuterColor] 105 retain]; 106 107 _inactiveToolCellColor = [kUIColor_ToolsPanel_InactiveToolCellColor retain]; 108 109 [[self cells] makeObjectsPerformSelector: @selector(setBackgroundColor:) 110 withObject: _inactiveToolCellColor]; 111 112 [self deselectAllCells]; 113} 114 115@end 116