00001 #ifndef VideoExcel_SelectionCollectionItem_h
00002 #define VideoExcel_SelectionCollectionItem_h
00003
00004 #include "OglGui/Window.h"
00005 #include "SelectionCollectionListener.h"
00006 #include "OglGui/Menu.h"
00007
00008 namespace Impala {
00009 namespace Application {
00010 namespace VideoExcel {
00011
00012 class SelectionCollectionItem : public OglGui::Window,
00013 OglGui::MenuListener
00014 {
00015 public:
00016 typedef OglGui::Window Window;
00017 typedef OglGui::StaticText StaticText;
00018 typedef OglGui::MenuTopPane MenuTopPane;
00019 typedef OglGui::Menu Menu;
00020
00021 SelectionCollectionItem(Window* parent, int id, unsigned long bgColor) :
00022 Window(parent, 80, 80)
00023 {
00024 Init(id, bgColor);
00025 }
00026
00027 void SetItemName(String text)
00028 {
00029 mItemText->SetText(text);
00030 }
00031
00032 void SetItemCounts(int total, int visible)
00033 {
00034 std::ostringstream stotal;
00035 stotal << total;
00036 mItemCount->SetText(stotal.str());
00037 std::ostringstream svisible;
00038 svisible << visible;
00039 mItemVisCount->SetText(svisible.str());
00040 }
00041
00042 virtual void MouseFunc(int msg, int but, int state, int x, int y)
00043 {
00044 if (mListener && msg == oglMouseUp && but == oglLeftButton)
00045 mListener->SelectCollectionEvent(mId);
00046
00047 if (msg == oglMouseDown && but == oglRightButton)
00048 {
00049 int rx=0, ry=0;
00050 ToTopWindow(this, rx, ry);
00051 mContextMenu->Open(rx+x,ry+y);
00052 }
00053 }
00054
00055 void SetListener(SelectionCollectionListener *target)
00056 {
00057 mListener = target;
00058 }
00059
00060 void SetHighlighted(bool highLight)
00061 {
00062 SetBorderFillShaded(highLight ? DEEP_SHADE_UP : DEEP_SHADE_DOWN);
00063 SetBorderType(highLight ? BEV_LINE : BEV_INVISIBLE);
00064 }
00065
00066 virtual void OnMenuItem(Menu *src, int menuIdx, String itemName,
00067 int itemIdx, void *userData)
00068 {
00069 ILOG_DEBUG("Selected option " << itemIdx << " menuIdx " << menuIdx <<
00070 " itemName " << itemName);
00071
00072
00073 if (!mListener)
00074 return;
00075
00076 if (itemIdx == 1)
00077 mListener->SelectCollectionEvent(mId);
00078 if (itemIdx == 2)
00079 mListener->SelectCollectionInvertedEvent(mId);
00080 if (itemIdx == 3)
00081 mListener->AddCollectionToSelectionEvent(mId);
00082 if (itemIdx == 4)
00083 mListener->RemoveCollectionFromSelectionEvent(mId);
00084 }
00085
00086 private :
00087
00088 void Init(int id, unsigned long bgColor)
00089 {
00090 mId = id;
00091 mBgcolor = bgColor;
00092 mListener = 0;
00093
00094 SetBorderBackground(bgColor);
00095 SetRoundness(16, 16, 16, 16);
00096 SetBorderFillShaded(-2);
00097 SetBorderType(-1);
00098
00099 mItemText = new StaticText(this, 0, 0, W(), 20, "");
00100 mItemCount = new StaticText(this, 0, 20, W(), 20, "");
00101 mItemVisCount = new StaticText(this, 0, 44, W(), 20, "");
00102 mItemVisCount->SetTextShadowed(true);
00103 mItemCount->SetForeground(0xff555555);
00104
00105 oglSys.SetNoMouseInput(mItemText->GetOGLWND(),1);
00106 oglSys.SetNoMouseInput(mItemCount->GetOGLWND(),1);
00107 oglSys.SetNoMouseInput(mItemVisCount->GetOGLWND(),1);
00108
00109 RepositionViewports();
00110 ScaleChildren();
00111 SetAllowChildScaling(false);
00112
00113 SetItemName("unknown");
00114 SetItemCounts(0, 0);
00115
00116 MenuTopPane* top = new MenuTopPane(this);
00117 mContextMenu = new Menu(top, 1, 180);
00118 mContextMenu->AddItem("Show only these", 1);
00119 mContextMenu->AddItem("Show everything but these", 2);
00120 if (id > 1)
00121 {
00122 mContextMenu->AddItem("Add these to view", 3);
00123 mContextMenu->AddItem("Remove these from view", 4);
00124 mContextMenu->AddItem("Empty this bucket", 5);
00125 }
00126 if (id == -1)
00127 {
00128 mContextMenu->SetOptions(2, Menu::DISABLED, true);
00129 mContextMenu->SetOptions(3, Menu::DISABLED, true);
00130 mContextMenu->SetOptions(4, Menu::DISABLED, true);
00131 mContextMenu->SetOptions(5, Menu::DISABLED, true);
00132 }
00133 else
00134 {
00135 mContextMenu->AddItem("Save selection as...", 8);
00136 mContextMenu->AddItem("Load selection", 9);
00137 }
00138 mContextMenu->SetMenuListener(this, 0);
00139 }
00140
00141 int mId;
00142 unsigned long mBgcolor;
00143
00144 StaticText* mItemText;
00145 StaticText* mItemCount;
00146 StaticText* mItemVisCount;
00147 Menu* mContextMenu;
00148
00149 SelectionCollectionListener* mListener;
00150
00151 ILOG_VAR_DEC;
00152 };
00153
00154 ILOG_VAR_INIT(SelectionCollectionItem, Application.VideoExcel);
00155
00156 }
00157 }
00158 }
00159
00160 #endif // SelectionCollectionItem_h