void MaratisPlayer::loadProject(MProject* proj, const char * filename) { MWindow * window = MWindow::getInstance(); MEngine * engine = MEngine::getInstance(); // working directory char workingDir[256]; getRepertory(workingDir, filename); window->setWorkingDirectory(workingDir); // restart restart(); loadGamePlugin(); // renderer changeRenderer(proj->renderer.c_str()); // if we have a package manager, try to load the package if(MPackageManager* pPackMan = MEngine::getInstance()->getPackageManager()) { char projName[256]; getLocalFilename(projName, workingDir, filename); if(char* ext = strstr(projName, ".mproj")) { sprintf(ext, ".npk"); char packageFile[256]; getGlobalFilename(packageFile, workingDir, projName); pPackMan->loadPackage(packageFile); } } // load start level engine->loadLevel(proj->startLevel.c_str()); }
void Ut_MPositionIndicatorView::testNoActivityInSwitcher() { QFETCH(QRectF, range); m_controller->setRange(range); MWindow window; MScene *scene = new MScene; window.setScene(scene); window.show(); scene->addItem(m_controller); window.showMinimized(); QVERIFY(window.isInSwitcher()); QVERIFY(m_controller->isOnDisplay()); MOnDisplayChangeEvent displayExited(false, QRectF()); qApp->sendEvent(m_controller, &displayExited); QVERIFY(!m_subject->d_func()->hideTimer->isActive()); QCOMPARE(m_subject->d_func()->fadeAnimation->state(), QAbstractAnimation::Stopped); QCOMPARE(m_subject->contentOpacity(), qreal(0.0)); MOnDisplayChangeEvent displayEntered(true, QRectF()); qApp->sendEvent(m_controller, &displayEntered); QVERIFY(!m_subject->d_func()->hideTimer->isActive()); QCOMPARE(m_subject->d_func()->fadeAnimation->state(), QAbstractAnimation::Stopped); QCOMPARE(m_subject->contentOpacity(), qreal(0.0)); scene->removeItem(m_controller); delete scene; }
void MaratisPlayer::graphicLoop(void) { MWindow * window = MWindow::getInstance(); MEngine * engine = MEngine::getInstance(); MRenderingContext * render = engine->getRenderingContext(); // game MGame * game = engine->getGame(); if(game) { if(game->isRunning()) { render->disableScissorTest(); render->setViewport(0, 0, window->getWidth(), window->getHeight()); game->draw(); } else { render->clear(M_BUFFER_COLOR); } } else { render->clear(M_BUFFER_COLOR); } }
void drawLogo(void) { MWindow * window = MWindow::getInstance(); MGui2d quad; quad.setPosition(MVector2((window->getWidth()-512)*0.5f, (window->getHeight()-512)*0.5f)); quad.setScale(MVector2(512, 512)); quad.drawTexturedQuad(logoTextureId); }
void ToolBarPage::onDisappear() { setBackButtonVisible(true); setMenuActionsVisible(true); applicationWindow()->setStyleName(defaultStyleName); MWindow *window = MApplication::activeWindow(); if (!wasFullScreen && window && window->isFullScreen()) window->showNormal(); }
bool MPositionIndicatorViewPrivate::isInSwitcher() const { bool isInSwitcher = false; if (controller->scene() && !controller->scene()->views().isEmpty()) { MWindow* win = qobject_cast<MWindow*>(controller->scene()->views().at(0)); if (win) { isInSwitcher = win->isInSwitcher(); } } return isInSwitcher; }
void copySysOSX(const char* projName) { #ifdef _DEBUG const char * appName = "MaratisPlayerDebug"; #else const char * appName = "MaratisPlayer"; #endif MWindow * window = MWindow::getInstance(); MEngine* engine = MEngine::getInstance(); MSystemContext* system = engine->getSystemContext(); char filename[256]; getLocalFilename(filename, system->getWorkingDirectory(), projName); if(char* ext = strstr(filename, ".mproj")) { MProject proj; if(proj.loadXML(projName)) { strcpy(ext, ".app"); char path[256]; char srcName[256]; char destName[256]; char appPath[256]; char level[256]; getLocalFilename(level, system->getWorkingDirectory(), proj.startLevel.c_str()); getGlobalFilename(appPath, getPubDir(), filename); sprintf(path, "../../../%s.app", appName); getGlobalFilename(srcName, window->getCurrentDirectory(), path); copyDirectory(srcName, appPath); strcpy(ext, ""); sprintf(srcName, "%s/Contents/MacOS/%s", appPath, appName); strcpy(ext, ".mproj"); embedProject(srcName, srcName, filename, level, proj.renderer.c_str()); chmod(srcName, 0777); // we need to put all data in app/Contents/Resources/ sprintf(destName, "%s/Contents/Resources", appPath); createDirectory(destName); s_dataDir = destName; } } }
// global functions void set2dMode(MRenderingContext * render) { MWindow * window = MWindow::getInstance(); render->setViewport(0, 0, window->getWidth(), window->getHeight()); // set ortho projection render->setMatrixMode(M_MATRIX_PROJECTION); render->loadIdentity(); render->setOrthoView(0, (float)window->getWidth(), (float)window->getHeight(), 0, 1.0f, -1.0f); render->setMatrixMode(M_MATRIX_MODELVIEW); render->loadIdentity(); }
bool MozQOrientationSensorFilter::filter(QOrientationReading* reading) { switch (reading->orientation()) { //The Top edge of the device is pointing up. case QOrientationReading::TopDown: mWindowRotationAngle = 90; break; //The Top edge of the device is pointing down. case QOrientationReading::TopUp: mWindowRotationAngle = 270; break; //The Left edge of the device is pointing up. case QOrientationReading::LeftUp: mWindowRotationAngle = 180; break; //The Right edge of the device is pointing up. case QOrientationReading::RightUp: mWindowRotationAngle = 0; break; //The Face of the device is pointing up. case QOrientationReading::FaceUp: //The Face of the device is pointing down. case QOrientationReading::FaceDown: //The orientation is unknown. case QOrientationReading::Undefined: default: return true; } mWindowRotationTransform = QTransform(); mWindowRotationTransform.rotate(mWindowRotationAngle); #ifdef MOZ_ENABLE_MEEGOTOUCH if (XRE_GetProcessType() == GoannaProcessType_Default) { MWindow* window = MApplication::activeWindow(); if (window && window->sceneManager()) { window->sceneManager()-> setOrientationAngle((M::OrientationAngle)mWindowRotationAngle, MSceneManager::ImmediateTransition); } } #else Q_EMIT orientationChanged(); #endif return true; // don't store the reading in the sensor }
int DialogClone::do_image_partition() { MWindow window; QString befehl; QString _Datum_clone = window.Zeit_auslesen(); Qt::CheckState state; lbl_save->setText (tr("already saved", "bereits gesichert")); state = chk_zip->checkState(); flag_clone =3; if (img_partition_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a partition.", "Sie müssen eine Partition auswählen.\n")); return 0; } if (folder_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a folder.", "Sie müssen ein Verzeichnis auswählen.\n")); return 0; } partition_exist_size_int = img_partition_size.toInt(); // Überprüfen, ob System oder Home-Partition auf der Festplatte vorhanden ist int part_art_clone = mountpoint(img_partition_clone); if (part_art_clone == 1){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("On the hard drive exist a root or a home partition. You must need a live-CD.", "Auf der Festplatte ist eine root- oder home Partition. Sie müssen eine Live-CD benutzen.\n")); return 0; } if (state == Qt::Checked) befehl = "dd if=/dev/" + img_partition_clone + " | gzip --best > " + folder_clone + "/" + img_partition_clone + "-" + _Datum_clone + "-gz.part.fsa"; else befehl = "dd if=/dev/" + img_partition_clone + " of=" + folder_clone + "/" + img_partition_clone + "-" + _Datum_clone + "-part.fsa bs=1M 2>" + homepath + "/.config/qt5-fsarchiver/disk.txt"; thread1.setValues( 0,befehl); int ret = questionMessage(tr(" Do you want really built a image from a partition? ", " Wollen Sie wirklich ein Abbild einer Partition erstellen? ") ); if (ret == 2) return 0; if (ret == 1){ bt_end->setEnabled(false); bt_save->setEnabled(false); ViewProzent(); this->setCursor(Qt::WaitCursor); if (state == Qt::Checked){ read_write_hd(); startThread1(1); } else startThread1(0); qDebug() << "The image is created"; } return 0; }
void DialogDIR::esc_end() { MWindow window; QString befehl; if (thread_run_dir > 0) { int ret = questionMessage(tr("Do you want really break the save or restore from the folder?", "Wollen Sie wirklich die Sicherung oder Wiederherstellung der Verzeichnisse beenden?")); if (thread_run_dir == 1 && ret == 1) { flag_end_dir= 1; befehl = "rm " + SicherungsFolderFileName_dir; system (befehl.toLatin1().data()); if (window.bit_version() == "64") { thread1.terminate(); thread1.wait(); close(); } if (window.bit_version() == "32") { befehl = "kill -15 " + pid1_dir; //fsarchiver abbrechen system (befehl.toLatin1().data()); befehl = "kill -15 " + pid_dir; //fsarchiver abbrechen system (befehl.toLatin1().data()); close(); } } if (thread_run_dir == 2 && ret == 1 ) { flag_end_dir= 1; if (window.bit_version() == "64") { thread1.terminate(); thread1.wait(); close(); } if (window.bit_version() == "32") { befehl = "kill -15 " + pid1_dir; //fsarchiver abbrechen system (befehl.toLatin1().data()); befehl = "kill -15 " + pid_dir; //fsarchiver abbrechen system (befehl.toLatin1().data()); close(); } } } }
int MozQOrientationSensorFilter::GetWindowRotationAngle() { #ifdef MOZ_ENABLE_MEEGOTOUCH if (XRE_GetProcessType() == GoannaProcessType_Default) { MWindow* window = MApplication::activeWindow(); if (window) { M::OrientationAngle angle = window->orientationAngle(); if (mWindowRotationAngle != angle) { mWindowRotationAngle = angle; mWindowRotationTransform = QTransform(); mWindowRotationTransform.rotate(mWindowRotationAngle); } } } #endif return mWindowRotationAngle; }
void sh_lua_callback(MGuiEditText * editText, MGUI_EVENT_TYPE event) { MWindow * rootWindow = editText->getRootWindow(); if(event == MGUI_EVENT_ON_CHANGE) { sh_lua_syntax(editText->getText(), editText->getTextColoring()); } else if(event == MGUI_EVENT_MOUSE_BUTTON_DOWN && rootWindow->isMouseButtonPressed(MMOUSE_BUTTON_LEFT)) { if(rootWindow->getPreviousClicElapsedTime() <= 500) // double click { int charId = (int)editText->getCharId(); int begin, end; sh_select_word(editText->getText(), charId, &begin, &end); editText->setSelection(begin, end); } } }
void draw(void) { MWindow * window = MWindow::getInstance(); MEngine * engine = MEngine::getInstance(); MRenderingContext * render = engine->getRenderingContext(); MGame * game = engine->getGame(); // set basic viewport render->disableScissorTest(); render->setViewport(0, 0, window->getWidth(), window->getHeight()); if(game) { if(game->isRunning()) { game->draw(); } } window->swapBuffer(); }
void MaratisPlayer::loadGamePlugin(void) { char gameFile[256]; MWindow * window = MWindow::getInstance(); #ifdef WIN32 getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.dll"); #elif __APPLE__ getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.dylib"); #elif linux getGlobalFilename(gameFile, window->getWorkingDirectory(), "Game.so"); #endif // try to load any other plugins in the game directory first // as the game may expect these to be loaded vector<string> files; readDirectory(window->getWorkingDirectory(), &files); for(vector<string>::iterator iFile = files.begin(); iFile != files.end(); iFile++) { if(*iFile == gameFile) continue; #ifdef WIN32 if(iFile->find(".dll") != string::npos) #elif __APPLE__ if(iFile->find(".dylib") != string::npos) #elif linux if(iFile->find(".so") != string::npos) #endif { char pluginPath[256]; getGlobalFilename(pluginPath, window->getWorkingDirectory(), iFile->c_str()); MPlugin* plugin = new MPlugin(); plugin->load(pluginPath); if(plugin->getFilename()) m_plugins.push_back(plugin); else SAFE_DELETE(plugin); } } // After all other plugins are loaded, we can load the game // as we assume all prerequisites are loaded SAFE_DELETE(m_gamePlugin); m_gamePlugin = new MPlugin(); m_gamePlugin->load(gameFile); }
// screen void MWinContext::getScreenSize(unsigned int * width, unsigned int * height) { MWindow * window = MWindow::getInstance(); *width = window->getWidth(); *height = window->getHeight(); }
// cursor void MWinContext::setCursorPosition(int x, int y) { MWindow * window = MWindow::getInstance(); window->setCursorPos(window->getXPosition() + x, window->getYPosition() + y); }
// main int main(int argc, char **argv) { setlocale(LC_NUMERIC, "C"); unsigned int width = 800; unsigned int height = 400; bool fullscreen = false; // get engine MEngine* engine = MEngine::getInstance(); // get window MWindow* window = MWindow::getInstance(); window->setPointerEvent(windowEvents); // window events // create window if(! window->create("Maratis - ManualUse example", width, height, 32, fullscreen)) { MLOG(4, "window create failed"); return 0; } if(fullscreen) window->hideCursor(); // set current directory { char rep[256]; getRepertory(rep, argv[0]); window->setCurrentDirectory(rep); } // create virtual contexts MSoundContext * soundContext = new MALContext(); MRenderingContext * render = new MGLContext(); MPhysicsContext * physics = new MBulletContext(); MScriptContext * script = new MScript(); MInputContext * input = new MInput(); MSystemContext * system = new MWinContext(); MLOG(5, "Render version: " << render->getRendererVersion()); // create default Level and Game MLevel * level = new MLevel(); MGame * game = new MyGame(); // MyGame // init MEngine (you can replace all contexts by others and add or use different data loaders) engine->setSoundContext(soundContext); // sound context engine->setRenderingContext(render); // rendering context engine->setPhysicsContext(physics); // physics context engine->setScriptContext(script); // script context engine->setInputContext(input); // input context engine->setSystemContext(system); // system context engine->getImageLoader()->addLoader(M_loadImage); // image loader engine->getSoundLoader()->addLoader(M_loadSound); // sound loader // engine->getLevelLoader()->addLoader(xmlLevelLoad); // level loader : uncomment if wanted engine->getFontLoader()->addLoader(M_loadFont); // font loader // engine->getFontLoader()->addLoader(M_loadBinFont); // bin font loader : uncomment if wanted // add some default "Maratis" behaviors : uncomment if wanted or add custom // engine->getBehaviorManager()->addBehavior(MBLookAt::getStaticName(), M_OBJECT3D_CAMERA, MBLookAt::getNew); // engine->getBehaviorManager()->addBehavior(MBFollow::getStaticName(), M_OBJECT3D, MBFollow::getNew); // add renderers engine->getRendererManager()->addRenderer(MStandardRenderer::getStaticName(), MStandardRenderer::getNew); engine->getRendererManager()->addRenderer(MFixedRenderer::getStaticName(), MFixedRenderer::getNew); // mesh loader engine->getMeshLoader()->addLoader(xmlMeshLoad); engine->getArmatureAnimLoader()->addLoader(xmlArmatureAnimLoad); engine->getTexturesAnimLoader()->addLoader(xmlTextureAnimLoad); engine->getMaterialsAnimLoader()->addLoader(xmlMaterialAnimLoad); // set level engine->setLevel(level); // set game engine->setGame(game); // set renderer (standard) MRenderer * renderer = engine->getRendererManager()->getRendererByName("StandardRenderer")->getNewRenderer(); engine->setRenderer(renderer); // begin game game->begin(); // time unsigned int frequency = 60; unsigned long previousFrame = 0; unsigned long startTick = window->getSystemTick(); // on events while(window->isActive()) { // on events if(window->onEvents()) { // compute target tick unsigned long currentTick = window->getSystemTick(); unsigned long tick = currentTick - startTick; unsigned long frame = (unsigned long)(tick * (frequency * 0.001f)); // update elapsed time unsigned int i; unsigned int steps = (unsigned int)(frame - previousFrame); if(window->getFocus()) { // don't wait too much if(steps >= (frequency/2)) { update(); draw(); previousFrame += steps; continue; } // update for(i=0; i<steps; i++) { update(); previousFrame++; } // draw if(steps > 0){ draw(); } } else { previousFrame = frame; window->swapBuffer(); } } } MLOG(5, "ending game..."); game->end(); MLOG(5, "destroying renderer..."); renderer->destroy(); SAFE_DELETE(game); SAFE_DELETE(level); SAFE_DELETE(render); SAFE_DELETE(soundContext); SAFE_DELETE(physics); SAFE_DELETE(script); SAFE_DELETE(input); SAFE_DELETE(system); return 0; }
/*------------------------------------------------------------------------------*\ ( ) - \*------------------------------------------------------------------------------*/ void BmToolbar::UpdateLayout(bool recalcSizes) { if (LockLooper()) { // since we want the background tiles for the complete toolbar to appear // as one piece, we can't simply use the toolbar-background as view-bitmap // in all toolbar-buttons (horizontal wallpapering wouldn't work). // So, we render the complete wallpaper into a special bitmap, which is // then used by each toolbar-button when that creates its pictures. BRect rect = Bounds(); BmBitmapHandle* toolbarBackground = TheResources->IconByName("Toolbar_Background"); if (toolbarBackground) { delete mBackgroundBitmap; BView* view = new BView( rect, NULL, B_FOLLOW_NONE, 0); mBackgroundBitmap = new BBitmap( rect, B_RGBA32, true); mBackgroundBitmap->AddChild( view); mBackgroundBitmap->Lock(); float y=0.0; while(y < rect.Height()) { float x=0.0; while(x < rect.Width()) { view->DrawBitmap(toolbarBackground->bitmap, BPoint(x,y)); x += toolbarBackground->bitmap->Bounds().Width(); } y += toolbarBackground->bitmap->Bounds().Height(); } view->Sync(); mBackgroundBitmap->Unlock(); mBackgroundBitmap->RemoveChild(view); delete view; } // now step through all toolbar-buttons and let them create // their pictures: BView* group = ChildAt(0); if (group) { int32 count = group->CountChildren(); // Get maximum button size... float width=0, height=0; for( int32 c=0; c<count; ++c) { BmToolbarButton* tbb = dynamic_cast<BmToolbarButton*>(group->ChildAt(c)); if (tbb) BmToolbarButton::CalcMaxSize( width, height, tbb->Label().String(), tbb->NeedsLatch() ); } //...and layout all buttons according to this size: for( int32 c=0; c<count; ++c) { BmToolbarButton* tbb = dynamic_cast<BmToolbarButton*>(group->ChildAt(c)); if (tbb) tbb->CreateAllPictures(width, height); } MWindow* win = dynamic_cast<MWindow*>( Window()); if (win && recalcSizes) win->RecalcSize(); for( int32 c=0; c<count; ++c) group->ChildAt(c)->Invalidate(); } // FIXME: a little hackish, but we need to invalidate the whole window // anyway, since icons in other views will have changed, too. // Strangely enough, calling Invalidate() on the topmost child // doesn't work... Window()->ChildAt(0)->Hide(); Window()->ChildAt(0)->Show(); UnlockLooper(); } }
int DialogClone::do_image() { MWindow window; QString _Datum_clone = window.Zeit_auslesen(); QString befehl; int row; int pos; QString partition_exist; QString partition_exist_size; Qt::CheckState state; lbl_save->setText (tr("already saved", "bereits gesichert")); state = chk_zip->checkState(); flag_clone =2; row = listWidget_exist->currentRow(); if (row > -1){ partition_exist = part_clone[row][0] ; partition_exist_size = part_clone[row][1]; pos = partition_exist_size.indexOf("."); if (pos > 0) partition_exist_size = partition_exist_size.left(partition_exist_size.size() -2); partition_exist_size_int = partition_exist_size.toInt(); } partition_exist = partition_exist.left(partition_exist.size() -1); //qDebug() << "partition_exist_size_int" << partition_exist_size_int; //return 0; if (partition_exist == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a partition.", "Sie müssen eine Partition auswählen.\n")); return 0; } if (folder_clone == "" ){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("You must select a folder.", "Sie müssen ein Verzeichnis auswählen.\n")); return 0; } // Überprüfen, ob System oder Home-Partition auf der Festplatte vorhanden ist int part_art_clone = mountpoint(partition_exist); if (part_art_clone == 1){ QMessageBox::about(this, tr("Note", "Hinweis"), tr("On the hard drive exist a root or a home partition. You must need a live-CD.", "Auf der Festplatte ist eine root- oder home Partition. Sie müssen eine Live-CD benutzen.\n")); return 0; } partition_name = partition_exist.right(partition_exist.size() -4); if (state == Qt::Checked) befehl = "dd if=" + partition_exist + " | gzip --best > " + folder_clone + partition_name + "-" + _Datum_clone + ".gz.fsa"; else befehl = "dd if=" + partition_exist + " of=" + folder_clone + partition_name + "-" + _Datum_clone + ".img.fsa bs=1M 2>" + homepath + "/.config/qt5-fsarchiver/disk.txt"; thread1.setValues( 0,befehl); int ret = questionMessage(tr(" Do you want really built a image from the hard drive? ", " Wollen Sie wirklich ein Abbild der Festplatte erstellen? ") ); if (ret == 2) return 0; if (ret == 1){ bt_end->setEnabled(false); bt_save->setEnabled(false); ViewProzent(); this->setCursor(Qt::WaitCursor); if (state == Qt::Checked){ read_write_hd(); startThread1(1);} else startThread1(0); qDebug() << "The image is created"; } return 0; }
void MGuiWindow::draw(void) { MRenderingContext * render = MGui::getInstance()->getRenderingContext(); if(! isVisible()) return; MWindow * window = MWindow::getInstance(); rescaleScrollingBar(); render->enableScissorTest(); render->setScissor((int)getPosition().x, window->getHeight() - (int)getPosition().y - (unsigned int)getScale().y, (unsigned int)getScale().x, (unsigned int)getScale().y); // normal clear if((getNormalColor().w >= 1.0f) && (! hasNormalTexture())) { render->setClearColor(getNormalColor()); render->clear(M_BUFFER_COLOR); MGuiEvent guiEvent; guiEvent.type = MGUI_EVENT_DRAW; if(m_pointerEvent) m_pointerEvent(this, &guiEvent); // 2d mode set2dMode(render); render->disableDepthTest(); render->disableCullFace(); render->disableLighting(); render->enableBlending(); render->setBlendingMode(M_BLENDING_ALPHA); render->enableTexture(); } else { // background set2dMode(render); render->disableDepthTest(); render->disableCullFace(); render->disableLighting(); render->enableBlending(); render->setBlendingMode(M_BLENDING_ALPHA); if(hasNormalTexture()) // texture clear { render->enableTexture(); render->setColor4(getNormalColor()); drawTexturedQuad(getNormalTexture()); } else if(getNormalColor().w < 1.0f) { render->disableTexture(); render->setColor4(getNormalColor()); drawQuad(); } if(m_pointerEvent) { MGuiEvent guiEvent; guiEvent.type = MGUI_EVENT_DRAW; m_pointerEvent(this, &guiEvent); // 2d mode set2dMode(render); render->disableDepthTest(); render->disableCullFace(); render->disableLighting(); render->enableBlending(); render->setBlendingMode(M_BLENDING_ALPHA); render->enableTexture(); } } // gui render->pushMatrix(); render->translate(MVector3(getPosition().x, getPosition().y, 0)); render->pushMatrix(); render->translate(MVector3(getScroll().x, getScroll().y, 0)); // drawing unsigned int i; unsigned int oSize = m_objects.size(); for(i=0; i<oSize; i++) m_objects[i]->draw(); render->popMatrix(); // draw shadows if(hasShadow()) { render->disableScissorTest(); drawShadow(); render->enableScissorTest(); } // scolling slides if(isHorizontalScroll()) m_hScrollSlide.draw(); if(isVerticalScroll()) m_vScrollSlide.draw(); render->popMatrix(); }
// working directory const char * MWinContext::getWorkingDirectory(void) { MWindow * window = MWindow::getInstance(); return window->getWorkingDirectory(); }
// system tick unsigned long MWinContext::getSystemTick(void) { MWindow * window = MWindow::getInstance(); return window->getSystemTick(); }
bool MJapieApp::ProcessCommand( uint32 inCommand, const MMenu* inMenu, uint32 inItemIndex) { bool result = true; // MProject* project = MProject::Instance(); // if (project != nil and project->ProcessCommand(inCommand, inMenu, inItemIndex)) // return true; switch (inCommand) { case cmd_About: { MWindow* w = MWindow::GetFirstWindow(); GtkWidget* ww = nil; if (w != nil) ww = w->GetGtkWidget(); gtk_show_about_dialog(GTK_WINDOW(ww), "program_name", kAppName, "version", kVersionString, "copyright", "Copyright © 2007 Maarten L. Hekkelman", "comments", _("A simple development environment"), "website", "http://www.hekkelman.com/", nil); break; } case cmd_Preferences: MPrefsDialog::Create(); break; case cmd_Quit: if (not MSaverMixin::IsNavDialogVisible()) DoQuit(); break; case cmd_New: DoNew(); break; case cmd_Open: DoOpen(); break; case cmd_CloseAll: DoCloseAll(kSaveChangesClosingAllDocuments); break; case cmd_SaveAll: DoSaveAll(); break; // case cmd_ClearRecent: // DoClearRecent(); // break; // // case cmd_OpenRecent: // DoOpenRecent(inCommand); // break; case cmd_OpenTemplate: DoOpenTemplate(inMenu->GetItemLabel(inItemIndex)); break; case cmd_Find: MFindDialog::Instance().Select(); break; case cmd_FindInNextFile: MFindDialog::Instance().FindNext(); break; case cmd_OpenIncludeFile: new MFindAndOpenDialog(nil, nil); break; case cmd_Worksheet: ShowWorksheet(); break; // case cmd_ShowDiffWindow: // { // auto_ptr<MDiffWindow> w(new MDiffWindow); // w->Initialize(); // w->Show(); // w.release(); // break; // } // case 'DgTs': // { // auto_ptr<MDebuggerWindow> w(new MDebuggerWindow); // w->Initialize(); // w->Show(); // w.release(); // break; // } case cmd_SelectWindowFromMenu: DoSelectWindowFromWindowMenu(inItemIndex - 2); break; case 'test': break; case cmd_ShowDiffWindow: new MDiffWindow; break; default: result = false; break; } return result; }
bool MWindow::onEvents(void) { JOYCAPS caps; MWindow * window = MWindow::getInstance(); // joystick 1 if(joyGetDevCaps(JOYSTICKID1, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR) { JOYINFOEX joyinfo; MJoystick * joystick = window->getJoystick1(); joyinfo.dwSize = sizeof(JOYINFOEX); memset(&(joyinfo.dwFlags), 0, sizeof(JOYINFOEX) - sizeof(DWORD)); joyinfo.dwFlags = JOY_RETURNALL; joyGetPosEx(JOYSTICKID1, &joyinfo); updateJoystick(joystick, &caps, &joyinfo); MWinEvent events; events.type = MWIN_EVENT_JOYSTICK1_UPDATE; window->sendEvents(&events); joystick->flush(); } // joystick 2 if(joyGetDevCaps(JOYSTICKID2, &caps, sizeof(JOYCAPS)) == JOYERR_NOERROR) { JOYINFOEX joyinfo; MJoystick * joystick = window->getJoystick2(); joyinfo.dwSize = sizeof(JOYINFOEX); memset(&(joyinfo.dwFlags), 0, sizeof(JOYINFOEX) - sizeof(DWORD)); joyinfo.dwFlags = JOY_RETURNALL; joyGetPosEx(JOYSTICKID2, &joyinfo); updateJoystick(joystick, &caps, &joyinfo); MWinEvent events; events.type = MWIN_EVENT_JOYSTICK2_UPDATE; window->sendEvents(&events); joystick->flush(); } // mouse move event { POINT p; MWinEvent events; MMouse * mouse = MMouse::getInstance(); GetCursorPos(&p); p.x -= window->getXPosition(); p.y -= window->getYPosition(); int dx = p.x - mouse->getXPosition(); int dy = p.y - mouse->getYPosition(); if((dx != 0) || (dy != 0)) { mouse->setPosition(p.x, p.y); events.type = MWIN_EVENT_MOUSE_MOVE; events.data[0] = p.x; events.data[1] = p.y; window->sendEvents(&events); } } MSG msg; if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); return false; } return true; }
// main int main(int argc, char **argv) { setlocale(LC_NUMERIC, "C"); // get engine (first time call onstructor) MEngine * engine = MEngine::getInstance(); // get window (first time call onstructor) MWindow * window = MWindow::getInstance(); // create window window->create("Maratis", 1024,768, 32, false); // set current directory char rep[256]; getRepertory(rep, argv[0]); window->setCurrentDirectory(rep); // get Maratis (first time call onstructor) Maratis * maratis = Maratis::getInstance(); MRenderingContext * render = engine->getRenderingContext(); // init gui MGui * gui = MGui::getInstance(); gui->setRenderingContext(render); gui->addFont(new MGuiTextureFont("font/default.tga")); // init MaratisUI window->setPointerEvent(MaratisUI::windowEvents); // logo { MImage image; if(! M_loadImage("gui/Title.png", &image)) return 0; render->createTexture(&logoTextureId); render->bindTexture(logoTextureId); render->sendTextureImage(&image, false, false, false); // clear window draw(); MGuiText text("LOADING", MVector2(480, 280), 16, MVector4(1, 1, 1, 1)); text.draw(); window->swapBuffer(); } // load project if(argc > 1) { maratis->loadProject(argv[1]); } // time unsigned int frequency = 60; unsigned long previousFrame = 0; unsigned long startTick = window->getSystemTick(); int f = 0; int t = 0; // on events while(window->isActive()) { // on events if(window->onEvents()) { // compute target tick unsigned long currentTick = window->getSystemTick(); unsigned long tick = currentTick - startTick; unsigned long frame = (unsigned long)(tick * (frequency * 0.001f)); // update elapsed time unsigned int i; unsigned int steps = (unsigned int)(frame - previousFrame); if(window->getFocus()) { // don't wait too much if(steps >= (frequency/2)) { update(); draw(); previousFrame += steps; continue; } // update for(i=0; i<steps; i++) { update(); previousFrame++; t++; if(t == frequency) { MGame * game = engine->getGame(); if(game) { if(! game->isRunning()) MFilesUpdate::update(); } else { MFilesUpdate::update(); } //printf("fps:%d\n", f); t = 0; f = 0; } } // draw //if(steps > 0) { draw(); f++; } } else { previousFrame = frame; window->swapBuffer(); } } } gui->clear(); maratis->clear(); return 0; }
LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { MMouse * mouse = MMouse::getInstance(); MWindow * window = MWindow::getInstance(); MWinEvent events; if(window->isActive()) { switch(uMsg) { case WM_CREATE: { joySetCapture(hwnd, JOYSTICKID1, 0, FALSE); joySetCapture(hwnd, JOYSTICKID2, 0, FALSE); } break; case WM_KILLFOCUS: window->setFocus(false); break; case WM_SETFOCUS: window->setFocus(true); break; case WM_CLOSE: events.type = MWIN_EVENT_WINDOW_CLOSE; window->sendEvents(&events); return 0; case WM_DESTROY: { joyReleaseCapture(JOYSTICKID1); joyReleaseCapture(JOYSTICKID2); } break; case WM_SYSKEYDOWN: case WM_KEYDOWN: events.type = MWIN_EVENT_KEY_DOWN; events.data[0] = (int)wParam; window->sendEvents(&events); break; case WM_SYSKEYUP: case WM_KEYUP: events.type = MWIN_EVENT_KEY_UP; events.data[0] = (int)wParam; window->sendEvents(&events); break; case WM_SIZE: events.type = MWIN_EVENT_WINDOW_RESIZE; events.data[0] = (int)LOWORD(lParam); events.data[1] = (int)HIWORD(lParam); window->sendEvents(&events); break; case WM_MOVE: events.type = MWIN_EVENT_WINDOW_MOVE; events.data[0] = (int)(short)LOWORD(lParam); events.data[1] = (int)(short)HIWORD(lParam); window->sendEvents(&events); break; case WM_LBUTTONDOWN: SetCapture(hwnd); events.type = MWIN_EVENT_MOUSE_BUTTON_DOWN; events.data[0] = (int)MMOUSE_BUTTON_LEFT; window->sendEvents(&events); break; case WM_LBUTTONUP: ReleaseCapture(); events.type = MWIN_EVENT_MOUSE_BUTTON_UP; events.data[0] = (int)MMOUSE_BUTTON_LEFT; window->sendEvents(&events); break; case WM_CHAR: if(wParam == 8 || wParam == 32 || wParam == 13 || wParam == 9) // not return, space, delete etc.. break; events.type = MWIN_EVENT_CHAR; events.data[0] = (int)(char)wParam; window->sendEvents(&events); break; case WM_MBUTTONDOWN: SetCapture(hwnd); events.type = MWIN_EVENT_MOUSE_BUTTON_DOWN; events.data[0] = (int)MMOUSE_BUTTON_MIDDLE; window->sendEvents(&events); break; case WM_MBUTTONUP: ReleaseCapture(); events.type = MWIN_EVENT_MOUSE_BUTTON_UP; events.data[0] = (int)MMOUSE_BUTTON_MIDDLE; window->sendEvents(&events); break; case WM_RBUTTONDOWN: SetCapture(hwnd); events.type = MWIN_EVENT_MOUSE_BUTTON_DOWN; events.data[0] = (int)MMOUSE_BUTTON_RIGHT; window->sendEvents(&events); break; case WM_RBUTTONUP: ReleaseCapture(); events.type = MWIN_EVENT_MOUSE_BUTTON_UP; events.data[0] = (int)MMOUSE_BUTTON_RIGHT; window->sendEvents(&events); break; case WM_MOUSEWHEEL: events.type = MWIN_EVENT_MOUSE_WHEEL_MOVE; events.data[0] = CLAMP((int)((short)HIWORD(wParam) / (int)WHEEL_DELTA), -1, 1); window->sendEvents(&events); break; } } else { switch(uMsg) { case WM_NCPAINT: window->swapBuffer(); break; } } // Pass All unhandled Messages To DefWindowProc return DefWindowProc(hwnd, uMsg, wParam, lParam); }
// main int main(int argc, char **argv) { setlocale(LC_NUMERIC, "C"); char dir[256]; getDirectory(dir, argv[0]); MGUI_setCurrentDirectory(dir); // get engine MEngine *engine = MEngine::getInstance(); // init if (!MGUI_init()) return EXIT_FAILURE; // add loaders M_initFreeImage(); engine->getImageLoader()->addLoader(M_loadImage); // image loader //engine->getSoundLoader()->addLoader(M_loadSound); // sound loader //engine->getLevelLoader()->addLoader(xmlLevelLoad); // level loader : uncomment if wanted engine->getFontLoader()->addLoader(M_loadFont); // font loader //engine->getFontLoader()->addLoader(M_loadBinFont); // bin font loader : uncomment if wanted // mesh loader engine->getMeshLoader()->addLoader(xmlMeshLoad); engine->getArmatureAnimLoader()->addLoader(xmlArmatureAnimLoad); engine->getTexturesAnimLoader()->addLoader(xmlTextureAnimLoad); engine->getMaterialsAnimLoader()->addLoader(xmlMaterialAnimLoad); // create main window MWindow *window = MGUI_createWindow("Manual Use", 10, 10, 800, 600, winEvents); if (!window) { MGUI_close(); M_closeFreeImage(); return EXIT_FAILURE; } window->setDrawCallback(drawCallback); const float frequency = 60.0; double currentTick, startTick = MGUI_getTime(); unsigned int numFrame = 0; unsigned int currFrame = 0; unsigned int prevFrame = startTick * frequency; unsigned int steps, i; // update while (1) { ++numFrame; currentTick = MGUI_getTime(); if (currentTick - startTick >= 1.0) { startTick += 1.0; MLOG(6, "fps: " << numFrame << ", ft: " << 1000.0f / numFrame << "ms"); numFrame = 0; } currFrame = currentTick * frequency; steps = currFrame - prevFrame; prevFrame = currFrame; for (i = 0; i < steps; i++) game->update(); if (!MGUI_update()) break; } MGUI_close(); M_closeFreeImage(); return EXIT_SUCCESS; }