Пример #1
0
void hkDefaultDemo::mouseDown()
{
	HK_ASSERT(0x499454e1, m_mouseActive == false);

	// see if the user is picking - only if
	//   there is a display world!
	//   and we're not already picking
	hkgDisplayWorld* dw = m_env->m_displayWorld;
	if( m_env->m_mousePickingEnabled && dw )
	{
		hkgWindow* w = m_env->m_window;
		hkgViewport* v = w->getCurrentViewport();
		hkgCamera* c = v->getCamera();
		int vx, vy;
		v->getLowerLeftCoord(vx, vy);

		hkgViewportPickData pd;

		const int x = w->getMouse().getPosX() - vx;
		const int y = w->getMouse().getPosY() - vy;

		if (v->pick( x, y, dw, pd ))
		{
   			const int objectNum = pd.m_objectIndex;
			hkVector4 mousePosWorldSpace; mousePosWorldSpace.set( pd.m_worldPos[0], pd.m_worldPos[1], pd.m_worldPos[2]);

			float result[3];
			c->project( pd.m_worldPos[0], pd.m_worldPos[1], pd.m_worldPos[2], v->getWidth(), v->getHeight(), result );
			m_mousePosDepth = result[2];	// remember the z value

			//hkprintf( "GM: Try pick at [%d %d (%f)] ", x, y, m_mousePosDepth );
			//hkprintf( "World mouse pos: [%f %f %f]\n", pd.m_worldPos[0], pd.m_worldPos[1], pd.m_worldPos[2]);

			// find out if there is a (the first one) demo that has a rigid body attached
			// to this display object
			const hkgDisplayObject* dobject = dw->getDisplayObject( objectNum );
			m_mouseActive = objectPicked( dobject, mousePosWorldSpace, pd.m_objectPickData.m_geomIndex  );
		}
		else
		{
			m_mouseActive = objectPicked( HK_NULL, hkVector4::getZero(), 0  );
		}
	}
}
Пример #2
0
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
, m_editor(0)
, m_hooqPlayInjector(new PlatformInjector(this))
, m_hooqRecordInjector(new PlatformInjector(this))
, m_hooqLogger(0)
, m_hooqPlayer(0)
, m_interpreter(new Interpreter(this))
, m_server(new QTcpServer(this))
, m_testModel(new TestModel(this))
, m_testRunning(false)
, m_testResultsWindow(new TestResultsDialog(this))
, m_xmlDump(0)
{
	if(!m_interpreter->haveRequiredQtScriptExtensions())
	{
		QMessageBox::critical(0, tr("Couldn't load required QtScript extensions"), tr("Please install qtscriptgenerator for the version of Qt you are currently using. While recording in Hooq may work, playback will not be possible."));
	}

	if(!m_server->listen(QHostAddress::LocalHost, Hooq::Communication::serverPort()))
	{
		QMessageBox::critical(0, tr("Couldn't listen for applications"), tr("Hooq couldn't start listening for applications; you're probably running two copies of Hooq. Hooq will not work."));
	}

	m_editor = new ScriptEditor(m_interpreter->engine());
	setupUi(this);
	setStatusBar(0);

	populateTestSets();

	m_testList->setModel(m_testModel);
	PushButtonDelegate* delegate = new PushButtonDelegate(m_testList, this);
	delegate->addButton(1, QApplication::style()->standardIcon(QStyle::SP_MediaPlay));
	delegate->addButton(2, QApplication::style()->standardIcon(QStyle::SP_FileIcon));
	m_testList->setItemDelegate(delegate);

	m_testList->header()->setResizeMode(0, QHeaderView::Stretch);
	m_testList->header()->setResizeMode(1, QHeaderView::Fixed);
	m_testList->header()->setResizeMode(2, QHeaderView::Fixed);
	m_testList->header()->setStretchLastSection(false);

	m_contextMenu = new QMenu(this);
	m_contextMenu->addAction(tr("Run"), this, SLOT(runCurrentTest()));
	m_contextMenu->addAction(tr("Edit"), this, SLOT(editCurrentTest()));
	m_contextMenu->addSeparator();
	m_contextMenu->addAction(tr("Delete"), this, SLOT(deleteCurrentTest()));

	setTestSet(m_testSetEdit->currentText());

	m_testList->setContextMenuPolicy(Qt::CustomContextMenu);

	QObject* deleteObserver = new ModelIndexKeyEventObserver(QKeySequence::Delete, m_testList);

	connect(
		deleteObserver,
		SIGNAL(released(QModelIndex)),
		SLOT(deleteCurrentTest())
	);

	connect(
		m_testList,
		SIGNAL(customContextMenuRequested(QPoint)),
		SLOT(showTestContextMenu(QPoint))
	);

	connect(
		m_testSetEdit,
		SIGNAL(activated(QString)),
		SLOT(setTestSet(QString))
	);

	connect(
		m_runAllButton,
		SIGNAL(clicked()),
		SLOT(runAllTests())
	);

	connect(
		m_addTestButton,
		SIGNAL(clicked()),
		SLOT(startRecording())
	);

	connect(
		m_hooqRecordInjector,
		SIGNAL(finished(int)),
		SLOT(finishRecording())
	);

	connect(
		m_testNameEdit,
		SIGNAL(textChanged(QString)),
		SLOT(updateActionStates())
	);

	connect(
		m_addTestSetButton,
		SIGNAL(clicked()),
		SLOT(addTestSet())
	);

	connect(
		m_newTestSet,
		SIGNAL(triggered()),
		SLOT(addTestSet())
	);
	connect(
		m_editTestSet,
		SIGNAL(triggered()),
		SLOT(editTestSet())
	);
	connect(
		m_removeTestSet,
		SIGNAL(triggered()),
		SLOT(removeTestSet())
	);
	connect(
		m_exportSet,
		SIGNAL(triggered()),
		SLOT(exportCurrentSet())
	);
	connect(
		m_importSet,
		SIGNAL(triggered()),
		SLOT(importTestSet())
	);
	connect(
		m_editor,
		SIGNAL(pickRequested()),
		m_interpreter,
		SLOT(pickObject())
	);
	connect(
		m_editor,
		SIGNAL(startRequested()),
		SLOT(runEditorTest())
	);

	connect(
		m_editor,
		SIGNAL(exceptionThrown(QString, QStringList)),
		SLOT(logException(QString, QStringList))
	);

	connect(
		m_interpreter,
		SIGNAL(objectPicked(ObjectInformation)),
		m_editor,
		SLOT(objectPicked(ObjectInformation))
	);
	connect(
		m_interpreter,
		SIGNAL(objectNotFound(QString)),
		m_editor,
		SLOT(objectNotFound(QString))
	);
	connect(
		m_interpreter,
		SIGNAL(executionFailed(int)),
		m_editor,
		SLOT(handleApplicationExit(int))
	);

	connect(
		m_interpreter,
		SIGNAL(finished()),
		SLOT(testFinished())
	);
	connect(
		m_interpreter,
		SIGNAL(startApplicationAndAttach()),
		SLOT(startApplication())
	);

	connect(
		m_quit,
		SIGNAL(triggered()),
		qApp,
		SLOT(quit())
	);

	connect(
		m_aboutQt,
		SIGNAL(triggered()),
		qApp,
		SLOT(aboutQt())
	);

	connect(
		m_about,
		SIGNAL(triggered()),
		SLOT(about())
	);

	ColumnClickMapper* mapper = new ColumnClickMapper(m_testList);
	mapper->addMapping(1, this, SLOT(runTestScript(QModelIndex)));
	mapper->addMapping(2, this, SLOT(editTestScript(QModelIndex)));

	updateActionStates();
}