00001 #include "vuBasicSubViewer.h"
00002
00003 #include <iostream>
00004 #include <wx/event.h>
00005 #include "../vuUtilityWindow.h"
00006 #include "../wxUtilities/vuBasicUtility.h"
00007
00008 #define SCREEN_WIDTH 1400
00009 #define SCREEN_HEIGHT 1050
00010
00011
00012
00013
00014
00015 BEGIN_EVENT_TABLE(vuBasicSubViewerCanvas, vuGLCanvas)
00016 EVT_MOUSE_EVENTS(vuBasicSubViewerCanvas::OnMouse)
00017 EVT_CHAR(vuBasicSubViewerCanvas::OnChar)
00018 END_EVENT_TABLE();
00019
00020
00021
00022
00023
00024
00025 vuBasicSubViewer::vuBasicSubViewer(wxWindow *parent, vuString title)
00026 : wxDialog(parent,-1, title.c_str(),wxDefaultPosition, wxDefaultSize,
00027 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
00028 {
00029 m_ControlPosition = 0;
00030 m_IsMakeCanvasSizeEqual = true;
00031 m_MainSizer = NULL;
00032 m_ControlWindow = NULL;
00033 }
00034
00035 void vuBasicSubViewer::init(bool showControl)
00036 {
00037 m_MainSizer = new wxBoxSizer(wxHORIZONTAL);
00038 m_ControlWindow = new wxWindow(this, -1);
00039
00040 wxBoxSizer *horSpacer = new wxBoxSizer(wxHORIZONTAL);
00041 wxBoxSizer *verSpacer = new wxBoxSizer(wxVERTICAL);
00042
00043 verSpacer->Add(0,10);
00044
00045 addLeftRight(verSpacer, m_ControlWindow);
00046
00047 horSpacer->Add(10,0);
00048 horSpacer->Add(verSpacer);
00049 horSpacer->Add(10,0);
00050 horSpacer->Layout();
00051
00052
00053 m_ControlWindow->SetSizer(horSpacer);
00054 horSpacer->Fit(m_ControlWindow);
00055
00056 if (getCanvas()) m_MainSizer->Add(getCanvas(),1,wxEXPAND);
00057
00058 if (showControl) {
00059 m_MainSizer->Add(m_ControlWindow);
00060 m_ControlPosition = 1;
00061 }
00062 else {
00063 m_ControlWindow->Show(false);
00064 m_ControlPosition = 0;
00065 }
00066
00067
00068 SetSizer(m_MainSizer);
00069 SetAutoLayout(true);
00070 m_MainSizer->Layout();
00071 m_MainSizer->Fit(this);
00072 }
00073
00074 vuBasicSubViewer::~vuBasicSubViewer()
00075 {
00076 m_MainSizer = NULL;
00077 m_ControlWindow = NULL;
00078 }
00079
00080 void vuBasicSubViewer::redraw()
00081 {
00082 if (getCanvas()) getCanvas()->redraw();
00083 }
00084
00085
00086
00087
00088
00089 void vuBasicSubViewer::glOnMouse(wxMouseEvent &event)
00090 {
00091 if (getCanvas() == NULL) return;
00092
00093 if (event.LeftDClick()) {
00094 showHideControl();
00095 getCanvas()->redraw();
00096 }
00097 else if (event.RightDClick()) {
00098 makeCanvasSizeEqual();
00099 getCanvas()->redraw();
00100 }
00101 }
00102
00103 bool vuBasicSubViewer::isControlVisible()
00104 {
00105 return (m_ControlPosition != 0);
00106 }
00107
00108
00109
00110
00111
00112
00113 void vuBasicSubViewer::showControl(bool doShow)
00114 {
00115 if (!IsShown()) return;
00116 if (getCanvas() == NULL) return;
00117
00118 dword width = getCanvas()->getWidth();
00119 dword height = getCanvas()->getHeight();
00120 dword ctrWidth = m_ControlWindow->GetSize().GetWidth();
00121 int xPos = GetPosition().x + 1;
00122 int yPos = GetPosition().y + 1;
00123
00124 int oldPos = m_ControlPosition;
00125
00126 if (doShow == isControlVisible()) return;
00127
00128 if (m_ControlPosition == 0)
00129 m_ControlPosition = ((xPos + width + ctrWidth) > SCREEN_WIDTH) ? -1 : 1;
00130 else
00131 m_ControlPosition = 0;
00132
00133 bool isVisible = (m_ControlPosition != 0);
00134
00135
00136 if (m_ControlPosition == -1) xPos -= ctrWidth;
00137 if (oldPos == -1) xPos += ctrWidth;
00138 if (isVisible) width += ctrWidth;
00139
00140 SetSize(xPos,yPos, width,height);
00141
00142
00143 m_ControlWindow->Show(isVisible);
00144
00145 if (isVisible) {
00146 if (m_ControlPosition == 1)
00147 m_MainSizer->Add(m_ControlWindow);
00148 else
00149 m_MainSizer->Prepend(m_ControlWindow);
00150 }
00151 else {
00152 if (oldPos == 1)
00153 m_MainSizer->Remove(1);
00154 else
00155 m_MainSizer->Remove(0);
00156 }
00157 }
00158
00159
00160 void vuBasicSubViewer::showHideControl()
00161 {
00162 bool doShow = (m_ControlPosition == 0);
00163
00164 showControl(doShow);
00165 }
00166
00167 void vuBasicSubViewer::makeCanvasSizeEqual()
00168 {
00169 vuBasicUtility *parent = (vuBasicUtility *)GetParent();
00170 vuBasicGLCanvas *canvas = NULL;
00171 dword width = 200;
00172 dword height = 200;
00173 dword ctrWidth = 0;
00174 int xPos = GetPosition().x;
00175 int yPos = GetPosition().y;
00176
00177 if (parent != NULL) canvas = (vuBasicGLCanvas *)parent->getCanvas();
00178
00179 if (canvas != NULL && m_IsMakeCanvasSizeEqual) {
00180 width = canvas->getWidth();
00181 height = canvas->getHeight();
00182 m_IsMakeCanvasSizeEqual = false;
00183 }
00184 else
00185 m_IsMakeCanvasSizeEqual = true;
00186
00187 if (m_ControlPosition != 0)
00188 ctrWidth = m_ControlWindow->GetSize().GetWidth();
00189
00190 if ((xPos + width + ctrWidth) > SCREEN_WIDTH)
00191 xPos = SCREEN_WIDTH - width - ctrWidth;
00192
00193 if ((yPos + height) > SCREEN_HEIGHT)
00194 yPos = SCREEN_HEIGHT - height - 30;
00195
00196 SetSize(xPos,yPos, width+ctrWidth, height);
00197 }
00198
00199
00200
00201
00202
00203
00204
00205
00206 vuBasicSubViewerCanvas::vuBasicSubViewerCanvas(vuBasicSubViewer *parent,
00207 wxWindowID id) :
00208 vuGLCanvas(parent, id)
00209 {
00210 }
00211
00212 vuBasicSubViewerCanvas::~vuBasicSubViewerCanvas()
00213 {
00214 }
00215
00216
00217 void vuBasicSubViewerCanvas::OnMouse(wxMouseEvent &event)
00218 {
00219 ((vuBasicSubViewer *)GetParent())->glOnMouse(event);
00220 }