00001
00002
00003 #ifndef Impala_Application_TagsLife_TagsWeekBarPlot_h
00004 #define Impala_Application_TagsLife_TagsWeekBarPlot_h
00005
00006 #ifndef OglGui_WindowView2D_h
00007 #include "OglGui/WindowView2D.h"
00008 #endif
00009
00010 #include "BarPlot.h"
00011
00012 namespace Impala {
00013 namespace Application {
00014 namespace TagsLife {
00015
00016 class TagsWeekBarPlot : public BarPlot
00017 {
00018 public:
00019 TagsWeekBarPlot(Window* parent, int x, int y, int w, int h) :
00020 BarPlot(parent, x, y, w, h)
00021 {
00022 Init(w,h);
00023 }
00024
00025 virtual void DisplayFunc()
00026 {
00027 OGC oldOGC;
00028 OGCSave(&oldOGC);
00029 BarPlot::DisplayFunc();
00030 mDetailSensorWnd->SetDimensions(W(), mSlotSize);
00031 if (NrVisible() != 0)
00032 {
00033 SetSolidLineColor(mBarBorderColor);
00034 HandleDetailView();
00035 }
00036 OGCRestore(&oldOGC);
00037 }
00038
00039
00040 virtual void
00041 WindowMouseEvent(OglGui::Window *src, int msg, int but, int state,
00042 int x, int y, void *userData )
00043 {
00044 BarPlot::WindowMouseEvent(src, msg, but, state, x, y, userData);
00045 if (userData == (void*) WEEKWND_IDX)
00046 WeekWndMouseEvent(src, msg, x, y);
00047 if (userData == (void*) DETAILWND_IDX)
00048 DetailWndMouseEvent(src, msg, x, y);
00049 }
00050
00051 protected:
00052
00053
00054 void DetailWndMouseEvent(Window* wnd, int msg, int x, int y)
00055 {
00056 if (msg == oglMouseMove && mRefIdx != (mFirstVisible + x / mSlotSize))
00057 msg = oglMouseEnter;
00058 if (msg == oglMouseEnter)
00059 {
00060 mDetailView->SetVisible(false);
00061 mRefIdx = mFirstVisible + x / mSlotSize;
00062 if(!mSlotSize || !mCache) return;
00063 OGLVIEW *v = mCache->GetViewFromCache(mSource->GetID(mRefIdx));
00064 if(v == 0 || v->im == 0) return;
00065
00066 topX = AXIS_X+(mRefIdx-mFirstVisible+0.5)*mSlotSize-50;
00067 topY = -100;
00068
00069 ILOG_DEBUG("Showing image of " << v->im->w << "x" << v->im->h << " at " << topX << "," << topY);
00070
00071 ToTopWindow(this,topX,topY);
00072 mDetailView->SetDimensions(topX,topY,100,100);
00073 mDetailView->SetImage(v->im);
00074 mDetailView->SetVisible(true);
00075 }
00076 if (msg == oglMouseLeave)
00077 mDetailView->SetVisible(false);
00078 }
00079
00080
00081 void WeekWndMouseEvent(Window* wnd, int msg, int x, int y)
00082 {
00083 int nrVis = NrVisible();
00084
00085 if (nrVis!=0 && (msg == oglMouseEnter || msg == oglMouseMove))
00086 {
00087 int topX = AXIS_X + x + 10;
00088 int topY = -30;
00089
00090 ToTopWindow(this,topX,topY);
00091 mWeekText->SetDimensions(topX,topY,180,20);
00092 mWeekText->SetVisible(true);
00093
00094 int idx = mFirstVisible + x / mSlotSize;
00095 int week = mSource->GetSortedIntData(mColumnX, idx);
00096 mWeekText->SetText(Tag::flickrWeekToString(week));
00097 }
00098 if (msg == oglMouseLeave)
00099 mWeekText->SetVisible(false);
00100 }
00101
00102
00103 void HandleDetailView()
00104 {
00105 if (!mDetailView->GetVisible())
00106 return;
00107
00108 DrawLine(AXIS_X+(mRefIdx-mFirstVisible)*mSlotSize,AXIS_Y,topX,0);
00109 DrawLine(AXIS_X+(mRefIdx-mFirstVisible+1)*mSlotSize,AXIS_Y,topX+100,0);
00110 }
00111
00112 private:
00113 void Init(int w, int h)
00114 {
00115 Window* topWnd = this;
00116 while(topWnd->GetParent())
00117 topWnd = topWnd->GetParent();
00118 mDetailView = new WindowView2D(topWnd,0,0,10,10,0);
00119 mDetailView->Texturing(false);
00120
00121 mDetailView->SetVisible(false);
00122
00123 mWeekSensorWnd = new Window(this,AXIS_X,0,w,AXIS_Y);
00124 mWeekSensorWnd->ConnectTo(this,OglGui::TOLEFTRIGHT);
00125 mWeekSensorWnd->SetWindowListener(this, WEEKWND_IDX);
00126
00127 mWeekSensorWnd->GetOGLWND()->allMouseMotion = 1;
00128
00129 mDetailSensorWnd = new Window(this,AXIS_X,AXIS_Y,w,0);
00130 mDetailSensorWnd->ConnectTo(this,OglGui::TOLEFTRIGHT);
00131 mDetailSensorWnd->SetWindowListener(this, DETAILWND_IDX);
00132
00133 mDetailSensorWnd->GetOGLWND()->allMouseMotion = 1;
00134
00135 mWeekText = new StaticText(topWnd,0,0,100,20,"");
00136 mWeekText->SetRoundness(20,20,20,20);
00137 mWeekText->SetBorderType(BEV_LINE);
00138 mWeekText->SetBorderFillShaded(2);
00139 mWeekText->SetVisible(false);
00140 }
00141
00142 WindowView2D* mDetailView;
00143 int mRefIdx, topX, topY;
00144
00145 Window* mWeekSensorWnd;
00146 Window* mDetailSensorWnd;
00147 StaticText* mWeekText;
00148
00149 const static int WEEKWND_IDX = 1;
00150 const static int DETAILWND_IDX = 2;
00151
00152 ILOG_VAR_DEC;
00153 };
00154
00155 ILOG_VAR_INIT(TagsWeekBarPlot, Application.TagsLife);
00156
00157 }
00158 }
00159 }
00160
00161 #endif