QrScannerState.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef FREESHOP_QRSCANNERSTATE_HPP
  2. #define FREESHOP_QRSCANNERSTATE_HPP
  3. extern "C" {
  4. #include <quirc.h>
  5. }
  6. #ifdef _3DS
  7. #include <3ds.h>
  8. #include <cpp3ds/System/LinearAllocator.hpp>
  9. #endif
  10. #include <cpp3ds/System/Thread.hpp>
  11. #include <cpp3ds/System/Mutex.hpp>
  12. #include <cpp3ds/Window/Window.hpp>
  13. #include <cpp3ds/Graphics/RectangleShape.hpp>
  14. #include <cpp3ds/Graphics/Texture.hpp>
  15. #include <TweenEngine/TweenManager.h>
  16. #include "State.hpp"
  17. #include "../TweenObjects.hpp"
  18. #include "../GUI/NinePatch.hpp"
  19. namespace FreeShop {
  20. class QrScannerState: public State {
  21. public:
  22. QrScannerState(StateStack& stack, Context& context, StateCallback callback);
  23. ~QrScannerState();
  24. virtual void renderTopScreen(cpp3ds::Window& window);
  25. virtual void renderBottomScreen(cpp3ds::Window& window);
  26. virtual bool update(float delta);
  27. virtual bool processEvent(const cpp3ds::Event& event);
  28. private:
  29. void scanQrCode();
  30. void startCamera();
  31. void close();
  32. private:
  33. cpp3ds::Thread m_camThread;
  34. cpp3ds::Mutex m_camMutex;
  35. std::vector<cpp3ds::Uint8> m_camBuffer;
  36. #ifdef _3DS
  37. std::vector<cpp3ds::Uint8, cpp3ds::LinearAllocator<cpp3ds::Uint8>> m_textureBuffer;
  38. std::vector<cpp3ds::Uint8, cpp3ds::LinearAllocator<cpp3ds::Uint8>> m_rawTextureBuffer;
  39. #endif
  40. bool m_capturing;
  41. bool m_threadRunning;
  42. bool m_requestedClose;
  43. cpp3ds::Mutex m_mutexRequest;
  44. cpp3ds::Mutex m_mutexDraw;
  45. bool m_displayError;
  46. bool m_hideQrBorder;
  47. cpp3ds::Text m_textError;
  48. cpp3ds::Text m_textCloseError;
  49. util3ds::TweenRectangleShape m_cameraScreen;
  50. cpp3ds::Texture m_cameraTexture;
  51. util3ds::TweenNinePatch m_qrBorder;
  52. cpp3ds::Text m_closeCaption;
  53. cpp3ds::RectangleShape m_bottomBackground;
  54. TweenEngine::TweenManager m_tweenManager;
  55. struct quirc *m_qr;
  56. };
  57. } // namespace FreeShop
  58. #endif //FREESHOP_QRSCANNERSTATE_HPP