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:
@@ -24,11 +24,12 @@
|
|||||||
#include "sdlkit.h"
|
#include "sdlkit.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <cstdio>
|
||||||
#include <stdarg.h>
|
#include <cstdarg>
|
||||||
#include <stdlib.h>
|
#include <cstdlib>
|
||||||
#include <time.h>
|
#include <ctime>
|
||||||
#include <math.h>
|
#include <cmath>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
@@ -200,6 +201,7 @@ bool LoadSettings(char* filename)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
size_t n;
|
size_t n;
|
||||||
|
(void)n;
|
||||||
int version=0;
|
int version=0;
|
||||||
n = fread(&version, 1, sizeof(int), file);
|
n = fread(&version, 1, sizeof(int), file);
|
||||||
if(version!=100 && version!=101 && version!=102)
|
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);
|
else memset(stream, 0, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExportWAV(char* filename)
|
bool ExportWAV(const char* filename)
|
||||||
{
|
{
|
||||||
FILE* foutput=fopen(filename, "wb");
|
FILE* foutput=fopen(filename, "wb");
|
||||||
if(!foutput)
|
if(!foutput)
|
||||||
@@ -1089,9 +1091,11 @@ void DrawScreen()
|
|||||||
DrawBar(490-1-2, 380-1-2, 102+4, 19+4, 0x000000);
|
DrawBar(490-1-2, 380-1-2, 102+4, 19+4, 0x000000);
|
||||||
if(Button(490, 380, false, "EXPORT .WAV", 16))
|
if(Button(490, 380, false, "EXPORT .WAV", 16))
|
||||||
{
|
{
|
||||||
char filename[256];
|
std::string filename = new_file(".wav");
|
||||||
if(FileSelectorSave(filename, 0))
|
//char filename[256];
|
||||||
ExportWAV(filename);
|
//if(FileSelectorSave(filename, 0))
|
||||||
|
if(filename.size() > 0)
|
||||||
|
ExportWAV(filename.c_str());
|
||||||
}
|
}
|
||||||
char str[10];
|
char str[10];
|
||||||
sprintf(str, "%i HZ", wav_freq);
|
sprintf(str, "%i HZ", wav_freq);
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ extern int vcurbutton;
|
|||||||
|
|
||||||
extern Spriteset font;
|
extern Spriteset font;
|
||||||
|
|
||||||
std::string new_file()
|
std::string new_file(const std::string& forced_extension)
|
||||||
{
|
{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
SDL_EnableUNICODE(1);
|
SDL_EnableUNICODE(1);
|
||||||
@@ -256,12 +256,16 @@ std::string new_file()
|
|||||||
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||||
SDL_EnableUNICODE(0);
|
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;
|
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;
|
using namespace std;
|
||||||
|
|
||||||
@@ -293,9 +297,9 @@ void DrawFileSelectScreen(std::list<std::string>& files, char* buf, bool& gotFil
|
|||||||
done = true;
|
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 != "")
|
if(s != "")
|
||||||
{
|
{
|
||||||
ioNew(s, true, true);
|
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
|
// FIXME: Needs directory browsing
|
||||||
|
|
||||||
@@ -358,7 +362,7 @@ bool select_file (char *buf)
|
|||||||
}
|
}
|
||||||
sdlupdate();
|
sdlupdate();
|
||||||
|
|
||||||
DrawFileSelectScreen(files, buf, gotFile, done);
|
DrawFileSelectScreen(files, buf, gotFile, done, showNewButton);
|
||||||
|
|
||||||
SDL_Delay(5);
|
SDL_Delay(5);
|
||||||
|
|
||||||
@@ -367,9 +371,6 @@ bool select_file (char *buf)
|
|||||||
return gotFile;
|
return gotFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FileSelectorLoad(file,y) select_file(file)
|
|
||||||
#define FileSelectorSave(file,y) select_file(file)
|
|
||||||
|
|
||||||
void sdlquit ()
|
void sdlquit ()
|
||||||
{
|
{
|
||||||
ddkFree();
|
ddkFree();
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
#define SDLKIT_H
|
#define SDLKIT_H
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
|
||||||
#define ERROR(x) error(__FILE__, __LINE__, #x)
|
#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);
|
//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 FileSelectorLoad(file,y) select_file(file, false)
|
||||||
#define FileSelectorSave(file,y) select_file(file)
|
#define FileSelectorSave(file,y) select_file(file, true)
|
||||||
|
|
||||||
void sdlquit ();
|
void sdlquit ();
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ int LoadTGA(Spriteset& tiles, const char *filename)
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
int n;
|
int n;
|
||||||
|
(void)n;
|
||||||
n = fread(&id_length, 1, 1, file);
|
n = fread(&id_length, 1, 1, file);
|
||||||
n = fread(crap, 1, 11, file);
|
n = fread(crap, 1, 11, file);
|
||||||
width=0;
|
width=0;
|
||||||
@@ -41,6 +42,7 @@ int LoadTGA(Spriteset& tiles, const char *filename)
|
|||||||
n = fread(&height, 1, 2, file); // height
|
n = fread(&height, 1, 2, file); // height
|
||||||
n = fread(&byte, 1, 1, file); // bits
|
n = fread(&byte, 1, 1, file); // bits
|
||||||
channels=byte/8;
|
channels=byte/8;
|
||||||
|
(void)channels;
|
||||||
n = fread(&byte, 1, 1, file); // image descriptor byte (per-bit info)
|
n = fread(&byte, 1, 1, file); // image descriptor byte (per-bit info)
|
||||||
for(i=0;i<id_length;i++)
|
for(i=0;i<id_length;i++)
|
||||||
n = fread(&byte, 1, 1, file); // image description
|
n = fread(&byte, 1, 1, file); // image description
|
||||||
|
|||||||
Reference in New Issue
Block a user