1
0

gradient.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #ifndef _GRADIENT_H
  2. #define _GRADIENT_H
  3. #include <bfc/wasabi_std.h>
  4. #include <bfc/string/StringW.h>
  5. #include <tataki/color/filteredcolor.h>
  6. class GradientPoint
  7. {
  8. public:
  9. GradientPoint(float p, ARGB32 c, const wchar_t *group=L"") : pos(p), dist(0), color(c, group), x(0), y(0) { }
  10. float pos;
  11. double dist;
  12. FilteredColor color;
  13. float x, y;
  14. static int compareItem(GradientPoint *p1, GradientPoint* p2) {
  15. int r = CMP3(p1->pos, p2->pos);
  16. if (r == 0) return CMP3(p1, p2);
  17. else return r;
  18. }
  19. };
  20. class Gradient
  21. {
  22. public:
  23. Gradient();
  24. virtual ~Gradient();
  25. void setX1(float x1);
  26. void setY1(float y1);
  27. void setX2(float x2);
  28. void setY2(float y2);
  29. void clearPoints();
  30. void addPoint(float pos, ARGB32 color);
  31. // "pos=color;pos=color" "0.25=34,45,111"
  32. void setPoints(const wchar_t *str);
  33. void setReverseColors(int c);
  34. void setAntialias(int c);
  35. void setMode(const wchar_t *mode);
  36. void setGammaGroup(const wchar_t *group);
  37. // note: this will automatically premultiply against alpha
  38. void renderGradient(ARGB32 *bits, int width, int height, int pitch=0);
  39. protected:
  40. virtual void onParamChange() { }
  41. ARGB32 getPixelCirc(double x, double y);
  42. private:
  43. float gradient_x1, gradient_y1, gradient_x2, gradient_y2;
  44. class GradientList : public PtrListQuickSorted<GradientPoint, GradientPoint> { };
  45. GradientList list;
  46. void renderGrad(ARGB32 *bits, int len, int *positions);
  47. int reverse_colors;
  48. int antialias;
  49. StringW mode, gammagroup;
  50. };
  51. #endif