- [NEW] res() without arguments returns width and height of window.
- [NEW] camera() without arguments returns 'x' and 'y' of camera. - [NEW] palcolor() to set or get a color from the palette (replaces setcolor() & getcolor() ). - [NEW] paltrans() to set or get which color index is transparent (replaces settrans() & gettrans() ). - [RENAME] sspr() to blit(), spr_r() to blit_r() - [NEW] mouse() returns both x and y mouse coordinates. - [DEPRECATED] setcolor(), getcolor(), settrans(), gettrans(), spr(), sspr(), spr_r(), mousex(), mousey(), abs(), ceil(), flr(), sgn(), sin(), cos(), atan2(), sqrt(), max(), mid(), min(), tostr(), ascii(), strlen(), fopen(), fopenres(), fclose(), feof(), fwritei(), fwrited(), fwrites(), fwritew(), fwriteb(), fwriteln(), freadi(), freadd(), freads(), freadw(), freadb() - [FIX] Now the background on resizable windows is filled with black instead of garbage. - [FIX] Compiling on Linux uses POSIX functions.
This commit is contained in:
154
mini.cpp
154
mini.cpp
@@ -412,6 +412,8 @@ int main(int argc,char*argv[]){
|
||||
mouse_just_pressed = 0;
|
||||
pad_just_pressed = SDL_CONTROLLER_BUTTON_INVALID;
|
||||
}
|
||||
SDL_SetRenderDrawColor(mini_ren, 0, 0, 0, 255);
|
||||
SDL_RenderClear(mini_ren);
|
||||
SDL_LockTexture(mini_bak, NULL, (void**)&pixels, &pitch);
|
||||
for (uint32_t i=0;i<screen_surface->size;++i) pixels[i] = palette[screen_surface->p[i]];
|
||||
SDL_UnlockTexture(mini_bak);
|
||||
@@ -877,7 +879,7 @@ void spr(uint8_t n, int x, int y, float w, float h, bool flip_x, bool flip_y) {
|
||||
}
|
||||
}
|
||||
|
||||
void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y, bool invert) {
|
||||
void blit(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool flip_x, bool flip_y, bool invert) {
|
||||
if (dw==0) dw=sw;
|
||||
if (dh==0) dh=sh;
|
||||
float sdx = float(sw)/float(dw);
|
||||
@@ -898,7 +900,7 @@ void sspr(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, bool f
|
||||
}
|
||||
}
|
||||
|
||||
void spr_r(int sx, int sy, int sw, int sh, int x, int y, float a)
|
||||
void blit_r(int sx, int sy, int sw, int sh, int x, int y, float a)
|
||||
{
|
||||
const int x0 = sw>>1;
|
||||
const int y0 = sh>>1;
|
||||
@@ -1103,158 +1105,10 @@ bool beat(int16_t i) {
|
||||
}
|
||||
}
|
||||
|
||||
/*float abs(float x) {
|
||||
return SDL_fabsf(x);
|
||||
}*/
|
||||
|
||||
float flr(float x) {
|
||||
return SDL_floorf(x);
|
||||
}
|
||||
|
||||
float sgn(float x) {
|
||||
return x >= 0 ? 1 : -1;
|
||||
}
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
float ceil(float x) {
|
||||
return SDL_ceilf(x);
|
||||
}
|
||||
|
||||
float sin(float x) {
|
||||
return SDL_sinf(x);
|
||||
}
|
||||
|
||||
float cos(float x) {
|
||||
return SDL_cosf(x);
|
||||
}
|
||||
|
||||
float atan2(float dx, float dy) {
|
||||
return SDL_atan2f(dx, dy);
|
||||
}
|
||||
|
||||
float sqrt(float x) {
|
||||
return SDL_sqrtf(x);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
float max(float x, float y) {
|
||||
return SDL_max(x, y);
|
||||
}
|
||||
|
||||
float mid(float x, float y, float z) {
|
||||
return max(x, min(y, z));
|
||||
}
|
||||
|
||||
float min(float x, float y) {
|
||||
return SDL_min(x, y);
|
||||
}
|
||||
|
||||
int utfstrlen(const char *str) {
|
||||
const int size_in_bytes = SDL_strlen(str);
|
||||
int size_in_utfchars = 0;
|
||||
for (int i=0;i<size_in_bytes;++i) if ((unsigned char)str[i] != 194 && (unsigned char)str[i] != 195) size_in_utfchars++;
|
||||
return size_in_utfchars;
|
||||
}
|
||||
|
||||
int rnd(int x) {
|
||||
return rand()%x;
|
||||
}
|
||||
|
||||
/*void srand(int x) {
|
||||
srand(x);
|
||||
}*/
|
||||
|
||||
char tostr_tmp[1024];
|
||||
const char* tostr(int val) {
|
||||
return SDL_itoa(val, tostr_tmp, 10);
|
||||
}
|
||||
|
||||
/*void debug(const char *str) {
|
||||
printf("%s\n",str);
|
||||
}*/
|
||||
|
||||
uint8_t ascii(const char *str, uint8_t index) {
|
||||
return str[index];
|
||||
}
|
||||
|
||||
char fstr[1024];
|
||||
|
||||
void fopen(const char *filename, uint8_t mode) {
|
||||
if (file != NULL) fclose(file);
|
||||
file = fopen(filename, mode==0?"r":"w");
|
||||
}
|
||||
|
||||
void fopenres(const char *filename) {
|
||||
if (file != NULL) fclose(file);
|
||||
int size;
|
||||
file = file_getfilepointer(filename, size);
|
||||
}
|
||||
|
||||
void fclose() {
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
bool feof() {
|
||||
return feof(file);
|
||||
}
|
||||
|
||||
void fwritei(int value) {
|
||||
sprintf(fstr, "%i ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwrited(float value) {
|
||||
sprintf(fstr, "%f ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
void fwrites(const char *value) {
|
||||
sprintf(fstr, "\"%s\" ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwritew(const char *value) {
|
||||
sprintf(fstr, "%s ", value);
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwriteb(bool value) {
|
||||
sprintf(fstr, value?"true ":"false ");
|
||||
fwrite(fstr, strlen(fstr), 1, file);
|
||||
}
|
||||
|
||||
void fwriteln() {
|
||||
fwrite("\n", 1, 1, file);
|
||||
}
|
||||
|
||||
int freadi() {
|
||||
int value;
|
||||
fscanf(file, "%i", &value);
|
||||
return value;
|
||||
}
|
||||
|
||||
float freadd() {
|
||||
float value;
|
||||
fscanf(file, "%f", &value);
|
||||
return value;
|
||||
}
|
||||
const char *freads() {
|
||||
fscanf(file, " \"%[^\"]\"", &fstr[0]);
|
||||
//fscanf(file, "\"%[^\"]\"", &fstr);
|
||||
return fstr;
|
||||
}
|
||||
|
||||
const char *freadw() {
|
||||
fscanf(file, "%s", &fstr[0]);
|
||||
return fstr;
|
||||
}
|
||||
|
||||
bool freadb() {
|
||||
fscanf(file, "%s", &fstr[0]);
|
||||
return strcmp(fstr, "true")==0?true:false;
|
||||
}
|
||||
|
||||
void playmusic(const char *filename, const int loop) {
|
||||
int size;
|
||||
char *buffer = file_getfilebuffer(filename, size);
|
||||
|
||||
Reference in New Issue
Block a user