Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 Savoir-faire Linux Inc. |
| 3 | * Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | */ |
| 19 | |
| 20 | #import "ConferenceOverlayView.h" |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 21 | #import "CustomBackgroundView.h" |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 22 | |
| 23 | @implementation ConferenceOverlayView |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 24 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 25 | CGFloat const margin = 2; |
| 26 | CGFloat const controlSize = 25; |
| 27 | CGFloat const minWidth = 140; |
| 28 | CGFloat const minHeight = 80; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 29 | |
| 30 | - (instancetype)initWithFrame:(NSRect)frame |
| 31 | { |
| 32 | self = [super initWithFrame:frame]; |
| 33 | if (self) { |
| 34 | self.translatesAutoresizingMaskIntoConstraints = false; |
| 35 | [self setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable | NSViewMinYMargin | NSViewMaxYMargin | NSViewMinXMargin | NSViewMaxXMargin]; |
| 36 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sizeChanged) name:NSWindowDidResizeNotification object:nil]; |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 37 | self.wantsLayer = true; |
| 38 | self.layer.masksToBounds = false; |
| 39 | [self addViews]; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 40 | } |
| 41 | return self; |
| 42 | } |
| 43 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 44 | - (void)addViews { |
| 45 | self.increasedBackgroundView = [[NSView alloc] init]; |
| 46 | [self.increasedBackgroundView setWantsLayer: YES]; |
| 47 | self.increasedBackgroundView.layer.backgroundColor = [[NSColor colorWithCalibratedRed: 0 green: 0 blue: 0 alpha: 0.8] CGColor]; |
| 48 | self.increasedBackgroundView.translatesAutoresizingMaskIntoConstraints = false; |
| 49 | [self addSubview: self.increasedBackgroundView]; |
| 50 | self.increasedBackgroundView.hidden = true; |
| 51 | self.increasedBackgroundView.layer.masksToBounds = true; |
| 52 | self.increasedBackgroundView.layer.cornerRadius = 6; |
| 53 | |
| 54 | self.backgroundView = [[NSView alloc] init]; |
| 55 | [self.backgroundView setWantsLayer: YES]; |
| 56 | self.backgroundView.layer.backgroundColor = [[NSColor colorWithCalibratedRed: 0 green: 0 blue: 0 alpha: 0.6] CGColor]; |
| 57 | self.backgroundView.translatesAutoresizingMaskIntoConstraints = false; |
| 58 | [self addSubview: self.backgroundView]; |
| 59 | self.backgroundView.hidden = true; |
| 60 | |
| 61 | //participat state |
| 62 | self.audioState = [[CustomBackgroundView alloc] init]; |
| 63 | self.audioState.backgroundType = RECTANGLE_WITH_ROUNDED_RIGHT_CORNER; |
| 64 | [self.audioState.widthAnchor constraintEqualToConstant: controlSize].active = true; |
| 65 | [self.audioState.heightAnchor constraintEqualToConstant: controlSize].active = true; |
| 66 | NSImage* audioImage = [NSImage imageNamed: @"ic_moderator_audio_muted.png"]; |
| 67 | self.audioState.image = audioImage; |
| 68 | |
| 69 | self.moderatorState = [[CustomBackgroundView alloc] init]; |
| 70 | self.moderatorState.backgroundType = RECTANGLE; |
| 71 | [self.moderatorState.widthAnchor constraintEqualToConstant: controlSize].active = true; |
| 72 | [self.moderatorState.heightAnchor constraintEqualToConstant: controlSize].active = true; |
| 73 | NSImage* moderatorImage = [NSImage imageNamed: @"ic_moderator.png"]; |
| 74 | self.moderatorState.image = moderatorImage; |
| 75 | |
| 76 | self.hostState = [[CustomBackgroundView alloc] init]; |
| 77 | self.hostState.backgroundType = RECTANGLE; |
| 78 | [self.hostState.widthAnchor constraintEqualToConstant: controlSize].active = true; |
| 79 | [self.hostState.heightAnchor constraintEqualToConstant: controlSize].active = true; |
| 80 | NSImage* hostImage = [NSImage imageNamed: @"ic_star.png"]; |
| 81 | self.hostState.image = hostImage; |
| 82 | |
| 83 | self.cusp = [[CustomBackgroundView alloc] init]; |
| 84 | self.cusp.backgroundType = CUSP; |
| 85 | [self.cusp.widthAnchor constraintEqualToConstant: 6].active = true; |
| 86 | [self.cusp.heightAnchor constraintEqualToConstant: controlSize].active = true; |
| 87 | |
| 88 | NSArray *statesViews = [NSArray arrayWithObjects: self.hostState, self.moderatorState, self.audioState, self.cusp, nil]; |
| 89 | self.states = [NSStackView stackViewWithViews: statesViews]; |
| 90 | self.states.spacing = 0; |
| 91 | [self addSubview: self.states]; |
| 92 | |
| 93 | //actions |
| 94 | self.maximize = [self getActionbutton]; |
| 95 | NSImage* maximizeImage = [NSImage imageNamed: @"ic_moderator_maximize.png"]; |
| 96 | [self.maximize setImage: maximizeImage]; |
| 97 | [self.maximize setAction:@selector(maximize:)]; |
| 98 | [self.maximize setTarget:self]; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 99 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 100 | self.minimize = [self getActionbutton]; |
| 101 | NSImage* minimizeImage = [NSImage imageNamed: @"ic_moderator_minimize.png"]; |
| 102 | [self.minimize setImage: minimizeImage]; |
| 103 | [self.minimize setAction:@selector(minimize:)]; |
| 104 | [self.minimize setTarget:self]; |
| 105 | |
| 106 | self.hangup = [self getActionbutton]; |
| 107 | NSImage* hangupImage = [NSImage imageNamed: @"ic_moderator_hangup.png"]; |
| 108 | [self.hangup setImage: hangupImage]; |
| 109 | [self.hangup setAction:@selector(finishCall:)]; |
| 110 | [self.hangup setTarget:self]; |
| 111 | |
| 112 | self.setModerator = [self getActionbutton]; |
| 113 | NSImage* setModeratorImage = [NSImage imageNamed: @"ic_moderator.png"]; |
| 114 | [self.setModerator setImage: setModeratorImage]; |
| 115 | [self.setModerator setAction:@selector(setModerator:)]; |
| 116 | [self.setModerator setTarget:self]; |
| 117 | |
| 118 | self.muteAudio = [self getActionbutton]; |
| 119 | NSImage* muteAudioImage = [NSImage imageNamed: @"ic_moderator_audio_muted.png"]; |
| 120 | [self.muteAudio setImage: muteAudioImage]; |
| 121 | [self.muteAudio setAction:@selector(muteAudio:)]; |
| 122 | [self.muteAudio setTarget:self]; |
| 123 | |
| 124 | NSArray *actions = [NSArray arrayWithObjects: self.setModerator, self.muteAudio, self.maximize, self.minimize, self.hangup, nil]; |
| 125 | self.buttonsContainer = [NSStackView stackViewWithViews: actions]; |
| 126 | self.buttonsContainer.orientation = NSUserInterfaceLayoutOrientationHorizontal; |
| 127 | self.buttonsContainer.spacing = 5; |
| 128 | |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 129 | self.usernameLabel = [[NSTextView alloc] init]; |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 130 | self.usernameLabel.alignment = NSTextAlignmentCenter; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 131 | self.usernameLabel.textColor = [NSColor whiteColor]; |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 132 | self.usernameLabel.editable = false; |
| 133 | self.usernameLabel.drawsBackground = false; |
| 134 | self.usernameLabel.font = [NSFont userFontOfSize: 13.0]; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 135 | self.usernameLabel.translatesAutoresizingMaskIntoConstraints = false; |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 136 | [self.usernameLabel.heightAnchor constraintEqualToConstant: 20].active = true; |
| 137 | [self.usernameLabel.widthAnchor constraintGreaterThanOrEqualToConstant: 60].active = true; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 138 | self.usernameLabel.textContainer.maximumNumberOfLines = 1; |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 139 | |
| 140 | NSArray* infoItems = [NSArray arrayWithObjects: self.usernameLabel, self.buttonsContainer, nil]; |
| 141 | |
| 142 | self.infoContainer = [NSStackView stackViewWithViews: infoItems]; |
| 143 | self.infoContainer.orientation = NSUserInterfaceLayoutOrientationVertical; |
| 144 | self.infoContainer.spacing = 0; |
| 145 | self.infoContainer.distribution = NSStackViewDistributionFillEqually; |
| 146 | self.infoContainer.alignment = NSLayoutAttributeCenterX; |
| 147 | [self.backgroundView addSubview: self.infoContainer]; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 148 | } |
| 149 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 150 | - (IconButton*) getActionbutton { |
| 151 | IconButton* button = [[IconButton alloc] init]; |
| 152 | button.transparent = true; |
| 153 | [button.widthAnchor constraintEqualToConstant: controlSize].active = true; |
| 154 | [button.heightAnchor constraintEqualToConstant: controlSize].active = true; |
| 155 | button.title = @""; |
| 156 | button.buttonDisableColor = [NSColor lightGrayColor]; |
| 157 | button.bgColor = [NSColor clearColor]; |
| 158 | button.imageColor = [NSColor whiteColor]; |
| 159 | button.imagePressedColor = [NSColor lightGrayColor]; |
| 160 | button.imageInsets = margin; |
| 161 | button.translatesAutoresizingMaskIntoConstraints = false; |
| 162 | return button; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 163 | } |
| 164 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 165 | - (void)configureView { |
| 166 | [self.backgroundView.widthAnchor constraintEqualToAnchor:self.widthAnchor multiplier: 1].active = TRUE; |
| 167 | [self.backgroundView.topAnchor constraintEqualToAnchor:self.topAnchor].active = true; |
| 168 | [self.backgroundView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor].active = true; |
| 169 | [self.backgroundView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor].active = true; |
| 170 | |
| 171 | [self.states.topAnchor constraintEqualToAnchor:self.topAnchor].active = true; |
| 172 | [self.states.leadingAnchor constraintEqualToAnchor:self.leadingAnchor].active = true; |
| 173 | |
| 174 | [self.infoContainer.centerYAnchor constraintEqualToAnchor:self.centerYAnchor constant:1].active = true; |
| 175 | [self.infoContainer.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:1].active = true; |
| 176 | |
| 177 | [self.increasedBackgroundView.centerYAnchor constraintEqualToAnchor:self.centerYAnchor constant:1].active = true; |
| 178 | [self.increasedBackgroundView.centerXAnchor constraintEqualToAnchor:self.centerXAnchor constant:1].active = true; |
| 179 | [self.increasedBackgroundView.widthAnchor constraintEqualToConstant:minWidth].active = true; |
| 180 | [self.increasedBackgroundView.heightAnchor constraintEqualToConstant:minHeight].active = true; |
| 181 | } |
| 182 | |
| 183 | - (IBAction)minimize:(id) sender { |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 184 | [self.delegate minimizeParticipant]; |
| 185 | } |
| 186 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 187 | - (IBAction)maximize:(id) sender { |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 188 | [self.delegate maximizeParticipant:self.participant.uri active: self.participant.active]; |
| 189 | } |
| 190 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 191 | - (IBAction)finishCall:(id) sender { |
kkostiuk | c04f447 | 2021-01-25 09:32:18 -0500 | [diff] [blame] | 192 | [self.delegate hangUpParticipant: self.participant.uri]; |
| 193 | } |
| 194 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 195 | - (IBAction)muteAudio:(id) sender { |
kkostiuk | c04f447 | 2021-01-25 09:32:18 -0500 | [diff] [blame] | 196 | [self.delegate muteParticipantAudio: self.participant.uri state: !self.participant.audioModeratorMuted]; |
| 197 | } |
| 198 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 199 | - (IBAction)setModerator:(id) sender { |
kkostiuk | c04f447 | 2021-01-25 09:32:18 -0500 | [diff] [blame] | 200 | [self.delegate setModerator:self.participant.uri state: !self.participant.isModerator]; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | - (void)sizeChanged { |
Kateryna Kostiuk | 8f07386 | 2020-09-30 09:28:15 -0400 | [diff] [blame] | 204 | if (self.superview == nil) { |
| 205 | return; |
| 206 | } |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 207 | NSArray* constraints = [NSArray arrayWithObjects: self.widthConstraint, self.heightConstraint, self.centerXConstraint, self.centerYConstraint, nil]; |
| 208 | [self.superview removeConstraints: constraints]; |
| 209 | [self.superview layoutSubtreeIfNeeded]; |
| 210 | CGSize viewSize = self.superview.frame.size; |
| 211 | if (viewSize.width == 0 || viewSize.height == 0 || self.framesize.width == 0 || self.framesize.height == 0 || self.participant.width == 0 || self.participant.hight == 0) { |
Kateryna Kostiuk | a9908a3 | 2020-09-10 10:10:58 -0400 | [diff] [blame] | 212 | self.frame = CGRectZero; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 213 | return; |
| 214 | } |
| 215 | CGFloat viewRatio = viewSize.width / viewSize.height; |
| 216 | CGFloat frameRatio = self.framesize.width / self.framesize.height; |
| 217 | CGFloat ratio = viewRatio * (1/frameRatio); |
| 218 | // calculate size for all participants |
| 219 | CGFloat allViewsWidth = viewSize.width; |
| 220 | CGFloat allViewsHeight = viewSize.height; |
| 221 | if (ratio < 1) { |
| 222 | allViewsHeight = allViewsHeight * ratio; |
| 223 | } else { |
| 224 | allViewsWidth = allViewsWidth / ratio; |
| 225 | } |
| 226 | CGFloat widthRatio = self.participant.width / self.framesize.width; |
| 227 | CGFloat heightRatio = self.participant.hight / self.framesize.height; |
| 228 | |
| 229 | CGFloat overlayWidth = allViewsWidth * widthRatio; |
| 230 | CGFloat overlayHeight = allViewsHeight * heightRatio; |
| 231 | CGFloat ratioX = overlayWidth / viewSize.width; |
| 232 | CGFloat ratioY = overlayHeight / viewSize.height; |
| 233 | CGFloat offsetx = (viewSize.width - allViewsWidth) * 0.5; |
| 234 | CGFloat offsety = (viewSize.height - allViewsHeight) * 0.5; |
| 235 | CGFloat centerX = (offsetx + (self.participant.x * (overlayWidth / self.participant.width))+ overlayWidth * 0.5) / (viewSize.width * 0.5); |
| 236 | CGFloat centerY = (offsety + (self.participant.y * (overlayHeight / self.participant.hight)) + overlayHeight * 0.5) / (viewSize.height * 0.5); |
| 237 | |
| 238 | self.centerXConstraint = [NSLayoutConstraint constraintWithItem:self |
| 239 | attribute:NSLayoutAttributeCenterX |
| 240 | relatedBy:NSLayoutRelationEqual toItem:self.superview |
| 241 | attribute:NSLayoutAttributeCenterX |
| 242 | multiplier:centerX constant:0]; |
| 243 | self.centerYConstraint = [NSLayoutConstraint constraintWithItem:self |
| 244 | attribute:NSLayoutAttributeCenterY |
| 245 | relatedBy:NSLayoutRelationEqual toItem:self.superview |
| 246 | attribute:NSLayoutAttributeCenterY |
| 247 | multiplier:centerY constant:0]; |
| 248 | self.widthConstraint = |
| 249 | [self.widthAnchor constraintEqualToAnchor:self.superview.widthAnchor multiplier: ratioX]; |
| 250 | self.heightConstraint = [self.heightAnchor constraintEqualToAnchor:self.superview.heightAnchor multiplier: ratioY]; |
| 251 | self.widthConstraint.active = YES; |
| 252 | self.heightConstraint.active = YES; |
| 253 | self.centerXConstraint.active = YES; |
| 254 | self.centerYConstraint.active = YES; |
| 255 | [self layoutSubtreeIfNeeded]; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | - (void)updateViewWithParticipant:(ConferenceParticipant) participant { |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 259 | bool sizeChanged = self.participant.width != participant.width || self.participant.hight != participant.hight |
| 260 | || self.participant.x != participant.x || self.participant.y != participant.y; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 261 | self.participant = participant; |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 262 | [self updateButtonsState]; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 263 | [self sizeChanged]; |
| 264 | self.usernameLabel.string = self.participant.bestName; |
| 265 | } |
| 266 | |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 267 | -(void) updateButtonsState { |
kkostiuk | ddfad89 | 2021-02-17 15:26:37 -0500 | [diff] [blame] | 268 | bool audioMuted = self.participant.audioModeratorMuted || self.participant.audioLocalMuted; |
| 269 | self.audioState.hidden = !audioMuted; |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 270 | self.moderatorState.hidden = !self.participant.isModerator || [self.delegate isParticipantHost: self.participant.uri]; |
| 271 | self.hostState.hidden = ![self.delegate isParticipantHost: self.participant.uri]; |
| 272 | self.cusp.hidden = (self.audioState.hidden && self.moderatorState.hidden && self.hostState.hidden); |
| 273 | BackgroundType type = self.audioState.hidden ? RECTANGLE_WITH_ROUNDED_RIGHT_CORNER : RECTANGLE; |
| 274 | if (!self.moderatorState.hidden && self.moderatorState.backgroundType != type) { |
| 275 | self.moderatorState.backgroundType = type; |
| 276 | [self.moderatorState setNeedsDisplay:YES]; |
| 277 | } |
| 278 | if (!self.hostState.hidden && self.hostState.backgroundType != type) { |
| 279 | self.hostState.backgroundType = type; |
| 280 | [self.hostState setNeedsDisplay:YES]; |
| 281 | } |
| 282 | bool couldManageConference = [self.delegate isMasterCall] || [self.delegate isCallModerator]; |
| 283 | self.buttonsContainer.hidden = !couldManageConference; |
| 284 | if (!couldManageConference) { |
| 285 | return; |
| 286 | } |
| 287 | int layout = [self.delegate getCurrentLayout]; |
| 288 | if (layout < 0) |
| 289 | return; |
| 290 | BOOL showConferenceHostOnly = !self.participant.isLocal && [self.delegate isMasterCall]; |
| 291 | BOOL hangupEnabled = ![self.delegate isParticipantHost: self.participant.uri]; |
| 292 | BOOL showMaximized = layout != 2; |
| 293 | BOOL showMinimized = !(layout == 0 || (layout == 1 && !self.participant.active)); |
| 294 | self.setModerator.enabled = showConferenceHostOnly; |
| 295 | self.hangup.enabled = hangupEnabled; |
| 296 | self.minimize.hidden = !showMinimized; |
| 297 | self.maximize.hidden = !showMaximized; |
kkostiuk | ddfad89 | 2021-02-17 15:26:37 -0500 | [diff] [blame] | 298 | NSImage* muteAudioImage = audioMuted ? [NSImage imageNamed: @"ic_moderator_audio_muted.png"] : |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 299 | [NSImage imageNamed: @"ic_moderator_audio_unmuted.png"]; |
| 300 | [self.muteAudio setImage: muteAudioImage]; |
kkostiuk | ddfad89 | 2021-02-17 15:26:37 -0500 | [diff] [blame] | 301 | self.muteAudio.enabled = !self.participant.audioLocalMuted; |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 302 | } |
| 303 | |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 304 | -(void)mouseEntered:(NSEvent *)theEvent { |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 305 | self.backgroundView.hidden = NO; |
| 306 | auto size1 = self.frame.size; |
| 307 | if (size1.width < minWidth && size1.height < minHeight) { |
| 308 | self.increasedBackgroundView.hidden = false; |
| 309 | self.backgroundView.layer.backgroundColor = [[NSColor clearColor] CGColor]; |
| 310 | } |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 311 | [super mouseEntered:theEvent]; |
| 312 | } |
| 313 | |
| 314 | -(void)mouseExited:(NSEvent *)theEvent { |
kkostiuk | 3a2c9f7 | 2021-01-27 10:30:49 -0500 | [diff] [blame] | 315 | self.backgroundView.hidden = YES; |
| 316 | self.increasedBackgroundView.hidden = true; |
| 317 | self.backgroundView.layer.backgroundColor = [[NSColor colorWithCalibratedRed: 0 green: 0 blue: 0 alpha: 0.6] CGColor]; |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 318 | [super mouseExited:theEvent]; |
| 319 | } |
| 320 | |
Kateryna Kostiuk | cd02788 | 2020-09-08 10:59:31 -0400 | [diff] [blame] | 321 | -(void)mouseUp:(NSEvent *)theEvent |
| 322 | { |
| 323 | [super mouseUp:theEvent]; |
| 324 | if ([theEvent clickCount] == 1) { |
| 325 | [self performSelector:@selector(singleTap) withObject:nil afterDelay:[NSEvent doubleClickInterval]]; |
| 326 | } else if (theEvent.clickCount == 2) { |
| 327 | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(singleTap) object:nil]; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | - (void)singleTap { |
| 332 | [self.delegate maximizeParticipant:self.participant.uri active: self.participant.active]; |
| 333 | } |
| 334 | |
Kateryna Kostiuk | 1705a5a | 2020-08-26 09:48:00 -0400 | [diff] [blame] | 335 | - (void)ensureTrackingArea { |
| 336 | if (trackingArea == nil) { |
| 337 | trackingArea = [[NSTrackingArea alloc] initWithRect:NSZeroRect |
| 338 | options:NSTrackingInVisibleRect |
| 339 | | NSTrackingActiveAlways |
| 340 | | NSTrackingMouseEnteredAndExited owner:self userInfo:nil]; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | - (void)updateTrackingAreas { |
| 345 | [super updateTrackingAreas]; |
| 346 | [self ensureTrackingArea]; |
| 347 | if (![[self trackingAreas] containsObject:trackingArea]) { |
| 348 | [self addTrackingArea:trackingArea]; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | |
| 353 | @end |