diff --git a/sfxr/main.cpp b/sfxr/main.cpp index 8d5b79d..506d84c 100644 --- a/sfxr/main.cpp +++ b/sfxr/main.cpp @@ -24,11 +24,12 @@ #include "sdlkit.h" #include "tools.h" -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "SDL.h" @@ -200,6 +201,7 @@ bool LoadSettings(char* filename) return false; size_t n; + (void)n; int version=0; n = fread(&version, 1, sizeof(int), file); if(version!=100 && version!=101 && version!=102) @@ -558,7 +560,7 @@ static void SDLAudioCallback(void *userdata, Uint8 *stream, int len) else memset(stream, 0, len); } -bool ExportWAV(char* filename) +bool ExportWAV(const char* filename) { FILE* foutput=fopen(filename, "wb"); if(!foutput) @@ -1089,9 +1091,11 @@ void DrawScreen() DrawBar(490-1-2, 380-1-2, 102+4, 19+4, 0x000000); if(Button(490, 380, false, "EXPORT .WAV", 16)) { - char filename[256]; - if(FileSelectorSave(filename, 0)) - ExportWAV(filename); + std::string filename = new_file(".wav"); + //char filename[256]; + //if(FileSelectorSave(filename, 0)) + if(filename.size() > 0) + ExportWAV(filename.c_str()); } char str[10]; sprintf(str, "%i HZ", wav_freq); diff --git a/sfxr/sdlkit.cpp b/sfxr/sdlkit.cpp index a5d78d0..266e689 100644 --- a/sfxr/sdlkit.cpp +++ b/sfxr/sdlkit.cpp @@ -202,7 +202,7 @@ extern int vcurbutton; extern Spriteset font; -std::string new_file() +std::string new_file(const std::string& forced_extension) { using namespace std; SDL_EnableUNICODE(1); @@ -256,12 +256,16 @@ std::string new_file() SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); SDL_EnableUNICODE(0); - // FIXME: Force .sfxr + //if(result.size() == 0) + // throw runtime_error("New file name is empty string."); + + if(result.size() < 6 || result.substr(result.size()-1 - 4, string::npos) != forced_extension) + result += forced_extension; return result; } -void DrawFileSelectScreen(std::list& files, char* buf, bool& gotFile, bool& done) +void DrawFileSelectScreen(std::list& files, char* buf, bool& gotFile, bool& done, bool showNewButton) { using namespace std; @@ -293,9 +297,9 @@ void DrawFileSelectScreen(std::list& files, char* buf, bool& gotFil done = true; } - if(Button(10, 160, false, "NEW FILE", 401)) + if(showNewButton && Button(120, 10, false, "NEW FILE", 401)) { - string s = new_file(); + string s = new_file(".sfxr"); if(s != "") { ioNew(s, true, true); @@ -321,7 +325,7 @@ void DrawFileSelectScreen(std::list& files, char* buf, bool& gotFil } -bool select_file (char *buf) +bool select_file (char *buf, bool showNewButton) { // FIXME: Needs directory browsing @@ -358,7 +362,7 @@ bool select_file (char *buf) } sdlupdate(); - DrawFileSelectScreen(files, buf, gotFile, done); + DrawFileSelectScreen(files, buf, gotFile, done, showNewButton); SDL_Delay(5); @@ -367,9 +371,6 @@ bool select_file (char *buf) return gotFile; } -#define FileSelectorLoad(file,y) select_file(file) -#define FileSelectorSave(file,y) select_file(file) - void sdlquit () { ddkFree(); diff --git a/sfxr/sdlkit.h b/sfxr/sdlkit.h index 65eb4c3..8b03857 100644 --- a/sfxr/sdlkit.h +++ b/sfxr/sdlkit.h @@ -24,6 +24,7 @@ #define SDLKIT_H #include "SDL.h" +#include #define ERROR(x) error(__FILE__, __LINE__, #x) @@ -75,10 +76,11 @@ void ddkSetMode (int width, int height, int bpp, int refreshrate, int fullscreen //void selected_file (GtkWidget *button, GtkFileSelection *fs); -bool select_file (char *buf); +bool select_file (char *buf, bool showNewButton); +std::string new_file(const std::string& forced_extension); -#define FileSelectorLoad(file,y) select_file(file) -#define FileSelectorSave(file,y) select_file(file) +#define FileSelectorLoad(file,y) select_file(file, false) +#define FileSelectorSave(file,y) select_file(file, true) void sdlquit (); diff --git a/sfxr/tools.cpp b/sfxr/tools.cpp index 49ce024..5995d79 100644 --- a/sfxr/tools.cpp +++ b/sfxr/tools.cpp @@ -33,6 +33,7 @@ int LoadTGA(Spriteset& tiles, const char *filename) return -1; int n; + (void)n; n = fread(&id_length, 1, 1, file); n = fread(crap, 1, 11, file); width=0; @@ -41,6 +42,7 @@ int LoadTGA(Spriteset& tiles, const char *filename) n = fread(&height, 1, 2, file); // height n = fread(&byte, 1, 1, file); // bits channels=byte/8; + (void)channels; n = fread(&byte, 1, 1, file); // image descriptor byte (per-bit info) for(i=0;i