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.

82 lines
2.1 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. void drawRect(const int2* points,const Rgba* colors)
  27. {
  28. int left = tmax<int>(points[0].x,0);
  29. int top = tmax<int>(points[0].y,0);
  30. int right = tmin<int>(points[2].x,_width);
  31. int bottom = tmin<int>(points[2].y,_height);
  32. float w = right - left;
  33. float h = bottom - top;
  34. for (int x = left ; x < right ; ++ x)
  35. {
  36. Rgba color1 = colorLerp(colors[0],colors[1],(x - left)/w);
  37. Rgba color2 = colorLerp(colors[3],colors[2],(x - left)/w);
  38. for (int y = top ; y < bottom ; ++ y)
  39. {
  40. Rgba color = colorLerp(color1,color2,(y - top)/h);
  41. setPixelEx(x,y,color);
  42. }
  43. }
  44. }
  45. public:
  46. void drawLine(float2 pt1,float2 pt2,Rgba color1,Rgba color2);
  47. void drawPoints(float2 pt1,Rgba4Byte color)
  48. {
  49. }
  50. inline void setPixelEx(unsigned x,unsigned y,Rgba color)
  51. {
  52. _buffer[y * _width + x] = color;
  53. }
  54. inline void setPixel(unsigned x,unsigned y,Rgba color)
  55. {
  56. if (x >= _width || y >= _height)
  57. {
  58. return;
  59. }
  60. _buffer[y * _width + x] = color;
  61. }
  62. };
  63. }