git repos / sago_multi_scrambler_puzzle2

commit b37af5c7

Poul Sander · 2022-04-17 20:18
b37af5c7287e6baa8be4dfc8422c6e64a8bd435e patch · browse files
parent 7077d031b3514149f7c3c5ca631848d61ccddd25

Now scales the image without stretching

Changed files

M src/PuzzleSingleImageState.cpp before
M src/PuzzleSingleImageState.hpp before
M src/sago_common.cpp before
diff --git a/src/PuzzleSingleImageState.cpp b/src/PuzzleSingleImageState.cpp index f661be1..54c2df2 100644 --- a/src/PuzzleSingleImageState.cpp +++ b/src/PuzzleSingleImageState.cpp
@@ -42,7 +42,12 @@ void PuzzleSingleImageState::ProcessInput(const SDL_Event& event, bool &processe
}
void PuzzleSingleImageState::Draw(SDL_Renderer* target) {
- SDL_RenderCopy(target, this->pictureTex, NULL, NULL);
+ SDL_Rect rect;
+ rect.x = 0;
+ rect.y = 0;
+ rect.h = resized_image_height;
+ rect.w = resized_image_width;
+ SDL_RenderCopy(target, this->pictureTex, &rect, NULL);
}
@@ -58,7 +63,11 @@ void PuzzleSingleImageState::LoadPictureFromFile(const std::string& filename, SD
std::cerr << "Failed to load " << filename << std::endl;
return;
}
+ source_image_height = bitmapSurface->h;
+ source_image_width = bitmapSurface->w;
+ resized_image_width = double(resized_image_height) * (double(source_image_width)/double(source_image_height));
this->pictureTex = SDL_CreateTextureFromSurface(renderer, bitmapSurface);
+ std::cerr << resized_image_width << ", " << resized_image_height << "\n";
SDL_FreeSurface(bitmapSurface);
}
diff --git a/src/PuzzleSingleImageState.hpp b/src/PuzzleSingleImageState.hpp index 1d6ce84..458c103 100644 --- a/src/PuzzleSingleImageState.hpp +++ b/src/PuzzleSingleImageState.hpp
@@ -42,4 +42,8 @@ private:
bool isActive = true;
SDL_Texture* pictureTex = NULL;
+ int source_image_height = 1;
+ int source_image_width = 1;
+ const int resized_image_height = 700;
+ int resized_image_width = 1;
};
\ No newline at end of file
diff --git a/src/sago_common.cpp b/src/sago_common.cpp index 4a98ac1..6efcddf 100644 --- a/src/sago_common.cpp +++ b/src/sago_common.cpp
@@ -111,6 +111,7 @@ void InitGame() {
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2");
win = SDL_CreateWindow(GAMENAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_RESIZABLE);
globalData.screen = SDL_CreateRenderer(win, -1, rendererFlags);
+ SDL_RenderSetLogicalSize(globalData.screen, globalData.xsize, globalData.ysize);
dataHolder.invalidateAll(globalData.screen);
globalData.spriteHolder.reset(new sago::SagoSpriteHolder(dataHolder));