ColorMapTest.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This may look like C code, but it's really -*- C++ -*-
  2. #include <Wt/WContainerWidget>
  3. #include <Wt/WPaintDevice>
  4. #include <Wt/WPaintedWidget>
  5. #include <Wt/WPainter>
  6. #include <Wt/WColor>
  7. #include <Wt/WFont>
  8. #include <Wt/WRectF>
  9. #include <Wt/Chart/WStandardColorMap>
  10. #include <map>
  11. using namespace Wt;
  12. using namespace Wt::Chart;
  13. class ColorMapTest : public Wt::WPaintedWidget
  14. {
  15. public:
  16. ColorMapTest(Wt::WContainerWidget *parent = 0)
  17. : Wt::WPaintedWidget(parent)
  18. {
  19. resize(500, 300);
  20. std::vector<WStandardColorMap::Pair> colormap;
  21. colormap.push_back(WStandardColorMap::Pair(0,WColor(darkRed)));
  22. colormap.push_back(WStandardColorMap::Pair(1,WColor(red)));
  23. colormap.push_back(WStandardColorMap::Pair(2,WColor(gray)));
  24. colormap_ = new WStandardColorMap(0,3,colormap, false);
  25. colormap2_ = new WStandardColorMap(0,2,colormap, true);
  26. }
  27. ~ColorMapTest()
  28. {
  29. delete colormap_;
  30. delete colormap2_;
  31. }
  32. protected:
  33. void paintEvent(Wt::WPaintDevice *paintDevice) {
  34. WPainter painter(paintDevice);
  35. painter.translate(50,0);
  36. colormap_->paintLegend(&painter);
  37. painter.translate(150,0);
  38. colormap2_->paintLegend(&painter);
  39. painter.translate(150,0);
  40. colormap2_->discretise(5);
  41. colormap2_->paintLegend(&painter);
  42. }
  43. private:
  44. Wt::Chart::WStandardColorMap *colormap_;
  45. Wt::Chart::WStandardColorMap *colormap2_;
  46. };