Source/GGBUtils.m
author Jens Alfke <jens@mooseyard.com>
Wed Mar 12 15:51:32 2008 -0700 (2008-03-12)
changeset 6 af9b2b929b03
parent 0 e9f7ba4718e1
child 7 428a194e3e59
permissions -rw-r--r--
Fixed: An exception in the Go game if you mouse down on the board but then drag to the captured-pieces area and release the mouse.
     1 /*  Copyright © 2008 Jens Alfke. All Rights Reserved.
     2 
     3     Redistribution and use in source and binary forms, with or without modification, are permitted
     4     provided that the following conditions are met:
     5 
     6     * Redistributions of source code must retain the above copyright notice, this list of conditions
     7       and the following disclaimer.
     8     * Redistributions in binary form must reproduce the above copyright notice, this list of
     9       conditions and the following disclaimer in the documentation and/or other materials provided
    10       with the distribution.
    11 
    12     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
    13     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 
    14     FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRI-
    15     BUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    16     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
    17     PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
    18     CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 
    19     THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    20 */
    21 #import "GGBUtils.h"
    22 
    23 #if TARGET_OS_ASPEN
    24 #import <AudioToolbox/AudioToolbox.h>
    25 #endif
    26 
    27 
    28 void setObj( id *variable, id newValue )
    29 {
    30     if( *variable != newValue ) {
    31         [*variable release];
    32         *variable = [newValue retain];
    33     }
    34 }
    35 
    36 void setObjCopy( id<NSCopying> *variable, id<NSCopying> newValue )
    37 {
    38     if( *variable != newValue ) {
    39         [*variable release];
    40         *variable = [(id)newValue copy];
    41     }
    42 }
    43 
    44 
    45 void PlaySound( NSString* name )
    46 {
    47 #if TARGET_OS_ASPEN
    48     NSURL *url = [NSURL fileURLWithPath: [@"/Library/Sounds/" stringByAppendingPathComponent: name]];
    49     SystemSoundID soundID;
    50     if( AudioServicesCreateSystemSoundID((CFURLRef)url,&soundID) != noErr ) {
    51         NSLog(@"Couldn't load sound %@",url);
    52         return;
    53     }
    54     AudioServicesPlaySystemSound(soundID);
    55 #else
    56     [[NSSound soundNamed: name] play];
    57 #endif
    58 }
    59 
    60 void Beep()
    61 {
    62 #if TARGET_OS_ASPEN
    63     AudioServicesPlaySystemSound(kSystemSoundID_UserPreferredAlert);
    64 #else
    65     NSBeep();
    66 #endif
    67 }