diff --git a/source/code/BlockGameSdl.hpp b/source/code/BlockGameSdl.hpp index 17768d2..7ef6ff9 100644 --- a/source/code/BlockGameSdl.hpp +++ b/source/code/BlockGameSdl.hpp @@ -89,7 +89,7 @@ public: void PrintTextCenteredBoard(int x, int y, sago::SagoTextField& field) { field.Draw(globalData.screen, x+topx+60, y+topy+20, - sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::center); + sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::center, &globalData.logicalResize); } void SetTopXY(int tx, int ty) { @@ -376,11 +376,11 @@ public: sago::SagoSprite backback = globalData.spriteHolder->GetSprite(border.border_sprite); DrawIMG(backback, globalData.screen, this->GetTopX()+border.border_sprite_offset.first, this->GetTopY()+border.border_sprite_offset.second); - this->scoreLabel.Draw(globalData.screen, this->GetTopX()+border.score_label_offset.first,this->GetTopY()+border.score_label_offset.second); - this->timeLabel.Draw(globalData.screen, this->GetTopX()+border.time_label_offset.first,this->GetTopY()+border.time_label_offset.second); - this->chainLabel.Draw(globalData.screen, this->GetTopX()+border.chain_label_offset.first,this->GetTopY()+border.chain_label_offset.second); - this->speedLabel.Draw(globalData.screen, this->GetTopX()+border.speed_label_offset.first,this->GetTopY()+border.speed_label_offset.second); - globalData.spriteHolder->GetSprite(globalData.theme.back_board).DrawScaled(globalData.screen, SDL_GetTicks(), this->GetTopX(),this->GetTopY(), BOARD_WIDTH, BOARD_HEIGHT); + this->scoreLabel.Draw(globalData.screen, this->GetTopX()+border.score_label_offset.first,this->GetTopY()+border.score_label_offset.second, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); + this->timeLabel.Draw(globalData.screen, this->GetTopX()+border.time_label_offset.first,this->GetTopY()+border.time_label_offset.second, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); + this->chainLabel.Draw(globalData.screen, this->GetTopX()+border.chain_label_offset.first,this->GetTopY()+border.chain_label_offset.second, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); + this->speedLabel.Draw(globalData.screen, this->GetTopX()+border.speed_label_offset.first,this->GetTopY()+border.speed_label_offset.second, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); + globalData.spriteHolder->GetSprite(globalData.theme.back_board).DrawScaled(globalData.screen, SDL_GetTicks(), this->GetTopX(),this->GetTopY(), BOARD_WIDTH, BOARD_HEIGHT, &globalData.logicalResize); PaintBricks(); if (stageClear) { @@ -392,7 +392,7 @@ public: static sago::SagoTextField movesPuzzleLabel; sagoTextSetHelpFont(movesPuzzleLabel); movesPuzzleLabel.SetText(strHolder); - movesPuzzleLabel.Draw(globalData.screen, topx+5, topy+5); + movesPuzzleLabel.Draw(globalData.screen, topx+5, topy+5, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); } if (puzzleMode && stageButtonStatus == SBpuzzleMode) { @@ -412,7 +412,7 @@ public: static sago::SagoTextField lastPuzzleLabel; sagoTextSetHelpFont(lastPuzzleLabel); lastPuzzleLabel.SetText(_("Last puzzle")); - lastPuzzleLabel.Draw(globalData.screen, topx+5, topy+5); + lastPuzzleLabel.Draw(globalData.screen, topx+5, topy+5, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); } } if (stageClear && stageButtonStatus == SBstageClear) { @@ -432,12 +432,12 @@ public: static sago::SagoTextField lastStageLabel; sagoTextSetHelpFont(lastStageLabel); lastStageLabel.SetText(_("Last stage")); - lastStageLabel.Draw(globalData.screen, topx+5, topy+5); + lastStageLabel.Draw(globalData.screen, topx+5, topy+5, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); } } if (!bGameOver && stop > 20) { stopIntField.SetText(std::to_string(stop/10)); - stopIntField.Draw(globalData.screen, 240+topx, -40+topy); + stopIntField.Draw(globalData.screen, 240+topx, -40+topy, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); } #if DEBUG @@ -445,7 +445,7 @@ public: sagoTextSetBlueFont(aiStatusField); strHolder = "AI_status: " + std::to_string(AIstatus)+ ", "+ std::to_string(AIlineToClear); aiStatusField.SetText(strHolder); - aiStatusField.Draw(globalData.screen, topx+5, topy+5); + aiStatusField.Draw(globalData.screen, topx+5, topy+5, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); } #endif if (!bGameOver) { @@ -500,15 +500,15 @@ public: if (bGameOver) { if (hasWonTheGame) { - globalData.tbWinner.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center); + globalData.tbWinner.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center, &globalData.logicalResize); } else { if (bDraw) { - globalData.tbDraw.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center); + globalData.tbDraw.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center, &globalData.logicalResize); } else { if (this->infostring.empty()) { - globalData.tbGameOver.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center); + globalData.tbGameOver.Draw(globalData.screen, topx+150, topy+200, sago::SagoTextField::Alignment::center, &globalData.logicalResize); } } } @@ -517,14 +517,14 @@ public: std::string strHolder; strHolder = std::to_string(this->GetScore()+this->GetHandicap()); player_score.SetText(strHolder); - player_score.Draw(globalData.screen, this->GetTopX()+border.score_label_offset.first,this->GetTopY()+border.score_label_offset.second+22); + player_score.Draw(globalData.screen, this->GetTopX()+border.score_label_offset.first,this->GetTopY()+border.score_label_offset.second+22, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); if (this->GetAIenabled()) { player_name.SetText(_("AI")); } else { player_name.SetText(name); } - player_name.Draw(globalData.screen, this->GetTopX()+10,this->GetTopY()-34); + player_name.Draw(globalData.screen, this->GetTopX()+10,this->GetTopY()-34, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); if (this->isTimeTrial()) { int tid = (int)SDL_GetTicks()-this->GetGameStartedAt(); int minutes; @@ -568,14 +568,14 @@ public: } player_time.SetText(strHolder); } - player_time.Draw(globalData.screen, this->GetTopX()+border.time_label_offset.first,this->GetTopY()+border.time_label_offset.second+22); + player_time.Draw(globalData.screen, this->GetTopX()+border.time_label_offset.first,this->GetTopY()+border.time_label_offset.second+22, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); strHolder = std::to_string(this->GetChains()); player_chain.SetText(strHolder); - player_chain.Draw(globalData.screen, this->GetTopX()+border.chain_label_offset.first,this->GetTopY()+border.chain_label_offset.second+22); + player_chain.Draw(globalData.screen, this->GetTopX()+border.chain_label_offset.first,this->GetTopY()+border.chain_label_offset.second+22, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); //drawspeedLevel: strHolder = std::to_string(this->GetSpeedLevel()); player_speed.SetText(strHolder); - player_speed.Draw(globalData.screen, this->GetTopX()+border.speed_label_offset.first,this->GetTopY()+border.speed_label_offset.second+22); + player_speed.Draw(globalData.screen, this->GetTopX()+border.speed_label_offset.first,this->GetTopY()+border.speed_label_offset.second+22, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); if ((this->isStageClear()) &&(this->GetTopY()+700+50*(this->GetStageClearLimit()-this->GetLinesCleared())-this->GetPixels()-1<600+this->GetTopY())) { oldBubleX = this->GetTopX()+280; oldBubleY = this->GetTopY()+650+50*(this->GetStageClearLimit()-this->GetLinesCleared())-this->GetPixels()-1; @@ -593,9 +593,9 @@ public: objectiveField.SetText(_("Objective:")); sagoTextSetHelpFont(gametypeNameField); gametypeNameField.SetText(infostringName); - gametypeNameField.Draw(globalData.screen, this->GetTopX()+7,this->GetTopY()+10); - objectiveField.Draw(globalData.screen, this->GetTopX()+7, this->GetTopY()+160); - infoBox.Draw(globalData.screen, this->GetTopX()+7, this->GetTopY()+160+32); + gametypeNameField.Draw(globalData.screen, this->GetTopX()+7,this->GetTopY()+10, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); + objectiveField.Draw(globalData.screen, this->GetTopX()+7, this->GetTopY()+160, sago::SagoTextField::Alignment::left, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); + infoBox.Draw(globalData.screen, this->GetTopX()+7, this->GetTopY()+160+32, sago::SagoTextField::Alignment::left, &globalData.logicalResize); int y = this->GetTopY()+400; static sago::SagoTextBox controldBox; @@ -603,7 +603,7 @@ public: sagoTextSetHelpFont(controldBox); controldBox.SetMaxWidth(290); controldBox.SetText(controldBoxText); - controldBox.Draw(globalData.screen, this->GetTopX()+7,y); + controldBox.Draw(globalData.screen, this->GetTopX()+7,y, sago::SagoTextField::Alignment::left, &globalData.logicalResize); } } diff --git a/source/code/main.cpp b/source/code/main.cpp index 710ea40..58bb345 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp @@ -219,7 +219,7 @@ static int InitImages(sago::SagoSpriteHolder& holder) { /*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/ void DrawIMG(const sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y) { - sprite.Draw(target, SDL_GetTicks(),x,y); + sprite.Draw(target, SDL_GetTicks(),x,y, &globalData.logicalResize); } void DrawIMG_Bounded(const sago::SagoSprite& sprite, SDL_Renderer* target, int x, int y, int minx, int miny, int maxx, int maxy) { @@ -228,7 +228,7 @@ void DrawIMG_Bounded(const sago::SagoSprite& sprite, SDL_Renderer* target, int x bounds.y = miny; bounds.w = maxx-minx; bounds.h = maxy-miny; - sprite.DrawBounded(target, SDL_GetTicks(),x,y,bounds); + sprite.DrawBounded(target, SDL_GetTicks(),x,y,bounds, &globalData.logicalResize); } SDL_Window* sdlWindow; @@ -463,7 +463,7 @@ static void DrawBalls() { DrawIMG(globalData.iChainFrame, globalData.screen, x, y); getSmallInt(globalData.theTextManager.textArray[i].getText())->Draw(globalData.screen, x+12, y+7, - sago::SagoTextField::Alignment::center); + sago::SagoTextField::Alignment::center, sago::SagoTextField::VerticalAlignment::top, &globalData.logicalResize); } } } //DrawBalls @@ -680,7 +680,7 @@ void DrawEverything(int xsize, int ysize,BlockGameSdl* theGame, BlockGameSdl* th //draw exit - bExit.Draw(globalData.screen,SDL_GetTicks(), xsize-bExitOffset, ysize-bExitOffset); + bExit.Draw(globalData.screen,SDL_GetTicks(), xsize-bExitOffset, ysize-bExitOffset, &globalData.logicalResize); DrawBalls(); #if DEBUG @@ -1472,6 +1472,9 @@ int runGame(Gametype gametype, int level) { globalData.theTextManager.update(); bool mustWriteScreenshot = false; + int mousex; + int mousey; + globalData.logicalResize.PhysicalToLogical(globalData.mousex, globalData.mousey, mousex, mousey); BlockGameAction a; a.tick = SDL_GetTicks(); @@ -1480,6 +1483,9 @@ int runGame(Gametype gametype, int level) { while ( SDL_PollEvent(&event) ) { UpdateMouseCoordinates(event, globalData.mousex, globalData.mousey); + int mousex; + int mousey; + globalData.logicalResize.PhysicalToLogical(globalData.mousex, globalData.mousey, mousex, mousey); if ( event.type == SDL_QUIT ) { Config::getInstance()->setShuttingDown(5); done = 1; @@ -1656,33 +1662,34 @@ int runGame(Gametype gametype, int level) { bool pressed = false; int x = 0; int y = 0; - theGame.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y); + + theGame.GetBrickCoordinateFromMouse(pressed, mousex, mousey, x, y); if (pressed) { a.action = BlockGameAction::Action::MOUSE_DOWN; a.x = x; a.y = y; theGame.DoAction(a); } - theGame2.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y); + theGame2.GetBrickCoordinateFromMouse(pressed, mousex, mousey, x, y); if (pressed) { a.action = BlockGameAction::Action::MOUSE_DOWN; a.x = x; a.y = y; theGame2.DoAction(a); } - mouseDownX = event.button.x; - mouseDownY = event.button.y; + mouseDownX = mousex; + mouseDownY = mousey; } if (event.button.button == SDL_BUTTON_RIGHT) { bool pressed = false; int x = 0; int y = 0; - theGame.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y); + theGame.GetBrickCoordinateFromMouse(pressed, mousex, mousey, x, y); if (pressed) { a.action = BlockGameAction::Action::PUSH; theGame.DoAction(a); } - theGame2.GetBrickCoordinateFromMouse(pressed, event.button.x, event.button.y, x, y); + theGame2.GetBrickCoordinateFromMouse(pressed, mousex, mousey, x, y); if (pressed) { a.action = BlockGameAction::Action::PUSH; theGame2.DoAction(a); @@ -1691,8 +1698,8 @@ int runGame(Gametype gametype, int level) { } if (event.type == SDL_MOUSEBUTTONUP) { if (event.button.button == SDL_BUTTON_LEFT) { - int x = event.button.x; - int y = event.button.y; + int x = mousex; + int y = mousey; a.action = BlockGameAction::Action::MOUSE_UP; theGame.DoAction(a); theGame2.DoAction(a); @@ -1715,7 +1722,7 @@ int runGame(Gametype gametype, int level) { if (pressed) { int mx = 0; int my = 0; - theGame.GetBrickCoordinateFromMouse(pressed, event.motion.x, event.motion.y, mx, my); + theGame.GetBrickCoordinateFromMouse(pressed, mousex, mousey, mx, my); if (pressed) { if (mx != x) { a.action = BlockGameAction::Action::MOUSE_MOVE; @@ -1728,7 +1735,7 @@ int runGame(Gametype gametype, int level) { if (pressed) { int mx = 0; int my = 0; - theGame2.GetBrickCoordinateFromMouse(pressed, event.motion.x, event.motion.y, mx, my); + theGame2.GetBrickCoordinateFromMouse(pressed, mousex, mousey, mx, my); if (pressed) { if (mx != x) { a.action = BlockGameAction::Action::MOUSE_MOVE; @@ -1758,24 +1765,24 @@ int runGame(Gametype gametype, int level) { bMouseUp = false; DrawBackground(globalData.screen); - if (stageButtonStatus != SBdontShow && (globalData.mousex > theGame.GetTopX()+globalData.cordNextButton.x) - && (globalData.mousex < theGame.GetTopX()+globalData.cordNextButton.x+globalData.cordNextButton.xsize) - && (globalData.mousey > theGame.GetTopY()+globalData.cordNextButton.y) - && (globalData.mousey < theGame.GetTopY()+globalData.cordNextButton.y+globalData.cordNextButton.ysize)) { + if (stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+globalData.cordNextButton.x) + && (mousex < theGame.GetTopX()+globalData.cordNextButton.x+globalData.cordNextButton.xsize) + && (mousey > theGame.GetTopY()+globalData.cordNextButton.y) + && (mousey < theGame.GetTopY()+globalData.cordNextButton.y+globalData.cordNextButton.ysize)) { //Clicked the next button after a stage clear or puzzle nextLevel(theGame, SDL_GetTicks()); } - if (stageButtonStatus != SBdontShow && (globalData.mousex > theGame.GetTopX()+globalData.cordRetryButton .x) - &&(globalData.mousex < theGame.GetTopX()+globalData.cordRetryButton.x+globalData.cordRetryButton.xsize) - &&(globalData.mousey > theGame.GetTopY()+globalData.cordRetryButton.y) - &&(globalData.mousey < theGame.GetTopY()+globalData.cordRetryButton.y+globalData.cordRetryButton.ysize)) { + if (stageButtonStatus != SBdontShow && (mousex > theGame.GetTopX()+globalData.cordRetryButton .x) + &&(mousex < theGame.GetTopX()+globalData.cordRetryButton.x+globalData.cordRetryButton.xsize) + &&(mousey > theGame.GetTopY()+globalData.cordRetryButton.y) + &&(mousey < theGame.GetTopY()+globalData.cordRetryButton.y+globalData.cordRetryButton.ysize)) { //Clicked the retry button retryLevel(theGame, SDL_GetTicks()); } - if (globalData.mousex > globalData.xsize-bExitOffset && globalData.mousex < globalData.xsize-bExitOffset+bExitSize && - globalData.mousey > globalData.ysize-bExitOffset && globalData.mousey < globalData.ysize-bExitOffset+bExitSize) { + if (mousex > globalData.xsize-bExitOffset && mousex < globalData.xsize-bExitOffset+bExitSize && + mousey > globalData.ysize-bExitOffset && mousey < globalData.ysize-bExitOffset+bExitSize) { done = 1; } }