You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.7 KiB

5 years ago
  1. #pragma once
  2. #include "CELLMath.hpp"
  3. namespace CELL
  4. {
  5. enum DRAWMODE
  6. {
  7. DM_POINTS = 0,
  8. DM_LINES = 1,
  9. DM_LINE_LOOP = 2,
  10. DM_LINE_STRIP = 3,
  11. };
  12. class Raster
  13. {
  14. public:
  15. Rgba* _buffer;
  16. int _width;
  17. int _height;
  18. Rgba _color;
  19. public:
  20. Raster(int w,int h,void* buffer);
  21. ~Raster(void);
  22. void clear();
  23. void drawPoint(int x,int y, Rgba color,int ptSize);
  24. void drawArrays(DRAWMODE mode,const float2* points,int count);
  25. void drawFilleRect(int startX,int startY,int w,int h)
  26. {
  27. int left = tmax<int>(startX,0);
  28. int top = tmax<int>(startY,0);
  29. int right = tmin<int>(startX + w,_width);
  30. int bottom = tmin<int>(startY + h,_height);
  31. for (int x = left ; x < right ; ++ x)
  32. {
  33. for (int y = top ; y < bottom ; ++ y)
  34. {
  35. setPixelEx(x,y,_color);
  36. }
  37. }
  38. }
  39. public:
  40. void drawLine(float2 pt1,float2 pt2,Rgba color1,Rgba color2);
  41. void drawPoints(float2 pt1,Rgba4Byte color)
  42. {
  43. }
  44. inline void setPixelEx(unsigned x,unsigned y,Rgba color)
  45. {
  46. _buffer[y * _width + x] = color;
  47. }
  48. inline void setPixel(unsigned x,unsigned y,Rgba color)
  49. {
  50. if (x >= _width || y >= _height)
  51. {
  52. return;
  53. }
  54. _buffer[y * _width + x] = color;
  55. }
  56. };
  57. }