frogatto-1.3.1+dfsg/0000755000175000017500000000000012063314014014150 5ustar vincentvincentfrogatto-1.3.1+dfsg/INSTALL0000644000175000017500000000114312060740335015206 0ustar vincentvincentPrerequisites: You'll need to have these libraries with equivalent development versions to build Frogatto: boost_iostreams >= 1.35.0 boost_regex >= 1.35.0 boost_asio >= 1.35.0 boost_system >= 1.35.0 libsdl >= 1.2.7 libsdl-image >= 1.2 (with png support) libsdl-mixer >= 1.2 (with Vorbis support) libsdl-ttf >= 2.0.8 gl glu glew ccache libz Building: To build, type 'make'. The Makefile will probably work. :) If it doesn't you may have to tweak it for your platform. The executable 'game' will be created which you can run. To access the level editor, press CTRL-E during the game. Have fun! frogatto-1.3.1+dfsg/LICENSE0000644000175000017500000000116312060740335015164 0ustar vincentvincentThe Frogatto game and all content is available for download free of charge from http://www.frogatto.com. The game may be redistributed for non-commercial purposes so long as the entire package is kept in-tact and unmodified. This license must also be included and kept in-tact. It is forbidden to distribute the game, or any portion thereof for any commercial or revenue-generating purpose. The source code to the game -- limited to the C++ source code files found in the "src" directory -- is also available for license under the GNU GPL version 3 or later. See the LICENSE file in that directory for the details of the GPL. frogatto-1.3.1+dfsg/Makefile0000755000175000017500000000542412060740335015626 0ustar vincentvincent# # Main Makefile, intended for use on Linux/X11 and compatible platforms # using GNU Make. # # It should guess the paths to the game dependencies on its own, except for # Boost which is assumed to be installed to the default locations. If you have # installed Boost to a non-standard location, you will need to override CXXFLAGS # and LDFLAGS with any applicable -I and -L arguments. # # The main options are: # # CCACHE The ccache binary that should be used when USE_CCACHE is # enabled (see below). Defaults to 'ccache'. # CXX C++ compiler comand line. # CXXFLAGS Additional C++ compiler options. # OPTIMIZE If set to 'yes' (default), builds with compiler # optimizations enabled (-O2). You may alternatively use # CXXFLAGS to set your own optimization options. # LDFLAGS Additional linker options. # USE_CCACHE If set to 'yes' (default), builds using the CCACHE binary # to run the compiler. If ccache is not installed (i.e. # found in PATH), this option has no effect. # OPTIMIZE=yes CCACHE?=ccache USE_CCACHE?=$(shell which $(CCACHE) 2>&1 > /dev/null && echo yes) ifneq ($(USE_CCACHE),yes) CCACHE= endif ifeq ($(OPTIMIZE),yes) BASE_CXXFLAGS += -O2 endif # Initial compiler options, used before CXXFLAGS and CPPFLAGS. BASE_CXXFLAGS += -g -fno-inline-functions -fthreadsafe-statics -Wnon-virtual-dtor -Werror -Wignored-qualifiers -Wformat -Wswitch # Compiler include options, used after CXXFLAGS and CPPFLAGS. INC := $(shell pkg-config --cflags x11 sdl glu glew SDL_image libpng zlib) # Linker library options. LIBS := $(shell pkg-config --libs x11 ) -lSDLmain \ $(shell pkg-config --libs sdl glu glew SDL_image libpng zlib) -lSDL_ttf -lSDL_mixer include Makefile.common %.o : src/%.cpp $(CCACHE) $(CXX) \ $(BASE_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(INC) -DIMPLEMENT_SAVE_PNG \ -c $< $(CXX) $(BASE_CXXFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(INC) -DIMPLEMENT_SAVE_PNG -MM $< > $*.d @mv -f $*.d $*.d.tmp @sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \ sed -e 's/^ *//' -e 's/$$/:/' >> $*.d @rm -f $*.d.tmp game: $(objects) $(CCACHE) $(CXX) \ $(BASE_CXXFLAGS) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(INC) \ $(objects) -o game \ $(LIBS) -lboost_regex-mt -lboost_system-mt -lpthread -fthreadsafe-statics # pull in dependency info for *existing* .o files -include $(objects:.o=.d) server: $(server_objects) $(CCACHE) $(CXX) \ $(BASE_CXXFLAGS) $(LDFLAGS) $(CXXFLAGS) $(CPPFLAGS) \ $(server_objects) -o server \ $(LIBS) -lboost_regex-mt -lboost_system-mt -lboost_thread-mt -lboost_iostreams-mt clean: rm -f *.o *.d game assets: ./game --utility=compile_levels ./game --utility=compile_objects frogatto-1.3.1+dfsg/Makefile.common0000755000175000017500000000670512060740335017120 0ustar vincentvincent# # This file contains lists of object files for our build targets. # Please keep every file in separate lines to make diff and patching easier. # # Game engine objects = \ IMG_savepng.o \ achievements.o \ animation_creator.o \ animation_preview_widget.o \ animation_widget.o \ asserts.o \ background.o \ background_task_pool.o \ base64.o \ blur.o \ border_widget.o \ button.o \ character_editor_dialog.o \ checkbox.o \ checksum.o \ code_editor_dialog.o \ code_editor_widget.o \ color_chart.o \ compress.o \ current_generator.o \ decimal.o \ difficulty.o \ drag_widget.o \ dropdown_widget.o \ editor_dialogs.o \ editor_formula_functions.o \ editor_layers_dialog.o \ editor_stats_dialog.o \ editor_variable_info.o \ external_text_editor.o \ clipboard.o \ collision_utils.o \ color_utils.o \ controls.o \ controls_dialog.o \ custom_object.o \ custom_object_callable.o \ custom_object_dialog.o \ custom_object_functions.o \ custom_object_type.o \ debug_console.o \ dialog.o \ draw_number.o \ draw_scene.o \ draw_tile.o \ editor.o \ editor_level_properties_dialog.o \ editor_module_properties_dialog.o \ entity.o \ file_chooser_dialog.o \ filesystem.o \ font.o \ formula.o \ formula_callable_definition.o \ formula_constants.o \ formula_function.o \ formula_function_registry.o \ formula_profiler.o \ formula_tokenizer.o \ formula_variable_storage.o \ frame.o \ framed_gui_element.o \ game_registry.o \ geometry.o \ gles2.o \ globals.o \ graphical_font.o \ graphical_font_label.o \ grid_widget.o \ group_property_editor_dialog.o \ gui_formula_functions.o \ gui_section.o \ hex_map.o \ hex_object.o \ hex_tile.o \ hex_tileset_editor_dialog.o \ http_client.o \ http_server.o \ i18n.o \ image_widget.o \ input.o \ iphone_controls.o \ joystick.o \ json_parser.o \ json_tokenizer.o \ key.o \ key_button.o \ label.o \ level.o \ level_logic.o \ level_object.o \ level_runner.o \ level_solid_map.o \ light.o \ load_level_nothread.o \ main.o \ md5.o \ message_dialog.o \ module.o \ module_web_server.o \ movement_script.o \ multi_tile_pattern.o \ multiplayer.o \ object_events.o \ options_dialog.o \ particle_system.o \ pathfinding.o \ pause_game_dialog.o \ playable_custom_object.o \ player_info.o \ preferences.o \ preprocessor.o \ preview_tileset_widget.o \ progress_bar.o \ property_editor_dialog.o \ random.o \ raster.o \ raster_distortion.o \ rectangle_rotator.o \ scrollbar_widget.o \ scrollable_widget.o \ segment_editor_dialog.o \ settings_dialog.o \ shaders.o \ sys.o \ slider.o \ solid_map.o \ sound.o \ speech_dialog.o \ stats.o \ stats_server.o \ stats_server_main.o \ stats_web_server.o \ string_utils.o \ surface_cache.o \ surface_formula.o \ surface_palette.o \ surface_scaling.o \ surface.o \ tbs_ai_player.o \ tbs_bot.o \ tbs_client.o \ tbs_functions.o \ tbs_game.o \ tbs_server.o \ tbs_web_server.o \ texture.o \ texture_frame_buffer.o \ text_editor_widget.o \ thread.o \ tile_map.o \ tileset_editor_dialog.o \ tooltip.o \ translate.o \ tree_view_widget.o \ utils.o \ variant.o \ variant_callable.o \ variant_utils.o \ water.o \ water_particle_system.o \ weather_particle_system.o \ widget.o \ widget_factory.o \ wml_formula_callable.o \ unit_test.o \ formula_test.o \ loading_screen.o \ utility_object_compiler.o \ utility_query.o \ utility_render_level.o \ vector_text.o \ wm.o # Server server_objects = \ server.o \ simple_wml.o frogatto-1.3.1+dfsg/README0000644000175000017500000000105712060740335015041 0ustar vincentvincentFrogatto & Friends is an old-school 2D platformer game, starring a certain quixotic frog. It's a big adventure with all the classic fun - you fight monsters, collect coins, talk to people, and buy new stuff. Also, Frogatto has a very flexible game engine you can use to make your own creations. The game's source code license can be found in the LICENSE file in the distribution. See INSTALL for instructions on building from source, or check the Downloads page [http://www.frogatto.com/download] in our website for ready to use packages for your platform. frogatto-1.3.1+dfsg/src/0000755000175000017500000000000012060740335014745 5ustar vincentvincentfrogatto-1.3.1+dfsg/src/Appirater.h0000644000175000017500000001527712060740335017061 0ustar vincentvincent/* This file is part of Appirater. Copyright (c) 2010, Arash Payan All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * Appirater.h * appirater * * Created by Arash Payan on 9/5/09. * http://arashpayan.com * Copyright 2010 Arash Payan. All rights reserved. */ #import extern NSString *const kAppiraterFirstUseDate; extern NSString *const kAppiraterUseCount; extern NSString *const kAppiraterSignificantEventCount; extern NSString *const kAppiraterCurrentVersion; extern NSString *const kAppiraterRatedCurrentVersion; extern NSString *const kAppiraterDeclinedToRate; /* Place your Apple generated software id here. */ #define APPIRATER_APP_ID 382015046 /* Your app's name. */ #define APPIRATER_APP_NAME [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleNameKey] /* This is the message your users will see once they've passed the day+launches threshold. */ #define APPIRATER_MESSAGE [NSString stringWithFormat:@"If you enjoy playing %@, would you mind taking a moment to rate it? It won't take more than a minute. Thanks for your support!", APPIRATER_APP_NAME] /* This is the title of the message alert that users will see. */ #define APPIRATER_MESSAGE_TITLE [NSString stringWithFormat:@"Rate %@", APPIRATER_APP_NAME] /* The text of the button that rejects reviewing the app. */ #define APPIRATER_CANCEL_BUTTON @"No, Thanks" /* Text of button that will send user to app review page. */ #define APPIRATER_RATE_BUTTON [NSString stringWithFormat:@"Rate %@", APPIRATER_APP_NAME] /* Text for button to remind the user to review later. */ #define APPIRATER_RATE_LATER @"Remind me later" /* Users will need to have the same version of your app installed for this many days before they will be prompted to rate it. */ #define APPIRATER_DAYS_UNTIL_PROMPT 15 // double /* An example of a 'use' would be if the user launched the app. Bringing the app into the foreground (on devices that support it) would also be considered a 'use'. You tell Appirater about these events using the two methods: [Appirater appLaunched:] [Appirater appEnteredForeground:] Users need to 'use' the same version of the app this many times before before they will be prompted to rate it. */ #define APPIRATER_USES_UNTIL_PROMPT 10 // integer /* A significant event can be anything you want to be in your app. In a telephone app, a significant event might be placing or receiving a call. In a game, it might be beating a level or a boss. This is just another layer of filtering that can be used to make sure that only the most loyal of your users are being prompted to rate you on the app store. If you leave this at a value of -1, then this won't be a criteria used for rating. To tell Appirater that the user has performed a significant event, call the method: [Appirater userDidSignificantEvent:]; */ #define APPIRATER_SIG_EVENTS_UNTIL_PROMPT -1 // integer /* Once the rating alert is presented to the user, they might select 'Remind me later'. This value specifies how long (in days) Appirater will wait before reminding them. */ #define APPIRATER_TIME_BEFORE_REMINDING 1 // double /* 'YES' will show the Appirater alert everytime. Useful for testing how your message looks and making sure the link to your app's review page works. */ #define APPIRATER_DEBUG 0 @interface Appirater : NSObject { } /* DEPRECATED: While still functional, it's better to use appLaunched:(BOOL)canPromptForRating instead. Calls [Appirater appLaunched:YES]. See appLaunched: for details of functionality. */ + (void)appLaunched; /* Tells Appirater that the app has launched, and on devices that do NOT support multitasking, the 'uses' count will be incremented. You should call this method at the end of your application delegate's application:didFinishLaunchingWithOptions: method. If the app has been used enough to be rated (and enough significant events), you can suppress the rating alert by passing NO for canPromptForRating. The rating alert will simply be postponed until it is called again with YES for canPromptForRating. The rating alert can also be triggered by appEnteredForeground: and userDidSignificantEvent: (as long as you pass YES for canPromptForRating in those methods). */ + (void)appLaunched:(BOOL)canPromptForRating; /* Tells Appirater that the app was brought to the foreground on multitasking devices. You should call this method from the application delegate's applicationWillEnterForeground: method. If the app has been used enough to be rated (and enough significant events), you can suppress the rating alert by passing NO for canPromptForRating. The rating alert will simply be postponed until it is called again with YES for canPromptForRating. The rating alert can also be triggered by appLaunched: and userDidSignificantEvent: (as long as you pass YES for canPromptForRating in those methods). */ + (void)appEnteredForeground:(BOOL)canPromptForRating; /* Tells Appirater that the user performed a significant event. A significant event is whatever you want it to be. If you're app is used to make VoIP calls, then you might want to call this method whenever the user places a call. If it's a game, you might want to call this whenever the user beats a level boss. If the user has performed enough significant events and used the app enough, you can suppress the rating alert by passing NO for canPromptForRating. The rating alert will simply be postponed until it is called again with YES for canPromptForRating. The rating alert can also be triggered by appLaunched: and appEnteredForeground: (as long as you pass YES for canPromptForRating in those methods). */ + (void)userDidSignificantEvent:(BOOL)canPromptForRating; @end frogatto-1.3.1+dfsg/src/Appirater.m0000644000175000017500000003234312060740335017057 0ustar vincentvincent/* This file is part of Appirater. Copyright (c) 2010, Arash Payan All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* * Appirater.m * appirater * * Created by Arash Payan on 9/5/09. * http://arashpayan.com * Copyright 2010 Arash Payan. All rights reserved. */ #import "Appirater.h" #import #include #include "globals.h" NSString *const kAppiraterFirstUseDate = @"kAppiraterFirstUseDate"; NSString *const kAppiraterUseCount = @"kAppiraterUseCount"; NSString *const kAppiraterSignificantEventCount = @"kAppiraterSignificantEventCount"; NSString *const kAppiraterCurrentVersion = @"kAppiraterCurrentVersion"; NSString *const kAppiraterRatedCurrentVersion = @"kAppiraterRatedCurrentVersion"; NSString *const kAppiraterDeclinedToRate = @"kAppiraterDeclinedToRate"; NSString *const kAppiraterReminderRequestDate = @"kAppiraterReminderRequestDate"; NSString *templateReviewURL = @"itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=APP_ID&onlyLatestVersion=true&pageNumber=0&sortOrdering=1&type=Purple+Software"; NSString *templateReviewURLIpad = @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=APP_ID"; @interface Appirater (hidden) - (BOOL)connectedToNetwork; + (Appirater*)sharedInstance; - (void)showRatingAlert; - (BOOL)ratingConditionsHaveBeenMet; - (void)incrementUseCount; @end @implementation Appirater (hidden) - (BOOL)connectedToNetwork { // Create zero addy struct sockaddr_in zeroAddress; bzero(&zeroAddress, sizeof(zeroAddress)); zeroAddress.sin_len = sizeof(zeroAddress); zeroAddress.sin_family = AF_INET; // Recover reachability flags SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress); SCNetworkReachabilityFlags flags; BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags); CFRelease(defaultRouteReachability); if (!didRetrieveFlags) { NSLog(@"Error. Could not recover network reachability flags"); return NO; } BOOL isReachable = flags & kSCNetworkFlagsReachable; BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired; BOOL nonWiFi = flags & kSCNetworkReachabilityFlagsTransientConnection; NSURL *testURL = [NSURL URLWithString:@"http://www.apple.com/"]; NSURLRequest *testRequest = [NSURLRequest requestWithURL:testURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:20.0]; NSURLConnection *testConnection = [[NSURLConnection alloc] initWithRequest:testRequest delegate:self]; return ((isReachable && !needsConnection) || nonWiFi) ? (testConnection ? YES : NO) : NO; } + (Appirater*)sharedInstance { static Appirater *appirater = nil; if (appirater == nil) { @synchronized(self) { if (appirater == nil) appirater = [[Appirater alloc] init]; } } return appirater; } - (void)showRatingAlert { UIAlertView *alertView = [[[UIAlertView alloc] initWithTitle:APPIRATER_MESSAGE_TITLE message:APPIRATER_MESSAGE delegate:self cancelButtonTitle:APPIRATER_CANCEL_BUTTON otherButtonTitles:APPIRATER_RATE_BUTTON, APPIRATER_RATE_LATER, nil] autorelease]; pause_stack++; //Frogatto-specific [alertView show]; } - (BOOL)ratingConditionsHaveBeenMet { if (APPIRATER_DEBUG) return YES; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSDate *dateOfFirstLaunch = [NSDate dateWithTimeIntervalSince1970:[userDefaults doubleForKey:kAppiraterFirstUseDate]]; NSTimeInterval timeSinceFirstLaunch = [[NSDate date] timeIntervalSinceDate:dateOfFirstLaunch]; NSTimeInterval timeUntilRate = 60 * 60 * 24 * APPIRATER_DAYS_UNTIL_PROMPT; if (timeSinceFirstLaunch < timeUntilRate) return NO; // check if the app has been used enough int useCount = [userDefaults integerForKey:kAppiraterUseCount]; if (useCount <= APPIRATER_USES_UNTIL_PROMPT) return NO; // check if the user has done enough significant events int sigEventCount = [userDefaults integerForKey:kAppiraterSignificantEventCount]; if (sigEventCount <= APPIRATER_SIG_EVENTS_UNTIL_PROMPT) return NO; // has the user previously declined to rate this version of the app? if ([userDefaults boolForKey:kAppiraterDeclinedToRate]) return NO; // has the user already rated the app? if ([userDefaults boolForKey:kAppiraterRatedCurrentVersion]) return NO; // if the user wanted to be reminded later, has enough time passed? NSDate *reminderRequestDate = [NSDate dateWithTimeIntervalSince1970:[userDefaults doubleForKey:kAppiraterReminderRequestDate]]; NSTimeInterval timeSinceReminderRequest = [[NSDate date] timeIntervalSinceDate:reminderRequestDate]; NSTimeInterval timeUntilReminder = 60 * 60 * 24 * APPIRATER_TIME_BEFORE_REMINDING; if (timeSinceReminderRequest < timeUntilReminder) return NO; return YES; } - (void)incrementUseCount { // get the app's version NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey]; // get the version number that we've been tracking NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSString *trackingVersion = [userDefaults stringForKey:kAppiraterCurrentVersion]; if (trackingVersion == nil) { trackingVersion = version; [userDefaults setObject:version forKey:kAppiraterCurrentVersion]; } if (APPIRATER_DEBUG) NSLog(@"APPIRATER Tracking version: %@", trackingVersion); if ([trackingVersion isEqualToString:version]) { // check if the first use date has been set. if not, set it. NSTimeInterval timeInterval = [userDefaults doubleForKey:kAppiraterFirstUseDate]; if (timeInterval == 0) { timeInterval = [[NSDate date] timeIntervalSince1970]; [userDefaults setDouble:timeInterval forKey:kAppiraterFirstUseDate]; } // increment the use count int useCount = [userDefaults integerForKey:kAppiraterUseCount]; useCount++; [userDefaults setInteger:useCount forKey:kAppiraterUseCount]; if (APPIRATER_DEBUG) NSLog(@"APPIRATER Use count: %d", useCount); } else { // it's a new version of the app, so restart tracking [userDefaults setObject:version forKey:kAppiraterCurrentVersion]; [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterFirstUseDate]; [userDefaults setInteger:1 forKey:kAppiraterUseCount]; [userDefaults setInteger:0 forKey:kAppiraterSignificantEventCount]; [userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion]; [userDefaults setBool:NO forKey:kAppiraterDeclinedToRate]; [userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate]; } [userDefaults synchronize]; } - (void)incrementSignificantEventCount { // get the app's version NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey]; // get the version number that we've been tracking NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSString *trackingVersion = [userDefaults stringForKey:kAppiraterCurrentVersion]; if (trackingVersion == nil) { trackingVersion = version; [userDefaults setObject:version forKey:kAppiraterCurrentVersion]; } if (APPIRATER_DEBUG) NSLog(@"APPIRATER Tracking version: %@", trackingVersion); if ([trackingVersion isEqualToString:version]) { // check if the first use date has been set. if not, set it. NSTimeInterval timeInterval = [userDefaults doubleForKey:kAppiraterFirstUseDate]; if (timeInterval == 0) { timeInterval = [[NSDate date] timeIntervalSince1970]; [userDefaults setDouble:timeInterval forKey:kAppiraterFirstUseDate]; } // increment the significant event count int sigEventCount = [userDefaults integerForKey:kAppiraterSignificantEventCount]; sigEventCount++; [userDefaults setInteger:sigEventCount forKey:kAppiraterSignificantEventCount]; if (APPIRATER_DEBUG) NSLog(@"APPIRATER Significant event count: %d", sigEventCount); } else { // it's a new version of the app, so restart tracking [userDefaults setObject:version forKey:kAppiraterCurrentVersion]; [userDefaults setDouble:0 forKey:kAppiraterFirstUseDate]; [userDefaults setInteger:0 forKey:kAppiraterUseCount]; [userDefaults setInteger:1 forKey:kAppiraterSignificantEventCount]; [userDefaults setBool:NO forKey:kAppiraterRatedCurrentVersion]; [userDefaults setBool:NO forKey:kAppiraterDeclinedToRate]; [userDefaults setDouble:0 forKey:kAppiraterReminderRequestDate]; } [userDefaults synchronize]; } @end @implementation Appirater - (void)incrementAndRate:(NSNumber*)_canPromptForRating { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [self incrementUseCount]; if ([_canPromptForRating boolValue] == YES && [self ratingConditionsHaveBeenMet] && [self connectedToNetwork]) { [self performSelectorOnMainThread:@selector(showRatingAlert) withObject:nil waitUntilDone:NO]; } [pool release]; } - (void)incrementSignificantEventAndRate:(NSNumber*)_canPromptForRating { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [self incrementSignificantEventCount]; if ([_canPromptForRating boolValue] == YES && [self ratingConditionsHaveBeenMet] && [self connectedToNetwork]) { [self performSelectorOnMainThread:@selector(showRatingAlert) withObject:nil waitUntilDone:NO]; } [pool release]; } + (void)appLaunched { [Appirater appLaunched:YES]; } + (void)appLaunched:(BOOL)canPromptForRating { /* We only count launches on non-multitasking devices, because multitasking devices also get a usage call when they come into the foreground and we don't want to count app launches as two uses on multitasking devices. */ //UIDevice *device = [UIDevice currentDevice]; //if ([device respondsToSelector:@selector(multitaskingSupported)] && // [device multitaskingSupported]) //{ // return; //} NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating]; [NSThread detachNewThreadSelector:@selector(incrementAndRate:) toTarget:[Appirater sharedInstance] withObject:_canPromptForRating]; [_canPromptForRating release]; } + (void)appEnteredForeground:(BOOL)canPromptForRating { NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating]; [NSThread detachNewThreadSelector:@selector(incrementAndRate:) toTarget:[Appirater sharedInstance] withObject:_canPromptForRating]; [_canPromptForRating release]; } + (void)userDidSignificantEvent:(BOOL)canPromptForRating { NSNumber *_canPromptForRating = [[NSNumber alloc] initWithBool:canPromptForRating]; [NSThread detachNewThreadSelector:@selector(incrementSignificantEventAndRate:) toTarget:[Appirater sharedInstance] withObject:_canPromptForRating]; [_canPromptForRating release]; } - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; switch (buttonIndex) { case 0: { // they don't want to rate it [userDefaults setBool:YES forKey:kAppiraterDeclinedToRate]; [userDefaults synchronize]; break; } case 1: { // they want to rate it NSString *reviewURL = nil; // figure out which URL to use. iPad only apps have to use a different app store URL NSDictionary *bundleDictionary = [[NSBundle mainBundle] infoDictionary]; if ([bundleDictionary objectForKey:@"UISupportedInterfaceOrientations"] != nil && [bundleDictionary objectForKey:@"UISupportedInterfaceOrientations~ipad"] == nil) { // it's an iPad only app, so use the iPad url reviewURL = [templateReviewURLIpad stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%d", APPIRATER_APP_ID]]; } else // iPhone or Universal app, so we can use the direct url reviewURL = [templateReviewURL stringByReplacingOccurrencesOfString:@"APP_ID" withString:[NSString stringWithFormat:@"%d", APPIRATER_APP_ID]]; [userDefaults setBool:YES forKey:kAppiraterRatedCurrentVersion]; [userDefaults synchronize]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:reviewURL]]; break; } case 2: // remind them later [userDefaults setDouble:[[NSDate date] timeIntervalSince1970] forKey:kAppiraterReminderRequestDate]; [userDefaults synchronize]; break; default: break; } pause_stack--; //Frogatto-specific } @end frogatto-1.3.1+dfsg/src/CMakeLists.txt0000644000175000017500000000746312060740335017517 0ustar vincentvincent# # This file contains lists of object files for our build targets. # Please keep every file in separate lines to make diff and patching easier. # set( FROGATTO_SRC_PLATFORM "" ) set( FROGATTO_LIB_PLATFORM "" ) if( WIN32 ) set( FROGATTO_SRC_PLATFORM frogatto-resouces.rc ) set( FROGATTO_LIB_PLATFORM shlwapi.lib pthreadVC2.lib glew32.lib ) endif( WIN32 ) # Game engine add_executable( frogatto IMG_savepng.cpp achievements.cpp animation_preview_widget.cpp asserts.cpp background.cpp blur.cpp border_widget.cpp button.cpp character_editor_dialog.cpp checkbox.cpp checksum.cpp code_editor_widget.cpp code_editor_dialog.cpp current_generator.cpp decimal.cpp editor_dialogs.cpp editor_formula_functions.cpp editor_layers_dialog.cpp editor_stats_dialog.cpp editor_variable_info.cpp external_text_editor.cpp clipboard.cpp collision_utils.cpp color_utils.cpp controls.cpp controls_dialog.cpp custom_object.cpp custom_object_callable.cpp custom_object_functions.cpp custom_object_type.cpp debug_console.cpp dialog.cpp draw_number.cpp draw_scene.cpp draw_tile.cpp editor.cpp editor_level_properties_dialog.cpp entity.cpp filesystem.cpp font.cpp formula.cpp formula_callable_definition.cpp formula_constants.cpp formula_function.cpp formula_function_registry.cpp formula_profiler.cpp formula_tokenizer.cpp formula_variable_storage.cpp frame.cpp framed_gui_element.cpp game_registry.cpp geometry.cpp globals.cpp graphical_font.cpp graphical_font_label.cpp grid_widget.cpp group_property_editor_dialog.cpp gui_formula_functions.cpp gui_section.cpp i18n.cpp image_widget.cpp input.cpp iphone_controls.cpp joystick.cpp json_parser.cpp json_tokenizer.cpp key.cpp key_button.cpp label.cpp level.cpp level_logic.cpp level_object.cpp level_runner.cpp level_solid_map.cpp light.cpp load_level.cpp main.cpp md5.cpp message_dialog.cpp module.cpp movement_script.cpp multi_tile_pattern.cpp multiplayer.cpp object_events.cpp options_dialog.cpp package.cpp particle_system.cpp pathfinding.cpp pause_game_dialog.cpp playable_custom_object.cpp player_info.cpp preferences.cpp preprocessor.cpp preview_tileset_widget.cpp property_editor_dialog.cpp random.cpp raster.cpp raster_distortion.cpp rectangle_rotator.cpp scrollbar_widget.cpp scrollable_widget.cpp segment_editor_dialog.cpp settings_dialog.cpp slider.cpp solid_map.cpp sound.cpp speech_dialog.cpp stats.cpp string_utils.cpp surface_cache.cpp surface_formula.cpp surface_palette.cpp surface_scaling.cpp surface.cpp text_editor_widget.cpp text_entry_widget.cpp texture.cpp texture_frame_buffer.cpp text_entry_widget.cpp thread.cpp tile_map.cpp tileset_editor_dialog.cpp tooltip.cpp translate.cpp utils.cpp variant.cpp variant_callable.cpp variant_utils.cpp water.cpp water_particle_system.cpp weather_particle_system.cpp widget.cpp unit_test.cpp formula_test.cpp loading_screen.cpp utility_object_compiler.cpp utility_query.cpp utility_render_level.cpp vector_text.cpp wml_formula_callable.cpp ${FROGATTO_SRC_PLATFORM} ) target_link_libraries( frogatto ${OPENGL_LIBRARIES} ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY} ${SDLTTF_LIBRARY} ${SDLMIXER_LIBRARY} ${FROGATTO_LIB_PLATFORM} ) # Server add_executable( server server.cpp simple_wml.cpp ) # ## Unit test #add_executable( formula_test_objects # filesystem.cpp # formula_function.cpp # formula_tokenizer.cpp # string_utils.cpp # variant.cpp # wml_node.cpp # wml_parser.cpp # wml_utils.cpp # wml_writer.cpp ) # ## Unit test #add_executable( wml_modify_test_objects # filesystem.cpp # string_utils.cpp # wml_node.cpp # wml_parser.cpp # wml_utils.cpp ) # ## Unit test #add_executable( wml_schema_test_objects # filesystem.cpp # string_utils.cpp # wml_node.cpp # wml_parser.cpp # wml_utils.cpp ) #frogatto-1.3.1+dfsg/src/IMG_savepng.cpp0000644000175000017500000002247712060740335017624 0ustar vincentvincent/* Based on zlib license - see http://www.gzip.org/zlib/zlib_license.html This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. "Philip D. Bober" */ /** * 4/17/04 - IMG_SavePNG & IMG_SavePNG_RW - Philip D. Bober * 11/08/2004 - Compr fix, levels -1,1-7 now work - Tyler Montbriand */ #ifdef IMPLEMENT_SAVE_PNG #include #include #endif #include #include #include "graphics.hpp" #include #include "base64.hpp" #include "filesystem.hpp" #include "http_client.hpp" #include "IMG_savepng.h" #include "preferences.hpp" #include "stats.hpp" #include "surface.hpp" int IMG_SaveFrameBuffer(const char* file, int compression) { const int w = preferences::actual_screen_width(); const int h = preferences::actual_screen_height(); graphics::surface s(SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 24, SURFACE_MASK_RGB)); glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, s->pixels); unsigned char* pixels = (unsigned char*)s->pixels; for(int n = 0; n != h/2; ++n) { unsigned char* s1 = pixels + n*w*3; unsigned char* s2 = pixels + (h-n-1)*w*3; for(int m = 0; m != w*3; ++m) { std::swap(s1[m], s2[m]); } } const int result = IMG_SavePNG(file, s.get(), compression); if(result == -1) { fprintf(stderr, "FAILED TO SAVE SCREENSHOT\n"); return result; } fprintf(stderr, "SAVED SCREENSHOT TO %s.\n", file); return result; } int IMG_SavePNG(const char *file, SDL_Surface *surf,int compression){ #ifdef IMPLEMENT_SAVE_PNG SDL_RWops *fp; int ret; fp=SDL_RWFromFile(file,"wb"); if( fp == NULL ) { return (-1); } ret=IMG_SavePNG_RW(fp,surf,compression); SDL_RWclose(fp); return ret; #else return -1; #endif } #ifdef IMPLEMENT_SAVE_PNG static void png_write_data(png_structp png_ptr,png_bytep data, png_size_t length){ SDL_RWops *rp = (SDL_RWops*) png_get_io_ptr(png_ptr); SDL_RWwrite(rp,data,1,length); } #endif int IMG_SavePNG_RW(SDL_RWops *src, SDL_Surface *surf,int compression){ #ifdef IMPLEMENT_SAVE_PNG png_structp png_ptr; png_infop info_ptr; SDL_PixelFormat *fmt=NULL; SDL_Surface *tempsurf=NULL; int ret,funky_format,used_alpha; unsigned int i; Uint8 temp_alpha; png_colorp palette; Uint8 *palette_alpha=NULL; png_byte **row_pointers=NULL; png_ptr=NULL;info_ptr=NULL;palette=NULL;ret=-1; funky_format=0; if( !src || !surf) { goto savedone; /* Nothing to do. */ } row_pointers=(png_byte **)malloc(surf->h * sizeof(png_byte*)); if (!row_pointers) { SDL_SetError("Couldn't allocate memory for rowpointers"); goto savedone; } png_ptr=png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL); if (!png_ptr){ SDL_SetError("Couldn't allocate memory for PNG file"); goto savedone; } info_ptr= png_create_info_struct(png_ptr); if (!info_ptr){ SDL_SetError("Couldn't allocate image information for PNG file"); goto savedone; } /* setup custom writer functions */ png_set_write_fn(png_ptr,(voidp)src,png_write_data,NULL); if (setjmp(png_jmpbuf(png_ptr))){ SDL_SetError("Unknown error writing PNG"); goto savedone; } if(compression>Z_BEST_COMPRESSION) compression=Z_BEST_COMPRESSION; if(compression == Z_NO_COMPRESSION) // No compression { png_set_filter(png_ptr,0,PNG_FILTER_NONE); png_set_compression_level(png_ptr,Z_NO_COMPRESSION); } else if(compression<0) // Default compression png_set_compression_level(png_ptr,Z_DEFAULT_COMPRESSION); else png_set_compression_level(png_ptr,compression); fmt=surf->format; if(fmt->BitsPerPixel==8){ /* Paletted */ png_set_IHDR(png_ptr,info_ptr, surf->w,surf->h,8,PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); palette=(png_colorp) malloc(fmt->palette->ncolors * sizeof(png_color)); if (!palette) { SDL_SetError("Couldn't create memory for palette"); goto savedone; } for (i=0;ipalette->ncolors;i++) { palette[i].red=fmt->palette->colors[i].r; palette[i].green=fmt->palette->colors[i].g; palette[i].blue=fmt->palette->colors[i].b; } png_set_PLTE(png_ptr,info_ptr,palette,fmt->palette->ncolors); if (surf->flags&SDL_SRCCOLORKEY) { Uint32 colorkey; #if defined(__ANDROID__) && SDL_VERSION_ATLEAST(1, 3, 0) SDL_GetColorKey(surf, &colorkey); #else colorkey = fmt->colorkey; #endif palette_alpha=(Uint8 *)malloc((colorkey+1)*sizeof(Uint8)); if (!palette_alpha) { SDL_SetError("Couldn't create memory for palette transparency"); goto savedone; } /* FIXME: memset? */ for (i=0;i<(colorkey+1);i++) { palette_alpha[i]=255; } palette_alpha[colorkey]=0; png_set_tRNS(png_ptr,info_ptr,palette_alpha,colorkey+1,NULL); } }else{ /* Truecolor */ if (fmt->Amask) { png_set_IHDR(png_ptr,info_ptr, surf->w,surf->h,8,PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); } else { png_set_IHDR(png_ptr,info_ptr, surf->w,surf->h,8,PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); } } png_write_info(png_ptr, info_ptr); if (fmt->BitsPerPixel==8) { /* Paletted */ for(i=0;ih;i++){ row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch; } if(SDL_MUSTLOCK(surf)){ SDL_LockSurface(surf); } png_write_image(png_ptr, row_pointers); if(SDL_MUSTLOCK(surf)){ SDL_UnlockSurface(surf); } }else{ /* Truecolor */ if(fmt->BytesPerPixel==3){ if(fmt->Amask){ /* check for 24 bit with alpha */ funky_format=1; }else{ /* Check for RGB/BGR/GBR/RBG/etc surfaces.*/ #if SDL_BYTEORDER == SDL_BIG_ENDIAN if(fmt->Rmask!=0xFF0000 || fmt->Gmask!=0x00FF00 || fmt->Bmask!=0x0000FF){ #else if(fmt->Rmask!=0x0000FF || fmt->Gmask!=0x00FF00 || fmt->Bmask!=0xFF0000){ #endif funky_format=1; } } }else if (fmt->BytesPerPixel==4){ if (!fmt->Amask) { /* check for 32bit but no alpha */ funky_format=1; }else{ /* Check for ARGB/ABGR/GBAR/RABG/etc surfaces.*/ #if SDL_BYTEORDER == SDL_BIG_ENDIAN if(fmt->Rmask!=0xFF000000 || fmt->Gmask!=0x00FF0000 || fmt->Bmask!=0x0000FF00 || fmt->Amask!=0x000000FF){ #else if(fmt->Rmask!=0x000000FF || fmt->Gmask!=0x0000FF00 || fmt->Bmask!=0x00FF0000 || fmt->Amask!=0xFF000000){ #endif funky_format=1; } } }else{ /* 555 or 565 16 bit color */ funky_format=1; } if (funky_format) { /* Allocate non-funky format, and copy pixeldata in*/ if(fmt->Amask){ #if SDL_BYTEORDER == SDL_BIG_ENDIAN tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); #else tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); #endif }else{ #if SDL_BYTEORDER == SDL_BIG_ENDIAN tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x00000000); #else tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000); #endif } if(!tempsurf){ SDL_SetError("Couldn't allocate temp surface"); goto savedone; } if(surf->flags&SDL_SRCALPHA){ #if defined(__ANDROID__) && SDL_VERSION_ATLEAST(1, 3, 0) SDL_GetSurfaceAlphaMod(surf, &temp_alpha); #else temp_alpha=fmt->alpha; #endif used_alpha=1; SDL_SetAlpha(surf,0,255); /* Set for an opaque blit */ }else{ used_alpha=0; } if(SDL_BlitSurface(surf,NULL,tempsurf,NULL)!=0){ SDL_SetError("Couldn't blit surface to temp surface"); SDL_FreeSurface(tempsurf); goto savedone; } if (used_alpha) { SDL_SetAlpha(surf,SDL_SRCALPHA,(Uint8)temp_alpha); /* Restore alpha settings*/ } for(i=0;ih;i++){ row_pointers[i]= ((png_byte*)tempsurf->pixels) + i*tempsurf->pitch; } if(SDL_MUSTLOCK(tempsurf)){ SDL_LockSurface(tempsurf); } png_write_image(png_ptr, row_pointers); if(SDL_MUSTLOCK(tempsurf)){ SDL_UnlockSurface(tempsurf); } SDL_FreeSurface(tempsurf); } else { for(i=0;ih;i++){ row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch; } if(SDL_MUSTLOCK(surf)){ SDL_LockSurface(surf); } png_write_image(png_ptr, row_pointers); if(SDL_MUSTLOCK(surf)){ SDL_UnlockSurface(surf); } } } png_write_end(png_ptr, NULL); ret=0; /* got here, so nothing went wrong. YAY! */ savedone: /* clean up and return */ png_destroy_write_struct(&png_ptr,&info_ptr); if (palette) { free(palette); } if (palette_alpha) { free(palette_alpha); } if (row_pointers) { free(row_pointers); } return ret; #else return -1; #endif } frogatto-1.3.1+dfsg/src/IMG_savepng.h0000644000175000017500000000326312060740335017261 0ustar vincentvincent/* Based on zlib license - see http://www.gzip.org/zlib/zlib_license.html This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. "Philip D. Bober" Modified by David White */ #ifndef __IMG_SAVETOPNG_H__ #define __IMG_SAVETOPNG_H__ #include "graphics.hpp" #define IMG_COMPRESS_OFF 0 #define IMG_COMPRESS_MAX 9 #define IMG_COMPRESS_DEFAULT -1 int IMG_SaveFrameBuffer(const char* file, int compression=5); /** * Takes a filename, a surface to save, and a compression level. The * compression level can be 0(min) through 9(max), or -1(default). */ int IMG_SavePNG(const char* file, SDL_Surface* surf, int compression=5); /** * Takes a SDL_RWops pointer, a surface to save, and a compression level. * compression can be 0(min) through 9(max), or -1(default). */ int IMG_SavePNG_RW(SDL_RWops* src, SDL_Surface* surf, int compression); #endif/*__IMG_SAVETOPNG_H__*/ frogatto-1.3.1+dfsg/src/LICENSE0000644000175000017500000010451312060740335015756 0ustar vincentvincent GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . frogatto-1.3.1+dfsg/src/SConscript0000755000175000017500000000136212060740335016764 0ustar vincentvincent# vi: syntax=python:et:ts=4 Import("*") makefile = file(File('#/Makefile.common').abspath) target = None sources_map = {} contents = makefile.read() objectlines = [line for line in contents.replace("\\\n","").split("\n") if "objects =" in line] for line in objectlines: (target, rest) = line.split("objects =") if len(target) == 0: target = "game" else: target = target.rstrip("_") sources_map[target] = [o for o in [object.strip().replace(".o", ".cpp") for object in rest.strip().split()] if o not in env["exclude"]] binaries = [] for key in sources_map: prog = env.Program("#/" + key + build_suffix, sources_map[key]) binaries.append(env.Alias(key, prog)) all = env.Alias("all", binaries) env.Default(all) frogatto-1.3.1+dfsg/src/SDLMain.h0000644000175000017500000000054312060740335016347 0ustar vincentvincent/* SDLMain.m - main entry point for our Cocoa-ized SDL app Initial Version: Darrell Walisser Non-NIB-Code & other changes: Max Horn Feel free to customize this file to suit your needs */ #import @interface SDLMain : NSObject { } -(IBAction) toggleFullscreen: (id)sender; @end frogatto-1.3.1+dfsg/src/SDLMain.m0000644000175000017500000000461712060740335016362 0ustar vincentvincent/* SDLMain.m - main entry point for our Cocoa-ized SDL app Initial Version: Darrell Walisser Non-NIB-Code & other changes: Max Horn Feel free to customize this file to suit your needs Heavily modified by Ben Anderman. */ #import "SDL.h" #import "SDLMain.h" #import /* for MAXPATHLEN */ #import #include "utils.hpp" static int gArgc; static char **gArgv; static BOOL gFinderLaunch; @interface SDLApplication : NSApplication @end @implementation SDLApplication /* Invoked from the Quit menu item */ - (void)terminate:(id)sender { /* Post a SDL_QUIT event */ SDL_Event event; event.type = SDL_QUIT; SDL_PushEvent(&event); } - (BOOL)_handleKeyEquivalent:(NSEvent *)theEvent { [[self mainMenu] performKeyEquivalent:theEvent]; return YES; } - (void) sendEvent:(NSEvent *)event { if(NSKeyDown == [event type] || NSKeyUp == [event type]) { if([event modifierFlags] & NSCommandKeyMask) [super sendEvent: event]; } else { [super sendEvent: event]; } } @end /* The main class of the application, the application's delegate */ @implementation SDLMain /* Called when the internal event loop has just started running */ - (void) applicationDidFinishLaunching: (NSNotification *) note { setenv ("SDL_ENABLEAPPEVENTS", "1", 1); int status; /* Set the working directory to the .app's parent directory */ chdir([[[NSBundle mainBundle] resourcePath] fileSystemRepresentation]); /* Hand off to main application code */ status = SDL_main (gArgc, gArgv); /* We're done, thank you for playing */ exit(status); } - (IBAction) toggleFullscreen: (id)sender { toggle_fullscreen(); } @end #ifdef main # undef main #endif /* Main entry point to executable - should *not* be SDL_main! */ int main (int argc, char **argv) { /* Copy the arguments into a global variable */ int i; /* This is passed if we are launched by double-clicking */ if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) { gArgc = 1; gFinderLaunch = YES; } else { gArgc = argc; gFinderLaunch = NO; } gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1)); assert (gArgv != NULL); for (i = 0; i < gArgc; i++) gArgv[i] = argv[i]; gArgv[i] = NULL; [SDLApplication sharedApplication]; [NSBundle loadNibNamed:@"SDLMain" owner:NSApp]; [NSApp run]; return 0; } frogatto-1.3.1+dfsg/src/SampleOFDelegate.h0000644000175000017500000000047212060740335020222 0ustar vincentvincent#pragma once #import "OpenFeintDelegate.h" @interface SampleOFDelegate : NSObject< OpenFeintDelegate > - (void)dashboardWillAppear; - (void)dashboardDidAppear; - (void)dashboardWillDisappear; - (void)dashboardDidDisappear; - (void)userLoggedIn:(NSString*)userId; - (BOOL)showCustomOpenFeintApprovalScreen; @endfrogatto-1.3.1+dfsg/src/SampleOFDelegate.mm0000644000175000017500000000114612060740335020403 0ustar vincentvincent#import "SampleOFDelegate.h" #import "OpenFeint+UserOptions.h" #include "globals.h" @implementation SampleOFDelegate - (void)dashboardWillAppear { pause_stack++; of_dashboard_visible = true; } - (void)dashboardDidAppear { } - (void)dashboardWillDisappear { } - (void)dashboardDidDisappear { pause_stack--; of_dashboard_visible = false; } - (void)offlineUserLoggedIn:(NSString*)userId { NSLog(@"User logged in, but OFFLINE. UserId: %@", userId); } - (void)userLoggedIn:(NSString*)userId { NSLog(@"User logged in. UserId: %@", userId); } - (BOOL)showCustomOpenFeintApprovalScreen { return NO; } @endfrogatto-1.3.1+dfsg/src/achievements.cpp0000644000175000017500000000346312060740335020132 0ustar vincentvincent#include #include #include "achievements.hpp" #include "filesystem.hpp" #include "foreach.hpp" #include "formula_callable.hpp" #include "i18n.hpp" #include "json_parser.hpp" #include "preferences.hpp" #include "string_utils.hpp" #include "of_bridge.h" #include "variant.hpp" namespace { std::map cache; } achievement_ptr achievement::get(const std::string& id) { if(cache.empty()) { variant node; try { node = (json::parse_from_file("data/achievements.cfg")); } catch(json::parse_error&) { cache[""]; //mark as loaded return achievement_ptr(); } foreach(variant achievement_node, node["achievement"].as_list()) { achievement_ptr a(new achievement(achievement_node)); cache[a->id()] = a; } } return cache[id]; } achievement::achievement(variant node) : id_(node["id"].as_string()), name_(i18n::tr(node["name"].as_string())), description_(i18n::tr(node["description"].as_string())), points_(node["points"].as_int()), of_id_(node["of_id"].as_int()) { } namespace { std::vector* achievements = NULL; } bool attain_achievement(const std::string& id) { if(achievements == NULL) { achievements = new std::vector; variant val = preferences::registry()->query_value("achievements"); if(val.is_string()) { *achievements = util::split(val.as_string()); std::sort(achievements->begin(), achievements->end()); } } if(std::binary_search(achievements->begin(), achievements->end(), id)) { return false; } #ifdef ENABLE_OPENFEINT achievement_ptr a = achievement::get(id); of_earn_achievement(a->of_id()); #endif achievements->push_back(id); std::sort(achievements->begin(), achievements->end()); preferences::registry()->mutate_value("achievements", variant(util::join(*achievements))); return true; } frogatto-1.3.1+dfsg/src/achievements.hpp0000644000175000017500000000131612060740335020132 0ustar vincentvincent#ifndef ACHIEVEMENTS_HPP_INCLUDED #define ACHIEVEMENTS_HPP_INCLUDED #include #include #include "variant.hpp" class achievement; typedef boost::shared_ptr achievement_ptr; class achievement { public: static achievement_ptr get(const std::string& id); explicit achievement(variant node); const std::string& id() const { return id_; } const std::string& name() const { return name_; } const std::string& description() const { return description_; } int points() const { return points_; } int of_id() const { return of_id_; } private: std::string id_, name_, description_; int points_, of_id_; }; bool attain_achievement(const std::string& id); #endif frogatto-1.3.1+dfsg/src/animation_creator.cpp0000644000175000017500000004546112060740335021161 0ustar vincentvincent#ifndef NO_EDITOR #include #include #include #include "animation_creator.hpp" #include "draw_scene.hpp" #include "dropdown_widget.hpp" #include "file_chooser_dialog.hpp" #include "foreach.hpp" #include "frame.hpp" #include "graphics.hpp" #include "level.hpp" #include "message_dialog.hpp" #include "module.hpp" #include "preferences.hpp" #include "raster.hpp" #include "slider.hpp" #include "surface_cache.hpp" namespace gui { namespace { void do_draw_scene() { draw_scene(level::current(), last_draw_position()); } int slider_transform(double d) { // normalize to [-20.0,20.0] range. d = (d - 0.5) * 2.0 * 20; double d_abs = abs(d); if(d_abs > 10) { // Above 10 units we go non-linear. return int((d < 0 ? -1.0 : 1.0) * pow(10, d_abs/10)); } return int(d); } // Given two variants, which are maps merge the properties from v2 into v1 that // don't already exist in v1. void variant_map_merge(variant& v1, const variant& v2) { std::map::const_iterator v2it = v2.as_map().begin(); std::map::const_iterator v2end = v2.as_map().end(); while(v2it != v2end) { std::map::const_iterator v1it = v1.as_map().find(v2it->first); if(v1it == v1.as_map().end()) { v1.add_attr(v2it->first, v2it->second); } v2it++; } } void load_default_properties(std::map* def_properties) { // integer properties (*def_properties)[variant("frames")] = variant(1); (*def_properties)[variant("frames_per_row")] = variant(-1); (*def_properties)[variant("duration")] = variant(-1); (*def_properties)[variant("pad")] = variant(0); (*def_properties)[variant("rotate")] = variant(0); (*def_properties)[variant("blur")] = variant(0); (*def_properties)[variant("damage")] = variant(0); (*def_properties)[variant("feet_x")] = variant(0); (*def_properties)[variant("feet_y")] = variant(0); (*def_properties)[variant("velocity_x")] = variant(INT_MIN); (*def_properties)[variant("velocity_y")] = variant(INT_MIN); (*def_properties)[variant("accel_x")] = variant(INT_MIN); (*def_properties)[variant("accel_y")] = variant(INT_MIN); (*def_properties)[variant("scale")] = variant(2); (*def_properties)[variant("id")] = variant("id"); //(*def_properties)[variant("image")] = variant(""); std::vector v; //rects (*def_properties)[variant("rect")] = variant(&v); (*def_properties)[variant("collide")] = variant(&v); (*def_properties)[variant("hit")] = variant(&v); (*def_properties)[variant("platform")] = variant(&v); // some bools (*def_properties)[variant("reverse")] = variant::from_bool(false); (*def_properties)[variant("play_backwards")] = variant::from_bool(false); (*def_properties)[variant("rotate_on_slope")] = variant::from_bool(false); } std::map& get_default_properties() { static std::map defs; if(defs.empty()) { load_default_properties(&defs); } return defs; } } animation_creator_dialog::animation_creator_dialog(int x, int y, int w, int h, const variant& anims) : dialog(x,y,w,h), selected_frame_(-1), dragging_slider_(false), changed_(false), simple_options_(true) { set_clear_bg_amount(255); reset_current_object(); if(anims.is_list()) { anims_ = anims.as_list(); if(anims_.size() > 0) { selected_frame_ = 0; current_ = anims_[selected_frame_]; } } else if(anims.is_map() && anims.has_key("image")){ anims_.push_back(anims); } set_process_hook(boost::bind(&animation_creator_dialog::process, this)); init(); } std::vector animation_creator_dialog::common_animation_list() { // List of common animations. std::vector v; v.push_back("stand"); v.push_back("normal"); v.push_back("hurt"); v.push_back("turn"); v.push_back("walk"); v.push_back("spring"); v.push_back("fly"); v.push_back("jump"); v.push_back("fall"); v.push_back("open"); v.push_back("ajar"); v.push_back("close"); v.push_back("land"); v.push_back("thrown"); v.push_back("lose_wings"); v.push_back("portrait"); v.push_back("swim"); v.push_back("attack"); v.push_back("cling"); v.push_back("fire"); v.push_back("jump_attack"); v.push_back("run"); v.push_back("crouch"); v.push_back("enter_crouch"); v.push_back("enter_lookup"); v.push_back("flash"); v.push_back("leave_crouch"); v.push_back("lookup"); v.push_back("pushed"); v.push_back("roll"); v.push_back("run_attack"); v.push_back("shoot"); return v; } void animation_creator_dialog::init() { const int border_offset = 35; int current_height = 35; int hpad = 10; clear(); // Add copy desintation box grid_ptr g(new grid(2)); g->set_hpad(20); g->add_col(button_ptr(new button(new label("Set Destination", 14), boost::bind(&animation_creator_dialog::set_destination, this)))) .add_col(label_ptr(new label(copy_path_, graphics::color_green(), 14))); g->add_col(widget_ptr(new label("", graphics::color_yellow(), 12))) .add_col(widget_ptr(new label("Images will be copied to the destination directory", graphics::color_yellow(), 12))); add_widget(g, border_offset, current_height); current_height += g->height() + hpad; // Add current list of animations g.reset(new grid(3)); g->set_dim(width()/2, height()/5); g->set_max_height(height()/5); g->set_show_background(true); g->set_hpad(10); g->set_header_row(0); g->allow_selection(true); g->add_col(label_ptr(new label("Identifier", 14))) .add_col(label_ptr(new label("Image Path", 14))) .add_col(label_ptr(new label("Area in Image", 14))); foreach(const variant& v, anims_) { std::stringstream ss; rect r; if(v.has_key("rect")) { r = rect(v["rect"]); } else if(v.has_key("x") && v.has_key("y") && v.has_key("w") && v.has_key("h")) { r = rect(v["x"].as_int(), v["y"].as_int(), v["w"].as_int(), v["h"].as_int()); } ss << r; g->add_col(label_ptr(new label(v.has_key("id") ? v["id"].as_string() : "", 12))) .add_col(label_ptr(new label(v.has_key("image") ? v["image"].as_string() : "", 12))) .add_col(label_ptr(new label(ss.str(), 12))); } g->register_selection_callback(boost::bind(&animation_creator_dialog::select_animation, this, _1)); add_widget(g, border_offset, current_height); current_height += g->height() + hpad; g.reset(new grid(3)); g->set_max_height(int(height()/2 - 50)); g->set_zorder(1); dropdown_widget_ptr id_entry(new dropdown_widget(common_animation_list(), 150, 28, dropdown_widget::DROPDOWN_COMBOBOX)); id_entry->set_font_size(14); id_entry->set_text(current_.has_key("id") ? current_["id"].as_string() : "normal"); id_entry->set_dropdown_height(height() - current_height - border_offset); id_entry->set_on_change_handler(boost::bind(&animation_creator_dialog::on_id_change, this, id_entry, _1)); id_entry->set_on_select_handler(boost::bind(&animation_creator_dialog::on_id_set, this, id_entry, _1, _2)); g->add_col(widget_ptr(new label("Identifier: ", graphics::color_white(), 14))) .add_col(widget_ptr(id_entry)) .finish_row(); g->add_col(button_ptr(new button(new label("Choose Image File", 14), boost::bind(&animation_creator_dialog::set_image_file, this)))) .add_col(widget_ptr(new label(rel_path_, graphics::color_green(), 14))) .finish_row(); std::pair p; foreach(p, current_.as_map()) { if(p.second.is_int() && show_attribute(p.first)) { text_editor_widget_ptr entry(new text_editor_widget(100, 28)); std::stringstream ss; ss << p.second.as_int(); entry->set_text(ss.str()); slider_ptr slide(new slider(200, boost::bind((&animation_creator_dialog::change_slide), this, p.first.as_string(), entry, _1), 0.5)); slide->set_drag_end(boost::bind(&animation_creator_dialog::end_slide, this, p.first.as_string(), slide, entry, _1)); entry->set_on_change_handler(boost::bind(&animation_creator_dialog::change_text, this, p.first.as_string(), entry, slide)); entry->set_on_enter_handler(boost::bind(&animation_creator_dialog::execute_change_text, this, p.first.as_string(), entry, slide)); entry->set_on_tab_handler(boost::bind(&animation_creator_dialog::execute_change_text, this, p.first.as_string(), entry, slide)); g->add_col(widget_ptr(new label(p.first.as_string(), graphics::color_white(), 12))) .add_col(entry) .add_col(slide); } } add_widget(g, border_offset, current_height); current_height += g->height() + hpad; // Add/Delete animation buttons g.reset(new grid(4)); g->set_hpad(50); g->add_col(button_ptr(new button(new label("New", 14), boost::bind(&animation_creator_dialog::anim_new, this)))) .add_col(button_ptr(new button(new label("Save", 14), boost::bind(&animation_creator_dialog::anim_save, this, (dialog*)NULL)))) .add_col(button_ptr(new button(new label("Delete", 14), boost::bind(&animation_creator_dialog::anim_del, this)))) .add_col(button_ptr(new button(new label("Finish", 14), boost::bind(&animation_creator_dialog::finish, this)))); add_widget(g, border_offset, height() - border_offset - g->height()); current_height = height() - border_offset - g->height(); checkbox_ptr cb = new checkbox("Simplified Options", simple_options_, boost::bind(&animation_creator_dialog::set_option, this), BUTTON_SIZE_DOUBLE_RESOLUTION); add_widget(cb, border_offset, current_height - cb->height() - 10); } void animation_creator_dialog::process() { int border_offset = 35; try { if(animation_preview_widget::is_animation(current_)) { if(!animation_preview_) { animation_preview_.reset(new animation_preview_widget(current_)); animation_preview_->set_rect_handler(boost::bind(&animation_creator_dialog::set_animation_rect, this, _1)); animation_preview_->set_solid_handler(boost::bind(&animation_creator_dialog::move_solid_rect, this, _1, _2)); animation_preview_->set_pad_handler(boost::bind(&animation_creator_dialog::set_integer_attr, this, "pad", _1)); animation_preview_->set_num_frames_handler(boost::bind(&animation_creator_dialog::set_integer_attr, this, "frames", _1)); animation_preview_->set_frames_per_row_handler(boost::bind(&animation_creator_dialog::set_integer_attr, this, "frames_per_row", _1)); animation_preview_->set_loc(width() - int(width()*0.42) - border_offset, border_offset); animation_preview_->set_dim(int(width()*0.42), height()-border_offset*2); animation_preview_->init(); } else { animation_preview_->set_object(current_); } } } catch (type_error&) { if(animation_preview_) { animation_preview_.reset(); } } catch(frame::error&) { // skip } catch(validation_failure_exception&) { if(animation_preview_) { animation_preview_.reset(); } } catch(graphics::load_image_error&) { if(animation_preview_) { animation_preview_.reset(); } } if(animation_preview_) { animation_preview_->process(); } } void animation_creator_dialog::handle_draw() const { dialog::handle_draw(); if(animation_preview_) { animation_preview_->draw(); } } bool animation_creator_dialog::handle_event(const SDL_Event& event, bool claimed) { if(animation_preview_) { claimed = animation_preview_->process_event(event, claimed) || claimed; if(claimed) { return claimed; } } return dialog::handle_event(event, claimed); } void animation_creator_dialog::set_animation_rect(rect r) { if(current_.is_null() == false) { current_.add_attr(variant("rect"), r.write()); changed_ = true; } init(); } void animation_creator_dialog::move_solid_rect(int dx, int dy) { if(current_.is_null() == false) { variant solid_area = current_["solid_area"]; if(!solid_area.is_list() || solid_area.num_elements() != 4) { return; } foreach(const variant& num, solid_area.as_list()) { if(!num.is_int()) { return; } } rect area(solid_area); area = rect(area.x() + dx, area.y() + dy, area.w(), area.h()); current_.add_attr(variant("solid_area"), area.write()); changed_ = true; } } void animation_creator_dialog::set_integer_attr(const char* attr, int value) { changed_ = true; //std::cerr << "set_integer_attr: " << attr << ": " << value << std::endl; slider_offset_[attr] = value; if(current_.is_null() == false) { current_.add_attr(variant(attr), variant(value)); } init(); } void animation_creator_dialog::on_id_change(dropdown_widget_ptr editor, const std::string& s) { if(current_.is_null() == false) { current_.add_attr(variant("id"), variant(s)); changed_ = true; } } void animation_creator_dialog::on_id_set(dropdown_widget_ptr editor, int selection, const std::string& s) { if(current_.is_null() == false) { current_.add_attr(variant("id"), variant(s)); changed_ = true; } init(); } void animation_creator_dialog::set_image_file() { gui::filter_list f; f.push_back(gui::filter_pair("Image Files", ".*?\\.(png|jpg|gif|bmp|tif|tiff|tga|webp|xpm|xv|pcx)")); f.push_back(gui::filter_pair("All Files", ".*")); gui::file_chooser_dialog open_dlg( int(preferences::virtual_screen_width()*0.1), int(preferences::virtual_screen_height()*0.1), int(preferences::virtual_screen_width()*0.8), int(preferences::virtual_screen_height()*0.8), f); open_dlg.set_background_frame("empty_window"); open_dlg.set_draw_background_fn(do_draw_scene); open_dlg.show_modal(); if(open_dlg.cancelled() == false) { image_file_ = open_dlg.get_file_name(); int offs = image_file_.rfind("/"); image_file_name_ = image_file_.substr(offs+1); if(current_.is_null() == false) { current_.add_attr(variant("image"), variant(image_file_)); changed_ = true; } rel_path_ = sys::compute_relative_path(module::get_module_path("") + "images", copy_path_ + "/" + image_file_name_); } init(); } void animation_creator_dialog::change_text(const std::string& s, text_editor_widget_ptr editor, slider_ptr slide) { if(!dragging_slider_) { int i; std::istringstream(editor->text()) >> i; slide->set_position(0.5); if(current_.is_null() == false) { current_.add_attr(variant(s), variant(i)); } changed_ = true; } } void animation_creator_dialog::execute_change_text(const std::string& s, text_editor_widget_ptr editor, slider_ptr slider) { if(!dragging_slider_) { int i; std::istringstream(editor->text()) >> i; slider->set_position(0.5); set_integer_attr(s.c_str(), i); } } void animation_creator_dialog::change_slide(const std::string& s, text_editor_widget_ptr editor, double d) { dragging_slider_ = true; std::ostringstream ss; int i = slider_transform(d) + slider_offset_[s]; ss << i; editor->set_text(ss.str()); if(current_.is_null() == false) { current_.add_attr(variant(s), variant(i)); } changed_ = true; //int soffs = slider_offset_[s]; //set_integer_attr(s.c_str(), i); //slider_offset_[s] = soffs; } void animation_creator_dialog::end_slide(const std::string& s, slider_ptr slide, text_editor_widget_ptr editor, double d) { int i = slider_transform(d) + slider_offset_[s]; set_integer_attr(s.c_str(), i); slide->set_position(0.5); dragging_slider_ = false; init(); } void animation_creator_dialog::anim_del() { check_anim_changed(); if(selected_frame_ >= 0 && size_t(selected_frame_) < anims_.size()) { anims_.erase(anims_.begin() + selected_frame_); selected_frame_ = -1; } reset_current_object(); init(); } void animation_creator_dialog::anim_new() { check_anim_changed(); reset_current_object(); init(); } void animation_creator_dialog::reset_current_object() { get_default_properties().clear(); current_ = variant(&get_default_properties()); current_.add_attr(variant("image"), variant(image_file_)); //image_file_name_.clear(); //image_file_.clear(); //rel_path_.clear(); copy_path_ = module::get_module_path("") + "images"; selected_frame_ = -1; // reset the slider offsets. for(std::map::iterator it = slider_offset_.begin(); it != slider_offset_.end(); it++) { it->second = 0; } if(animation_preview_) { animation_preview_.reset(); } } void animation_creator_dialog::anim_save(dialog* d) { // Save the current animation parameters, overwriting current animation values. if(current_.is_null() == false) { if(selected_frame_ == -1) { // copy file sys::copy_file(image_file_, copy_path_ + "/" + image_file_name_); // important to fix up image path current_.add_attr(variant("image"), variant(rel_path_)); // erase any properties still as defaults. std::map::const_iterator vit = current_.as_map().begin(); std::map::const_iterator end = current_.as_map().end(); while(vit != end) { std::map::const_iterator dit = get_default_properties().find(vit->first); if(dit != get_default_properties().end()) { if(vit->second == dit->second) { current_.remove_attr((vit++)->first); } else { vit++; } } else { vit++; } } // add the animation to list anims_.push_back(current_); } else { anims_[selected_frame_] = current_; } } changed_ = false; reset_current_object(); if(d) { d->close(); } else { init(); } } void animation_creator_dialog::check_anim_changed() { if(changed_) { // Create message box with Save/Cancel options. dialog d((width()-400)/2, (height()-300)/2, 400, 300); d.set_background_frame("empty_window"); d.set_padding(20); label_ptr title = new label("Animation has changed.", graphics::color_white(), 24); d.add_widget(title, (d.width()-title->width())/2, 50); grid_ptr g = new grid(2); g->set_header_row(40); g->add_col(widget_ptr(new button("Save", boost::bind(&animation_creator_dialog::anim_save, this, &d)))) .add_col(widget_ptr(new button("Discard", boost::bind(&dialog::cancel, &d)))); d.add_widget(g, (d.width()-g->width())/2, 30+70+title->height()); d.show_modal(); changed_ = false; init(); } } void animation_creator_dialog::select_animation(int index) { // index 0 is our label row. if(index < 1 || size_t(index) > anims_.size()) { return; } check_anim_changed(); selected_frame_ = index - 1; current_ = anims_[selected_frame_]; variant_map_merge(current_, variant(&get_default_properties())); init(); } void animation_creator_dialog::set_destination() { file_chooser_dialog dir_dlg( int(preferences::virtual_screen_width()*0.2), int(preferences::virtual_screen_height()*0.2), int(preferences::virtual_screen_width()*0.6), int(preferences::virtual_screen_height()*0.6), gui::filter_list(), true, module::get_module_path("") + "images"); dir_dlg.set_background_frame("empty_window"); dir_dlg.set_draw_background_fn(do_draw_scene); dir_dlg.use_relative_paths(true); dir_dlg.show_modal(); if(dir_dlg.cancelled() == false) { copy_path_ = dir_dlg.get_path(); rel_path_ = sys::compute_relative_path(module::get_module_path("") + "images", copy_path_ + "/" + image_file_name_); } init(); } void animation_creator_dialog::finish() { check_anim_changed(); close(); } void animation_creator_dialog::set_option() { simple_options_ = !simple_options_; init(); } bool animation_creator_dialog::show_attribute(variant v) { if(!simple_options_) { return true; } std::string s = v.as_string(); if(s == "frames" || s == "frames_per_row" || s == "duration" || s == "pad") { return true; } return false; } } #endif // NO_EDITOR frogatto-1.3.1+dfsg/src/animation_creator.hpp0000644000175000017500000000477712060740335021173 0ustar vincentvincent#pragma once #ifndef ANIMATION_CREATOR_HPP_INCLUDED #define ANIMATION_CREATOR_HPP_INCLUDED #ifndef NO_EDITOR #include #include #include #include #include "animation_preview_widget.hpp" #include "checkbox.hpp" #include "button.hpp" #include "dialog.hpp" #include "dropdown_widget.hpp" #include "graphics.hpp" #include "grid_widget.hpp" #include "label.hpp" #include "raster.hpp" #include "slider.hpp" #include "text_editor_widget.hpp" #include "variant.hpp" namespace gui { class animation_creator_dialog : public virtual dialog { public: animation_creator_dialog(int x, int y, int w, int h, const variant& anims=variant()); virtual ~animation_creator_dialog() {} variant get_animations() { return variant(&anims_); } void process(); protected: void init(); void set_destination(); void select_animation(int index); void set_option(); void anim_del(); void anim_new(); void anim_save(dialog* d); void finish(); bool show_attribute(variant v); void check_anim_changed(); void reset_current_object(); virtual void handle_draw() const; virtual bool handle_event(const SDL_Event& event, bool claimed); private: std::vector anims_; variant current_; // Holds the currently selected variant. int selected_frame_; std::string copy_path_; std::string image_file_name_; // file name. std::string image_file_; // full path. std::string rel_path_; // Path relative to modules images path. bool changed_; // current animation modified? bool simple_options_; // simplified list of options. std::vector common_animation_list(); void on_id_change(dropdown_widget_ptr editor, const std::string& s); void on_id_set(dropdown_widget_ptr editor, int selection, const std::string& s); void set_image_file(); void change_text(const std::string& s, text_editor_widget_ptr editor, slider_ptr slider); void execute_change_text(const std::string& s, text_editor_widget_ptr editor, slider_ptr slider); void change_slide(const std::string& s, text_editor_widget_ptr editor, double d); void end_slide(const std::string& s, slider_ptr slide, text_editor_widget_ptr editor, double d); void set_animation_rect(rect r); void move_solid_rect(int dx, int dy); void set_integer_attr(const char* attr, int value); typedef std::pair slider_offset_pair; std::map slider_offset_; bool dragging_slider_; animation_preview_widget_ptr animation_preview_; }; } #endif // NO_EDITOR #endif // ANIMATION_CREATOR_HPP_INCLUDED frogatto-1.3.1+dfsg/src/animation_preview_widget.cpp0000644000175000017500000006232012060740335022537 0ustar vincentvincent#ifndef NO_EDITOR #include #include "animation_preview_widget.hpp" #include "button.hpp" #include "foreach.hpp" #include "formatter.hpp" #include "pathfinding.hpp" #include "raster.hpp" #include "solid_map.hpp" #include "surface_cache.hpp" #include "texture.hpp" namespace { using graphics::surface; const unsigned char RedBorder[] = {0xf9, 0x30, 0x3d}; const unsigned char BackgroundColor[] = {0x6f, 0x6d, 0x51}; bool is_pixel_border(const surface& s, int x, int y) { if(x < 0 || y < 0 || x >= s->w || y >= s->h) { return false; } unsigned char* pixel = reinterpret_cast(s->pixels) + y*s->pitch + x*4; for(int n = 0; n != 3; ++n) { if(pixel[n] != RedBorder[n]) { return false; } } return true; } bool is_pixel_alpha(const surface& s, const point& p) { unsigned char* pixel = reinterpret_cast(s->pixels) + p.y*s->pitch + p.x*4; if(pixel[3] == 0) { return true; } for(int n = 0; n != 3; ++n) { if(pixel[n] != BackgroundColor[n]) { return false; } } return true; } rect get_border_rect(const surface& s, int x, int y) { int w = 0, h = 0; while(is_pixel_border(s, x + w + 1, y)) { ++w; } while(is_pixel_border(s, x, y + h + 1) && is_pixel_border(s, x + w, y + h + 1)) { ++h; } if(w == 0 || h == 0) { return rect(); } return rect(x+1, y+1, w-1, h-1); } int path_cost_fn(const surface& s, const point& p1, const point& p2) { bool a1 = is_pixel_alpha(s, p1); bool a2 = is_pixel_alpha(s, p2); if(a1 && a2) return 2; else if(a1 ^ a2) return 1; return 0; } rect get_border_rect_heuristic_search(const surface& s, int ox, int oy, int max_cost) { int x1 = INT_MAX, y1 = INT_MAX, x2 = INT_MIN, y2 = INT_MIN; if(ox < 0 || oy < 0 || ox >= s->w || oy >= s->h) { return rect::from_coordinates(ox,oy,ox+1,oy+1); } const rect r(0, 0, s->w, s->h); if(is_pixel_alpha(s, point(ox, oy))) { return rect::from_coordinates(ox,oy,ox+1,oy+1); } typedef pathfinding::graph_node graph_node; typedef graph_node::graph_node_ptr graph_node_ptr; typedef std::map graph_node_list; graph_node_list node_list; std::deque open_list; typedef std::pair reachable_node; std::vector reachable; bool searching = true; try { graph_node_ptr current = graph_node_ptr(new graph_node(point(ox, oy))); current->set_cost(0, 0); current->set_on_open_list(true); open_list.push_back(current); node_list[point(ox, oy)] = current; while(searching && !open_list.empty()) { current = open_list.front(); open_list.pop_front(); current->set_on_open_list(false); current->set_on_closed_list(true); if(current->G() <= max_cost) { reachable.push_back(reachable_node(current->get_node_value(), is_pixel_alpha(s, current->get_node_value()))); } foreach(const point& p, pathfinding::get_neighbours_from_rect(current->get_node_value(), 1, 1, r)) { graph_node_list::const_iterator neighbour_node = node_list.find(p); int g_cost = path_cost_fn(s, p, current->get_node_value()) + current->G(); if(neighbour_node == node_list.end()) { graph_node_ptr new_node = graph_node_ptr(new graph_node(point(p.x, p.y))); new_node->set_parent(current); new_node->set_cost(g_cost, 0); new_node->set_on_open_list(true); node_list[p] = new_node; if(g_cost > max_cost) { new_node->set_on_closed_list(true); } else { new_node->set_on_open_list(true); open_list.push_back(new_node); } } else if(neighbour_node->second->on_closed_list() || neighbour_node->second->on_open_list()) { if(g_cost < neighbour_node->second->G()) { neighbour_node->second->G(g_cost); neighbour_node->second->set_parent(current); } } else { throw "Path error node on list, but not on open or closed lists"; } } } } catch(...) { std::cerr << "get_border_rect_heuristic_search(): Caught exception" << std::endl; } foreach(const reachable_node& rn, reachable) { if(rn.second) { if(rn.first.x < x1) x1 = rn.first.x; if(rn.first.x > x2) x2 = rn.first.x; if(rn.first.y < y1) y1 = rn.first.y; if(rn.first.y > y2) y2 = rn.first.y; } } std::cerr << "CALC RECT " << x1 << "," << y1 << "," << x2 << "," << y2 << std::endl; //std::cerr << "PIXEL: 0x" << std::hex << int(pixel[0]) << ",0x" << int(pixel[1]) << ",0x" << int(pixel[2]) << ",0x" << int(pixel[3]) << std::endl; return rect::from_coordinates(x1, y1, x2, y2); } rect get_border_rect_around_loc(const surface& s, int ox, int oy) { int x = ox, y = oy; std::cerr << "SEARCHING FOR BORDER AROUND " << x << "," << y << "\n"; while(y >= 0 && !is_pixel_border(s, x, y)) { --y; } while(x >= 0 && is_pixel_border(s, x, y)) { --x; } ++x; std::cerr << "STEPPED TO " << x << "," << y << "\n"; if(y >= 0 && is_pixel_border(s, x, y)) { std::cerr << "RETURNING " << get_border_rect(s, x, y) << "\n"; return get_border_rect(s, x, y); } else { std::cerr << "TRYING HEURISTIC SEARCH AROUND " << ox << "," << oy << std::endl; return get_border_rect_heuristic_search(s, ox, oy, 10); } } bool find_full_animation(const surface& s, const rect& r, int* pad, int* num_frames, int* frames_per_row) { const int x = r.x() + r.w()/2; const int y = r.y() + r.h()/2; int next_x = x + r.w(); if(next_x >= s->w) { std::cerr << "FAIL FIND " << next_x << " >= " << s->w << "\n"; return false; } rect next_rect = get_border_rect_around_loc(s, next_x, y); std::cerr << "NEXT RECT: " << next_rect << " VS " << r << "\n"; if(next_rect.w() != r.w() || next_rect.h() != r.h()) { return false; } *pad = next_rect.x() - r.x2(); *num_frames = 2; std::vector rect_row; rect_row.push_back(r); rect_row.push_back(next_rect); std::cerr << "SETTING... " << get_border_rect_around_loc(s, next_x + r.w() + *pad, y) << " VS " << rect(next_rect.x() + next_rect.w() + *pad, y, r.w(), r.h()) << "\n"; while(next_x + r.w() + *pad < s->w && get_border_rect_around_loc(s, next_x + r.w() + *pad, y) == rect(next_rect.x() + next_rect.w() + *pad, r.y(), r.w(), r.h())) { std::cerr << "ITER\n"; *num_frames += 1; next_x += r.w() + *pad; next_rect = rect(next_rect.x() + next_rect.w() + *pad, r.y(), r.w(), r.h()); rect_row.push_back(next_rect); } *frames_per_row = *num_frames; bool row_valid = true; while(row_valid) { int index = 0; foreach(rect& r, rect_row) { rect next_rect(r.x(), r.y() + r.h() + *pad, r.w(), r.h()); std::cerr << "MATCHING: " << get_border_rect_around_loc(s, next_rect.x() + next_rect.w()/2, next_rect.y() + next_rect.h()/2) << " VS " << next_rect << "\n"; if(next_rect.y2() >= s->h || get_border_rect_around_loc(s, next_rect.x() + next_rect.w()/2, next_rect.y() + next_rect.h()/2) != next_rect) { std::cerr << "MISMATCH: " << index << "/" << rect_row.size() << " -- " << get_border_rect_around_loc(s, next_rect.x() + next_rect.w()/2, next_rect.y() + next_rect.h()/2) << " VS " << next_rect << "\n"; row_valid = false; break; } r = next_rect; ++index; } if(row_valid) { *num_frames += *frames_per_row; } } return true; } } namespace gui { bool animation_preview_widget::is_animation(variant obj) { return !obj.is_null() && obj["image"].is_string() && !obj["image"].as_string().empty(); } animation_preview_widget::animation_preview_widget(const variant& v, game_logic::formula_callable* e) : widget(v,e), cycle_(0), zoom_label_(NULL), pos_label_(NULL), scale_(0), anchor_x_(-1), anchor_y_(-1), anchor_pad_(-1), has_motion_(false), dragging_sides_bitmap_(0), moving_solid_rect_(false), anchor_solid_x_(-1), anchor_solid_y_(-1) { ASSERT_LOG(get_environment() != 0, "You must specify a callable environment"); if(v.has_key("on_rect_change")) { rect_handler_ = boost::bind(&animation_preview_widget::rect_handler_delegate, this, _1); ffl_rect_handler_ = get_environment()->create_formula(v["on_rect_change"]); } if(v.has_key("on_pad_change")) { pad_handler_ = boost::bind(&animation_preview_widget::pad_handler_delegate, this, _1); ffl_pad_handler_ = get_environment()->create_formula(v["on_pad_change"]); } if(v.has_key("on_frames_change")) { num_frames_handler_ = boost::bind(&animation_preview_widget::num_frames_handler_delegate, this, _1); ffl_num_frames_handler_ = get_environment()->create_formula(v["on_frames_change"]); } if(v.has_key("on_frames_per_row_change")) { frames_per_row_handler_ = boost::bind(&animation_preview_widget::frames_per_row_handler_delegate, this, _1); ffl_frames_per_row_handler_ = get_environment()->create_formula(v["on_frames_per_row_change"]); } if(v.has_key("on_solid_change")) { solid_handler_ = boost::bind(&animation_preview_widget::solid_handler_delegate, this, _1, _2); ffl_solid_handler_ = get_environment()->create_formula(v["on_solid_change"]); } try { set_object(v); } catch(type_error&) { } catch(frame::error&) { } catch(validation_failure_exception&) { } catch(graphics::load_image_error&) { } } animation_preview_widget::animation_preview_widget(variant obj) : cycle_(0), zoom_label_(NULL), pos_label_(NULL), scale_(0), anchor_x_(-1), anchor_y_(-1), anchor_pad_(-1), has_motion_(false), dragging_sides_bitmap_(0), moving_solid_rect_(false), anchor_solid_x_(-1), anchor_solid_y_(-1) { set_environment(); set_object(obj); } void animation_preview_widget::init() { widgets_.clear(); button* b = new button("+", boost::bind(&animation_preview_widget::zoom_in, this)); b->set_loc(x() + 10, y() + height() - b->height() - 5); widgets_.push_back(widget_ptr(b)); b = new button("-", boost::bind(&animation_preview_widget::zoom_out, this)); b->set_loc(x() + 40, y() + height() - b->height() - 5); widgets_.push_back(widget_ptr(b)); zoom_label_ = new label("Zoom: 100%"); zoom_label_->set_loc(b->x() + b->width() + 10, b->y()); widgets_.push_back(widget_ptr(zoom_label_)); pos_label_ = new label(""); pos_label_->set_loc(zoom_label_->x() + zoom_label_->width() + 8, zoom_label_->y()); widgets_.push_back(widget_ptr(pos_label_)); b = new button("Reset", boost::bind(&animation_preview_widget::reset_rect, this)); b->set_loc(pos_label_->x() + pos_label_->width() + 58, y() + height() - b->height() - 5); widgets_.push_back(widget_ptr(b)); } void animation_preview_widget::set_object(variant obj) { if(obj == obj_) { return; } frame* f = new frame(obj); obj_ = obj; frame_.reset(f); cycle_ = 0; } void animation_preview_widget::process() { } void animation_preview_widget::handle_draw() const { int mousex, mousey; int mouse_buttons = SDL_GetMouseState(&mousex, &mousey); graphics::draw_rect(rect(x(),y(),width(),height()), graphics::color(0,0,0,196)); rect image_area(x(), y(), (width()*3)/4, height() - 30); const graphics::texture image_texture(graphics::texture::get(obj_["image"].as_string(), graphics::texture::NO_STRIP_SPRITESHEET_ANNOTATIONS)); if(image_texture.valid()) { #ifndef SDL_VIDEO_OPENGL_ES const graphics::clip_scope clipping_scope(image_area.sdl_rect()); #endif // SDL_VIDEO_OPENGL_ES const bool view_locked = mouse_buttons && locked_focus_.w()*locked_focus_.h(); rect focus_area; if(frame_->num_frames_per_row() == 0) { focus_area = rect(); } else { focus_area = rect(frame_->area().x(), frame_->area().y(), (frame_->area().w() + frame_->pad())*frame_->num_frames_per_row(), (frame_->area().h() + frame_->pad())*(frame_->num_frames()/frame_->num_frames_per_row() + (frame_->num_frames()%frame_->num_frames_per_row() ? 1 : 0))); } if(view_locked) { focus_area = locked_focus_; } else { locked_focus_ = focus_area; } GLfloat scale = 2.0; for(int n = 0; n != abs(scale_); ++n) { scale *= (scale_ < 0 ? 0.5f : 2.0f); } if(!view_locked) { while(image_area.w()*scale*2.0f < image_area.w() && image_area.h()*scale*2.0f < image_area.h()) { scale *= 2.0f; scale_++; update_zoom_label(); } while(focus_area.w()*scale > image_area.w() || focus_area.h()*scale > image_area.h()) { scale *= 0.5f; scale_--; update_zoom_label(); } } const int show_width = image_area.w()/scale; const int show_height = image_area.h()/scale; int x1 = focus_area.x() + (focus_area.w() - show_width)/2; int y1 = focus_area.y() + (focus_area.h() - show_height)/2; if(x1 < 0) { x1 = 0; } if(y1 < 0) { y1 = 0; } int x2 = x1 + show_width; int y2 = y1 + show_height; if(x2 > image_texture.width()) { x1 -= (x2 - image_texture.width()); x2 = image_texture.width(); if(x1 < 0) { x1 = 0; } } if(y2 > image_texture.height()) { y1 -= (y2 - image_texture.height()); y2 = image_texture.height(); if(y1 < 0) { y1 = 0; } } int xpos = image_area.x(); int ypos = image_area.y(); src_rect_ = rect(x1, y1, x2 - x1, y2 - y1); dst_rect_ = rect(xpos, ypos, (x2-x1)*scale, (y2-y1)*scale); graphics::blit_texture(image_texture, xpos, ypos, (x2-x1)*scale, (y2-y1)*scale, 0.0, GLfloat(x1)/image_texture.width(), GLfloat(y1)/image_texture.height(), GLfloat(x2)/image_texture.width(), GLfloat(y2)/image_texture.height()); if(!mouse_buttons) { dragging_sides_bitmap_ = 0; } for(int n = 0; n != frame_->num_frames(); ++n) { const int row = n/frame_->num_frames_per_row(); const int col = n%frame_->num_frames_per_row(); const int x = xpos - x1*scale + (frame_->area().x() + col*(frame_->area().w()+frame_->pad()))*scale; const int y = ypos - y1*scale + (frame_->area().y() + row*(frame_->area().h()+frame_->pad()))*scale; const rect box(x, y, frame_->area().w()*scale, frame_->area().h()*scale); graphics::draw_hollow_rect(box.sdl_rect(), n == 0 ? graphics::color_yellow() : graphics::color_white(), frame_->frame_number(cycle_) == n ? 0xFF : 0x88); if(n == 0 && !mouse_buttons) { bool rect_chosen = false; if(box.w() > 10 && box.h() > 10) { rect_chosen = point_in_rect(point(mousex, mousey), rect(box.x()+5, box.y()+5, box.w()-10, box.h()-10)); } if(rect_chosen || point_in_rect(point(mousex, mousey), rect(box.x(), box.y()-4, box.w(), 9))) { dragging_sides_bitmap_ |= TOP_SIDE; graphics::draw_rect(rect(box.x(), box.y()-1, box.w(), 2).sdl_rect(), graphics::color_red()); } if(rect_chosen || !(dragging_sides_bitmap_&TOP_SIDE) && point_in_rect(point(mousex, mousey), rect(box.x(), box.y2()-4, box.w(), 9))) { dragging_sides_bitmap_ |= BOTTOM_SIDE; graphics::draw_rect(rect(box.x(), box.y2()-1, box.w(), 2).sdl_rect(), graphics::color_red()); } if(rect_chosen || point_in_rect(point(mousex, mousey), rect(box.x()-4, box.y(), 9, box.h()))) { dragging_sides_bitmap_ |= LEFT_SIDE; graphics::draw_rect(rect(box.x()-1, box.y(), 2, box.h()).sdl_rect(), graphics::color_red()); } if(rect_chosen || (!dragging_sides_bitmap_&LEFT_SIDE) && point_in_rect(point(mousex, mousey), rect(box.x2()-4, box.y(), 9, box.h()))) { dragging_sides_bitmap_ |= RIGHT_SIDE; graphics::draw_rect(rect(box.x2()-1, box.y(), 2, box.h()).sdl_rect(), graphics::color_red()); } } else if(n != 0 && !mouse_buttons) { if(point_in_rect(point(mousex, mousey), box)) { dragging_sides_bitmap_ = PADDING; graphics::draw_rect(box.sdl_rect(), graphics::color_yellow(), 128); } } } if(anchor_x_ != -1 && !dragging_sides_bitmap_ && SDL_GetMouseState(&mousex, &mousey) && point_in_rect(point(mousex, mousey), dst_rect_)) { const point p1 = mouse_point_to_image_loc(point(mousex, mousey)); const point p2 = mouse_point_to_image_loc(point(anchor_x_, anchor_y_)); int xpos1 = xpos - x1*scale + p1.x*scale; int xpos2 = xpos - x1*scale + p2.x*scale; int ypos1 = ypos - y1*scale + p1.y*scale; int ypos2 = ypos - y1*scale + p2.y*scale; if(xpos2 < xpos1) { std::swap(xpos1, xpos2); } if(ypos2 < ypos1) { std::swap(ypos1, ypos2); } rect area(xpos1, ypos1, xpos2 - xpos1, ypos2 - ypos1); graphics::draw_hollow_rect(area.sdl_rect(), graphics::color_white()); } } rect preview_area(x() + (width()*3)/4, y(), width()/4, height()); GLfloat scale = 1.0; while(false && (frame_->width()*scale > preview_area.w() || frame_->height()*scale > preview_area.h())) { scale *= 0.5; } const int framex = preview_area.x() + (preview_area.w() - frame_->width()*scale)/2; const int framey = preview_area.y() + (preview_area.h() - frame_->height()*scale)/2; frame_->draw(framex, framey, true, false, cycle_, 0, scale); if(++cycle_ >= frame_->duration()) { cycle_ = 0; } solid_rect_ = rect(); const_solid_info_ptr solid = frame_->solid(); if(solid && solid->area().w()*solid->area().h()) { const rect area = solid->area(); solid_rect_ = rect(framex + area.x(), framey + area.y(), area.w(), area.h()); graphics::draw_rect(solid_rect_, graphics::color(255, 255, 255, 64)); } foreach(const_widget_ptr w, widgets_) { w->draw(); } } point animation_preview_widget::mouse_point_to_image_loc(const point& p) const { const double xpos = double(p.x - dst_rect_.x())/double(dst_rect_.w()); const double ypos = double(p.y - dst_rect_.y())/double(dst_rect_.h()); const int x = src_rect_.x() + (double(src_rect_.w()) + 1.0)*xpos; const int y = src_rect_.y() + (double(src_rect_.h()) + 1.0)*ypos; return point(x, y); } bool animation_preview_widget::handle_event(const SDL_Event& event, bool claimed) { foreach(widget_ptr w, widgets_) { claimed = w->process_event(event, claimed) || claimed; } if(event.type == SDL_MOUSEBUTTONUP) { moving_solid_rect_ = false; } if(event.type == SDL_MOUSEMOTION) { has_motion_ = true; const SDL_MouseMotionEvent& e = event.motion; if(moving_solid_rect_) { if(solid_handler_) { const int x = e.x/2; const int y = e.y/2; solid_handler_(x - anchor_solid_x_, y - anchor_solid_y_); anchor_solid_x_ = x; anchor_solid_y_ = y; } return claimed; } point p(e.x, e.y); if(point_in_rect(p, dst_rect_)) { p = mouse_point_to_image_loc(p); pos_label_->set_text(formatter() << p.x << "," << p.y); } if(e.state && dragging_sides_bitmap_) { int delta_x = e.x - anchor_x_; int delta_y = e.y - anchor_y_; if(scale_ >= 0) { for(int n = 0; n < scale_+1; ++n) { delta_x >>= 1; delta_y >>= 1; } } int x1 = anchor_area_.x(); int x2 = anchor_area_.x2(); int y1 = anchor_area_.y(); int y2 = anchor_area_.y2(); if(dragging_sides_bitmap_&LEFT_SIDE) { x1 += delta_x; if(x1 > x2 - 1) { x1 = x2 - 1; } } if(dragging_sides_bitmap_&RIGHT_SIDE) { x2 += delta_x; if(x2 < x1 + 1) { x2 = x1 + 1; } } if(dragging_sides_bitmap_&TOP_SIDE) { y1 += delta_y; if(y1 > y2 - 1) { y1 = y2 - 1; } } if(dragging_sides_bitmap_&BOTTOM_SIDE) { y2 += delta_y; if(y2 < y1 + 1) { y2 = y1 + 1; } } const int width = x2 - x1; const int height = y2 - y1; rect area(x1, y1, width, height); if(area != frame_->area() && rect_handler_) { rect_handler_(area); } if(dragging_sides_bitmap_&PADDING && pad_handler_) { const int new_pad = anchor_pad_ + delta_x; if(new_pad != frame_->pad()) { pad_handler_(new_pad); } } } } else if(event.type == SDL_MOUSEBUTTONDOWN) { moving_solid_rect_ = false; const SDL_MouseButtonEvent& e = event.button; const point p(e.x, e.y); anchor_area_ = frame_->area(); anchor_pad_ = frame_->pad(); has_motion_ = false; if(point_in_rect(p, dst_rect_)) { claimed = true; anchor_x_ = e.x; anchor_y_ = e.y; } else { anchor_x_ = anchor_y_ = -1; if(point_in_rect(p, solid_rect_)) { moving_solid_rect_ = true; anchor_solid_x_ = e.x/2; anchor_solid_y_ = e.y/2; } } } else if(event.type == SDL_MOUSEBUTTONUP && anchor_x_ != -1) { const SDL_MouseButtonEvent& e = event.button; point anchor(anchor_x_, anchor_y_); point p(e.x, e.y); if(anchor == p && !has_motion_) { claimed = true; p = mouse_point_to_image_loc(p); graphics::surface surf = graphics::surface_cache::get(obj_["image"].as_string()); std::vector surf_key; surf_key.push_back(surf); if(surf) { surf = graphics::texture::build_surface_from_key(surf_key, surf->w, surf->h); } if(surf) { rect area = get_border_rect_around_loc(surf, p.x, p.y); if(area.w() > 0) { if(rect_handler_) { rect_handler_(area); } int pad = frame_->pad(); int num_frames = 1; int frames_per_row = 1; if(find_full_animation(surf, area, &pad, &num_frames, &frames_per_row)) { if(pad_handler_) { pad_handler_(pad); } if(num_frames_handler_) { std::cerr << "SETTING NUM FRAMES TO " << num_frames << "\n"; num_frames_handler_(num_frames); } if(frames_per_row_handler_) { frames_per_row_handler_(frames_per_row); } } } } } else if(!dragging_sides_bitmap_ && point_in_rect(anchor, dst_rect_) && point_in_rect(p, dst_rect_)) { claimed = true; anchor = mouse_point_to_image_loc(anchor); p = mouse_point_to_image_loc(p); int x1 = anchor.x; int y1 = anchor.y; int x2 = p.x; int y2 = p.y; if(x2 < x1) { std::swap(x1, x2); } if(y2 < y1) { std::swap(y1, y2); } rect area(x1, y1, x2 - x1, y2 - y1); if(rect_handler_) { rect_handler_(area); } } anchor_x_ = anchor_y_ = -1; } return claimed; } void animation_preview_widget::zoom_in() { ++scale_; update_zoom_label(); } void animation_preview_widget::zoom_out() { --scale_; update_zoom_label(); } void animation_preview_widget::reset_rect() { if(rect_handler_) { rect_handler_(rect(0,0,0,0)); } } void animation_preview_widget::update_zoom_label() const { if(zoom_label_) { int percent = 100; for(int n = 0; n != abs(scale_); ++n) { if(scale_ > 0) { percent *= 2; } else { percent /= 2; } } zoom_label_->set_text(formatter() << "Zoom: " << percent << "%"); } } void animation_preview_widget::set_rect_handler(boost::function handler) { rect_handler_ = handler; } void animation_preview_widget::set_pad_handler(boost::function handler) { pad_handler_ = handler; } void animation_preview_widget::set_num_frames_handler(boost::function handler) { num_frames_handler_ = handler; } void animation_preview_widget::set_frames_per_row_handler(boost::function handler) { frames_per_row_handler_ = handler; } void animation_preview_widget::set_solid_handler(boost::function handler) { solid_handler_ = handler; } void animation_preview_widget::rect_handler_delegate(rect r) { using namespace game_logic; if(get_environment()) { map_formula_callable_ptr callable = map_formula_callable_ptr(new map_formula_callable(get_environment())); callable->add("new_rect", r.write()); variant value = ffl_rect_handler_->execute(*callable); get_environment()->execute_command(value); } else { std::cerr << "animation_preview_widget::rect_handler_delegate() called without environment!" << std::endl; } } void animation_preview_widget::pad_handler_delegate(int pad) { using namespace game_logic; if(get_environment()) { map_formula_callable_ptr callable = map_formula_callable_ptr(new map_formula_callable(get_environment())); callable->add("new_pad", variant(pad)); variant value = ffl_pad_handler_->execute(*callable); get_environment()->execute_command(value); } else { std::cerr << "animation_preview_widget::pad_handler_delegate() called without environment!" << std::endl; } } void animation_preview_widget::num_frames_handler_delegate(int frames) { using namespace game_logic; if(get_environment()) { map_formula_callable_ptr callable = map_formula_callable_ptr(new map_formula_callable(get_environment())); callable->add("new_frames", variant(frames)); variant value = ffl_num_frames_handler_->execute(*callable); get_environment()->execute_command(value); } else { std::cerr << "animation_preview_widget::num_frames_handler_delegate() called without environment!" << std::endl; } } void animation_preview_widget::frames_per_row_handler_delegate(int frames_per_row) { using namespace game_logic; if(get_environment()) { map_formula_callable_ptr callable = map_formula_callable_ptr(new map_formula_callable(get_environment())); callable->add("new_frames_per_row", variant(frames_per_row)); variant value = ffl_frames_per_row_handler_->execute(*callable); get_environment()->execute_command(value); } else { std::cerr << "animation_preview_widget::frames_per_row_handler_delegate() called without environment!" << std::endl; } } void animation_preview_widget::solid_handler_delegate(int x, int y) { using namespace game_logic; if(get_environment()) { map_formula_callable_ptr callable = map_formula_callable_ptr(new map_formula_callable(get_environment())); callable->add("new_solidx", variant(x)); callable->add("new_solidy", variant(y)); variant value = ffl_solid_handler_->execute(*callable); get_environment()->execute_command(value); } else { std::cerr << "animation_preview_widget::solid_handler_delegate() called without environment!" << std::endl; } } void animation_preview_widget::set_value(const std::string& key, const variant& v) { if(key == "object") { try { set_object(v); } catch(type_error&) { } catch(frame::error&) { } catch(validation_failure_exception&) { } catch(graphics::load_image_error&) { } } widget::set_value(key, v); } variant animation_preview_widget::get_value(const std::string& key) const { if(key == "object") { return obj_; } return widget::get_value(key); } } #endif // !NO_EDITOR frogatto-1.3.1+dfsg/src/animation_preview_widget.hpp0000644000175000017500000000514012060740335022541 0ustar vincentvincent#ifndef ANIMATION_PREVIEW_WIDGET_HPP_INCLUDED #define ANIMATION_PREVIEW_WIDGET_HPP_INCLUDED #ifndef NO_EDITOR #include #include #include "frame.hpp" #include "label.hpp" #include "variant.hpp" #include "widget.hpp" namespace gui { class animation_preview_widget : public widget { public: static bool is_animation(variant obj); explicit animation_preview_widget(variant obj); explicit animation_preview_widget(const variant& v, game_logic::formula_callable* e); void init(); void set_object(variant obj); void process(); void set_rect_handler(boost::function); void set_pad_handler(boost::function); void set_num_frames_handler(boost::function); void set_frames_per_row_handler(boost::function); void set_solid_handler(boost::function); protected: virtual void set_value(const std::string& key, const variant& v); virtual variant get_value(const std::string& key) const; private: void handle_draw() const; bool handle_event(const SDL_Event& event, bool claimed); void zoom_in(); void zoom_out(); void reset_rect(); point mouse_point_to_image_loc(const point& p) const; variant obj_; boost::scoped_ptr frame_; mutable int cycle_; std::vector widgets_; mutable gui::label* zoom_label_; gui::label* pos_label_; mutable int scale_; void update_zoom_label() const; mutable rect src_rect_, dst_rect_; //anchors for mouse dragging events. int anchor_x_, anchor_y_; rect anchor_area_; int anchor_pad_; bool has_motion_; mutable rect locked_focus_; mutable int dragging_sides_bitmap_; enum { LEFT_SIDE = 1, RIGHT_SIDE = 2, TOP_SIDE = 4, BOTTOM_SIDE = 8, PADDING = 16 }; mutable rect solid_rect_; bool moving_solid_rect_; int anchor_solid_x_, anchor_solid_y_; boost::function rect_handler_; boost::function pad_handler_; boost::function num_frames_handler_; boost::function frames_per_row_handler_; boost::function solid_handler_; void rect_handler_delegate(rect r); void pad_handler_delegate(int pad); void num_frames_handler_delegate(int frames); void frames_per_row_handler_delegate(int frames_per_row); void solid_handler_delegate(int x, int y); game_logic::formula_ptr ffl_rect_handler_; game_logic::formula_ptr ffl_pad_handler_; game_logic::formula_ptr ffl_num_frames_handler_; game_logic::formula_ptr ffl_frames_per_row_handler_; game_logic::formula_ptr ffl_solid_handler_; }; typedef boost::intrusive_ptr animation_preview_widget_ptr; } #endif // !NO_EDITOR #endif frogatto-1.3.1+dfsg/src/animation_widget.cpp0000644000175000017500000000435012060740335020775 0ustar vincentvincent#include "animation_widget.hpp" #include "color_utils.hpp" #include "raster.hpp" namespace gui { animation_widget::animation_widget(int w, int h, const variant& node) : cycle_(0), play_sequence_count_(0), max_sequence_plays_(20) { set_dim(w,h); if(node.is_map() && node.has_key("animation")) { nodes_ = node["animation"].as_list(); } else if(node.is_list()) { nodes_ = node.as_list(); } else { ASSERT_LOG(false, "animation_widget: passed in node must be either a list of animations or a map containing an \"animation\" list."); } init(); } animation_widget::animation_widget(const variant& v, game_logic::formula_callable* e) : widget(v,e), cycle_(0), play_sequence_count_(0) { nodes_ = v["animation"].as_list(); max_sequence_plays_ = v["max_sequence_plays"].as_int(20); // Range of other options to add display label true/false // Auto-repeat single frame (id) -- more useful from set_value() // Arbitrary label (as string or map) init(); } void animation_widget::init() { current_anim_ = nodes_.begin(); play_sequence_count_ = 0; frame_.reset(new frame(*current_anim_)); label_.reset(new label(frame_->id(), graphics::color_yellow(), 16)); label_->set_loc((width() - label_->width())/2, height()-label_->height()); } void animation_widget::handle_draw() const { rect preview_area(x(), y(), width(), height() - (label_ ? label_->height() : 0)); const GLfloat scale = GLfloat(std::min(preview_area.w()/frame_->width(), preview_area.h()/frame_->height())); const int framex = preview_area.x() + (preview_area.w() - int(frame_->width()*scale))/2; const int framey = preview_area.y() + (preview_area.h() - int(frame_->height()*scale))/2; frame_->draw(framex, framey, true, false, cycle_, 0, scale); if(++cycle_ >= frame_->duration()) { cycle_ = 0; if(++play_sequence_count_ > max_sequence_plays_) { play_sequence_count_ = 0; if(++current_anim_ == nodes_.end()) { current_anim_ = nodes_.begin(); } frame_.reset(new frame(*current_anim_)); label_.reset(new label(frame_->id(), graphics::color_yellow(), 16)); label_->set_loc((width() - label_->width())/2, height()-label_->height()); } } glPushMatrix(); glTranslatef(GLfloat(x() & ~1), GLfloat(y() & ~1), 0.0); if(label_) { label_->draw(); } glPopMatrix(); } } frogatto-1.3.1+dfsg/src/animation_widget.hpp0000644000175000017500000000204212060740335020776 0ustar vincentvincent#pragma once #ifndef ANIMATION_WIDGET_HPP_INCLUDED #define ANIMATION_WIDGET_HPP_INCLUDED #include #include #include "frame.hpp" #include "geometry.hpp" #include "label.hpp" #include "widget.hpp" namespace gui { class animation_widget : public virtual widget { public: animation_widget(int w, int h, const variant& node); animation_widget(const variant& v, game_logic::formula_callable* e); void set_sequence_play_count(int count) { max_sequence_plays_ = count; } protected: virtual void handle_draw() const; private: void init(); std::vector nodes_; mutable label_ptr label_; mutable boost::scoped_ptr frame_; mutable int cycle_; mutable int play_sequence_count_; // Number of times to repeat play each animation sequence. int max_sequence_plays_; mutable std::vector::const_iterator current_anim_; }; typedef boost::intrusive_ptr animation_widget_ptr; typedef boost::intrusive_ptr const_animation_widget_ptr; } #endif frogatto-1.3.1+dfsg/src/array_callable.hpp0000644000175000017500000000423312060740335020415 0ustar vincentvincent#pragma once #ifndef ARRAY_CALLABLE_HPP_INCLUDED #define ARRAY_CALLABLE_HPP_INCLUDED #include #include "asserts.hpp" #include "formula_callable.hpp" #include "graphics.hpp" #include "variant.hpp" namespace game_logic { class float_array_callable : public formula_callable { public: explicit float_array_callable(std::vector* f, int ne = 1) : ne_(ne) { f_.swap(*f); } virtual void set_value(const std::string& key, const variant& value) { if(key == "floats" || key == "value") { ASSERT_LOG(value.is_list(), "Must be a list type"); f_.resize(value.num_elements()); for(size_t n = 0; n < value.num_elements(); ++n) { f_[n] = GLfloat(value[n].as_decimal().as_float()); } } } virtual variant get_value(const std::string& key) const { if(key == "floats" || key == "value") { std::vector v; for(size_t n = 0; n < f_.size(); ++n) { v.push_back(variant(f_[n])); } return variant(&v); } else if(key == "size") { return variant(f_.size()); } return variant(); } const std::vector& floats() { return f_; } int num_elements() const { return ne_; } private: int ne_; std::vector f_; }; class short_array_callable : public formula_callable { public: explicit short_array_callable(std::vector* s, int ne = 1) : ne_(ne) { s_.swap(*s); } virtual void set_value(const std::string& key, const variant& value) { if(key == "shorts" || key == "value") { ASSERT_LOG(value.is_list(), "Must be a list type"); s_.resize(value.num_elements()); for(size_t n = 0; n < value.num_elements(); ++n) { s_[n] = GLshort(value[n].as_int()); } } } variant get_value(const std::string& key) const { if(key == "shorts" || key == "value") { std::vector v; for(size_t n = 0; n < s_.size(); ++n) { v.push_back(variant(s_[n])); } return variant(&v); } else if(key == "size") { return variant(s_.size()); } return variant(); } const std::vector& shorts() { return s_; } int num_elements() const { return ne_; } private: int ne_; std::vector s_; }; } #endif frogatto-1.3.1+dfsg/src/asserts.cpp0000644000175000017500000000303612060740335017137 0ustar vincentvincent#include #ifndef NO_EDITOR #include "editor.hpp" #endif #include "asserts.hpp" #include "level.hpp" #include "stats.hpp" #include "variant.hpp" #if defined(_WINDOWS) #include "SDL_syswm.h" #endif void report_assert_msg(const std::string& m) { if(level::current_ptr()) { std::cerr << "ATTEMPTING TO SEND CRASH REPORT...\n"; std::map obj; obj[variant("type")] = variant("crash"); obj[variant("msg")] = variant(m); #ifndef NO_EDITOR obj[variant("editor")] = variant(editor::last_edited_level().empty() == false); #else obj[variant("editor")] = variant(false); #endif stats::record(variant(&obj), level::current_ptr()->id()); stats::flush_and_quit(); } #if defined(__native_client__) std::cerr << m; #endif #if defined(__ANDROID__) __android_log_print(ANDROID_LOG_INFO, "Frogatto", m.c_str()); #endif #if defined(_WINDOWS) SDL_SysWMinfo SysInfo; SDL_VERSION(&SysInfo.version); if(SDL_GetWMInfo(&SysInfo) > 0) { ::MessageBoxA(SysInfo.window, m.c_str(), "Assertion failed", MB_OK|MB_ICONSTOP); } #endif } validation_failure_exception::validation_failure_exception(const std::string& m) : msg(m) { std::cerr << "ASSERT FAIL: " << m << "\n"; } namespace { int throw_validation_failure = 0; } bool throw_validation_failure_on_assert() { return throw_validation_failure != 0; } assert_recover_scope::assert_recover_scope() { throw_validation_failure++; } assert_recover_scope::~assert_recover_scope() { throw_validation_failure--; } void output_backtrace() { std::cerr << get_call_stack() << "\n"; } frogatto-1.3.1+dfsg/src/asserts.hpp0000644000175000017500000001032612060740335017144 0ustar vincentvincent#ifndef ASSERTS_HPP_INCLUDED #define ASSERTS_HPP_INCLUDED #include #include #include #include #if defined(__ANDROID__) #include #include #define LOG(str_data) \ do{ std::stringstream oss; \ oss << str_data; \ __android_log_print(ANDROID_LOG_INFO, "Frogatto", oss.str().c_str()); }while(0) #else #define LOG(fmt,...) do {}while(0) #endif // ANDROID #if defined(_WINDOWS) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN #endif #include #ifndef _DEBUG //#define abort() do{exit(1);}while(0) #endif #endif void report_assert_msg(const std::string& m ); struct validation_failure_exception { explicit validation_failure_exception(const std::string& m); std::string msg; }; bool throw_validation_failure_on_assert(); void output_backtrace(); class assert_recover_scope { public: assert_recover_scope(); ~assert_recover_scope(); }; //various asserts of standard "equality" tests, such as "equals", "not equals", "greater than", etc. Example usage: //ASSERT_NE(x, y); #define ASSERT_EQ(a,b) if((a) != (b)) { std::ostringstream s; s << __FILE__ << ":" << __LINE__ << " ASSERT EQ FAILED: " << #a << " != " << #b << ": " << (a) << " != " << (b) << "\n"; if(throw_validation_failure_on_assert()) { throw validation_failure_exception(s.str()); } else { std::cerr << s.str(); output_backtrace(); report_assert_msg(s.str()); abort(); } } #define ASSERT_NE(a,b) if((a) == (b)) { std::ostringstream s; s << __FILE__ << ":" << __LINE__ << " ASSERT NE FAILED: " << #a << " == " << #b << ": " << (a) << " == " << (b) << "\n"; if(throw_validation_failure_on_assert()) { throw validation_failure_exception(s.str()); } else { std::cerr << s.str(); output_backtrace(); report_assert_msg(s.str()); abort(); } } #define ASSERT_GE(a,b) if((a) < (b)) { std::ostringstream s; s << __FILE__ << ":" << __LINE__ << " ASSERT GE FAILED: " << #a << " < " << #b << ": " << (a) << " < " << (b) << "\n"; if(throw_validation_failure_on_assert()) { throw validation_failure_exception(s.str()); } else { std::cerr << s.str(); output_backtrace(); report_assert_msg(s.str()); abort(); } } #define ASSERT_LE(a,b) if((a) > (b)) { std::ostringstream s; s << __FILE__ << ":" << __LINE__ << " ASSERT LE FAILED: " << #a << " > " << #b << ": " << (a) << " > " << (b) << "\n"; if(throw_validation_failure_on_assert()) { throw validation_failure_exception(s.str()); } else { std::cerr << s.str(); output_backtrace(); report_assert_msg(s.str()); abort(); } } #define ASSERT_GT(a,b) if((a) <= (b)) { std::ostringstream s; s << __FILE__ << ":" << __LINE__ << " ASSERT GT FAILED: " << #a << " <= " << #b << ": " << (a) << " <= " << (b) << "\n"; if(throw_validation_failure_on_assert()) { throw validation_failure_exception(s.str()); } else { std::cerr << s.str(); output_backtrace(); report_assert_msg(s.str()); abort(); } } #define ASSERT_LT(a,b) if((a) >= (b)) { std::ostringstream s; s << __FILE__ << ":" << __LINE__ << " ASSERT LT FAILED: " << #a << " >= " << #b << ": " << (a) << " >= " << (b) << "\n"; if(throw_validation_failure_on_assert()) { throw validation_failure_exception(s.str()); } else { std::cerr << s.str(); output_backtrace(); report_assert_msg(s.str()); abort(); } } #define ASSERT_INDEX_INTO_VECTOR(a,b) if((a) < 0 || size_t(a) >= (b).size()) { std::ostringstream s; s << __FILE__ << ":" << __LINE__ << " ASSERT INDEX INTO VECTOR FAILED: " << #a << " (" << (a) << " indexes " << #b << " (" << (b).size() << ")\n"; if(throw_validation_failure_on_assert()) { throw validation_failure_exception(s.str()); } else { std::cerr << s.str(); output_backtrace(); report_assert_msg(s.str()); abort(); } } //for custom logging. Example usage: //ASSERT_LOG(x != y, "x not equal to y. Value of x: " << x << ", y: " << y); #define ASSERT_LOG(_a,_b) if( !(_a) ) { std::ostringstream _s; _s << __FILE__ << ":" << __LINE__ << " ASSERTION FAILED: " << _b << "\n"; if(throw_validation_failure_on_assert()) { throw validation_failure_exception(_s.str()); } else { std::cerr << _s.str(); output_backtrace(); report_assert_msg(_s.str()); abort(); } } #define VALIDATE_LOG(a,b) if( !(a) ) { std::ostringstream s; s << __FILE__ << ":" << __LINE__ << " VALIDATION FAILED: " << b << "\n"; throw validation_failure_exception(s.str()); } #endif frogatto-1.3.1+dfsg/src/background.cpp0000644000175000017500000003727512060740335017606 0ustar vincentvincent#include #include #include #include #include "background.hpp" #include "color_utils.hpp" #include "filesystem.hpp" #include "foreach.hpp" #include "formatter.hpp" #include "graphics.hpp" #include "json_parser.hpp" #include "level.hpp" #include "module.hpp" #include "preferences.hpp" #include "raster.hpp" #include "surface_palette.hpp" #include "variant.hpp" #include "variant_utils.hpp" namespace { //a cache key with background name and palette ID. typedef std::pair cache_key; typedef std::map > bg_cache; bg_cache cache; #ifndef NO_EDITOR std::set listening_for_files, files_updated; void on_bg_file_updated(std::string path) { files_updated.insert(path); } #endif // NO_EDITOR } #ifndef NO_EDITOR void background::load_modified_backgrounds() { static int prev_nitems = 0; const int nitems = cache.size(); if(prev_nitems == nitems && files_updated.empty()) { return; } prev_nitems = nitems; std::set error_paths; for(bg_cache::iterator j = cache.begin(); j != cache.end(); ++j) { if(j->second->file_.empty()) { continue; } if(listening_for_files.count(j->second->file_) == 0) { sys::notify_on_file_modification(j->second->file_, boost::bind(on_bg_file_updated, j->second->file_)); listening_for_files.insert(j->second->file_); } if(files_updated.count(j->second->file_)) { background backup = *j->second; try { const std::string path = "data/backgrounds/" + j->second->id_ + ".cfg"; *j->second = background(json::parse_from_file(path), j->first.second); } catch(...) { std::cerr << "ERROR REFRESHING BACKGROUND\n"; error_paths.insert(j->second->file_); } j->second->id_ = backup.id_; j->second->file_ = backup.file_; } } } #endif // NO_EDITOR boost::shared_ptr background::get(const std::string& name, int palette_id) { const cache_key id(name, palette_id); boost::shared_ptr& obj = cache[id]; if(!obj) { const std::string fname = "data/backgrounds/" + name + ".cfg"; obj.reset(new background(json::parse_from_file(fname), palette_id)); obj->id_ = name; obj->file_ = module::map_file(fname); } return obj; } std::vector background::get_available_backgrounds() { std::vector files; module::get_files_in_dir("data/backgrounds/", &files); std::vector result; foreach(const std::string& fname, files) { if(fname.size() > 4 && std::equal(fname.end() - 4, fname.end(), ".cfg")) { result.push_back(std::string(fname.begin(), fname.end() - 4)); } } return result; } background::background(variant node, int palette) : palette_(palette) { top_ = string_to_color(node["top"].as_string()); bot_ = string_to_color(node["bottom"].as_string()); if(palette_ != -1) { top_ = graphics::map_palette(top_, palette); bot_ = graphics::map_palette(bot_, palette); } width_ = node["width"].as_int(); height_ = node["height"].as_int(); foreach(variant layer_node, node["layer"].as_list()) { layer bg; bg.image = layer_node["image"].as_string(); bg.image_formula = layer_node["image_formula"].as_string_default(); bg.xscale = layer_node["xscale"].as_int(100); bg.yscale = layer_node["yscale"].as_int(100); bg.xspeed = layer_node["xspeed"].as_int(0); bg.xpad = layer_node["xpad"].as_int(0); bg.xoffset = layer_node["xoffset"].as_int(0); bg.yoffset = layer_node["yoffset"].as_int(0); bg.scale = layer_node["scale"].as_int(1); bg.blend = layer_node["blend"].as_bool(true); bg.notile = layer_node["notile"].as_bool(false); if(bg.scale < 1) { bg.scale = 1; } std::string blend_mode = layer_node["mode"].as_string_default(); #if defined(__GLEW_H__) if(GLEW_EXT_blend_minmax) { if(blend_mode == "GL_MAX") { bg.mode = GL_MAX; } else if(blend_mode == "GL_MIN") { bg.mode = GL_MIN; } else { bg.mode = GL_FUNC_ADD; } } #endif std::fill(bg.color, bg.color + 4, GLfloat(0.0)); bg.color[0] = layer_node["red"].as_decimal(decimal(1.0)).as_float(); bg.color[1] = layer_node["green"].as_decimal(decimal(1.0)).as_float(); bg.color[2] = layer_node["blue"].as_decimal(decimal(1.0)).as_float(); bg.color[3] = layer_node["alpha"].as_decimal(decimal(1.0)).as_float(); if(layer_node.has_key("color_above")) { bg.color_above.reset(new SDL_Color); *bg.color_above = string_to_color(layer_node["color_above"].as_string()); if(palette_ != -1) { *bg.color_above = graphics::map_palette(*bg.color_above, palette); } } if(layer_node.has_key("color_below")) { bg.color_below.reset(new SDL_Color); *bg.color_below = string_to_color(layer_node["color_below"].as_string()); if(palette_ != -1) { *bg.color_below = graphics::map_palette(*bg.color_below, palette); } } bg.y1 = layer_node["y1"].as_int(); bg.y2 = layer_node["y2"].as_int(); bg.foreground = layer_node["foreground"].as_bool(false); bg.tile_upwards = layer_node["tile_upwards"].as_bool(false); bg.tile_downwards = layer_node["tile_downwards"].as_bool(false); layers_.push_back(bg); } } variant background::write() const { variant_builder res; char buf[128]; sprintf(buf, "%02x%02x%02x", top_.r, top_.g, top_.b); res.add("top", buf); sprintf(buf, "%02x%02x%02x", bot_.r, bot_.g, bot_.b); res.add("bottom", buf); res.add("width", formatter() << width_); res.add("height", formatter() << height_); foreach(const layer& bg, layers_) { variant_builder layer_node; layer_node.add("image", bg.image); layer_node.add("xscale", formatter() << bg.xscale); layer_node.add("yscale", formatter() << bg.yscale); layer_node.add("xspeed", formatter() << bg.xspeed); layer_node.add("xpad", formatter() << bg.xpad); layer_node.add("xoffset", formatter() << bg.xoffset); layer_node.add("yoffset", formatter() << bg.yoffset); layer_node.add("y1", formatter() << bg.y1); layer_node.add("y2", formatter() << bg.y2); layer_node.add("scale", formatter() << bg.scale); layer_node.add("red", formatter() << bg.color[0]); layer_node.add("green", formatter() << bg.color[1]); layer_node.add("blue", formatter() << bg.color[2]); layer_node.add("alpha", formatter() << bg.color[3]); if(bg.color_above) { sprintf(buf, "%02x%02x%02x", bg.color_above->r, bg.color_above->g, bg.color_above->b); layer_node.add("color_above", buf); } if(bg.color_below) { sprintf(buf, "%02x%02x%02x", bg.color_below->r, bg.color_below->g, bg.color_below->b); layer_node.add("color_below", buf); } if(bg.foreground) { layer_node.add("foreground", "true"); } if(bg.tile_upwards) { layer_node.add("tile_upwards", "true"); } if(bg.tile_downwards) { layer_node.add("tile_downwards", "true"); } res.add("layer", layer_node.build()); } return res.build(); } void background::draw(int x, int y, const rect& area, const std::vector& opaque_areas, int rotation, int cycle) const { const int height = height_ + offset_.y*2; //set the background colors for the level. The area above 'height' is //painted with the top color, and the area below height is painted with //the bottom color. For efficiency we do this using color clearing, with //scissors to divide the screen into top and bottom. if(height < y) { //the entire screen is full of the bottom color glClearColor(bot_.r/255.0, bot_.g/255.0, bot_.b/255.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); } else if(height > y + graphics::screen_height()) { //the entire screen is full of the top color. glClearColor(top_.r/255.0, top_.g/255.0, top_.b/255.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); } else { //both bottom and top colors are on the screen, so draw them both, //using scissors to delinate their areas. const int dist_from_bottom = y + graphics::screen_height() - height; glEnable(GL_SCISSOR_TEST); const int scissor_scale = preferences::double_scale() ? 2 : 1; //the scissor test does not respect any rotations etc. We use a rotation //to transform the iPhone's display, which is fine normally, but //here we have to accomodate the iPhone being "on its side" #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR glScissor(dist_from_bottom/scissor_scale, 0, (graphics::screen_height() - dist_from_bottom)/scissor_scale, graphics::screen_width()/scissor_scale); #else glScissor(0, dist_from_bottom, preferences::actual_screen_width(), preferences::actual_screen_width()*(1-dist_from_bottom/600)); #endif glClearColor(top_.r/255.0, top_.g/255.0, top_.b/255.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR glScissor(0, 0, dist_from_bottom/scissor_scale, graphics::screen_width()/scissor_scale); #else glScissor(0, 0, preferences::actual_screen_width(), dist_from_bottom); #endif glClearColor(bot_.r/255.0, bot_.g/255.0, bot_.b/255.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); } draw_layers(x, y, area, opaque_areas, rotation, cycle); } namespace { graphics::blit_queue blit_queue; void calculate_draw_areas(rect area, std::vector::const_iterator opaque1, std::vector::const_iterator opaque2, std::vector* areas) { if(opaque1 == opaque2) { areas->push_back(area); return; } rect sub_areas[4]; for(; opaque1 != opaque2; ++opaque1) { const int result = rect_difference(area, *opaque1, sub_areas); if(result == -1) { continue; } if(result != 1) { for(int n = 0; n < result; ++n) { calculate_draw_areas(sub_areas[n], opaque1+1, opaque2, areas); } return; } area = sub_areas[0]; } areas->push_back(area); } } void background::draw_layers(int x, int y, const rect& area_ref, const std::vector& opaque_areas, int rotation, int cycle) const { static std::vector areas; areas.clear(); calculate_draw_areas(area_ref, opaque_areas.begin(), opaque_areas.end(), &areas); for(std::vector::const_iterator i = layers_.begin(); i != layers_.end(); ++i) { const layer& bg = *i; if(bg.foreground == false) { for(std::vector::const_iterator a = areas.begin(); a != areas.end(); ++a) { draw_layer(x, y, *a, rotation, bg, cycle); } if(!blit_queue.empty() && (i+1 == layers_.end() || i->texture != (i+1)->texture || (i+1)->foreground || i->blend != (i+1)->blend)) { if(bg.blend == false) { glDisable(GL_BLEND); } blit_queue.set_texture(bg.texture.get_id()); blit_queue.do_blit(); blit_queue.clear(); if(bg.blend == false) { glEnable(GL_BLEND); } } } } } void background::draw_foreground(double xpos, double ypos, int rotation, int cycle) const { foreach(const layer& bg, layers_) { if(bg.foreground) { draw_layer(xpos, ypos, rect(xpos, ypos, graphics::screen_width(), graphics::screen_height()), rotation, bg, cycle); if(!blit_queue.empty()) { blit_queue.set_texture(bg.texture.get_id()); blit_queue.do_blit(); blit_queue.clear(); } } } } void background::set_offset(const point& offset) { offset_ = offset; } void background::draw_layer(int x, int y, const rect& area, int rotation, const background::layer& bg, int cycle) const { const double ScaleImage = 2.0; GLshort y1 = y + (bg.yoffset+offset_.y)*ScaleImage - (y*bg.yscale)/100; GLshort y2 = y1 + (bg.y2 - bg.y1)*ScaleImage; if(!bg.tile_downwards && y2 <= y) { return; } if(!bg.tile_downwards && y2 <= area.y()) { return; } if(!bg.tile_upwards && y1 > area.y2()) { return; } if(!bg.texture.valid()) { //currently do not cache loaded textures making them get reloaded //on every level. #if 1 bg.texture = graphics::texture::get_palette_mapped_no_cache(bg.image, palette_); #else if(palette_ == -1) { bg.texture = graphics::texture::get(bg.image, bg.image_formula); } else { bg.texture = graphics::texture::get_palette_mapped(bg.image, palette_); } #endif if(bg.y2 == 0) { bg.y2 = bg.texture.height(); } } if(!bg.texture.valid()) { return; } ASSERT_GT(bg.texture.height(), 0); ASSERT_GT(bg.texture.width(), 0); GLfloat v1 = bg.texture.translate_coord_y(double(bg.y1)/double(bg.texture.height())); GLfloat v2 = bg.texture.translate_coord_y(double(bg.y2)/double(bg.texture.height())); if(y1 < area.y()) { //Making y1 == y2 is problematic, so don't allow it. const int target_y = area.y() == y2 ? area.y()-1 : area.y(); v1 += (GLfloat(target_y - y1)/GLfloat(y2 - y1))*(v2 - v1); y1 = target_y; } if(bg.tile_upwards && y1 > area.y()) { v1 -= (GLfloat(y1 - area.y())/GLfloat(y2 - y1))*(v2 - v1); y1 = area.y(); } else if(bg.color_above && y1 > area.y()) { glEnable(GL_SCISSOR_TEST); const int xpos = area.x() - x; const int ypos = y1 - y; const int width = area.w(); const int height = y1 - area.y(); #if TARGET_OS_IPHONE glScissor((graphics::screen_height() - ypos)/2, (graphics::screen_width() - (xpos + width))/2, height/2, width/2); #else glScissor(xpos, graphics::screen_height() - ypos, width, height); #endif glClearColor(bg.color_above->r, bg.color_above->g, bg.color_above->b, 1.0); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); } if(bg.tile_downwards && y2 < area.y() + area.h()) { v2 += (GLfloat((area.y() + area.h()) - y2)/GLfloat(y2 - y1))*(v2 - v1); y2 = area.y() + area.h(); } else if(bg.color_below && y2 < area.y() + area.h()) { glEnable(GL_SCISSOR_TEST); const int xpos = area.x() - x; const int ypos = area.y() + area.h() - y; const int width = area.w(); const int height = area.y() + area.h() - y2; #if TARGET_OS_IPHONE glScissor((graphics::screen_height() - ypos)/2, (graphics::screen_width() - (xpos + width))/2, height/2, width/2); #else glScissor(xpos, graphics::screen_height() - ypos, width, height); #endif glClearColor(bg.color_below->r, bg.color_below->g, bg.color_below->b, 1.0); glClear(GL_COLOR_BUFFER_BIT); glDisable(GL_SCISSOR_TEST); } if(y2 > area.y() + area.h()) { v2 -= (GLfloat(y2 - (area.y() + area.h()))/GLfloat(y2 - y1))*(v2 - v1); y2 = area.y() + area.h(); } if(y2 <= y1) { return; } if(v1 > v2) { return; } //clamp [v1, v2] into the [0.0, 1.0] range if(v1 > 1.0) { const GLfloat f = floor(v1); v1 -= f; v2 -= f; } if(v1 < 0.0) { const GLfloat diff = v2 - v1; const GLfloat f = floor(-v1); v1 = 1.0 - (-v1 - f); v2 = v1 + diff; } int screen_width = area.w(); const double xscale = double(bg.xscale)/100.0; GLfloat xpos = (-GLfloat(bg.xspeed)*GLfloat(cycle)/1000 + int(GLfloat(x + bg.xoffset)*xscale))/GLfloat((bg.texture.width()+bg.xpad)*ScaleImage) + GLfloat(area.x() - x)/GLfloat((bg.texture.width()+bg.xpad)*ScaleImage); //clamp xpos into the [0.0, 1.0] range if(xpos > 0) { xpos -= floor(xpos); } else { while(xpos < 0) { xpos += 1.0; } //xpos += ceil(-xpos); } if(bg.xpad > 0) { xpos *= GLfloat(bg.texture.width() + bg.xpad)/GLfloat(bg.texture.width()); } glColor4f(bg.color[0], bg.color[1], bg.color[2], bg.color[3]); #if defined(__GLEW_H__) if (GLEW_EXT_blend_minmax && (GLEW_ARB_imaging || GLEW_VERSION_1_4)) { glBlendEquation(bg.mode); } #endif x = area.x(); y = area.y(); while(screen_width > 0) { const int texture_blit_width = (1.0 - xpos)*bg.texture.width()*ScaleImage; const int blit_width = std::min(texture_blit_width, screen_width); if(blit_width > 0) { const GLfloat xpos2 = xpos + GLfloat(blit_width)/(GLfloat(bg.texture.width())*2.0); const GLshort x1 = x; const GLshort x2 = x1 + blit_width; const GLfloat u1 = bg.texture.translate_coord_x(xpos); const GLfloat u2 = bg.texture.translate_coord_x(xpos2); blit_queue.repeat_last(); blit_queue.add(x1, y1, u1, v1); blit_queue.repeat_last(); blit_queue.add(x2, y1, u2, v1); blit_queue.add(x1, y2, u1, v2); blit_queue.add(x2, y2, u2, v2); } x += blit_width + bg.xpad*ScaleImage; xpos = 0.0; screen_width -= blit_width + bg.xpad*ScaleImage; } glColor4f(1.0,1.0,1.0,1.0); #if defined(__GLEW_H__) if (GLEW_EXT_blend_minmax && (GLEW_ARB_imaging || GLEW_VERSION_1_4)) { glBlendEquation(GL_FUNC_ADD); } #endif } frogatto-1.3.1+dfsg/src/background.hpp0000644000175000017500000000511212060740335017574 0ustar vincentvincent#ifndef BACKGROUND_HPP_INCLUDED #define BACKGROUND_HPP_INCLUDED #include #include #include #include "boost/shared_ptr.hpp" #include "graphics.hpp" #include "geometry.hpp" #include "texture.hpp" #include "variant.hpp" class level; //class which represents the background to a level. class background { public: static void load_modified_backgrounds(); //gets a background associated with a given ID. static boost::shared_ptr get(const std::string& id, int palette_id); //all available backgrounds. static std::vector get_available_backgrounds(); background(variant node, int palette); const std::string& id() const { return id_; } variant write() const; void draw(int x, int y, const rect& area, const std::vector& opaque_areas, int rotation, int cycle) const; void draw_foreground(double x, double y, int rotation, int cycle) const; void set_offset(const point& offset); private: void draw_layers(int x, int y, const rect& area, const std::vector& opaque_areas, int rotation, int cycle) const; std::string id_, file_; SDL_Color top_, bot_; int width_, height_; point offset_; struct layer { std::string image; std::string image_formula; mutable graphics::texture texture; int xscale, yscale; //scales are how quickly the background scrolls compared to normal ground movement when the player //walks around. They give us the illusion of 'depth'. 100 is normal ground, less=distant, more=closer int xspeed; //speed is how fast (in millipixels/cycle) the bg moves on its own. It's for drifting clounds/rivers. int xpad; //amount of empty space padding we put between int scale; //a multiplier on the dimensions of the image. Usually unused. int xoffset; int yoffset; GLfloat color[4]; boost::shared_ptr color_above, color_below; GLenum mode; //Do we use the regular 'GL_FUNC_ADD' blend mode, or do we do something special? Examples: //GL_MAX -> Max(src,dest) pixels, displays whichever's brighter. Useful for clouds. //GL_MIN -> vice-versa, useful for spooky mist. // Top and bottom edges of the background. mutable int y1, y2; //if true, this layer is actually drawn in the foreground. bool foreground; //if false we can disable blending while this is drawn bool blend; //if true prevents the image being tiled. bool notile; bool tile_upwards, tile_downwards; }; void draw_layer(int x, int y, const rect& area, int rotation, const layer& bg, int cycle) const; std::vector layers_; int palette_; }; #endif frogatto-1.3.1+dfsg/src/background_task_pool.cpp0000644000175000017500000000233112060740335021642 0ustar vincentvincent#include #include #include #include #include "background_task_pool.hpp" #include "foreach.hpp" #include "thread.hpp" namespace background_task_pool { namespace { int next_task_id = 0; struct task { boost::function job, on_complete; boost::shared_ptr thread; }; threading::mutex* completed_tasks_mutex = NULL; std::vector completed_tasks; std::map task_map; void run_task(boost::function job, int task_id) { job(); threading::lock(*completed_tasks_mutex); completed_tasks.push_back(task_id); } } manager::manager() { completed_tasks_mutex = new threading::mutex; } manager::~manager() { while(task_map.empty() == false) { pump(); } } void submit(boost::function job, boost::function on_complete) { task t = { job, on_complete, boost::shared_ptr(new threading::thread(boost::bind(run_task, job, next_task_id))) }; task_map[next_task_id] = t; ++next_task_id; } void pump() { std::vector completed; { threading::lock(*completed_tasks_mutex); completed.swap(completed_tasks); } foreach(int t, completed) { task_map[t].on_complete(); task_map.erase(t); } } } frogatto-1.3.1+dfsg/src/background_task_pool.hpp0000644000175000017500000000045412060740335021653 0ustar vincentvincent#ifndef BACKGROUND_TASK_POOL_HPP_INCLUDED #define BACKGROUND_TASK_POOL_HPP_INCLUDED #include namespace background_task_pool { struct manager { manager(); ~manager(); }; void pump(); void submit(boost::function job, boost::function on_complete); } #endif frogatto-1.3.1+dfsg/src/base64.cpp0000644000175000017500000001441212060740335016537 0ustar vincentvincent#include "asserts.hpp" #include "base64.hpp" #include "unit_test.hpp" namespace base64 { static const char _base64chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const unsigned char _base64inv[] = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00>\x00\x00\x00?456789:" ";<=\x00\x00\x00\x00\x00\x00\x00\x00\x01\x02\x03\x04\x05\x06\x07" "\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17" "\x18\x19\x00\x00\x00\x00\x00\x00\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'" "()*+,-./0123"; /*! Calculates the amount of buffer space required to encode a string of length n. \param n Number of characters to be encoded. \return Amount of buffer space required to encode the number of characters specified. */ static int encode_buffer_req(int n, int output_line_len) { // Allow for 3 characters expand to 4-characters n = ( ( ( n + 2 ) / 3 ) * 4 ); // Allow for every #OUTPUT_LINE_LENGTH characters. if(output_line_len > 0) { n += ( n / output_line_len ); } return n; } static void encode_block(std::vector::const_iterator& in_it, std::vector::iterator& out, int len) { unsigned char in[3]; for(int i = 0; i < 3; i++) { in[i] = len > i ? *in_it++ : 0; } *out++ = _base64chars[ in[ 0 ] >> 2 ]; *out++ = _base64chars[ ( ( in[ 0 ] & 3 ) << 4 ) | ( ( in[ 1 ] & 0xf0 ) >> 4 ) ]; *out++ = ( len > 1 ? _base64chars[ ( ( in[ 1 ] & 0x0f ) << 2 ) |( ( in[ 2 ] & 0xc0 ) >> 6 ) ] : '=' ); *out++ = ( len > 2 ? _base64chars[ in[ 2 ] & 0x3f ] : '=' ); } std::string b64encode(const std::string& data, int output_line_length) { const std::vector result = b64encode(std::vector(data.begin(), data.end()), output_line_length); return std::string(result.begin(), result.end()); } std::string b64decode(const std::string& data) { const std::vector result = b64decode(std::vector(data.begin(), data.end())); return std::string(result.begin(), result.end()); } std::vector b64encode(const std::vector& data, int output_line_length) { std::vector dest; dest.resize(encode_buffer_req(data.size(), output_line_length)); std::vector::const_iterator in_pos = data.begin(); std::vector::iterator out_pos = dest.begin(); int line_cnt = 0; for(unsigned i = 0; i < data.size(); i += 3) { encode_block( in_pos, out_pos, ( data.size() - i ) > 2 ? 3 : data.size() - i ); line_cnt += 4; if(line_cnt >= output_line_length) { line_cnt = 0; *out_pos++ = '\n'; } } if(line_cnt >= output_line_length) { *out_pos++ = '\n'; } return dest; } /*! \brief Calculate a quick estimate of the amount of bytes required to store the decoded base64 data. This is only an estimate as it assumes that there are no ignore characters in the data stream. \param n Number of encoded base64 characters. \return An estimate of the number buffer space required for the decode. */ static int decode_buffer_req(int n) { return ((n + 3) / 4) * 3; } /*! Test a character to determine if it is a valid base64 encode character. \param ch Character to test if it is in the expected base64 character set. \return Non-zero if the character is a valid base64 character. Zero if the character isn't valid. */ static bool is_base64_char(int ch) { if(ch >= 'A' && ch <= 'Z') return true; if(ch >= 'a' && ch <= 'z') return true; if(ch >= '0' && ch <= '9') return true; if(ch == '+' || ch == '/') return true; return false; } /*! \brief Takes a block of 4 base64 encoded characters and decodes them. \param in The block of base64 encoded characters, must come from the expected character set. \param out Pointer to place the 3 plaintext characters. */ static void decodeblock(const char* in, std::vector::iterator& out) { unsigned long nn = (_base64inv[in[0]] << 18) | (_base64inv[in[1]] << 12) | (_base64inv[in[2]] << 6) | (_base64inv[in[3]]); *out++ = (char)(nn >> 16); *out++ = (char)(nn >> 8); *out++ = (char)nn; } /*! \brief Decode a block of base64 encoded data. \param data Base64 encoded block of data. Data may contain other characters such as line-terminators and whitespace. \return A block of unencoded data, if unencoding was possible. */ std::vector b64decode(const std::vector& data) { std::vector dest; dest.resize(decode_buffer_req(data.size())); std::vector::const_iterator in_pos = data.begin(); std::vector::iterator out_pos = dest.begin(); char decode_buffer[ 4 ]; int ndx = 0; int cnt = 0; int padding = 0; for(unsigned i = 0; i < data.size(); i++) { int ch = *in_pos++; if( ch == '=' ) { ch = 'A'; padding++; } if(is_base64_char(ch)) { decode_buffer[ndx] = ch; if(++ndx >= 4) { ndx = 0; decodeblock(decode_buffer, out_pos); cnt += 3 - padding; padding = 0; } } } dest.resize(cnt); return dest; } } UNIT_TEST(base64_encode) { std::vector in; std::string ress("YQ=="); in.push_back('a'); std::vector resv = base64::b64encode(in); std::string s(resv.begin(), resv.end()); CHECK_EQ(s,ress) } UNIT_TEST(base64_encode_bin) { std::vector in; for(int i = 0; i < 256; i++) { in.push_back(i); } std::string ress = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4v\n" "MDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5f\n" "YGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6P\n" "kJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/\n" "wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v\n" "8PHy8/T19vf4+fr7/P3+/w=="; std::vector resv = base64::b64encode(in); std::string s(resv.begin(), resv.end()); CHECK_EQ(s,ress) } UNIT_TEST(base64_decode) { std::string s = "The quick brown fox jumps over the lazy dog"; std::vector resv = base64::b64decode(base64::b64encode(std::vector(s.begin(), s.end()))); std::string res(resv.begin(), resv.end()); CHECK_EQ(s, res); } frogatto-1.3.1+dfsg/src/base64.hpp0000644000175000017500000000065712060740335016552 0ustar vincentvincent#pragma once #ifndef BASE64_HPP_INCLUDED #define BASE64_HPP_INCLUDED #include #include namespace base64 { std::string b64encode(const std::string& data, int output_line_length=64); std::vector b64encode(const std::vector& data, int output_line_length=64); std::string b64decode(const std::string& data); std::vector b64decode(const std::vector& data); } #endif // BASE64_HPP_INCLUDED frogatto-1.3.1+dfsg/src/blur.cpp0000644000175000017500000000322112060740335016413 0ustar vincentvincent#include "graphics.hpp" #include "blur.hpp" #include "foreach.hpp" #include "frame.hpp" blur_info::blur_info(double alpha, double fade, int granularity) : alpha_(alpha), fade_(fade), granularity_(granularity) { } void blur_info::copy_settings(const blur_info& o) { alpha_ = o.alpha_; fade_ = o.fade_; granularity_ = o.granularity_; } void blur_info::next_frame(int start_x, int start_y, int end_x, int end_y, const frame* object_frame, int time_in_frame, bool facing, bool upside_down, float start_rotate, float rotate) { foreach(blur_frame& f, frames_) { f.fade -= fade_; } while(!frames_.empty() && frames_.front().fade <= 0.0) { frames_.pop_front(); } for(int n = 0; n < granularity_; ++n) { blur_frame f; f.object_frame = object_frame; f.x = (start_x*n + end_x*(granularity_ - n))/granularity_; f.y = (start_y*n + end_y*(granularity_ - n))/granularity_; f.time_in_frame = time_in_frame; f.facing = facing; f.upside_down = upside_down; f.rotate = (start_rotate*n + rotate*(granularity_ - n))/granularity_; f.fade = alpha_ + (fade_*(granularity_ - n))/granularity_; frames_.push_back(f); } } void blur_info::draw() const { GLfloat color[4]; #if defined(USE_GLES2) && defined(GL_ES_VERSION_2_0) glGetFloatv_1(GL_CURRENT_COLOR, color); #else glGetFloatv(GL_CURRENT_COLOR, color); #endif foreach(const blur_frame& f, frames_) { glColor4f(color[0], color[1], color[2], color[3]*f.fade); f.object_frame->draw(f.x, f.y, f.facing, f.upside_down, f.time_in_frame, f.rotate); } glColor4f(color[0], color[1], color[2], color[3]); } bool blur_info::destroyed() const { return granularity_ == 0 && frames_.empty(); } frogatto-1.3.1+dfsg/src/blur.hpp0000644000175000017500000000305112060740335016421 0ustar vincentvincent#ifndef BLUR_HPP_INCLUDED #define BLUR_HPP_INCLUDED #include class frame; //class which represents the blur information for a single object. //a blur contains three parameters: // - alpha: the initial alpha value of the blurred vision of the object. // - fade: the rate at which the alpha fades each frame // - granularity: the number of copies of the object that are made // every cycle. class blur_info { public: blur_info(double alpha, double fade, int granularity); //function to copy settings into another blur_info instance. This will //keep our blur_frames as they are, but copy in the alpha/fade/granularity //settings and so change our blur behavior from then on. void copy_settings(const blur_info& info); //function to progress to the next frame. We are given starting and //ending position of the object, along with its drawing settings. // //'granularity' copies of the object's image will be made, linearly //interpolated between start_x,start_y and end_x,end_y. void next_frame(int start_x, int start_y, int end_x, int end_y, const frame* f, int time_in_frame, bool facing, bool upside_down, float start_rotate, float rotate); void draw() const; //returns true iff our granularity is now 0 and we have no blur_frames. bool destroyed() const; private: struct blur_frame { const frame* object_frame; int time_in_frame; double x, y; bool facing, upside_down; float rotate; double fade; }; double alpha_; double fade_; int granularity_; std::deque frames_; }; #endif frogatto-1.3.1+dfsg/src/border_widget.cpp0000644000175000017500000000352012060740335020271 0ustar vincentvincent#include "asserts.hpp" #include "graphics.hpp" #include "border_widget.hpp" #include "raster.hpp" #include "widget_factory.hpp" namespace gui { border_widget::border_widget(widget_ptr child, graphics::color col, int border_size) : child_(child), color_(col), border_size_(border_size) { set_environment(); set_dim(child->width() + border_size*2, child->height() + border_size*2); child_->set_loc(border_size, border_size); } border_widget::border_widget(widget_ptr child, const SDL_Color& color, int border_size) : child_(child), color_(color.r, color.g, color.b, color.unused), border_size_(border_size) { set_environment(); set_dim(child->width() + border_size*2, child->height() + border_size*2); child_->set_loc(border_size, border_size); } border_widget::border_widget(const variant& v, game_logic::formula_callable* e) : widget(v,e) { ASSERT_LOG(v.is_map(), "TYPE ERROR: parameter to border widget must be a map"); color_ = v.has_key("color") ? graphics::color(0,0,0,255) : graphics::color(v["color"]); border_size_ = v.has_key("border_size") ? v["border_size"].as_int() : 2; child_ = widget_factory::create(v["child"], e); } void border_widget::set_color(const graphics::color& col) { color_ = col; } void border_widget::handle_process() { widget::handle_process(); child_->process(); } void border_widget::handle_draw() const { glPushMatrix(); graphics::draw_rect(rect(x(),y(),width(),height()), color_); glTranslatef(GLfloat(x()), GLfloat(y()), 0.0); child_->draw(); glPopMatrix(); } bool border_widget::handle_event(const SDL_Event& event, bool claimed) { SDL_Event ev = event; normalize_event(&ev); return child_->process_event(ev, claimed); } widget_ptr border_widget::get_widget_by_id(const std::string& id) { widget_ptr wx = child_->get_widget_by_id(id); if(wx) { return wx; } return widget::get_widget_by_id(id); } } frogatto-1.3.1+dfsg/src/border_widget.hpp0000644000175000017500000000160112060740335020274 0ustar vincentvincent#ifndef BORDER_WIDGET_HPP_INCLUDED #define BORDER_WIDGET_HPP_INCLUDED #include "graphics.hpp" #include "color_utils.hpp" #include "widget.hpp" namespace gui { //a widget which draws a border around another widget it holds as its child. class border_widget : public widget { public: border_widget(widget_ptr child, graphics::color col, int border_size=2); border_widget(widget_ptr child, const SDL_Color& color, int border_size=2); border_widget(const variant& v, game_logic::formula_callable* e); void set_color(const graphics::color& col); virtual widget_ptr get_widget_by_id(const std::string& id); protected: virtual void handle_draw() const; virtual void handle_process(); private: bool handle_event(const SDL_Event& event, bool claimed); widget_ptr child_; graphics::color color_; int border_size_; }; typedef boost::intrusive_ptr border_widget_ptr; } #endif frogatto-1.3.1+dfsg/src/button.cpp0000644000175000017500000001256012060740335016770 0ustar vincentvincent /* Copyright (C) 2007 by David White Part of the Silver Tree Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 or later. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. See the COPYING file for more details. */ #include #include "asserts.hpp" #include "button.hpp" #include "custom_object_functions.hpp" #include "iphone_controls.hpp" #include "formula.hpp" #include "label.hpp" #include "raster.hpp" #include "surface_cache.hpp" #include "framed_gui_element.hpp" #include "widget_factory.hpp" namespace gui { button::button(const std::string& str, boost::function onclick) : label_(new label(str, graphics::color_white())), onclick_(onclick), button_resolution_(BUTTON_SIZE_NORMAL_RESOLUTION), button_style_(BUTTON_STYLE_NORMAL), hpadding_(10), vpadding_(4), down_(false) { set_environment(); setup(); } button::button(widget_ptr label, boost::function onclick, BUTTON_STYLE button_style, BUTTON_RESOLUTION button_resolution) : label_(label), onclick_(onclick), button_resolution_(button_resolution), button_style_(button_style), down_(false), hpadding_(10), vpadding_(4) { set_environment(); setup(); } button::button(const variant& v, game_logic::formula_callable* e) : widget(v,e), down_(false) { variant label_var = v["label"]; label_ = label_var.is_map() ? widget_factory::create(label_var, e) : new label(label_var.as_string_default("Button"), graphics::color_white()); ASSERT_LOG(v.has_key("on_click"), "Button must be supplied with an on_click handler"); // create delegate for onclick ASSERT_LOG(get_environment() != 0, "You must specify a callable environment"); click_handler_ = get_environment()->create_formula(v["on_click"]); onclick_ = boost::bind(&button::click, this); button_resolution_ = v["resolution"].as_string_default("normal") == "normal" ? BUTTON_SIZE_NORMAL_RESOLUTION : BUTTON_SIZE_DOUBLE_RESOLUTION; button_style_ = v["style"].as_string_default("default") == "default" ? BUTTON_STYLE_DEFAULT : BUTTON_STYLE_NORMAL; hpadding_ = v["hpad"].as_int(10); vpadding_ = v["vpad"].as_int(4); if(v.has_key("padding")) { ASSERT_LOG(v["padding"].num_elements() == 2, "Incorrect number of padding elements specifed." << v["padding"].num_elements()); hpadding_ = v["padding"][0].as_int(); vpadding_ = v["padding"][1].as_int(); } setup(); } void button::click() { if(get_environment()) { variant value = click_handler_->execute(*get_environment()); get_environment()->execute_command(value); } else { std::cerr << "button::click() called without environment!" << std::endl; } } void button::setup() { if(button_style_ == BUTTON_STYLE_DEFAULT){ normal_button_image_set_ = framed_gui_element::get("default_button"); depressed_button_image_set_ = framed_gui_element::get("default_button_pressed"); focus_button_image_set_ = framed_gui_element::get("default_button_focus"); }else{ normal_button_image_set_ = framed_gui_element::get("regular_button"); depressed_button_image_set_ = framed_gui_element::get("regular_button_pressed"); focus_button_image_set_ = framed_gui_element::get("regular_button_focus"); } current_button_image_set_ = normal_button_image_set_; set_label(label_); } void button::set_label(widget_ptr label) { label_ = label; set_dim(label_->width()+hpadding_*2,label_->height()+vpadding_*2); } void button::handle_draw() const { label_->set_loc(x()+width()/2 - label_->width()/2,y()+height()/2 - label_->height()/2); current_button_image_set_->blit(x(),y(),width(),height(), button_resolution_ != 0); label_->draw(); } void button::handle_process() { widget::handle_process(); label_->process(); } bool button::handle_event(const SDL_Event& event, bool claimed) { if((event.type == SDL_MOUSEBUTTONDOWN || event.type == SDL_MOUSEBUTTONUP) && (event.button.button == SDL_BUTTON_WHEELUP || event.button.button == SDL_BUTTON_WHEELDOWN) && in_widget(event.button.x, event.button.y)) { // skip processing if mousewheel event return claimed; } if(claimed) { current_button_image_set_ = normal_button_image_set_; down_ = false; } if(event.type == SDL_MOUSEMOTION) { const SDL_MouseMotionEvent& e = event.motion; if(in_widget(e.x,e.y)) { current_button_image_set_ = down_ ? depressed_button_image_set_ : focus_button_image_set_; } else { current_button_image_set_ = normal_button_image_set_; } } else if(event.type == SDL_MOUSEBUTTONDOWN) { const SDL_MouseButtonEvent& e = event.button; if(in_widget(e.x,e.y)) { current_button_image_set_ = depressed_button_image_set_; down_ = true; claimed = true; } } else if(event.type == SDL_MOUSEBUTTONUP) { down_ = false; const SDL_MouseButtonEvent& e = event.button; if(current_button_image_set_ == depressed_button_image_set_) { if(in_widget(e.x,e.y)) { current_button_image_set_ = focus_button_image_set_; onclick_(); claimed = true; } else { current_button_image_set_ = normal_button_image_set_; } } } return claimed; } widget_ptr button::get_widget_by_id(const std::string& id) { if(label_ && label_->get_widget_by_id(id)) { return label_; } return widget::get_widget_by_id(id); } variant button::get_value(const std::string& key) const { if(key == "label") { return variant(label_.get()); } return widget::get_value(key); } } frogatto-1.3.1+dfsg/src/button.hpp0000644000175000017500000000414012060740335016770 0ustar vincentvincent /* Copyright (C) 2007 by David White Part of the Silver Tree Project This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 or later. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. See the COPYING file for more details. */ #ifndef BUTTON_HPP_INCLUDED #define BUTTON_HPP_INCLUDED #include #include "texture.hpp" #include "widget.hpp" #include "framed_gui_element.hpp" namespace gui { enum BUTTON_RESOLUTION { BUTTON_SIZE_NORMAL_RESOLUTION, BUTTON_SIZE_DOUBLE_RESOLUTION }; enum BUTTON_STYLE { BUTTON_STYLE_NORMAL, BUTTON_STYLE_DEFAULT }; //"default" means a visually fat-edged button - the one that gets pressed by hitting enter. This is standard gui lingo, it's what the dialogue "defaults" to doing when you press return. //a button widget. Forwards to a given function whenever it is clicked. class button : public widget { public: button(const std::string& label, boost::function onclick); button(widget_ptr label, boost::function onclick, BUTTON_STYLE button_style = BUTTON_STYLE_NORMAL, BUTTON_RESOLUTION button_resolution = BUTTON_SIZE_NORMAL_RESOLUTION); button(const variant& v, game_logic::formula_callable* e); virtual widget_ptr get_widget_by_id(const std::string& id); protected: virtual variant get_value(const std::string& key) const; void set_label(widget_ptr label); virtual void handle_process(); BUTTON_RESOLUTION button_resolution() const { return button_resolution_; } private: void setup(); void handle_draw() const; bool handle_event(const SDL_Event& event, bool claimed); void click(); int vpadding_; int hpadding_; BUTTON_RESOLUTION button_resolution_; BUTTON_STYLE button_style_; widget_ptr label_; boost::function onclick_; bool down_; game_logic::formula_ptr click_handler_; const_framed_gui_element_ptr normal_button_image_set_,depressed_button_image_set_,focus_button_image_set_,current_button_image_set_; }; typedef boost::intrusive_ptr