LineDrawer.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. FinalSun/FinalAlert 2 Mission Editor
  3. Copyright (C) 1999-2024 Electronic Arts, Inc.
  4. Authored by Matthias Wagner
  5. This program is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #pragma once
  17. #include <cinttypes>
  18. enum class LineStyle: int
  19. {
  20. Standard,
  21. Dotted_2,
  22. Dotted_3,
  23. Dotted_4,
  24. };
  25. class LineDrawer
  26. {
  27. public:
  28. LineDrawer(void* dest, int bytes_per_pixel, int width, int height, int pitch);
  29. void MoveTo(int to_x, int to_y);
  30. void LineTo(int to_x, int to_y, int color, LineStyle style = LineStyle::Standard);
  31. void DrawLine(int from_x, int from_y, int to_x, int to_y, int color, LineStyle style = LineStyle::Standard);
  32. void Rectangle(int from_x, int from_y, int to_x, int to_y, int color, LineStyle style = LineStyle::Standard);
  33. private:
  34. void SetPixel(char* dest, int cur_x, int cur_y, int color);
  35. void DrawLineImplX(int from_x, int from_y, int to_x, int to_y, int color, LineStyle style);
  36. void DrawLineImplY(int from_x, int from_y, int to_x, int to_y, int color, LineStyle style);
  37. private:
  38. void* m_dest;
  39. int m_bytes_per_pixel;
  40. int m_width;
  41. int m_height;
  42. int m_pitch;
  43. int m_last_x;
  44. int m_last_y;
  45. };