Fixed up the file saving and loading screen so it's not such a mess. Got rid of some compile warnings.

This commit is contained in:
grimfang4@gmail.com
2012-01-11 05:20:44 +00:00
parent 9616cc607d
commit f9e8fe119c
4 changed files with 31 additions and 22 deletions

View File

@@ -24,11 +24,12 @@
#include "sdlkit.h"
#include "tools.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <cstdio>
#include <cstdarg>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <string>
#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);

View File

@@ -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<std::string>& files, char* buf, bool& gotFile, bool& done)
void DrawFileSelectScreen(std::list<std::string>& files, char* buf, bool& gotFile, bool& done, bool showNewButton)
{
using namespace std;
@@ -293,9 +297,9 @@ void DrawFileSelectScreen(std::list<std::string>& 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<std::string>& 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();

View File

@@ -24,6 +24,7 @@
#define SDLKIT_H
#include "SDL.h"
#include <string>
#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 ();

View File

@@ -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<id_length;i++)
n = fread(&byte, 1, 1, file); // image description