gnustep-GRubik-0.1/000075500000000000000000000000001227735303000142205ustar00rootroot00000000000000gnustep-GRubik-0.1/Controller.h000064400000000000000000000005271227735303000165200ustar00rootroot00000000000000#import #import #import "Views.h" @interface Controller : NSObject { NSWindow *window; Rubik *rview; NSSlider *sliders[3]; } -(void)applicationDidFinishLaunching:(NSNotification *)aNotification; - makeGameWindow; - resetSliders; - scramble:(id)sender; - restore:(id)sender; @end gnustep-GRubik-0.1/Controller.m000064400000000000000000000067611227735303000165330ustar00rootroot00000000000000 #import #import "Controller.h" @implementation Controller - (void)applicationDidFinishLaunching:(NSNotification *)aNotification; { window = nil; srand48(time(NULL)); [self makeGameWindow]; } #define SLIDERHEIGHT 16 #define MARGIN 6 #define LABELWIDTH 20 - makeGameWindow { NSRect frame; NSView *view; int m = NSTitledWindowMask; int index; NSString *titles[3] = {@"x", @"y", @"z"}; ROT_ACTIVE tags[3] = { ROT_X, ROT_Y, ROT_Z }; NSBox *boardBox; NSRect contentRect; NSFont *font = [NSFont systemFontOfSize:SLIDERHEIGHT-3]; view = [[NSView alloc] initWithFrame: NSMakeRect(0, 0, DIMENSION, DIMENSION+SLIDERHEIGHT)]; rview = [[Rubik alloc] initAtPoint:NSMakePoint(0, 3*SLIDERHEIGHT+MARGIN) controller:self]; [view addSubview:rview]; for(index=0; index<3; index++){ NSTextField *textField; NSSlider *slider; textField = [[NSTextField alloc] initWithFrame: NSMakeRect(0, SLIDERHEIGHT*(2-index), LABELWIDTH, SLIDERHEIGHT)]; [textField setEditable:NO]; [textField setSelectable:NO]; [textField setBackgroundColor:[NSColor blackColor]]; [textField setTextColor:[NSColor whiteColor]]; [textField setStringValue:titles[index]]; [textField setFont:font]; [view addSubview:textField]; slider = sliders[index] = [[NSSlider alloc] initWithFrame: NSMakeRect(LABELWIDTH+3, SLIDERHEIGHT*(2-index), DIMENSION-LABELWIDTH-6, SLIDERHEIGHT)]; [slider setMinValue:0.0]; [slider setMaxValue:(2.0*M_PI)]; [slider setTarget:rview]; [slider setAction:@selector(angle:)]; [slider setTag:tags[index]]; [view addSubview:slider]; } boardBox = [[NSBox alloc] initWithFrame: NSMakeRect(0, 0, DIMENSION, DIMENSION)]; [boardBox setContentView:view]; [boardBox setContentViewMargins:NSMakeSize(MARGIN, MARGIN)]; [boardBox setTitle:@"Board"]; [boardBox setBorderType:NSGrooveBorder]; [boardBox sizeToFit]; frame = [NSWindow frameRectForContentRect:[boardBox frame] styleMask:m]; window = [[NSWindow alloc] initWithContentRect:frame styleMask:m backing:NSBackingStoreRetained defer:NO]; [window setMinSize:frame.size]; [window setTitle:@"Rubik's cube"]; [window setDelegate:self]; [window setFrame:frame display:YES]; [window setMaxSize:frame.size]; [window setContentView:boardBox]; [window setReleasedWhenClosed:YES]; // RELEASE(view); [window center]; [window orderFrontRegardless]; [window makeKeyWindow]; [window display]; return self; } - resetSliders { int s; for(s=0; s<3; s++){ [sliders[s] setFloatValue:0.0]; } return self; } - scramble:(id)sender { [rview resetCube]; [rview recomputeGeometry]; [rview scramble]; [rview setNeedsDisplay:YES]; [self resetSliders]; return self; } - restore:(id)sender; { [rview resetCube]; [rview recomputeGeometry]; [rview setNeedsDisplay:YES]; [self resetSliders]; return self; } @end gnustep-GRubik-0.1/GNUmakefile000064400000000000000000000010761227735303000162760ustar00rootroot00000000000000 GNUSTEP_INSTALLATION_DIR = $(GNUSTEP_SYSTEM_ROOT) GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles include $(GNUSTEP_MAKEFILES)/common.make # The application to be compiled APP_NAME = GRubik # The Objective-C source files to be compiled GRubik_OBJC_FILES = main.m \ Controller.m \ Views.m SHARED_CFLAGS += -g # The Resource files to be copied into the app's resources directory #// GRubik_RESOURCE_FILES = Icons/* -include GNUmakefile.preamble -include GNUmakefile.local include $(GNUSTEP_MAKEFILES)/application.make -include GNUmakefile.postamble gnustep-GRubik-0.1/GRubik.app/000075500000000000000000000000001227735303000161625ustar00rootroot00000000000000gnustep-GRubik-0.1/GRubik.app/GRubik000075500000000000000000000146221227735303000173000ustar00rootroot00000000000000#!/bin/sh # # Copyright (C) 1999 Free Software Foundation, Inc. # # Author: Adam Fedor # Date: May 1999 # # This file is part of the GNUstep Makefile Package. # # This library 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 2 # of the License, or (at your option) any later version. # # You should have received a copy of the GNU General Public # License along with this library; see the file COPYING.LIB. # If not, write to the Free Software Foundation, # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # This is a shell script which attempts to find the GNUstep executable # of the same name based on the current host and library_combo. #-------------------------------------------------------------------------- # Main body #-------------------------------------------------------------------------- if [ -z "$EXEEXT" ]; then EXEEXT= fi if [ -z "$LIBRARY_COMBO" ]; then LIBRARY_COMBO=gnu-gnu-gnu fi # Process arguments app=$0 show_available_platforms=0 show_relative_path=0 show_full_path=0 while true do case $1 in --script-help) echo usage: `basename $0` [--library-combo=...] echo " [--available-platforms][--full-executable-path]" echo " [--relative-executable-path] [arguments...]" echo echo " --library-combo=... specifies a GNUstep backend to use." echo " It overrides the default LIBRARY_COMBO environment variable." echo echo " --available-platforms displays a list of valid exec hosts" echo " --full-executable-path displays full path to executable" echo " --relative-executable-path displays subdirectory path" echo " arguments... are the arguments to the application." exit 0 ;; --library-combo=*) LIBRARY_COMBO=`echo $1 | sed 's/--library-combo=//'` shift ;; --available-platforms) show_available_platforms=1 exit 0 ;; --full-executable-path) show_full_path=1 break ;; --relative-executable-path) show_relative_path=1 break ;; *) break;; esac done if [ "$LIBRARY_COMBO" = nx ]; then LIBRARY_COMBO=nx-nx-nx elif [ "$LIBRARY_COMBO" = gnu ]; then LIBRARY_COMBO=gnu-gnu-gnu elif [ "$LIBRARY_COMBO" = fd ]; then LIBRARY_COMBO=gnu-fd-gnu fi export LIBRARY_COMBO # Find path to ourself app=`echo $app | sed 's%/*$%%'` dir=`dirname $app` case $app in /*) # An absolute path. full_appname=$dir;; */*) # A relative path full_appname=`(cd $dir; pwd)`;; *) # A path that needs to be searched if [ -n $GNUSTEP_PATHPREFIX_LIST ]; then SPATH=$GNUSTEP_PATHPREFIX_LIST else SPATH=$PATH fi SPATH=.:$SPATH IFS=: for path_dir in $SPATH; do if [ -d $path_dir/$dir ]; then full_appname=`(cd $path_dir/$dir; pwd)` break; fi if [ -d $path_dir/Applications/$dir ]; then full_appname=`(cd $path_dir/Applications/$dir; pwd)` break; fi done;; esac if [ -z "$full_appname" ]; then echo "Can't find absolute path for $app! Please specify full path when" echo "invoking executable" exit 1 fi # # get base app name # app=`echo $app | sed 's/\.[a-z]*$//'` app=`basename $app` appname= if [ -f "$full_appname/Resources/Info-gnustep.plist" ]; then # -n disable auto-print (for portability reasons) # /^ *NSExecutable *=/ matches every line beginning with # zero or more spaces, followed by 'NSExecutable', followed by zero or # more spaces, followed by '=' # to this line we apply the following commands: # s/"//g; which deletes all " in the line. # s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p; # which replaces 'NSExecutable = Gorm; ' with 'Gorm', then, because # of the 'p' at the end, prints out the result # q; which quits sed since we know there must be only a single line # to replace. appname=`sed -n -e '/^ *NSExecutable *=/ \ {s/"//g; s/^ *NSExecutable *= *\([^ ;]*\) *;.*/\1/p; q;}' \ "$full_appname/Resources/Info-gnustep.plist"` fi if [ -z "$appname" ]; then appname=$app fi appname="$appname$EXEEXT" if [ $show_available_platforms = 1 ]; then cd $full_appname #available_platforms exit 0 fi # # Determine the host information # if [ -z "$GNUSTEP_HOST" ]; then GNUSTEP_HOST=`(cd /tmp; $GNUSTEP_SYSTEM_ROOT/Makefiles/config.guess)` GNUSTEP_HOST=`(cd /tmp; $GNUSTEP_SYSTEM_ROOT/Makefiles/config.sub $GNUSTEP_HOST)` export GNUSTEP_HOST fi if [ -z "$GNUSTEP_HOST_CPU" ]; then GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/Makefiles/cpu.sh $GNUSTEP_HOST` GNUSTEP_HOST_CPU=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_cpu.sh $GNUSTEP_HOST_CPU` export GNUSTEP_HOST_CPU fi if [ -z "$GNUSTEP_HOST_VENDOR" ]; then GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/Makefiles/vendor.sh $GNUSTEP_HOST` GNUSTEP_HOST_VENDOR=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_vendor.sh $GNUSTEP_HOST_VENDOR` export GNUSTEP_HOST_VENDOR fi if [ -z "$GNUSTEP_HOST_OS" ]; then GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/Makefiles/os.sh $GNUSTEP_HOST` GNUSTEP_HOST_OS=`$GNUSTEP_SYSTEM_ROOT/Makefiles/clean_os.sh $GNUSTEP_HOST_OS` export GNUSTEP_HOST_OS fi # # Make sure the executable is there # if [ -x $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname ]; then relative_path=$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/$appname elif [ -x $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname ]; then relative_path=$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$appname elif [ -x $full_appname/$GNUSTEP_HOST_CPU/$appname ]; then relative_path=$GNUSTEP_HOST_CPU/$appname elif [ $appname != $app -a -x $full_appname/$appname ]; then relative_path=$appname else echo "$full_appname application does not have a binary for this kind of machine/operating system ($GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS)." exit 1 fi if [ $show_relative_path = 1 ]; then echo $relative_path exit 0 fi if [ $show_full_path = 1 ]; then echo $full_appname/$relative_path exit 0 fi if [ "$LIBRARY_COMBO" = nx-nx-nx -a $GNUSTEP_HOST_OS = nextstep4 ]; then if [ -f "$full_appname/library_paths.openapp" ]; then additional_library_paths="`cat $full_appname/library_paths.openapp`" fi else if [ -f "$full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/library_paths.openapp" ]; then additional_library_paths="`cat $full_appname/$GNUSTEP_HOST_CPU/$GNUSTEP_HOST_OS/$LIBRARY_COMBO/library_paths.openapp`" fi fi # Load up LD_LIBRARY_PATH . $GNUSTEP_SYSTEM_ROOT/Makefiles/ld_lib_path.sh exec $full_appname/$relative_path "$@" gnustep-GRubik-0.1/GRubik.app/Resources/000075500000000000000000000000001227735303000201345ustar00rootroot00000000000000gnustep-GRubik-0.1/GRubik.app/Resources/GRubik.desktop000064400000000000000000000001721227735303000227120ustar00rootroot00000000000000[Desktop Entry] Encoding=UTF-8 Type=Application Version=Rubik 0.1 Name=GRubik Exec=openapp GRubik.app #TryExec=GRubik.app gnustep-GRubik-0.1/GRubik.app/Resources/Info-gnustep.plist000064400000000000000000000010041227735303000235620ustar00rootroot00000000000000{ ApplicationDescription = "GNUstep Rubik\'s cube"; ApplicationName = GRubik; ApplicationRelease = "Rubik 0.1"; Authors = ( "Marko Riedel " ); Copyright = "Copyright (C) 2002 Free Software Foundation, Inc."; CopyrightDescription = "Released under the GNU General Public License 2.0"; FullVersionID = "0.1, July 2002"; NOTE = "Automatically generated, do not edit!"; NSExecutable = GRubik; NSMainNibFile = ""; NSPrincipalClass = NSApplication; }gnustep-GRubik-0.1/GRubikInfo.plist000064400000000000000000000005451227735303000173000ustar00rootroot00000000000000{ ApplicationName = "GRubik"; ApplicationDescription = "GNUstep Rubik's cube"; ApplicationRelease = "Rubik 0.1"; FullVersionID = "0.1, July 2002"; Authors = ("Marko Riedel "); Copyright = "Copyright (C) 2002 Free Software Foundation, Inc."; CopyrightDescription = "Released under the GNU General Public License 2.0"; } gnustep-GRubik-0.1/Views.h000064400000000000000000000021561227735303000154720ustar00rootroot00000000000000#import #import #import #import #define DIMENSION 300 #define DELTA 1e-8 #define SCRAMBLE 200 typedef struct { double x, y, z; int index; } Vertex, *VPtr; typedef enum { VIS_F_1 = 1, VIS_F_2, VIS_F_3 } VISIBILITY; typedef enum { ROT_X = 0, ROT_Y, ROT_Z } ROT_ACTIVE; @interface Rubik : NSView { id con; Vertex vertices[8]; Vertex indexed[8]; Vertex active[8]; Vertex sorted[8]; double angle; ROT_ACTIVE rprev, rcur; VISIBILITY vis; int visface[3]; int face[6][4]; int adjacent[6][4]; int edge[6][4]; NSColor *colors[8]; int data[6][3][3]; } - initAtPoint:(NSPoint)aPoint controller:(id)theCon; - resetCube; - scramble; - rotate:(Vertex *)vp aboutUnitVector:(ROT_ACTIVE)rv angle:(double)theta; - recomputeGeometry; - angle:(id)sender; - (BOOL)solved; - (void)drawRect:(NSRect)aRect; - (int)visFaceClicked:(NSPoint)loc; - rotateFace:(int)f clockwise:(BOOL)flag; - (void)mouseDown:(NSEvent *)theEvent; - (void)rightMouseDown:(NSEvent *)theEvent; @end gnustep-GRubik-0.1/Views.m000064400000000000000000000334121227735303000154760ustar00rootroot00000000000000 #import "Views.h" #import "Controller.h" @implementation Rubik - initAtPoint:(NSPoint)aPoint controller:(id)theCon { NSRect frame; int x, y, z, b1, b2, index; frame.origin = aPoint; frame.size.width = frame.size.height = DIMENSION; [super initWithFrame:frame]; [self setBoundsSize:NSMakeSize(4.0, 4.0)]; [self setBoundsOrigin:NSMakePoint(-2.0, -2.0)]; con = theCon; for(x=-1; x<=1; x+=2){ for(y=-1; y<=1; y+=2){ for(z=-1; z<=1; z+=2){ int index = 4*(x==-1 ? 0 : 1)+ 2*(y==-1 ? 0 : 1)+ (z==-1 ? 0 : 1); vertices[index].x = x; vertices[index].y = y; vertices[index].z = z; vertices[index].index = index; colors[index] = [NSColor colorWithDeviceRed:(x==-1 ? 0.0 : 1.0) green:(y==-1 ? 0.0 : 1.0) blue:(z==-1 ? 0.0 : 1.0) alpha:1.0]; [colors[index] retain]; } } } index = 0; for(b1=0; b1<=2; b1++){ for(b2=b1+1; b2<=2; b2++){ /* counterclockwise */ int reorient = index + 1-(index/2)%2; int temp; face[index][0] = 0; face[index][1] = face[index][0]+(1<x, y = v->y, z = v->z; switch(rv){ case ROT_X: v->y = y * cosTheta - z * sinTheta; v->z = y * sinTheta + z * cosTheta; break; case ROT_Y: v->x = x * cosTheta - z * sinTheta; v->z = x * sinTheta + z * cosTheta; break; case ROT_Z: v->x = x * cosTheta - y * sinTheta; v->y = x * sinTheta + y * cosTheta; } } return self; } - recomputeGeometry { int index, findex, upper; if(rcur!=rprev){ [self rotate:active aboutUnitVector:rcur angle:-angle]; memcpy(indexed, active, 8*sizeof(Vertex)); rprev = rcur; /* { double dx = indexed[0].x-indexed[1].x, dy = indexed[0].y-indexed[1].y, dz = indexed[0].z-indexed[1].z; NSLog(@"%le\n", dx*dx+dy*dy+dz*dz); } */ } memcpy(active, indexed, 8*sizeof(Vertex)); [self rotate:active aboutUnitVector:rcur angle:angle]; memcpy(sorted, active, 8*sizeof(Vertex)); for(upper=6; upper>=0; upper--){ for(index=0; index<=upper; index++){ if(sorted[index].y>sorted[index+1].y){ Vertex current; current = sorted[index]; sorted[index] = sorted[index+1]; sorted[index+1] = current; } } } index = 0; for(index=1; index<8; index++){ double delta = sorted[index].y-sorted[index-1].y; if(delta>DELTA){ break; } } if(index==1){ int v = sorted[0].index; vis = VIS_F_3; findex = 0; for(index=0; index<6; index++){ if(face[index][0]==v || face[index][1]==v || face[index][2]==v || face[index][3]==v){ visface[findex++] = index; } } } else if(index==2){ int v1 = sorted[0].index, v2 = sorted[1].index; vis = VIS_F_2; findex = 0; for(index=0; index<6; index++){ if((face[index][0]==v1 || face[index][1]==v1 || face[index][2]==v1 || face[index][3]==v1) && (face[index][0]==v2 || face[index][1]==v2 || face[index][2]==v2 || face[index][3]==v2)){ visface[findex++] = index; } } } else { int v1 = sorted[0].index, v2 = sorted[1].index, v3 = sorted[2].index, v4 = sorted[3].index; vis = VIS_F_1; findex = 0; for(index=0; index<6; index++){ if((face[index][0]==v1 || face[index][1]==v1 || face[index][2]==v1 || face[index][3]==v1) && (face[index][0]==v2 || face[index][1]==v2 || face[index][2]==v2 || face[index][3]==v2) && (face[index][0]==v3 || face[index][1]==v3 || face[index][2]==v3 || face[index][3]==v3) && (face[index][0]==v4 || face[index][1]==v4 || face[index][2]==v4 || face[index][3]==v4)){ visface[findex++] = index; } } } [self setNeedsDisplay:YES]; return self; } - angle:(id)sender { angle = [sender doubleValue]; rcur = [sender tag]; [self recomputeGeometry]; return self; } - (BOOL)solved { int f, row, col; for(f=0; f<6; f++){ for(row=0; row<3; row++){ for(col=0; col<3; col++){ if(data[f][row][col]!=data[f][1][1]){ return NO; } } } } return YES; } - (void)drawRect:(NSRect)aRect { NSRect bounds = [self bounds]; int findex; [colors[0] set]; PSrectfill(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); PSsetlinewidth(4.0/(float)DIMENSION); for(findex=0; findex #import #import #import #import "Controller.h" int main(int argc, const char **argv, char** env) { NSAutoreleasePool *pool; NSApplication *app; NSMenu *mainMenu, *subMenu; NSMenu *menu; NSMenuItem *menuItem, *subMenuItem; Controller *controller; pool = [NSAutoreleasePool new]; app = [NSApplication sharedApplication]; // // Create the Menu // // Main Menu mainMenu = AUTORELEASE ([NSMenu new]); // Info SubMenu menuItem = [mainMenu addItemWithTitle: @"Info" action: NULL keyEquivalent: @""]; menu = AUTORELEASE ([NSMenu new]); [mainMenu setSubmenu: menu forItem: menuItem]; [menu addItemWithTitle: @"Info Panel..." action: @selector (orderFrontStandardInfoPanel:) keyEquivalent: @""]; [menu addItemWithTitle: @"Preferences..." action: @selector (runPreferencesPanel:) keyEquivalent: @""]; [menu addItemWithTitle: @"Help..." action: @selector (orderFrontHelpPanel:) keyEquivalent: @"?"]; // Restore MenuItem. menuItem = [mainMenu addItemWithTitle: @"Restore" action: @selector(restore:) keyEquivalent: @""]; // Scramble MenuItem. menuItem = [mainMenu addItemWithTitle: @"Scramble" action: @selector(scramble:) keyEquivalent: @""]; // Hide MenuItem [mainMenu addItemWithTitle: @"Hide" action: @selector (hide:) keyEquivalent: @"h"]; // Quit MenuItem [mainMenu addItemWithTitle: @"Quit" action: @selector (terminate:) keyEquivalent: @"q"]; [app setMainMenu: mainMenu]; controller = [Controller new]; [app setDelegate: controller]; NSApplicationMain(argc, argv); [[NSUserDefaults standardUserDefaults] synchronize]; // RELEASE (controller); // RELEASE (pool); return 0; }