graphic_context_state.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Flexlay - A Generic 2D Game Editor
  2. // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #ifndef HEADER_FLEXLAY_GRAPHIC_CONTEXT_STATE_HPP
  17. #define HEADER_FLEXLAY_GRAPHIC_CONTEXT_STATE_HPP
  18. #include <ClanLib/Core/Math/rect.h>
  19. #include <memory>
  20. class CL_GraphicContext;
  21. class GraphicContextStateImpl;
  22. /** Helper class for capturing the state of a GraphicContext, with
  23. additional convenience functions to make handling GraphicContexts
  24. easier */
  25. class GraphicContextState
  26. {
  27. public:
  28. GraphicContextState();
  29. GraphicContextState(int w, int h);
  30. void set_size(int w, int h);
  31. void push(CL_GraphicContext* gc = 0) const;
  32. void pop (CL_GraphicContext* gc = 0) const;
  33. /** Return a rectangle in world coordinates that represents the area
  34. visible on the screen */
  35. CL_Rectf get_clip_rect() const;
  36. int get_width() const;
  37. int get_height() const;
  38. /** Set the current rotation angel */
  39. void set_rotation(float angle);
  40. /** Return the current rotation angel */
  41. float get_rotation() const;
  42. /** Move the center of the visible area to pos */
  43. void set_pos(const CL_Pointf& pos);
  44. CL_Pointf get_pos() const;
  45. /** Set zoom to z, while ensuring that the screen position \a pos
  46. (normaly the position of the mouse pointer) stays in the same
  47. position even after zoomed in/out */
  48. void set_zoom(CL_Pointf pos, float z);
  49. void set_zoom(float z);
  50. float get_zoom() const;
  51. void zoom_to (const CL_Rectf& rect);
  52. CL_Pointf screen2world(const CL_Point& pos);
  53. private:
  54. std::shared_ptr<GraphicContextStateImpl> impl;
  55. };
  56. #endif
  57. /* EOF */