root / branches / test / CCV_Select_Camera / addons / ofxNCore / src / MultiCams / MultiCams.cpp @ 67
View | Annotate | Download (22.7 KB)
| 1 | //! MultiCams.cpp
|
|---|---|
| 2 | /*!
|
| 3 | * |
| 4 | * |
| 5 | * Created by Yishi Guo on 05/31/2011. |
| 6 | * Copyright 2011 NUI Group. All rights reserved. |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include "MultiCams.h" |
| 11 | #include "Modules/ofxNCoreVision.h" |
| 12 | |
| 13 | //MultiCams::MultiCams( bool bDebug) {
|
| 14 | // // Add listeners
|
| 15 | // //ofAddListener( ofEvents.setup, this, &MultiCams::_setup );
|
| 16 | // //ofAddListener( ofEvents.update, this, &MultiCams::_update );
|
| 17 | // //ofAddListener( ofEvents.draw ,this, &MultiCams::_draw );
|
| 18 | // //ofAddListener( ofEvents.exit, this, &MultiCams::_exit );
|
| 19 | //
|
| 20 | // ofAddListener( ofEvents.mousePressed, this, &MultiCams::_mousePressed );
|
| 21 | // ofAddListener( ofEvents.mouseDragged, this, &MultiCams::_mouseDragged );
|
| 22 | // ofAddListener( ofEvents.mouseReleased, this, &MultiCams::_mouseReleased );
|
| 23 | //
|
| 24 | // ofAddListener( ofEvents.keyPressed, this, &MultiCams::_keyPressed );
|
| 25 | // ofAddListener( ofEvents.keyReleased, this, &MultiCams::_keyReleased );
|
| 26 | //
|
| 27 | //
|
| 28 | // bDebugMode = bDebug;
|
| 29 | // bFullMode = true; //! show all controls
|
| 30 | // _xmlFileName = "multicams.xml";
|
| 31 | //}
|
| 32 | |
| 33 | MultiCams::MultiCams() {
|
| 34 | ofAddListener( ofEvents.mousePressed, this, &MultiCams::_mousePressed ); |
| 35 | ofAddListener( ofEvents.mouseDragged, this, &MultiCams::_mouseDragged ); |
| 36 | ofAddListener( ofEvents.mouseReleased, this, &MultiCams::_mouseReleased ); |
| 37 | |
| 38 | ofAddListener( ofEvents.keyPressed, this, &MultiCams::_keyPressed ); |
| 39 | ofAddListener( ofEvents.keyReleased, this, &MultiCams::_keyReleased ); |
| 40 | |
| 41 | XAxis = 1;
|
| 42 | YAxis = 1;
|
| 43 | |
| 44 | //////////////////////////
|
| 45 | // SetDevices
|
| 46 | setDevices = NULL;
|
| 47 | bDevicesConfiguration = false;
|
| 48 | |
| 49 | //////////////////////////
|
| 50 | // Cams Utils
|
| 51 | utils = NULL;
|
| 52 | |
| 53 | bDraggingImage = false;
|
| 54 | draggingImage = new ofxGuiImage(); |
| 55 | |
| 56 | // set the value explicit
|
| 57 | devGrid = NULL;
|
| 58 | camsGrid = NULL;
|
| 59 | } |
| 60 | //--------------------------------------------------------------
|
| 61 | |
| 62 | MultiCams::~MultiCams() {
|
| 63 | |
| 64 | } |
| 65 | //--------------------------------------------------------------
|
| 66 | |
| 67 | void MultiCams::setup() {
|
| 68 | testInt = 0;
|
| 69 | testFont.loadFont( "verdana.ttf", 50, true, true ); |
| 70 | |
| 71 | controls = ofxGui::Instance( this ); |
| 72 | setupControls(); |
| 73 | |
| 74 | //! SetDevices
|
| 75 | if (setDevices == NULL ) { |
| 76 | setDevices = new SetDevices(); |
| 77 | setDevices->passInCamsUtils( utils ); |
| 78 | setDevices->setup(); |
| 79 | } |
| 80 | |
| 81 | //! init the X/Y
|
| 82 | _setXY( XAxis, YAxis ); |
| 83 | } |
| 84 | //--------------------------------------------------------------
|
| 85 | |
| 86 | void MultiCams::update( ofEventArgs &e ) {
|
| 87 | utils->update(); |
| 88 | if ( bDevicesConfiguration ) {
|
| 89 | setDevices->update(); |
| 90 | } else {
|
| 91 | devGrid->update(); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | //--------------------------------------------------------------
|
| 96 | |
| 97 | |
| 98 | void MultiCams::_mousePressed( ofMouseEventArgs &e ) {
|
| 99 | // TODO
|
| 100 | } |
| 101 | |
| 102 | //--------------------------------------------------------------
|
| 103 | |
| 104 | void MultiCams::_mouseDragged( ofMouseEventArgs &e ) {
|
| 105 | if ( bDraggingImage ) {
|
| 106 | draggingImage->setXYPos( e.x - draggingXOffset, e.y - draggingYOffset ); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | //--------------------------------------------------------------
|
| 111 | |
| 112 | void MultiCams::_mouseReleased( ofMouseEventArgs &e ) {
|
| 113 | if ( bDraggingImage ) {
|
| 114 | this->bDraggingImage = false;
|
| 115 | } |
| 116 | } |
| 117 | |
| 118 | //--------------------------------------------------------------
|
| 119 | |
| 120 | void MultiCams::_keyPressed( ofKeyEventArgs &e ) {
|
| 121 | |
| 122 | } |
| 123 | //--------------------------------------------------------------
|
| 124 | |
| 125 | void MultiCams::_keyReleased( ofKeyEventArgs &e ) {
|
| 126 | |
| 127 | } |
| 128 | //--------------------------------------------------------------
|
| 129 | |
| 130 | /*******************************************************
|
| 131 | * GUI |
| 132 | ********************************************************/ |
| 133 | void MultiCams::handleGui(int parameterId, int task, void* data, int length) { |
| 134 | if ( bDevicesConfiguration ) {
|
| 135 | setDevices->handleGui( parameterId, task, data, length ); |
| 136 | } else {
|
| 137 | _handleGui( parameterId, task, data, length ); |
| 138 | } |
| 139 | } |
| 140 | //--------------------------------------------------------------
|
| 141 | void MultiCams::_handleGui( int parameterId, int task, void* data, int length ) { |
| 142 | // DEBUG
|
| 143 | printf( "MultiCams::handGui\n" );
|
| 144 | switch( parameterId ) {
|
| 145 | //////////////////////////////////
|
| 146 | // DEVICES LIST
|
| 147 | //!
|
| 148 | case devicesListPanel_grid: |
| 149 | if ( length == sizeof(int) ) { |
| 150 | if ( task == kofxGui_Set_Grid_Dragging ) {
|
| 151 | int index = *(int*)data; |
| 152 | //! the camera index must less than camera count
|
| 153 | if ( index < utils->getCount() ) {
|
| 154 | if ( bDraggingImage == false ) { |
| 155 | bDraggingImage = true;
|
| 156 | draggingImage->init( dragging_image, "", 100, 100, |
| 157 | devGrid->getGridWidth(), devGrid->getGridHeight() ); |
| 158 | |
| 159 | draggingImage->setCamera( this->utils->getRawCam( index ) ); |
| 160 | |
| 161 | //! Set the X/Y coordinate offset
|
| 162 | draggingXOffset = devGrid->getDraggingXOffset(); |
| 163 | draggingYOffset = devGrid->getDraggingYOffset(); |
| 164 | |
| 165 | //! Tell camsGrid the dragging index
|
| 166 | camsGrid->setDraggingRawIndex( index ); |
| 167 | } |
| 168 | } else {
|
| 169 | bDraggingImage = false;
|
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | break;
|
| 174 | //! Show previous camera.
|
| 175 | case devicesListPanel_arrow_left: |
| 176 | if ( length == sizeof(bool) ) { |
| 177 | if (*(bool*)data) { |
| 178 | devGrid->previous(); |
| 179 | } |
| 180 | } |
| 181 | break;
|
| 182 | |
| 183 | //! Show next camera.
|
| 184 | case devicesListPanel_arrow_right: |
| 185 | if ( length == sizeof(bool) ) { |
| 186 | if (*(bool*)data) { |
| 187 | devGrid->next(); |
| 188 | } |
| 189 | } |
| 190 | break;
|
| 191 | |
| 192 | ////////////////////////////////////
|
| 193 | // GENERAL SETTINGS
|
| 194 | //! Start settings
|
| 195 | case generalSettingsPanel_start: |
| 196 | if ( length == sizeof(bool) ) { |
| 197 | if (*(bool*)data) { |
| 198 | removePanel( generalSettingsPanel ); |
| 199 | addPanel( step1Panel ); |
| 200 | } |
| 201 | } |
| 202 | break;
|
| 203 | //! Save settings and exit
|
| 204 | case generalSettingsPanel_save: |
| 205 | if ( length == sizeof(bool) ) { |
| 206 | if (*(bool*)data) { |
| 207 | // TODO save the settings to XML file
|
| 208 | if( _coreVision != NULL ) { |
| 209 | _coreVision->switchMultiCamsGUI( false );
|
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | break;
|
| 214 | //! Exit (Not settings saved)
|
| 215 | case generalSettingsPanel_cancel: |
| 216 | if ( length == sizeof(bool) ) { |
| 217 | if (*(bool*)data) { |
| 218 | if ( _coreVision != NULL ) { |
| 219 | _coreVision->switchMultiCamsGUI( false );
|
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | break;
|
| 224 | ////////////////////////////////////////
|
| 225 | // STEP 1
|
| 226 | //! X axis camera number
|
| 227 | case step1Panel_Xaxis: |
| 228 | if( length == sizeof(float) ) { |
| 229 | XAxis = *(float*)data;
|
| 230 | _setXY( XAxis, YAxis ); |
| 231 | printf( "XAxis: %f\n", *(float*)data ); |
| 232 | } |
| 233 | break;
|
| 234 | //! Y axis camera number
|
| 235 | case step1Panel_Yaxis: |
| 236 | if ( length == sizeof(float) ) { |
| 237 | YAxis = *(float*)data;
|
| 238 | _setXY( XAxis, YAxis ); |
| 239 | } |
| 240 | break;
|
| 241 | //! Previous
|
| 242 | case step1Panel_previous: |
| 243 | if ( length == sizeof(bool) ) { |
| 244 | if (*(bool*)data) { |
| 245 | removePanel( step1Panel ); |
| 246 | addPanel( generalSettingsPanel ); |
| 247 | } |
| 248 | } |
| 249 | break;
|
| 250 | //! Next - Go to step 2
|
| 251 | case step1Panel_next: |
| 252 | if ( length == sizeof(bool) ) { |
| 253 | if ( *(bool*)data) { |
| 254 | //! user must set the correct value
|
| 255 | if ( this->XAxis * this->YAxis <= this->utils->getCount() ) {
|
| 256 | removePanel( step1Panel ); |
| 257 | addPanel( step2Panel ); |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | break;
|
| 262 | |
| 263 | ////////////////////////////////////////
|
| 264 | // STEP 2
|
| 265 | //! Set Devices
|
| 266 | case step2Panel_setDevices: |
| 267 | if ( length == sizeof( bool ) ) { |
| 268 | if (*(bool*)data) { |
| 269 | switchSetDevicesGUI( true );
|
| 270 | } |
| 271 | } |
| 272 | break;
|
| 273 | //! Previous
|
| 274 | case step2Panel_previous: |
| 275 | if ( length == sizeof(bool) ) { |
| 276 | if (*(bool*)data) { |
| 277 | removePanel( step2Panel ); |
| 278 | addPanel( step1Panel ); |
| 279 | } |
| 280 | } |
| 281 | break;
|
| 282 | //! Next - Go to step 3
|
| 283 | case step2Panel_next: |
| 284 | if ( length == sizeof(bool) ) { |
| 285 | if (*(bool*)data) { |
| 286 | removePanel( step2Panel ); |
| 287 | addPanel( step3Panel ); |
| 288 | |
| 289 | //! Turn on the selection function
|
| 290 | devGrid->setMode( kofxGui_Grid_Selectable ); |
| 291 | } |
| 292 | } |
| 293 | break;
|
| 294 | ////////////////////////////////////////
|
| 295 | // STEP 3
|
| 296 | //! Previous step
|
| 297 | case step3Panel_previous: |
| 298 | if ( length == sizeof( bool ) ) { |
| 299 | if (*(bool*)data) { |
| 300 | removePanel( step3Panel ); |
| 301 | addPanel( step2Panel ); |
| 302 | |
| 303 | //! Turn off the selection function
|
| 304 | devGrid->setMode( kofxGui_Grid_Selectable, false );
|
| 305 | } |
| 306 | } |
| 307 | break;
|
| 308 | //! Next - Go to step 4
|
| 309 | case step3Panel_next: |
| 310 | if ( length == sizeof( bool ) ) { |
| 311 | if (*(bool*)data) { |
| 312 | removePanel( step3Panel ); |
| 313 | addPanel( step4Panel ); |
| 314 | |
| 315 | //! Turn off the selection function
|
| 316 | devGrid->setMode( kofxGui_Grid_Selectable, false );
|
| 317 | } |
| 318 | } |
| 319 | break;
|
| 320 | ///////////////////////////////////////
|
| 321 | // STEP 4
|
| 322 | //! Previous step
|
| 323 | case step4Panel_previous: |
| 324 | if ( length == sizeof( bool ) ) { |
| 325 | if (*(bool*)data) { |
| 326 | removePanel( step4Panel ); |
| 327 | addPanel( step3Panel ); |
| 328 | |
| 329 | //! Turn on the selection function
|
| 330 | devGrid->setMode( kofxGui_Grid_Selectable, true );
|
| 331 | } |
| 332 | } |
| 333 | break;
|
| 334 | //! Return to general settings panel
|
| 335 | case step4Panel_finish: |
| 336 | if ( length == sizeof( bool ) ) { |
| 337 | if (*(bool*)data) { |
| 338 | removePanel( step4Panel ); |
| 339 | addPanel( generalSettingsPanel ); |
| 340 | } |
| 341 | } |
| 342 | break;
|
| 343 | default:
|
| 344 | break;
|
| 345 | } |
| 346 | } |
| 347 | //--------------------------------------------------------------
|
| 348 | void MultiCams::setupControls() {
|
| 349 | |
| 350 | ////panel border color
|
| 351 | //controls->mGlobals->mBorderColor.r = 0;
|
| 352 | //controls->mGlobals->mBorderColor.g = 0;
|
| 353 | //controls->mGlobals->mBorderColor.b = 0;
|
| 354 | //controls->mGlobals->mBorderColor.a = .3;
|
| 355 | ////panel color
|
| 356 | //controls->mGlobals->mCoverColor.r = 1;
|
| 357 | //controls->mGlobals->mCoverColor.g = 1;
|
| 358 | //controls->mGlobals->mCoverColor.b = 1;
|
| 359 | //controls->mGlobals->mCoverColor.a = .4;
|
| 360 | ////control outline color
|
| 361 | //controls->mGlobals->mFrameColor.r = 0;
|
| 362 | //controls->mGlobals->mFrameColor.g = 0;
|
| 363 | //controls->mGlobals->mFrameColor.b = 0;
|
| 364 | //controls->mGlobals->mFrameColor.a = .3;
|
| 365 | ////text color
|
| 366 | //controls->mGlobals->mTextColor.r = 0;
|
| 367 | //controls->mGlobals->mTextColor.g = 0;
|
| 368 | //controls->mGlobals->mTextColor.b = 0;
|
| 369 | //controls->mGlobals->mTextColor.a = 1;
|
| 370 | ////button color
|
| 371 | //controls->mGlobals->mButtonColor.r = 1;
|
| 372 | //controls->mGlobals->mButtonColor.g = 0;
|
| 373 | //controls->mGlobals->mButtonColor.b = 0;
|
| 374 | //controls->mGlobals->mButtonColor.a = .8;
|
| 375 | ////slider tip color
|
| 376 | //controls->mGlobals->mHandleColor.r = 0;
|
| 377 | //controls->mGlobals->mHandleColor.g = 0;
|
| 378 | //controls->mGlobals->mHandleColor.b = 0;
|
| 379 | ////slider color
|
| 380 | //controls->mGlobals->mSliderColor.r = 1;
|
| 381 | //controls->mGlobals->mSliderColor.g = 0;
|
| 382 | //controls->mGlobals->mSliderColor.b = 0;
|
| 383 | //controls->mGlobals->mSliderColor.a = .8;
|
| 384 | |
| 385 | ////! label color
|
| 386 | //controls->mGlobals->mLabelColor.r = 0;
|
| 387 | //controls->mGlobals->mLabelColor.g = 0;
|
| 388 | //controls->mGlobals->mLabelColor.b = .2;
|
| 389 | //controls->mGlobals->mLabelColor.a = .8;
|
| 390 | } |
| 391 | //--------------------------------------------------------------
|
| 392 | |
| 393 | void MultiCams::updateControls() {
|
| 394 | controls->update( this->step1Panel_Xaxis, kofxGui_Set_Bool, &this->XAxis, sizeof(float) ); |
| 395 | controls->update( this->step1Panel_Yaxis, kofxGui_Set_Bool, &this->YAxis, sizeof(float) ); |
| 396 | } |
| 397 | //--------------------------------------------------------------
|
| 398 | |
| 399 | void MultiCams::addPanels() {
|
| 400 | |
| 401 | addPanel( camerasDisplayPanel ); |
| 402 | addPanel( generalSettingsPanel ); |
| 403 | addPanel( devicesListPanel ); |
| 404 | addPanel( informationPanel ); |
| 405 | |
| 406 | |
| 407 | //!
|
| 408 | controls->forceUpdate( true );
|
| 409 | controls->activate( true );
|
| 410 | } |
| 411 | //--------------------------------------------------------------
|
| 412 | //! Add the panel and the controls of it
|
| 413 | void MultiCams::addPanel( int id ) { |
| 414 | ofxGuiPanel* pPanel; |
| 415 | switch ( id ) {
|
| 416 | //! Cameras display panel
|
| 417 | case this->camerasDisplayPanel: |
| 418 | pPanel = controls->addPanel( |
| 419 | this->camerasDisplayPanel, "Cameras Display" , 30, 30, |
| 420 | OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING ); |
| 421 | camsGrid = (ofxGuiGrid*)pPanel->addGrid( camerasDisplayPanel_grid, "",
|
| 422 | 680, 320, XAxis, YAxis, |
| 423 | 10, 5, kofxGui_Grid_Display ); |
| 424 | camsGrid->setCamsUtils( utils ); |
| 425 | pPanel->mObjWidth = 700;
|
| 426 | pPanel->mObjHeight = 360;
|
| 427 | |
| 428 | pPanel->adjustToNewContent( 600, 0 ); |
| 429 | |
| 430 | break;
|
| 431 | //! General settings panel
|
| 432 | case generalSettingsPanel: |
| 433 | pPanel = controls->addPanel( |
| 434 | this->generalSettingsPanel, "General Settings", GENERAL_AREA_X,GENERAL_AREA_Y,
|
| 435 | OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING ); |
| 436 | pPanel->addButton( this->generalSettingsPanel_start, "Start Settings",
|
| 437 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 438 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 439 | pPanel->addButton( this->generalSettingsPanel_save, "Save",
|
| 440 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 441 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 442 | pPanel->addButton( this->generalSettingsPanel_cancel, "Cancel",
|
| 443 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 444 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 445 | |
| 446 | pPanel->mObjWidth = GENERAL_AREA_WIDTH; |
| 447 | pPanel->mObjHeight = GENERAL_AREA_HEIGHT; |
| 448 | |
| 449 | //pPanel->mObjects[1]->mObjX = 10; // [0]: "Save" button
|
| 450 | //pPanel->mObjects[1]->mObjY = 140;
|
| 451 | //pPanel->mObjects[2]->mObjX = 100; // [1]: "Cancel" button
|
| 452 | //pPanel->mObjects[2]->mObjY = 140;
|
| 453 | |
| 454 | pPanel->adjustToNewContent( 100, 0 ); |
| 455 | |
| 456 | break;
|
| 457 | //! Devices list panel
|
| 458 | case devicesListPanel: |
| 459 | pPanel = controls->addPanel( |
| 460 | this->devicesListPanel, "Devices List", 30, 420, |
| 461 | OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING ); |
| 462 | devGrid = (ofxGuiGrid*)pPanel->addGrid( devicesListPanel_grid, "", 553, 109, 4, 1, 5, 5, kofxGui_Grid_List ); |
| 463 | devGrid->setCamsUtils( utils ); |
| 464 | pPanel->addArrow( devicesListPanel_arrow_left, "", 53, 109, kofxGui_Arrow_Left ); |
| 465 | pPanel->addArrow( devicesListPanel_arrow_right, "", 50, 109, kofxGui_Arrow_Right ); |
| 466 | |
| 467 | pPanel->mObjWidth = 700;
|
| 468 | pPanel->mObjHeight = 150;
|
| 469 | |
| 470 | pPanel->mObjects[0]->mObjX = 73; //! [0]: devices grid |
| 471 | //pPanel->mObjects[0]->mObjY = 475;
|
| 472 | pPanel->mObjects[1]->mObjX = 10; //! [1]: left arrow |
| 473 | pPanel->mObjects[1]->mObjY = 32; |
| 474 | pPanel->mObjects[2]->mObjX = 637; //! [2]: right arrow |
| 475 | pPanel->mObjects[2]->mObjY = 32; |
| 476 | |
| 477 | |
| 478 | pPanel->adjustToNewContent( 600, 0 ); |
| 479 | |
| 480 | break;
|
| 481 | //! Information Panel
|
| 482 | case informationPanel: |
| 483 | pPanel = controls->addPanel( |
| 484 | this->informationPanel, "Information Settings", 760, 220, |
| 485 | OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING ); |
| 486 | pPanel->mObjWidth = 160;
|
| 487 | pPanel->mObjHeight = 350;
|
| 488 | |
| 489 | break;
|
| 490 | //! Step 1 Panel
|
| 491 | case step1Panel: |
| 492 | pPanel = controls->addPanel( |
| 493 | this->step1Panel, "Step 1", GENERAL_AREA_X, GENERAL_AREA_Y,
|
| 494 | OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING ); |
| 495 | pPanel->addLabel( step1Panel_tip, "",
|
| 496 | GENERAL_AREA_LABEL_WIDTH, GENERAL_AREA_LABEL_HEIGHT, |
| 497 | "Set matrix:", controls->mGlobals->mLabelColor );
|
| 498 | pPanel->addSlider( this->step1Panel_Xaxis, "X axis",
|
| 499 | GENERAL_AREA_SLIDER_WIDTH, GENERAL_AREA_SLIDER_HEIGHT, |
| 500 | 1, 8, XAxis, kofxGui_Display_Int, 0 ); |
| 501 | pPanel->addSlider( this->step1Panel_Yaxis, "Y axis",
|
| 502 | GENERAL_AREA_SLIDER_WIDTH, GENERAL_AREA_SLIDER_HEIGHT, |
| 503 | 1, 8, YAxis, kofxGui_Display_Int, 0 ); |
| 504 | pPanel->addButton( this->step1Panel_previous, "previous",
|
| 505 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 506 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 507 | pPanel->addButton( this->step1Panel_next, "next",
|
| 508 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 509 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 510 | pPanel->mObjWidth = GENERAL_AREA_WIDTH; |
| 511 | pPanel->mObjHeight = GENERAL_AREA_HEIGHT; |
| 512 | |
| 513 | pPanel->mObjects[3]->mObjX = GENERAL_AREA_PREV_X; // [3]: "previous" |
| 514 | pPanel->mObjects[3]->mObjY = GENERAL_AREA_PREV_Y;
|
| 515 | pPanel->mObjects[4]->mObjX = GENERAL_AREA_NEXT_X; // [4]: "next" |
| 516 | pPanel->mObjects[4]->mObjY = GENERAL_AREA_NEXT_Y;
|
| 517 | |
| 518 | pPanel->adjustToNewContent( 100, 0 ); |
| 519 | |
| 520 | break;
|
| 521 | //! Step 2 panel
|
| 522 | case step2Panel: |
| 523 | pPanel = controls->addPanel( |
| 524 | this->step2Panel, "Step 2", GENERAL_AREA_X, GENERAL_AREA_Y,
|
| 525 | OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING ); |
| 526 | pPanel->addLabel( this->step2Panel_tip, "",
|
| 527 | GENERAL_AREA_LABEL_WIDTH, GENERAL_AREA_LABEL_HEIGHT, |
| 528 | "Set Devices (optional)", controls->mGlobals->mLabelColor );
|
| 529 | pPanel->addButton( this->step2Panel_setDevices, "Set Devices",
|
| 530 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 531 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 532 | pPanel->addButton( this->step2Panel_previous, "previous",
|
| 533 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 534 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 535 | pPanel->addButton( this->step2Panel_next, "next",
|
| 536 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 537 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 538 | |
| 539 | pPanel->mObjWidth = GENERAL_AREA_WIDTH; |
| 540 | pPanel->mObjHeight = GENERAL_AREA_HEIGHT; |
| 541 | |
| 542 | pPanel->mObjects[2]->mObjX = GENERAL_AREA_PREV_X; // [2]: "previous" |
| 543 | pPanel->mObjects[2]->mObjY = GENERAL_AREA_PREV_Y;
|
| 544 | pPanel->mObjects[3]->mObjX = GENERAL_AREA_NEXT_X; // [3]: "next" |
| 545 | pPanel->mObjects[3]->mObjY = GENERAL_AREA_NEXT_Y;
|
| 546 | |
| 547 | pPanel->adjustToNewContent( 100, 0 ); |
| 548 | |
| 549 | break;
|
| 550 | //! Step 3 panel
|
| 551 | case step3Panel: |
| 552 | pPanel = controls->addPanel( |
| 553 | this->step3Panel, "Step 3", GENERAL_AREA_X, GENERAL_AREA_Y,
|
| 554 | OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING ); |
| 555 | pPanel->addLabel( this->step3Panel_tip, "",
|
| 556 | GENERAL_AREA_LABEL_WIDTH, GENERAL_AREA_LABEL_HEIGHT, |
| 557 | "Arrange the cameras", controls->mGlobals->mLabelColor );
|
| 558 | //pPanel->addMatrix( this->step3Panel_matrix, "Thumbnails",
|
| 559 | // GENERAL_AREA_MATRIX_WIDTH, GENERAL_AREA_MATRIX_HEIGHT,
|
| 560 | // XAxis, YAxis, kofxGui_Matrix_Clear, kofxGui_Button_Trigger, OFXGUI_MATRIX_SPACING );
|
| 561 | pPanel->addButton( this->step3Panel_previous,"Previous",
|
| 562 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 563 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 564 | pPanel->addButton( this->step3Panel_next, "Next",
|
| 565 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 566 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 567 | pPanel->mObjWidth = GENERAL_AREA_WIDTH; |
| 568 | pPanel->mObjHeight = GENERAL_AREA_HEIGHT; |
| 569 | |
| 570 | //pPanel->mObjects[1]->mObjX = 10; //! [1]: Matrix
|
| 571 | //pPanel->mObjects[1]->mObjY = 45;
|
| 572 | //pPanel->mObjects[2]->mObjX = GENERAL_AREA_PREV_X; //! [2]: Previous
|
| 573 | //pPanel->mObjects[2]->mObjY = GENERAL_AREA_PREV_Y;
|
| 574 | //pPanel->mObjects[3]->mObjX = GENERAL_AREA_NEXT_X; //! [3]: Next
|
| 575 | //pPanel->mObjects[3]->mObjY = GENERAL_AREA_NEXT_Y;
|
| 576 | pPanel->mObjects[1]->mObjX = GENERAL_AREA_PREV_X; //! [2]: Previous |
| 577 | pPanel->mObjects[1]->mObjY = GENERAL_AREA_PREV_Y;
|
| 578 | pPanel->mObjects[2]->mObjX = GENERAL_AREA_NEXT_X; //! [3]: Next |
| 579 | pPanel->mObjects[2]->mObjY = GENERAL_AREA_NEXT_Y;
|
| 580 | |
| 581 | pPanel->adjustToNewContent( 140, 0 ); |
| 582 | |
| 583 | break;
|
| 584 | |
| 585 | case step4Panel: |
| 586 | pPanel = controls->addPanel( |
| 587 | this->step4Panel, "Step 4", GENERAL_AREA_X, GENERAL_AREA_Y,
|
| 588 | OFXGUI_PANEL_BORDER, OFXGUI_PANEL_SPACING ); |
| 589 | pPanel->addLabel( this->step4Panel_tip, "",
|
| 590 | GENERAL_AREA_LABEL_WIDTH, GENERAL_AREA_LABEL_HEIGHT, |
| 591 | "Finishing (optional)", controls->mGlobals->mLabelColor );
|
| 592 | pPanel->addButton( this->step4Panel_calibration, "Calibration",
|
| 593 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 594 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 595 | pPanel->addButton( this->step4Panel_previous, "Previous",
|
| 596 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 597 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 598 | pPanel->addButton( this->step4Panel_finish, "Finish",
|
| 599 | OFXGUI_BUTTON_HEIGHT, OFXGUI_BUTTON_HEIGHT, |
| 600 | kofxGui_Button_Off, kofxGui_Button_Trigger ); |
| 601 | |
| 602 | pPanel->mObjWidth = GENERAL_AREA_WIDTH; |
| 603 | pPanel->mObjHeight = GENERAL_AREA_HEIGHT; |
| 604 | |
| 605 | pPanel->mObjects[2]->mObjX = GENERAL_AREA_PREV_X;
|
| 606 | pPanel->mObjects[2]->mObjY = GENERAL_AREA_PREV_Y;
|
| 607 | pPanel->mObjects[3]->mObjX = GENERAL_AREA_NEXT_X;
|
| 608 | pPanel->mObjects[3]->mObjY = GENERAL_AREA_NEXT_Y;
|
| 609 | |
| 610 | pPanel->adjustToNewContent( 100, 0 ); |
| 611 | break;
|
| 612 | |
| 613 | default:
|
| 614 | break;
|
| 615 | |
| 616 | } |
| 617 | } |
| 618 | //--------------------------------------------------------------
|
| 619 | |
| 620 | void MultiCams::removePanels() {
|
| 621 | controls->removePanel( this->camerasDisplayPanel ); |
| 622 | controls->removePanel( this->generalSettingsPanel ); |
| 623 | controls->removePanel( this->devicesListPanel ); |
| 624 | controls->removePanel( this->informationPanel ); |
| 625 | |
| 626 | controls->removePanel( this->step1Panel ); |
| 627 | controls->removePanel( this->step2Panel ); |
| 628 | controls->removePanel( this->step3Panel ); |
| 629 | controls->removePanel( this->step4Panel ); |
| 630 | } |
| 631 | //--------------------------------------------------------------
|
| 632 | |
| 633 | void MultiCams::removePanel( int id ) { |
| 634 | controls->removePanel( id ); |
| 635 | } |
| 636 | //--------------------------------------------------------------
|
| 637 | |
| 638 | /*******************************************************
|
| 639 | * Draw methods |
| 640 | ********************************************************/ |
| 641 | void MultiCams::draw() {
|
| 642 | //! Move this to "update" function
|
| 643 | if ( bDevicesConfiguration && setDevices->bShowInterface == false ) { |
| 644 | switchSetDevicesGUI( false ); //! Close the SetDevices, show MultiCams |
| 645 | } |
| 646 | if ( bDevicesConfiguration ) {
|
| 647 | setDevices->draw(); |
| 648 | } else {
|
| 649 | _draw(); //! Draw the self interface
|
| 650 | } |
| 651 | |
| 652 | } |
| 653 | |
| 654 | //--------------------------------------------------------------
|
| 655 | |
| 656 | void MultiCams::testDraw( ofEventArgs &e ) {
|
| 657 | ofSetColor( 0x654321 );
|
| 658 | ofFill(); |
| 659 | ofRect( 0, 0, ofGetWidth(), ofGetHeight() ); |
| 660 | } |
| 661 | |
| 662 | //--------------------------------------------------------------
|
| 663 | |
| 664 | void MultiCams::_draw() {
|
| 665 | ofSetColor( 0x123456 );
|
| 666 | ofFill(); |
| 667 | ofRect( 0, 0, ofGetWidth(), ofGetHeight() ); |
| 668 | |
| 669 | //string testStr = ofToString( testInt++ );
|
| 670 | |
| 671 | //// Set the font color to white.
|
| 672 | //ofSetColor( 0xFFFFFF );
|
| 673 | |
| 674 | ////! Draw the test string
|
| 675 | //testFont.drawString(
|
| 676 | // testStr,
|
| 677 | // ofGetWidth()/2 - testFont.stringWidth( testStr )/2,
|
| 678 | // ofGetHeight()/2/* - testFont.stringHeight( testStr )/2*/
|
| 679 | //);
|
| 680 | |
| 681 | controls->draw(); |
| 682 | |
| 683 | if ( bDraggingImage ) {
|
| 684 | this->draggingImage->draw(); |
| 685 | } |
| 686 | } |
| 687 | //--------------------------------------------------------------
|
| 688 | |
| 689 | /*******************************************************
|
| 690 | * PassIn Methods |
| 691 | ********************************************************/ |
| 692 | |
| 693 | void MultiCams::passInCoreVision( ofxNCoreVision* core ) {
|
| 694 | _coreVision = core; |
| 695 | } |
| 696 | //--------------------------------------------------------------
|
| 697 | |
| 698 | void MultiCams::passInCamsUtils( CamsUtils* utils ) {
|
| 699 | this->utils = utils; |
| 700 | } |
| 701 | |
| 702 | //--------------------------------------------------------------
|
| 703 | |
| 704 | |
| 705 | /*******************************************************
|
| 706 | * Load/Save Settings to XML File |
| 707 | ********************************************************/ |
| 708 | void MultiCams::loadXMLSettings() {
|
| 709 | ofLog( OF_LOG_VERBOSE, "Load MultiCams XML from" + _xmlFileName + "\n\n" ); |
| 710 | if ( XML.loadFile( _xmlFileName ) ) {
|
| 711 | ofLog( OF_LOG_VERBOSE, "Settings loaded!\n\n" );
|
| 712 | } else {
|
| 713 | ofLog( OF_LOG_VERBOSE, "No Settings Found...\n\n" );
|
| 714 | } |
| 715 | |
| 716 | this->windowTitle = XML.getValue( "CONFIG:APPLICATION:TITLE", "Multiple Camera Settings" ); |
| 717 | this->bDebugMode = XML.getValue( "CONFIG:BOOLEAN:DEBUG", 0 ); |
| 718 | this->winWidth = XML.getValue( "CONFIG:WINDOW:WIDTH", 950 ); |
| 719 | this->winHeight = XML.getValue( "CONFIG:WINDOW:HEIGHT", 600 ); |
| 720 | |
| 721 | } |
| 722 | //--------------------------------------------------------------
|
| 723 | void MultiCams::SaveXMLSettings() {
|
| 724 | //! Set values
|
| 725 | XML.setValue( "CONFIG:APPLICATION:TITLE", windowTitle );
|
| 726 | |
| 727 | //! Save the file
|
| 728 | XML.saveFile( _xmlFileName ); |
| 729 | } |
| 730 | //--------------------------------------------------------------
|
| 731 | |
| 732 | void MultiCams::switchSetDevicesGUI( bool showDevices ) { |
| 733 | if ( setDevices == NULL ) { |
| 734 | return;
|
| 735 | } |
| 736 | if ( showDevices ) {
|
| 737 | removePanels(); |
| 738 | setDevices->showInterface( true );
|
| 739 | bDevicesConfiguration = true;
|
| 740 | } else {
|
| 741 | setDevices->showInterface( false );
|
| 742 | addPanels(); |
| 743 | //! Goto step 2
|
| 744 | removePanel( generalSettingsPanel ); |
| 745 | addPanel( step2Panel ); |
| 746 | bDevicesConfiguration = false;
|
| 747 | } |
| 748 | } |
| 749 | //--------------------------------------------------------------
|
| 750 | |
| 751 | void MultiCams::_setXY( int x, int y ) { |
| 752 | if ( camsGrid != NULL ) { |
| 753 | camsGrid->setXY( XAxis, YAxis ); |
| 754 | } |
| 755 | if ( utils != NULL ) { |
| 756 | utils->setXY( XAxis, YAxis ); |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | //-------------------------------------------------------------- |
