tile_selector.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Flexlay - A Generic 2D Game Editor
  2. // Copyright (C) 2000 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_TILE_SELECTOR_HPP
  17. #define HEADER_FLEXLAY_TILE_SELECTOR_HPP
  18. #include <ClanLib/gui.h>
  19. #include "../tileset.hpp"
  20. class Tileset;
  21. class TileSelector : public CL_Component
  22. {
  23. public:
  24. typedef std::vector<int> Tiles;
  25. private:
  26. CL_SlotContainer slots;
  27. int width;
  28. int index;
  29. int offset;
  30. int old_offset;
  31. int mouse_over_tile;
  32. bool scrolling;
  33. bool region_select;
  34. CL_Point current_pos;
  35. CL_Point region_select_start;
  36. CL_Point mouse_pos;
  37. float scale;
  38. /** set of tiles that should be available in the TileSelector */
  39. Tiles tiles;
  40. Tileset tileset;
  41. protected:
  42. virtual ~TileSelector();
  43. public:
  44. /** width and height in number of tiles */
  45. TileSelector(const CL_Rect& rect, CL_Component* parent);
  46. void set_tileset(Tileset t);
  47. void set_tiles(const Tiles& t);
  48. Tiles get_tiles() const;
  49. /** Set the factor by which tiles are scaled down in the selector
  50. widged (ie. for better overview) */
  51. void set_scale(float s);
  52. void draw();
  53. /** Return the position of the mouse in x/y in tilesize */
  54. CL_Point get_mouse_tile_pos(const CL_InputEvent& event);
  55. private:
  56. CL_Rect get_selection();
  57. void mouse_move(const CL_InputEvent& event);
  58. void mouse_down(const CL_InputEvent& event);
  59. void mouse_up (const CL_InputEvent& event);
  60. };
  61. #endif
  62. /* EOF */