git repos / blockattack-game

commit afe1bac4

Poul Sander · 2020-05-24 18:34
afe1bac4e3f0c79f2f73cedfbeff19877daf3212 patch · browse files
parent 8f94a7f57fb2cec6495bec96d1bf3aef5dc3a916

Now possible to enter name with mouse. Can't delete though...

Changed files

M source/code/DialogBox.cpp before
M source/code/ReadKeyboard.h before
diff --git a/source/code/DialogBox.cpp b/source/code/DialogBox.cpp index 3f6755b..8ef8556 100644 --- a/source/code/DialogBox.cpp +++ b/source/code/DialogBox.cpp
@@ -131,6 +131,9 @@ static bool insideRect (int x, int y, int height, int width) {
return true;
}
+// For use with the mouse/gamepad keyboard
+int keyboardRowLimit = 20;
+
void DialogBox::Draw(SDL_Renderer* target) {
DrawBackground(globalData.screen);
@@ -156,12 +159,11 @@ void DialogBox::Draw(SDL_Renderer* target) {
}
const sago::SagoSprite& marked = globalData.spriteHolder->GetSprite("i_level_check_box_marked");
for (size_t i = 0; i<gamePadCharFields.size(); ++i) {
- int limit = 20;
if (selectedChar == static_cast<int>(i)) {
- marked.Draw(target, SDL_GetTicks(), globalData.xsize/2-400+(i%limit)*40-5, globalData.ysize/2+150+(i/limit)*40-5);
+ marked.Draw(target, SDL_GetTicks(), globalData.xsize/2-400+(i%keyboardRowLimit)*40-5, globalData.ysize/2+150+(i/keyboardRowLimit)*40-5);
}
sago::SagoTextField& f = gamePadCharFields.at(i);
- f.Draw(target, globalData.xsize/2-400+(i%limit)*40, globalData.ysize/2+150+(i/limit)*40);
+ f.Draw(target, globalData.xsize/2-400+(i%keyboardRowLimit)*40, globalData.ysize/2+150+(i/keyboardRowLimit)*40);
}
}
@@ -203,6 +205,25 @@ void DialogBox::ProcessInput(const SDL_Event& event, bool& processed) {
if (insideRect(x+325, y+128, 50, 250)) {
isActive = false;
}
+ for (size_t i = 0; i<gamePadCharFields.size(); ++i) {
+ sago::SagoTextField& f = gamePadCharFields.at(i);
+ auto topx = globalData.xsize/2-400+(i%keyboardRowLimit)*40-5;
+ auto topy = globalData.ysize/2+150+(i/keyboardRowLimit)*40-5;
+ if (insideRect(topx, topy, 30, 30)) {
+ std::cout << f.GetText() << " pressed\n";
+ rk->putchar(f.GetText());
+ }
+ }
+ }
+
+ if (1 /*TODO: Changed to only when mouse moves*/) {
+ for (size_t i = 0; i<gamePadCharFields.size(); ++i) {
+ auto topx = globalData.xsize/2-400+(i%keyboardRowLimit)*40-5;
+ auto topy = globalData.ysize/2+150+(i/keyboardRowLimit)*40-5;
+ if (insideRect(topx, topy, 30, 30)) {
+ selectedChar = i;
+ }
+ }
}
}
diff --git a/source/code/ReadKeyboard.h b/source/code/ReadKeyboard.h index ac4510b..9705ea1 100644 --- a/source/code/ReadKeyboard.h +++ b/source/code/ReadKeyboard.h
@@ -37,13 +37,13 @@ private:
int maxLength = 0;
std::string::iterator position;
std::string text_string;
- void putchar(const std::string& );
void removeChar();
public:
ReadKeyboard(void);
~ReadKeyboard(void);
ReadKeyboard(const char*);
int CharsBeforeCursor(); //Where should the cursor be placed?
+ void putchar(const std::string& );
bool ReadKey(const SDL_Event&);
bool ReadKey(SDL_Keycode); //true if key accepted
const std::string& GetString(void) const;