Skip to content

Conversation

@LumpBloom7
Copy link
Contributor

@LumpBloom7 LumpBloom7 commented Feb 24, 2019

This PR adds the ability to handle user input
InputManager is an object which takes all keyboard and mouse input and makes it easy to use.
InputDefinitions is an enum list of all usable keys(keyboard and mouse has one each) named in a simple format.

@LumpBloom7 LumpBloom7 changed the title Add facilities to render text Add facilities to handle input Feb 24, 2019
@BloomCreativeWorks BloomCreativeWorks deleted a comment Feb 24, 2019
@BloomCreativeWorks BloomCreativeWorks deleted a comment Feb 24, 2019
@BloomCreativeWorks BloomCreativeWorks deleted a comment Feb 24, 2019
@BloomCreativeWorks BloomCreativeWorks deleted a comment from kasmacioma Feb 24, 2019
This time fixing merge problems on GitHub and any build jobs.
Copy link
Collaborator

@kasmacioma kasmacioma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small review

@LumpBloom7
Copy link
Contributor Author

Thanks for the helpful review, will work on fixing all of it.

Anatoly Pitikin added 3 commits March 2, 2019 00:54
- Use enum class instead of enum
- Add const and noexcept qualifiers
- Make isPrintable private
- Rename m_will_quit and m_isLocked to m_quitState and m_lockState
- Simplify clearing m_printable in update()
@kasmacioma
Copy link
Collaborator

Hm, InputManager became big. I suggest to create some auxiliary classes (like input::Keyboard and input::Mouse) and use them in InputManager (with event type flag).

This is absolutely NOT complete. Still a lot of work to be done, but this should act as a starting point.
@LumpBloom7
Copy link
Contributor Author

LumpBloom7 commented Mar 2, 2019

Hm, InputManager became big. I suggest to create some auxiliary classes (like input::Keyboard and input::Mouse) and use them in InputManager (with event type flag).

Something like this?
https://github.com/LumpBloom7/BloomFramework/tree/test/input

If this is a good direction, I'll continue to work on this. Else I'll try another method.

EDIT: Several improvements were made in the next two commits.
EDIT2: I think I've misread your idea a bit. I thought you meant nested classes of some sort. (Although this may still work fine)

LumpBloom7 and others added 2 commits March 2, 2019 23:10
- Move all input staff to `bloom::input` namespace
- Move Keyboard and Mouse classes to separate file
- Rename Keyboard to KeyboardEvent and Mouse to MouseEvent
- Add set and clear methods for event classes (private methods)
- Add enum for event types
- Add reset() for InputManager to reset all events (private method)
- Mark isUp and isDown as deprecated (check comments for them)
@kasmacioma
Copy link
Collaborator

kasmacioma commented Mar 4, 2019

Anatoly Pitikin and others added 5 commits March 8, 2019 03:10
- Add ctors for KeyboardEvent and MouseEvent
- Rename clear to reset in KeyboardEvent and MouseEvent
- Add messages for deprecated funcs
- Store printable character as char
- Use pairs for pos, movement and scroll in MouseEvent
- Make enter and backspace printable
- Rework the logic of events handing
- Add flag for prevention the handling of [unhandled] events if quit event was handled
- Now InputManager::update will return current quit state w/o resetting it (to reset use resetQuit)
- Turn off InputManager::getType
- Adjust KeyboardKey::KEYBOARD_SIZE
- Add MOUSE_X1 and MOUSE_X2 to MouseButton
- Simplify `set` in MouseEvent and KeyboardEvent
- Add NoEvent to EventType
- Use std::bitset instead of std::array in KeyboardEvent
- Record all printable chars (and make m_printable as std::string)
- Add `getPos`, `getOffset` and `getScroll` to MouseEvent
- Add `wait` to InputManager to wait event (SDL_WaitEvent and SDL_WaitEventTimeout)
- Now `InputManager::update ` will return true if at least one event was handled, otherwise false will be returned
- Add internal SDL_Event to prevent creating new one each time `update` or `wait` is called
- Update getting mod keys (capslock, numlock) state
- Add `KeyboardEvent::capsLock` to check caps lock's state
- Move main handler from InputManager::update to InputManager::handle
- Rename isUp and isDown to wasDown and wasUp
- Add control of state change
- Now wasDown and wasUp will check if state was changed
- Add stateChanged func

You may check how wasUp and wasDown work by pressing 0, caps lock and LMB in the Test Bench
@LumpBloom7 LumpBloom7 marked this pull request as ready for review August 16, 2019 09:42
@LumpBloom7
Copy link
Contributor Author

I want to get this merged in as soon as possible. It has been on hold for way too long.

Do you think this is ready?

@LumpBloom7 LumpBloom7 requested a review from kasmacioma August 16, 2019 09:44
@LumpBloom7 LumpBloom7 changed the title Add facilities to handle input Initial implementation of InputManager Aug 16, 2019
LumpBloom7 and others added 2 commits August 16, 2019 20:20
* Remove old code

* [InputEvents] Use constexpr functions instead of macros

* Update and simplify keys and buttons naming

Use PascalCase (CamelCase) instead of UpperCase.

For keys naming was used https://docs.rs/sdl2/0.32.2/sdl2/keyboard/enum.Scancode.html

* Add KeyboardEvent::getPrintableRef

* Small simplifications

* Implement SymRecorder for KeyboardEvent

And store only last event char ('\0' if event is not printable)
SymRecorder [disabled by default] records all chars from events on demand (after it was activated) to printable user-friendly (means no more '\b' chars and all 'Enter' will be converted to "\r\n") string. 'Backspace' deletes last char.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants