Added tile_scale command that calls consoleScaleTiles(const char *string). This then converts the passed arguments of 'float x float y' (e.g., 'tile_scale 1.0 1.0' to scale to 1.0 times) to scaleTiles(float scale_x, float scale_y). If no argument is passed in the string, the default 2.0 scale is used. If the y property is not passed, the value of scale_x is used for scale_y.

master
kts 2013-11-17 17:05:55 -08:00
parent 4e6f983db8
commit bd67818190
2 changed files with 44 additions and 0 deletions

View File

@ -237,6 +237,7 @@ int interfaceInit() {
consoleAddCommand("quit", interfaceQuit);
consoleAddCommand("tickrate", interfaceSetInterval);
consoleAddCommand("set_video", interfaceVideoSetSize);
consoleAddCommand("tile_scale", consoleScaleTiles);
camera_surface = SDL_CreateRGBSurface(screen->flags, screen->w, screen->h, screen->format->BitsPerPixel, screen->format->Rmask, screen->format->Gmask, screen->format->Bmask, screen->format->Amask);
/* tile specific stuff */
@ -874,6 +875,47 @@ void interfaceVideoSetSize(const char *input_string) {
}
}
void consoleScaleTiles(const char *input_string) {
if (input_string) {
int i = 0;
int j = 0;
char height[15];
char width[15];
int position = 0;
while(input_string[i] != '\0') {
if (input_string[i] == ' ') {
width[j] = '\0';
position = 1;
i++; // skip the x
j = 0;
//} else if (input_string[i] == ' ') {
// height[j] = '\0';
// i++; // skip the space
// j = 0;
// break;
}
if (position == 0) {
width[j] = input_string[i];
} else if (position == 1) {
height[j] = input_string[i];
}
j++;
i++;
}
float scale_x = atof(width); // ... had to reverse order for it to work on win...
float scale_y = atof(height);
if (scale_x <= 0)
scale_x = 2.0; // default to 2.0 if scale_x is 0/invalid
if (scale_y <= 0)
scale_y = scale_x; // copy scale_x if scale_y unset/0/invalid
scaleTiles(scale_x, scale_y);
} else {
consoleLog("Syntax: widthxheight");
}
}
void loadFontFromMemory(struct Font *font, unsigned char *memory, unsigned int length, int width, int height) {
font->scale_x = 1.0f;
font->scale_y = 1.0f;

View File

@ -67,6 +67,8 @@ float g_tile_height;
Uint32 combinepixels(Uint32 pixel_1, Uint32 pixel_2);
/* --- tile stuff --- */
void consoleScaleTiles(const char *input_string);
void interfaceSetScale(float scale_x, float scale_y);
void loadSpritesheetFromMemory(struct Spritesheet *spritesheet, unsigned char *memory, unsigned int length, int width, int height, int columns);
void freeSpritesheet(struct Spritesheet *spritesheet);