Exemple #1
0
/*
 * Keyboard callback function
 *	Keys and their effects:
 *		a/A:	toggle animation
 *		1:	switch to camera position 1
 *		2:	switch to camera position 2
 *		5:	toggle light source 1
 *		6:	toggle light source 2
 *		7/d/D:	toggle disco lights
 *		q/Q:	quit program
 */
void keyboard(unsigned char key, int x, int y) {
    switch (key) {
    case 'A':
    case 'a':
        toggleAnimation();
        break;
    case 'D':
    case 'd':
        toggleDisco();
        break;
    case '1':
        switchCamera(0);
        break;
    case '2':
        switchCamera(1);
        break;
    case '5':
        toggleLight(0);
        break;
    case '6':
        toggleLight(1);
        break;
    case 'Q':
    case 'q':
        exit(0);
        break;
    default:
        break;
    }
}
Exemple #2
0
void NGLScene::keyPressEvent(QKeyEvent *_event)
{
  // this method is called every time the main window recives a key event.
  // we then switch on the key value and set the camera in the GLWindow
  switch (_event->key())
  {
  // escape key to quite
  case Qt::Key_Escape : QGuiApplication::exit(EXIT_SUCCESS); break;
  // show full screen
  case Qt::Key_F : showFullScreen(); break;
  // show windowed
  case Qt::Key_N : showNormal(); break;
  case Qt::Key_Q : changeWeight(Weights::POSE1,Direction::DOWN); break;
  case Qt::Key_W : changeWeight(Weights::POSE1,Direction::UP); break;

  case Qt::Key_A : changeWeight(Weights::POSE2,Direction::DOWN); break;
  case Qt::Key_S : changeWeight(Weights::POSE2,Direction::UP); break;
  case Qt::Key_Space : toggleAnimation(); break;
  case Qt::Key_Z : punchLeft(); break;
  case Qt::Key_X : punchRight(); break;

  default : break;
  }
  // finally update the GLWindow and re-draw
    update();
}
Exemple #3
0
GLObjectWindow::GLObjectWindow( QWidget* parent, const char* name )
    : QWidget( parent, name )
{

    // Create nice frames to put around the OpenGL widgets
    QFrame* f1 = new QFrame( this, "frame1" );
    f1->setFrameStyle( QFrame::Sunken | QFrame::Panel );
    f1->setLineWidth( 2 );

    // Create an OpenGL widget
    GLTexobj* c = new GLTexobj( f1, "glbox1");

    // Create a menu
    QPopupMenu *file = new QPopupMenu( this );
    file->insertItem( "Toggle Animation", c, SLOT(toggleAnimation()),
                      CTRL+Key_A );
    file->insertSeparator();
    file->insertItem( "Exit",  qApp, SLOT(quit()), CTRL+Key_Q );

    // Create a menu bar
    QMenuBar *m = new QMenuBar( this );
    m->setSeparator( QMenuBar::InWindowsStyle );
    m->insertItem("&File", file );

    // Create the three sliders; one for each rotation axis
    QSlider* x = new QSlider ( 0, 360, 60, 0, QSlider::Vertical, this, "xsl" );
    x->setTickmarks( QSlider::Left );
    connect( x, SIGNAL(valueChanged(int)), c, SLOT(setXRotation(int)) );

    QSlider* y = new QSlider ( 0, 360, 60, 0, QSlider::Vertical, this, "ysl" );
    y->setTickmarks( QSlider::Left );
    connect( y, SIGNAL(valueChanged(int)), c, SLOT(setYRotation(int)) );

    QSlider* z = new QSlider ( 0, 360, 60, 0, QSlider::Vertical, this, "zsl" );
    z->setTickmarks( QSlider::Left );
    connect( z, SIGNAL(valueChanged(int)), c, SLOT(setZRotation(int)) );


    // Now that we have all the widgets, put them into a nice layout

    // Put the sliders on top of each other
    QVBoxLayout* vlayout = new QVBoxLayout( 20, "vlayout");
    vlayout->addWidget( x );
    vlayout->addWidget( y );
    vlayout->addWidget( z );

    // Put the GL widget inside the frame
    QHBoxLayout* flayout1 = new QHBoxLayout( f1, 2, 2, "flayout1");
    flayout1->addWidget( c, 1 );

    // Top level layout, puts the sliders to the left of the frame/GL widget
    QHBoxLayout* hlayout = new QHBoxLayout( this, 20, 20, "hlayout");
    hlayout->setMenuBar( m );
    hlayout->addLayout( vlayout );
    hlayout->addWidget( f1, 1 );

}
void NGLScene::keyPressEvent(QKeyEvent *_event)
{
  // this method is called every time the main window recives a key event.
  // we then switch on the key value and set the camera in the NGLScene
  switch (_event->key())
  {
  // escape key to quite
  case Qt::Key_Escape : QGuiApplication::exit(EXIT_SUCCESS); break;
  // turn on wirframe rendering
  case Qt::Key_W : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break;
  // turn off wire frame
  case Qt::Key_S : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break;
  // show full screen
  case Qt::Key_F : showFullScreen(); break;
  // show windowed
  case Qt::Key_N : showNormal(); break;
  case Qt::Key_Space : toggleAnimation(); break;
  case Qt::Key_X : stepAnimation(); break;
  case Qt::Key_Left : m_rot+=5; break;
  case Qt::Key_Right : m_rot-=5; break;
  case Qt::Key_Down : m_y-=1.0; break;
  case Qt::Key_Up : m_y+=1.0; break;
  case Qt::Key_Plus :
  case Qt::Key_Equal :
    m_numBlocks+=5;
    if(m_numBlocks > 300)
      m_numBlocks=300;
  resetSim();
  break;
  case Qt::Key_Minus :
    m_numBlocks-=5;
    if(m_numBlocks<10)
      m_numBlocks=10;
    resetSim();
    break;

  case Qt::Key_0 : resetSim();break;

  default : break;
  }
  // finally update the GLWindow and re-draw
  //if (isExposed())
  m_firePos.set(cos(ngl::radians((m_rot)))*m_radius, m_y, sin(ngl::radians(m_rot))*m_radius);

  update();
}
Exemple #5
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    // main window
    QWidget win;

    // GL format
    QGLFormat format;
    format.setVersion(4,3);
    format.setProfile(QGLFormat::CoreProfile);
    MainView *glView = new MainView(format);

    QVBoxLayout *mainLayout = new QVBoxLayout(&win);
    mainLayout->addWidget(glView);

    QWidget *cPanel = new QWidget(&win);
    QHBoxLayout *cPanelLayout = new QHBoxLayout();
    cPanel->setLayout(cPanelLayout);

    QPushButton *sShotButton = new QPushButton("Screen Shot");
    cPanelLayout->addWidget(sShotButton);
    QObject::connect( sShotButton, SIGNAL(clicked()), glView, SLOT(takeScreenShot()) );

    QPushButton *switchButton = new QPushButton("Switch Buffers");
    cPanelLayout->addWidget(switchButton);
    QObject::connect(switchButton, SIGNAL(clicked()), glView, SLOT(switchModel()));

    QPushButton *animButton = new QPushButton("Start/Stop Animation");
    cPanelLayout->addWidget(animButton);
    QObject::connect(animButton, SIGNAL(clicked()), glView, SLOT(toggleAnimation()) );

    mainLayout->addWidget(cPanel);

    win.setLayout(mainLayout);
    win.setWindowTitle("Simple Scene");
    win.show();

    return app.exec();
}
int QGLViewer::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QGLWidget::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: viewerInitialized(); break;
        case 1: drawNeeded(); break;
        case 2: drawFinished((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 3: animateNeeded(); break;
        case 4: helpRequired(); break;
        case 5: axisIsDrawnChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 6: gridIsDrawnChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 7: FPSIsDisplayedChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 8: textIsEnabledChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 9: cameraIsEditedChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 10: stereoChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 11: pointSelected((*reinterpret_cast< const QMouseEvent*(*)>(_a[1]))); break;
        case 12: mouseGrabberChanged((*reinterpret_cast< qglviewer::MouseGrabber*(*)>(_a[1]))); break;
        case 13: setAxisIsDrawn((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 14: setAxisIsDrawn(); break;
        case 15: setGridIsDrawn((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 16: setGridIsDrawn(); break;
        case 17: setFPSIsDisplayed((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 18: setFPSIsDisplayed(); break;
        case 19: setTextIsEnabled((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 20: setTextIsEnabled(); break;
        case 21: setCameraIsEdited((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 22: setCameraIsEdited(); break;
        case 23: toggleAxisIsDrawn(); break;
        case 24: toggleGridIsDrawn(); break;
        case 25: toggleFPSIsDisplayed(); break;
        case 26: toggleTextIsEnabled(); break;
        case 27: toggleCameraIsEdited(); break;
        case 28: setBackgroundColor((*reinterpret_cast< const QColor(*)>(_a[1]))); break;
        case 29: setForegroundColor((*reinterpret_cast< const QColor(*)>(_a[1]))); break;
        case 30: setSceneRadius((*reinterpret_cast< float(*)>(_a[1]))); break;
        case 31: setSceneCenter((*reinterpret_cast< const qglviewer::Vec(*)>(_a[1]))); break;
        case 32: setSceneBoundingBox((*reinterpret_cast< const qglviewer::Vec(*)>(_a[1])),(*reinterpret_cast< const qglviewer::Vec(*)>(_a[2]))); break;
        case 33: showEntireScene(); break;
        case 34: setCamera((*reinterpret_cast< qglviewer::Camera*const(*)>(_a[1]))); break;
        case 35: setManipulatedFrame((*reinterpret_cast< qglviewer::ManipulatedFrame*(*)>(_a[1]))); break;
        case 36: setMouseGrabber((*reinterpret_cast< qglviewer::MouseGrabber*(*)>(_a[1]))); break;
        case 37: setFullScreen((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 38: setFullScreen(); break;
        case 39: setStereoDisplay((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 40: setStereoDisplay(); break;
        case 41: toggleFullScreen(); break;
        case 42: toggleStereoDisplay(); break;
        case 43: toggleCameraMode(); break;
        case 44: saveSnapshot((*reinterpret_cast< bool(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 45: saveSnapshot((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 46: saveSnapshot(); break;
        case 47: saveSnapshot((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< bool(*)>(_a[2]))); break;
        case 48: saveSnapshot((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 49: setSnapshotFileName((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 50: setSnapshotFormat((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 51: setSnapshotCounter((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 52: setSnapshotQuality((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 53: { bool _r = openSnapshotFormatDialog();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 54: snapshotToClipboard(); break;
        case 55: copyBufferToTexture((*reinterpret_cast< GLint(*)>(_a[1])),(*reinterpret_cast< GLenum(*)>(_a[2]))); break;
        case 56: copyBufferToTexture((*reinterpret_cast< GLint(*)>(_a[1]))); break;
        case 57: setAnimationPeriod((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 58: startAnimation(); break;
        case 59: stopAnimation(); break;
        case 60: animate(); break;
        case 61: toggleAnimation(); break;
        case 62: help(); break;
        case 63: aboutQGLViewer(); break;
        case 64: select((*reinterpret_cast< const QMouseEvent*(*)>(_a[1]))); break;
        case 65: select((*reinterpret_cast< const QPoint(*)>(_a[1]))); break;
        case 66: setSelectBufferSize((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 67: setSelectRegionWidth((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 68: setSelectRegionHeight((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 69: setSelectedName((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 70: setShortcut((*reinterpret_cast< KeyboardAction(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 71: setKeyboardAccelerator((*reinterpret_cast< KeyboardAction(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 72: setKeyDescription((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
        case 73: setKeyFrameKey((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 74: setPlayKeyFramePathStateKey((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 75: setPlayPathStateKey((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 76: setAddKeyFrameStateKey((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 77: setPathKey((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 78: setPathKey((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 79: setPlayPathKeyboardModifiers((*reinterpret_cast< QtKeyboardModifiers(*)>(_a[1]))); break;
        case 80: setAddKeyFrameKeyboardModifiers((*reinterpret_cast< QtKeyboardModifiers(*)>(_a[1]))); break;
        case 81: setMouseBinding((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< MouseHandler(*)>(_a[2])),(*reinterpret_cast< MouseAction(*)>(_a[3])),(*reinterpret_cast< bool(*)>(_a[4]))); break;
        case 82: setMouseBinding((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< MouseHandler(*)>(_a[2])),(*reinterpret_cast< MouseAction(*)>(_a[3]))); break;
        case 83: setWheelBinding((*reinterpret_cast< QtKeyboardModifiers(*)>(_a[1])),(*reinterpret_cast< MouseHandler(*)>(_a[2])),(*reinterpret_cast< MouseAction(*)>(_a[3])),(*reinterpret_cast< bool(*)>(_a[4]))); break;
        case 84: setWheelBinding((*reinterpret_cast< QtKeyboardModifiers(*)>(_a[1])),(*reinterpret_cast< MouseHandler(*)>(_a[2])),(*reinterpret_cast< MouseAction(*)>(_a[3]))); break;
        case 85: setHandlerKeyboardModifiers((*reinterpret_cast< MouseHandler(*)>(_a[1])),(*reinterpret_cast< QtKeyboardModifiers(*)>(_a[2]))); break;
        case 86: setHandlerStateKey((*reinterpret_cast< MouseHandler(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 87: setMouseStateKey((*reinterpret_cast< MouseHandler(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 88: initFromDOMElement((*reinterpret_cast< const QDomElement(*)>(_a[1]))); break;
        case 89: saveStateToFile(); break;
        case 90: { bool _r = restoreStateFromFile();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 91: setStateFileName((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 92: saveToFile((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 93: saveToFile(); break;
        case 94: { bool _r = restoreFromFile((*reinterpret_cast< const QString(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 95: { bool _r = restoreFromFile();
            if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; }  break;
        case 96: resetVisualHints(); break;
        case 97: delayedFullScreen(); break;
        case 98: hideMessage(); break;
        default: ;
        }
        _id -= 99;
    }
    return _id;
}
Exemple #7
0
void App::gui() {
	ImGuiIO& io = ImGui::GetIO();

	if (ImGui::BeginMainMenuBar()) {
		if (ImGui::BeginMenu("File")) {
			if (ImGui::MenuItem("New", io.OSXBehaviors ? "Cmd+N" : "Ctrl+N")) {
				newShader();
			}
			ImGui::Separator();
			if (ImGui::MenuItem("Open...", io.OSXBehaviors ? "Cmd+O" : "Ctrl+O")) {
				openShaderDialog();
			}
			if (ImGui::BeginMenu("Open Recent", !!recently_used_filepaths[most_recently_used_index])) {
				for (int i = 0; i < (int)ARRAY_COUNT(recently_used_filepaths); i++) {
					int index = (most_recently_used_index+i) % ARRAY_COUNT(recently_used_filepaths);
					if (recently_used_filepaths[index]) {
						char *menuitem_label = recently_used_filepaths[index];
						// we might include libgen.h and use basename(3) but there is no windows support...
						// TODO: test this on windows
						char *basename = strrchr(menuitem_label, '/');
						if (basename) menuitem_label = basename+1;
						if (ImGui::MenuItem(menuitem_label)) {
							loadShader(recently_used_filepaths[index]);
						}
						if (basename && ImGui::IsItemHovered()) {
							ImGui::SetTooltip("%s", recently_used_filepaths[index]);
						}
					} else break;
				}
				ImGui::Separator();
				if (ImGui::MenuItem("Clear Items")) {
					clearRecentlyUsedFilepaths();
				}
				ImGui::EndMenu();
			}
			// TODO: move this to settings pane eventually
			if (ImGui::MenuItem("Autoreload", nullptr, shader_file_autoreload)) {
				shader_file_autoreload = !shader_file_autoreload;
				writePreferences();
			}
			if (ImGui::MenuItem("Save", io.OSXBehaviors ? "Cmd+S" : "Ctrl+S", false, !!shader_filepath)) {
				saveShader();
			}
			if (ImGui::IsItemHovered() && shader_filepath) {
				ImGui::SetTooltip("%s", shader_filepath);
			}
			if (ImGui::MenuItem("Save As...", io.OSXBehaviors ? "Cmd+Shift+S" : "Ctrl+Shift+S", false, !!src_edit_buffer[0])) {
				saveShaderDialog();
			}
			ImGui::Separator();
			if (ImGui::MenuItem("Quit", io.OSXBehaviors ? "Cmd+Q" : "Ctrl+Q")) {
				quit = true;
			}
 			ImGui::EndMenu();
		}
		if (ImGui::BeginMenu("View")) {
			if (ImGui::MenuItem("Fullscreen", io.OSXBehaviors ? "Cmd+F" : "Ctrl+F", windowIsFullscreen())) {
				windowToggleFullscreen();
			}
			if (ImGui::MenuItem("Hide Controls", io.OSXBehaviors ? "Cmd+Shift+H" : "Ctrl+H", hide_gui)) {
				hide_gui = !hide_gui;
			}
			ImGui::Separator();
			if (ImGui::MenuItem(anim_play ? "Pause Animation" : "Play Animation", "Space")) {
				toggleAnimation();
			}
			if (ImGui::MenuItem("Reset Animation")) {
				frame_count = 0;
			}
			if (ImGui::MenuItem("Reset Camera")) {
				resetCamera();
			}
			ImGui::EndMenu();
		}
if (ImGui::BeginMenu("Tools")) {
	if (ImGui::MenuItem("Recompile Shader", io.OSXBehaviors ? "Cmd+B" : "Ctrl+B", false, !!src_edit_buffer[0])) {
		recompileShader();
	}
	ImGui::EndMenu();
}
if (ImGui::BeginMenu("Window")) {
	if (ImGui::MenuItem("Uniforms", io.OSXBehaviors ? "Cmd+1" : "Ctrl+1", show_uniforms_window)) {
		show_uniforms_window = !show_uniforms_window;
	}
	if (ImGui::MenuItem("Textures", io.OSXBehaviors ? "Cmd+2" : "Ctrl+2", show_textures_window)) {
		show_textures_window = !show_textures_window;
	}
	ImGui::Separator();
	if (ImGui::MenuItem("Camera", io.OSXBehaviors ? "Cmd+3" : "Ctrl+3", show_textures_window)) {
		show_camera_window = !show_camera_window;
	}
	ImGui::Separator();
	if (ImGui::MenuItem("Source editor", io.OSXBehaviors ? "Cmd+4" : "Ctrl+4", show_src_edit_window)) {
		show_src_edit_window = !show_src_edit_window;
	}
	ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
	}

	if (show_uniforms_window) {
		if (ImGui::Begin("Uniforms", &show_uniforms_window)) {
			if (ImGui::CollapsingHeader("Built-in uniform names")) {
				ImGui::InputText("Time", u_time_name, sizeof(u_time_name));
				ImGui::InputText("Resolution", u_resolution_name, sizeof(u_resolution_name));
				ImGui::InputText("View to World Matrix", u_view_to_world_name, sizeof(u_view_to_world_name));
				ImGui::InputText("World to View Matrix", u_world_to_view_name, sizeof(u_world_to_view_name));
			}
			ImGui::Separator();

			if (!compile_error_log) {
				ImGui::AlignFirstTextHeightToWidgets();
				ImGui::Text("Data"); ImGui::SameLine();
				if (ImGui::Button("Clear")) {
					if (uniform_data) {
						memset(uniform_data, 0, uniform_data_size);
					}
				} ImGui::SameLine();
				if (ImGui::Button("Save")) {
					writeUniformData();
				} ImGui::SameLine();
				if (ImGui::Button("Load")) {
					readUniformData();
				}
				for (int i = 0; i < uniform_count; i++) {
					// skip builtin uniforms
					if (!strcmp(u_time_name, uniforms[i].name)) continue;
					if (!strcmp(u_resolution_name, uniforms[i].name)) continue;
					if (!strcmp(u_view_to_world_name, uniforms[i].name)) continue;
					if (!strcmp(u_world_to_view_name, uniforms[i].name)) continue;
					uniforms[i].gui();
				}
			}
		}
		ImGui::End();
	}

	if (show_textures_window) {
		if (ImGui::Begin("Textures", &show_textures_window)) {
			ImGui::Columns(2);
			for (int tsi = 0; tsi < (int)ARRAY_COUNT(texture_slots); tsi++) {
				TextureSlot *texture_slot = texture_slots + tsi;

				ImGui::BeginGroup();
				ImGui::PushID(tsi);
				ImGui::Text("%d:", tsi);
				ImGui::SameLine();
				ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(0.0f, 0.6f, 0.6f));
				ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(0.0f, 0.7f, 0.7f));
				ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(0.0f, 0.8f, 0.8f));
				if (ImGui::SmallButton("x")) texture_slot->clear();
				ImGui::PopStyleColor(3);
				if (ImGui::Button(" 2D ")) openImageDialog(texture_slot);
				if (ImGui::Button("Cube")) openImageDialog(texture_slot, /*load_cube_cross*/true);
				ImGui::PopID();
				ImGui::EndGroup();

				ImGui::SameLine();
				//ImTextureID im_tex_id = (ImTextureID)(intptr_t)texture_slot->texture;
				ImGui::Image((void*)texture_slot, ImVec2(64, 64));
				if (ImGui::IsItemHovered() && texture_slot->image_filepath) {
					ImGui::SetTooltip("%s\n%dx%d", texture_slot->image_filepath,
						texture_slot->image_width, texture_slot->image_height);
				}

				if ((tsi & 1) && tsi + 1 != ARRAY_COUNT(texture_slots)) {
					ImGui::Separator();
				}
				else {
					ImGui::SameLine(); ImGui::Spacing();
				}
				ImGui::NextColumn();
			}
			ImGui::Columns(1);
		}
		ImGui::End();
	}

	if (show_camera_window) {
		if (ImGui::Begin("Camera", &show_camera_window)) {
			ImGui::DragFloat3("Location", camera_location.e);
			ImGui::SliderAngle("Pitch", &camera_euler_angles.x);
			ImGui::SliderAngle("Yaw", &camera_euler_angles.y);
			ImGui::SliderAngle("Roll", &camera_euler_angles.z);
			if (ImGui::Button("Reset")) resetCamera();
			ImGui::End();
		}
	}

	if (show_src_edit_window) {
		if (ImGui::Begin("Source editor", &show_src_edit_window)) {
			// TODO: add horizontal scrollbar
			ImGui::InputTextMultiline("##Text buffer", src_edit_buffer, sizeof(src_edit_buffer)-1,
				/*fullwidth, fullheight*/ImVec2(-1.0f, -1.0f), ImGuiInputTextFlags_AllowTabInput);
		}
		ImGui::End();
	}

	// overlay messages
	int overlay_flags = ImGuiWindowFlags_NoTitleBar
		| ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize
		| ImGuiWindowFlags_NoBringToFrontOnFocus
		| ImGuiWindowFlags_NoMove
		| ImGuiWindowFlags_NoSavedSettings;
	if (!shader_filepath && !src_edit_buffer[0]) {
		ImGui::SetNextWindowPosCenter();
		ImGui::Begin("Overlay", nullptr, ImVec2(0, 0), 0.3f, overlay_flags);
		ImGui::AlignFirstTextHeightToWidgets(); // valign text to button
		ImGui::Text("No fragment shader");
		ImGui::SameLine();
		if (ImGui::Button("Open")) openShaderDialog();
		ImGui::SameLine();
		if (ImGui::Button("New")) newShader();
		ImGui::End();
	} else if (compile_error_log) {
		ImGui::SetNextWindowPosCenter();
		ImGui::Begin("Overlay", nullptr, ImVec2(0, 0), 0.3f, overlay_flags);
		ImGui::TextUnformatted(compile_error_log);
		ImGui::End();
	}
}
Exemple #8
0
QWzmViewer::QWzmViewer(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow()), psModel(NULL), timer(new QTimer(this))
{
	QSettings settings;
	ui->setupUi(this);

	connectorsModel.setColumnCount(4);
	connectorsModel.setHeaderData(0, Qt::Horizontal, QString("X"));
	connectorsModel.setHeaderData(1, Qt::Horizontal, QString("Y"));
	connectorsModel.setHeaderData(2, Qt::Horizontal, QString("Z"));
	connectorsModel.setHeaderData(3, Qt::Horizontal, QString(tr("Type")));

	animationModel.setColumnCount(8);
	animationModel.setHeaderData(0, Qt::Horizontal, QString(tr("Time")));
	animationModel.setHeaderData(1, Qt::Horizontal, QString("Tex"));
	animationModel.setHeaderData(2, Qt::Horizontal, QString("Trs X"));
	animationModel.setHeaderData(3, Qt::Horizontal, QString("Trs Y"));
	animationModel.setHeaderData(4, Qt::Horizontal, QString("Trs Z"));
	animationModel.setHeaderData(5, Qt::Horizontal, QString("Rot X"));
	animationModel.setHeaderData(6, Qt::Horizontal, QString("Rot Y"));
	animationModel.setHeaderData(7, Qt::Horizontal, QString("Rot Z"));

	fileNameLabel = new QLabel(tr("No file loaded"), ui->statusBar);

	selectedMeshComboBox = new QComboBox(ui->statusBar);
	selectedMeshComboBox->setToolTip(tr("Selected Mesh"));
	selectedMeshComboBox->setEnabled(false);

	visibleMeshComboBox = new QComboBox(ui->statusBar);
	visibleMeshComboBox->setEnabled(false);
	visibleMeshComboBox->setToolTip(tr("Visible Mesh"));
	visibleMeshComboBox->addItem(tr("All"));

	teamComboBox = new QComboBox(ui->statusBar);
	teamComboBox->setToolTip(tr("Team Colour"));
	teamComboBox->addItem(tr("Green"));
	teamComboBox->addItem(tr("Yellow"));
	teamComboBox->addItem(tr("Grey"));
	teamComboBox->addItem(tr("Black"));
	teamComboBox->addItem(tr("Red"));
	teamComboBox->addItem(tr("Blue"));
	teamComboBox->addItem(tr("Pink"));
	teamComboBox->addItem(tr("Cyan"));

	scaleSlider = new QSlider(ui->statusBar);
	scaleSlider->setToolTip(tr("Scale"));
	scaleSlider->setRange(1, 1000);
	scaleSlider->setValue(100);
	scaleSlider->setOrientation(Qt::Horizontal);
	scaleSlider->setEnabled(false);

	ui->statusBar->addPermanentWidget(fileNameLabel);
	ui->statusBar->addPermanentWidget(selectedMeshComboBox);
	ui->statusBar->addPermanentWidget(visibleMeshComboBox);
	ui->statusBar->addPermanentWidget(teamComboBox);
	ui->statusBar->addPermanentWidget(scaleSlider);

	ui->connectorTableView->setModel(&connectorsModel);
	ui->animationTableView->setModel(&animationModel);

	ui->animationDockWidget->hide();
	ui->connectorDockWidget->hide();

	connect(timer, SIGNAL(timeout()), this, SLOT(tick()));
	connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(actionOpen()));
	connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
	connect(ui->actionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
	connect(ui->actionQuit, SIGNAL(triggered()), QApplication::instance(), SLOT(quit()));
	connect(ui->actionImport_3DS, SIGNAL(triggered()), this, SLOT(open3DS()));
	connect(ui->actionWireframe, SIGNAL(triggered()), this, SLOT(toggleWireframe()));
	connect(ui->actionHelpContents, SIGNAL(triggered()), ui->glView, SLOT(help()));
	connect(ui->actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
	connect(ui->actionAboutApplication, SIGNAL(triggered()), this, SLOT(actionAboutApplication()));
	connect(ui->actionAxis, SIGNAL(triggered()), ui->glView, SLOT(toggleAxisIsDrawn()));
	connect(ui->actionCulling, SIGNAL(triggered()), this, SLOT(toggleCulling()));
	connect(ui->actionAnimation, SIGNAL(triggered()), this, SLOT(toggleAnimation()));
	connect(ui->actionScaleModel, SIGNAL(triggered()), this, SLOT(toggleScale()));
	connect(selectedMeshComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setMesh(int)));
	connect(visibleMeshComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setVisibleMesh(int)));
	connect(teamComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(setTeam(int)));
	connect(ui->actionSwapYZ, SIGNAL(triggered()), this, SLOT(toggleSwapYZ()));
	connect(ui->actionReverseWinding, SIGNAL(triggered()), this, SLOT(toggleReverseWinding()));
	connect(ui->actionFlipVerticalTexCoords, SIGNAL(triggered()), this, SLOT(toggleFlipVerticalTexCoords()));
	connect(ui->actionFramesEditor, SIGNAL(toggled(bool)), this, SLOT(toggleEditAnimation(bool)));
	connect(ui->actionConnectorsEditor, SIGNAL(toggled(bool)), this, SLOT(toggleEditConnectors(bool)));
	connect(ui->animationDockWidget, SIGNAL(visibilityChanged(bool)), ui->actionFramesEditor, SLOT(setChecked(bool)));
	connect(ui->connectorDockWidget, SIGNAL(visibilityChanged(bool)), ui->actionConnectorsEditor, SLOT(setChecked(bool)));
	connect(ui->prependFrameButton, SIGNAL(pressed()), this, SLOT(prependFrame()));
	connect(ui->appendFrameButton, SIGNAL(pressed()), this, SLOT(appendFrame()));
	connect(ui->removeFrameButton, SIGNAL(pressed()), this, SLOT(removeFrame()));

	// Set defaults
	toggleAnimation();

	ui->actionSave->setEnabled(false);
	ui->actionSaveAs->setEnabled(false);

	restoreGeometry(settings.value("geometry").toByteArray());
	restoreState(settings.value("windowState").toByteArray());

	timer->start(25);
}