Commit 958cd073 authored by Kateryna Kostiuk's avatar Kateryna Kostiuk

Icon Button: add functionality

Add property to select button image color and category to track
button on hover

Change-Id: I13c144c1f31741f65239106dd22167e88312b80b
parent 33089875
......@@ -211,6 +211,8 @@ SET(ringclient_VIEWS
src/views/SendMessageCell.mm
src/views/SendMessagePanel.h
src/views/SendMessagePanel.mm
src/views/HoverButton.h
src/views/HoverButton.mm
)
SET(ringclient_OTHERS
......
/*
* Copyright (C) 2017 Savoir-faire Linux Inc.
* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
*
* This program 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.
*
* This program 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "IconButton.h"
@interface HoverButton : IconButton {
@private
NSTrackingArea *trackingArea;
}
/*
* Background color of the button when mouse inside
* default value : [NSColor ringBlue]
*/
@property (nonatomic, strong) NSColor* hoverColor;
/*
* Background color of the button when mouse outside
* default value : [NSColor clearColor];
*/
@property (nonatomic, strong) NSColor* mouseOutsideColor;
@end
/*
* Copyright (C) 2017 Savoir-faire Linux Inc.
* Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
*
* This program 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.
*
* This program 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#import "HoverButton.h"
#import "NSColor+RingTheme.h"
@implementation HoverButton
-(void) awakeFromNib {
[super awakeFromNib];
if(!self.hoverColor) {
self.hoverColor = [NSColor ringBlue];
}
if(!self.mouseOutsideColor) {
self.mouseOutsideColor = [NSColor clearColor];
}
self.bgColor = self.mouseOutsideColor;
}
-(void)mouseEntered:(NSEvent *)theEvent {
self.bgColor = self.hoverColor;
[super setNeedsDisplay:YES];
[super mouseEntered:theEvent];
}
-(void)mouseExited:(NSEvent *)theEvent {
self.bgColor = self.mouseOutsideColor;
[super setNeedsDisplay:YES];
[super mouseExited:theEvent];
}
- (void)ensureTrackingArea {
if (trackingArea == nil) {
trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect
options:NSTrackingInVisibleRect
| NSTrackingActiveAlways
| NSTrackingMouseEnteredAndExited owner:self userInfo:nil];
}
}
- (void)updateTrackingAreas {
[super updateTrackingAreas];
[self ensureTrackingArea];
if (![[self trackingAreas] containsObject:trackingArea]) {
[self addTrackingArea:trackingArea];
}
}
- (void)drawRect:(NSRect)dirtyRect
{
[super drawRect:dirtyRect];
}
-(void)mouseDown:(NSEvent *)theEvent
{
[super mouseDown:theEvent];
if(self.isEnabled) {
self.bgColor = self.mouseOutsideColor;
}
}
@end
......@@ -62,5 +62,12 @@
@property NSVisualEffectView* vibrantView;
/*
* Button image color
* default value : [NSColor white];
*/
@property (nonatomic, strong) NSColor* imageColor;
@end
......@@ -21,7 +21,12 @@
#import "NSColor+RingTheme.h"
@interface IconButton()
@property (nonatomic, strong) NSTrackingArea *trackingArea;
@end
@implementation IconButton
@synthesize trackingArea;
-(void) awakeFromNib {
if (!self.bgColor) {
......@@ -36,6 +41,7 @@
self.imageInsets = 8.0f;
self.pressed = NO;
}
-(void) setPressed:(BOOL)newVal
......@@ -50,9 +56,20 @@
NSColor* backgroundColor;
NSColor* backgroundStrokeColor;
NSColor* tintColor = [NSColor whiteColor];
NSColor* tintColor = self.imageColor ? self.imageColor : [NSColor whiteColor];
if (self.mouseDown || self.isPressed) {
if (self.bgColor == [NSColor clearColor]) {
backgroundColor = self.bgColor ;
backgroundStrokeColor = self.bgColor;
if(!self.isEnabled) {
tintColor = [[NSColor grayColor] colorWithAlphaComponent:0.3];
}
}
else if (!self.isEnabled) {
backgroundColor = [self.bgColor colorWithAlphaComponent:0.7];
backgroundStrokeColor = [self.bgColor colorWithAlphaComponent:0.7];
tintColor = [[NSColor grayColor] colorWithAlphaComponent:0.3];
} else if (self.mouseDown || self.isPressed) {
if (self.highlightColor) {
backgroundColor = self.highlightColor;
backgroundStrokeColor = [self.highlightColor darkenColorByValue:0.1];
......@@ -60,11 +77,9 @@
backgroundColor = [self.bgColor darkenColorByValue:0.3];
backgroundStrokeColor = [self.bgColor darkenColorByValue:0.4];
}
} else if (!self.isEnabled) {
backgroundColor = [self.bgColor colorWithAlphaComponent:0.7];
backgroundStrokeColor = [self.bgColor colorWithAlphaComponent:0.7];
tintColor = [[NSColor grayColor] colorWithAlphaComponent:0.3];
} else {
}
else {
backgroundColor = self.bgColor;
backgroundStrokeColor = [self.bgColor darkenColorByValue:0.1];
}
......
......@@ -166,8 +166,8 @@
<box verticalHuggingPriority="750" boxType="separator" translatesAutoresizingMaskIntoConstraints="NO" id="Sn1-dJ-QCw">
<rect key="frame" x="20" y="525" width="758" height="5"/>
</box>
<button toolTip="Record" horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ooq-vs-Xt1" customClass="IconButton">
<rect key="frame" x="20" y="537" width="40" height="40"/>
<button toolTip="Record" horizontalHuggingPriority="750" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="ooq-vs-Xt1" customClass="HoverButton">
<rect key="frame" x="20" y="534" width="40" height="40"/>
<constraints>
<constraint firstAttribute="height" constant="40" id="69o-49-0QB"/>
<constraint firstAttribute="width" constant="40" id="ImE-zq-KIj"/>
......@@ -180,9 +180,12 @@
<userDefinedRuntimeAttribute type="color" keyPath="highlightColor">
<color key="value" red="0.16862745100000001" green="0.70588235290000001" blue="0.78823529410000004" alpha="1" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="bgColor">
<userDefinedRuntimeAttribute type="color" keyPath="hoverColor">
<color key="value" red="0.16078431369999999" green="0.16078431369999999" blue="0.16078431369999999" alpha="0.80000000000000004" colorSpace="calibratedRGB"/>
</userDefinedRuntimeAttribute>
<userDefinedRuntimeAttribute type="color" keyPath="imageColor">
<color key="value" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="backPressed:" target="-2" id="Vfg-Ve-O7w"/>
......@@ -237,16 +240,21 @@
<outlet property="delegate" destination="-2" id="2u2-D4-htz"/>
</connections>
</textField>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UJf-cF-RAo" customClass="IconButton">
<rect key="frame" x="708" y="5" width="40" height="40"/>
<button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UJf-cF-RAo" customClass="HoverButton">
<rect key="frame" x="708" y="15" width="40" height="40"/>
<constraints>
<constraint firstAttribute="width" constant="40" id="TmF-ip-m4C"/>
<constraint firstAttribute="height" constant="40" id="rbQ-lE-sAq"/>
</constraints>
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="ic_action_send" imagePosition="overlaps" alignment="center" transparent="YES" imageScaling="proportionallyDown" inset="2" id="s6a-eK-t3T">
<buttonCell key="cell" type="square" bezelStyle="shadowlessSquare" image="ic_action_send" imagePosition="overlaps" alignment="center" enabled="NO" transparent="YES" imageScaling="proportionallyDown" inset="2" id="s6a-eK-t3T">
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="system"/>
</buttonCell>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="color" keyPath="imageColor">
<color key="value" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
</userDefinedRuntimeAttribute>
</userDefinedRuntimeAttributes>
<connections>
<action selector="sendMessage:" target="-2" id="5Cf-jA-eJM"/>
<binding destination="-2" name="enabled" keyPath="self.message.length" id="ZmZ-2N-CPX"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment