2 * \file SoundAndMusic.m
3 * \brief Define interface to sound and music configuration panel used by the
6 * Copyright (c) 2023 Eric Branlund
8 * This work is free software; you can redistribute it and/or modify it
9 * under the terms of either:
11 * a) the GNU General Public License as published by the Free Software
12 * Foundation, version 2, or
14 * b) the "Angband licence":
15 * This software may be copied and distributed for educational, research,
16 * and not for profit purposes provided that this copyright and statement
17 * are included in all such copies. Other copyrights may also apply.
20 #import "SoundAndMusic.h"
23 @implementation SoundAndMusicPanelController
26 * Don't use the implicit @synthesize since this property is declared in a
27 * superclass, NSWindowController.
33 * Handle property methods where need more than is provided by the default
36 - (BOOL)isSoundEnabled
38 return ([self soundEnabledControl]
39 && [self soundEnabledControl].state != NSControlStateValueOff)
44 - (void)setSoundEnabled:(BOOL)v
46 if ([self soundEnabledControl]) {
47 [self soundEnabledControl].state = (v) ?
48 NSControlStateValueOn : NSControlStateValueOff;
53 - (NSInteger)soundVolume
55 return ([self soundVolumeControl]) ?
56 [self soundVolumeControl].integerValue : 100;
60 - (void)setSoundVolume:(NSInteger)v
62 if ([self soundVolumeControl]) {
68 [self soundVolumeControl].integerValue = v;
73 - (BOOL)isMusicEnabled
75 return ([self musicEnabledControl]
76 && [self musicEnabledControl].state != NSControlStateValueOff)
81 - (void)setMusicEnabled:(BOOL)v
83 if ([self musicEnabledControl]) {
84 [self musicEnabledControl].state = (v) ?
85 NSControlStateValueOn : NSControlStateValueOff;
90 - (BOOL)isMusicPausedWhenInactive
92 return ([self musicPausedWhenInactiveControl]
93 && [self musicPausedWhenInactiveControl].state
94 != NSControlStateValueOn) ? NO : YES;
98 - (void)setMusicPausedWhenInactive:(BOOL)v
100 if ([self musicPausedWhenInactiveControl]) {
101 [self musicPausedWhenInactiveControl].state =
102 (v) ? NSControlStateValueOn : NSControlStateValueOff;
107 - (NSInteger)musicVolume
109 return ([self musicVolumeControl]) ?
110 [self musicVolumeControl].integerValue : 100;
114 - (void)setMusicVolume:(NSInteger)v
116 if ([self musicVolumeControl]) {
119 } else if (v > 100) {
122 [self musicVolumeControl].integerValue = v;
127 - (NSInteger)musicTransitionTime
129 return ([self musicTransitionTimeControl]) ?
130 [self musicTransitionTimeControl].integerValue : 0;
134 - (void)setMusicTransitionTime:(NSInteger)v
136 if ([self musicTransitionTimeControl]) {
139 } else if (v > [self musicTransitionTimeControl].maxValue) {
140 v = (NSInteger)([self musicTransitionTimeControl].maxValue);
142 [self musicTransitionTimeControl].integerValue = v;
148 * Supply the NSWindowDelegate's windowWillClose method to relay the close
149 * message through the SoundAndMusicChanges protocol.
151 - (void)windowWillClose:(NSNotification *)notification
153 if ([self changeHandler]) {
154 [[self changeHandler] soundAndMusicPanelWillClose];
160 * Override the NSWindowController property getter to get the appropriate nib
163 - (NSString *)windowNibName
165 return @"SoundAndMusic";
170 * Override the NSWindowController function to set some attributes on the
173 - (void)windowDidLoad
175 [super windowDidLoad];
176 self.window.floatingPanel = YES;
177 self.window.becomesKeyOnlyIfNeeded = YES;
178 [self.window center];
179 self.window.delegate = self;
183 - (IBAction)respondToSoundEnabledToggle:(id)sender
185 if ([self changeHandler]) {
186 [[self changeHandler] changeSoundEnabled:self.isSoundEnabled];
191 - (IBAction)respondToSoundVolumeSlider:(id)sender
193 if ([self changeHandler]) {
194 [[self changeHandler] changeSoundVolume:self.soundVolume];
199 - (IBAction)respondToMusicEnabledToggle:(id)sender
201 if ([self changeHandler]) {
202 [[self changeHandler] changeMusicEnabled:self.isMusicEnabled];
207 - (IBAction)respondToMusicPausedWhenInactiveToggle:(id)sender
209 if ([self changeHandler]) {
210 [[self changeHandler] changeMusicPausedWhenInactive:self.isMusicPausedWhenInactive];
215 - (IBAction)respondToMusicVolumeSlider:(id)sender
217 if ([self changeHandler]) {
218 [[self changeHandler] changeMusicVolume:self.musicVolume];
223 - (IBAction)respondToMusicTransitionTimeSlider:(id)sender
225 if ([self changeHandler]) {
226 [[self changeHandler] changeMusicTransitionTime:self.musicTransitionTime];