MeVisLabToolboxReference
|
00001 #ifndef __SoView2DLegend_H 00002 #define __SoView2DLegend_H 00003 //---------------------------------------------------------------------------------- 00004 // **InsertLicense** code 00005 //---------------------------------------------------------------------------------- 00007 00012 //---------------------------------------------------------------------------------- 00013 00014 #ifndef __SoView2DSystem_H 00015 #include "SoView2DSystem.h" 00016 #endif 00017 #ifndef __SoView2DExtension_H 00018 #include "SoView2DExtension.h" 00019 #endif 00020 00021 #include <Inventor/fields/SoFields.h> 00022 #include <vector> 00023 00024 class SoView2D; 00025 class View2DFont; 00026 00028 enum LegendFontSize { 00029 AUTO_SIZE_LEGEND = -1, 00030 SMALL_LEGEND = 0, 00031 MEDIUM_LEGEND = 1, 00032 LARGE_LEGEND = 2 00033 }; 00034 00037 class LegendItem { 00038 public: 00040 LegendItem(){color= SbColor(1,1,1); 00041 line_width=1.0f; 00042 stipple = 0xffff; 00043 }; 00044 00046 LegendItem(const LegendItem &li){*this = li;}; 00047 00049 const LegendItem& operator=(const LegendItem& li){ 00050 color = li.color; 00051 line_width = li.line_width; 00052 stipple = li.stipple; 00053 text = li.text; 00054 00055 return *this; 00056 }; 00057 00059 SbColor color; 00061 float line_width; 00063 unsigned short stipple; 00065 SbString text; 00066 }; 00067 00070 class SOVIEW2D_API SoView2DLegend : public SoView2DExtension { 00071 00072 SO_NODE_HEADER(SoView2DLegend); 00073 00074 public: 00076 enum LegendAlignPosition { 00077 LEGEND_TOP, 00078 LEGEND_BOTTOM, 00079 LEGEND_LEFT, 00080 LEGEND_RIGHT 00081 }; 00082 00084 enum LegendFormat { 00085 TEXT_LINE, 00086 LINE_TEXT 00087 }; 00088 00097 SoSFString legendString; 00098 00100 SoSFFloat margin; 00102 SoSFBool showLegend; 00104 SoSFEnum legendFontSize; 00106 SoSFEnum legendAlignment; 00108 SoSFEnum legendFormat; 00110 SoSFBool textShadow; 00112 SoSFBool drawTheBox; 00114 SoSFColor boxColor; 00115 00116 static void initClass(); 00117 00118 // Constructor 00119 SoView2DLegend(); 00120 00121 // toggle legend display 00122 void toggleLegend(); 00123 00124 protected: 00126 virtual void draw(View2DSliceList *dsl, View2DSlice* dslice, int slice); 00127 00128 // evaluates keyboard and mouse events 00129 virtual bool evalEvent(SoView2D* view2d, View2DSliceList* slicelist, View2DEvent* ec, View2DEventPhase phase); 00130 00132 virtual bool implementsManagedInteraction() const { return true; } 00133 00136 virtual bool implementsManagedInteractionAndClassicEventHandling() const { return true; } 00137 00139 virtual void fieldChanged(SoSensor* sensor); 00140 00141 private: 00143 void parseString(const SbString &string); 00144 00146 void drawLegend(View2DSlice* slice, const float dx1, const float dy1, const float dx2, const float dy2, const int width, const int height, 00147 View2DFont *font, const int fontSize, const int pos, const bool drawBox=FALSE); 00148 00150 int getFontSize(const int fontGroup) const; 00151 00153 std::vector<LegendItem>_legendVector; 00154 00156 long _lastEventSecs; 00158 long _lastEventUSecs; 00159 00160 SoCommandAction* _toggleLegendAction; 00161 }; 00162 00163 #endif