int main(int argc, char *argv[]) { char windowGroupId[64] = {0}; //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_cxt, 0); // Get the application's window group id so that it can be passed the identity library in cases // where a user may need to be interacted with on the application's behalf. screen_create_window(&screen_wnd, screen_cxt); screen_create_window_group( screen_wnd, NULL ); screen_get_window_property_cv( screen_wnd, SCREEN_PROPERTY_GROUP, sizeof( windowGroupId ), windowGroupId ); //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic if (EXIT_SUCCESS != initialize()) { fprintf(stderr, "initialize failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } if( EXIT_SUCCESS != identity_initialize( windowGroupId ) ) { fprintf(stderr, "Initialization of IDS Library failed\n"); bbutil_terminate(); screen_destroy_window(screen_wnd); screen_destroy_context(screen_cxt); return 0; } identity_trigger_get_username(); // ENTER APPLICATION EVENT LOOP while (!shutdown) { // Handle bps events, includes input and fd changes handle_events(); } identity_shutdown(); //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Use utility code to terminate EGL setup bbutil_terminate(); //Shut down BPS library for this process bps_shutdown(); screen_destroy_window(screen_wnd); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int Platform::enterMessagePump() { GP_ASSERT(_game); int rc; int eventType; int flags; int value; int position[2]; int domain; mtouch_event_t touchEvent; bool suspended = false; // Get the initial time. clock_gettime(CLOCK_REALTIME, &__timespec); __timeStart = timespec2millis(&__timespec); __timeAbsolute = 0L; _game->run(); // Message loop. while (true) { bps_event_t* event = NULL; while (true) { rc = bps_get_event(&event, 1); GP_ASSERT(rc == BPS_SUCCESS); if (event == NULL) break; domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { __screenEvent = screen_event_get_event(event); screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_TYPE, &eventType); switch (eventType) { case SCREEN_EVENT_MTOUCH_TOUCH: { screen_get_mtouch_event(__screenEvent, &touchEvent, 0); if (__gestureEventsProcessed.any()) rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL); if ( !rc && (__multiTouch || touchEvent.contact_id == 0) ) { gameplay::Platform::touchEventInternal(Touch::TOUCH_PRESS, touchEvent.x, touchEvent.y, touchEvent.contact_id); } break; } case SCREEN_EVENT_MTOUCH_RELEASE: { screen_get_mtouch_event(__screenEvent, &touchEvent, 0); if (__gestureEventsProcessed.any()) rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL); if ( !rc && (__multiTouch || touchEvent.contact_id == 0) ) { gameplay::Platform::touchEventInternal(Touch::TOUCH_RELEASE, touchEvent.x, touchEvent.y, touchEvent.contact_id); } if (__gestureSwipeRecognized) { __gestureSwipeRecognized = false; } break; } case SCREEN_EVENT_MTOUCH_MOVE: { screen_get_mtouch_event(__screenEvent, &touchEvent, 0); if (__gestureEventsProcessed.any()) rc = gestures_set_process_event(__gestureSet, &touchEvent, NULL); if ( !rc && (__multiTouch || touchEvent.contact_id == 0) ) { gameplay::Platform::touchEventInternal(Touch::TOUCH_MOVE, touchEvent.x, touchEvent.y, touchEvent.contact_id); } break; } case SCREEN_EVENT_POINTER: { static int mouse_pressed = 0; int buttons; int wheel; // A move event will be fired unless a button state changed. bool move = true; bool left_move = false; // This is a mouse move event, it is applicable to a device with a usb mouse or simulator. screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons); screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, position); screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel); // Handle left mouse. Interpret as touch if the left mouse event is not consumed. if (buttons & SCREEN_LEFT_MOUSE_BUTTON) { if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { left_move = true; } else { move = false; mouse_pressed |= SCREEN_LEFT_MOUSE_BUTTON; mouseOrTouchEvent(Mouse::MOUSE_PRESS_LEFT_BUTTON, Touch::TOUCH_PRESS, position[0], position[1]); } } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) { move = false; mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON; mouseOrTouchEvent(Mouse::MOUSE_RELEASE_LEFT_BUTTON, Touch::TOUCH_RELEASE, position[0], position[1]); } // Handle right mouse. if (buttons & SCREEN_RIGHT_MOUSE_BUTTON) { if ((mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) == 0) { move = false; mouse_pressed |= SCREEN_RIGHT_MOUSE_BUTTON; gameplay::Platform::mouseEventInternal(Mouse::MOUSE_PRESS_RIGHT_BUTTON, position[0], position[1], 0); } } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) { move = false; mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON; gameplay::Platform::mouseEventInternal(Mouse::MOUSE_RELEASE_RIGHT_BUTTON, position[0], position[1], 0); } // Handle middle mouse. if (buttons & SCREEN_MIDDLE_MOUSE_BUTTON) { if ((mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) == 0) { move = false; mouse_pressed |= SCREEN_MIDDLE_MOUSE_BUTTON; gameplay::Platform::mouseEventInternal(Mouse::MOUSE_PRESS_MIDDLE_BUTTON, position[0], position[1], 0); } } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) { move = false; mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON; gameplay::Platform::mouseEventInternal(Mouse::MOUSE_RELEASE_MIDDLE_BUTTON, position[0], position[1], 0); } // Fire a move event if none of the buttons changed. if (left_move) { mouseOrTouchEvent(Mouse::MOUSE_MOVE, Touch::TOUCH_MOVE, position[0], position[1]); } else if (move) { gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, position[0], position[1], 0); } // Handle mouse wheel events. if (wheel) { gameplay::Platform::mouseEventInternal(Mouse::MOUSE_WHEEL, position[0], position[1], -wheel); } break; } case SCREEN_EVENT_KEYBOARD: { screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags); screen_get_event_property_iv(__screenEvent, SCREEN_PROPERTY_KEY_SYM, &value); gameplay::Keyboard::KeyEvent evt = (flags & KEY_DOWN) ? gameplay::Keyboard::KEY_PRESS : gameplay::Keyboard::KEY_RELEASE; // Suppress key repeats. if ((flags & KEY_REPEAT) == 0) { keyEventInternal(evt, getKey(value)); if (evt == gameplay::Keyboard::KEY_PRESS && (flags & KEY_SYM_VALID)) { int unicode = getUnicode(value); if (unicode) keyEventInternal(gameplay::Keyboard::KEY_CHAR, unicode); } } break; } } } else if (domain == navigator_get_domain()) { switch (bps_event_get_code(event)) { case NAVIGATOR_SWIPE_DOWN: _game->menuEvent(); break; case NAVIGATOR_WINDOW_STATE: { navigator_window_state_t state = navigator_event_get_window_state(event); switch (state) { case NAVIGATOR_WINDOW_FULLSCREEN: _game->resume(); suspended = false; break; case NAVIGATOR_WINDOW_THUMBNAIL: case NAVIGATOR_WINDOW_INVISIBLE: if (!suspended) _game->pause(); suspended = true; break; } break; } case NAVIGATOR_EXIT: _game->exit(); break; } } else if (domain == sensor_get_domain()) { if (bps_event_get_code(event) == SENSOR_AZIMUTH_PITCH_ROLL_READING) { float azimuth; sensor_event_get_apr(event, &azimuth, &__pitch, &__roll); } } } // If we are done, then exit. if (_game->getState() == Game::UNINITIALIZED) break; if (!suspended) { _game->frame(); // Post the new frame to the display. // Note that there are a couple cases where eglSwapBuffers could fail // with an error code that requires a certain level of re-initialization: // // 1) EGL_BAD_NATIVE_WINDOW - Called when the surface we're currently using // is invalidated. This would require us to destroy our EGL surface, // close our OpenKODE window, and start again. // // 2) EGL_CONTEXT_LOST - Power management event that led to our EGL context // being lost. Requires us to re-create and re-initalize our EGL context // and all OpenGL ES state. // // For now, if we get these, we'll simply exit. rc = eglSwapBuffers(__eglDisplay, __eglSurface); if (rc != EGL_TRUE) { _game->exit(); perror("eglSwapBuffers"); break; } } } screen_stop_events(__screenContext); bps_shutdown(); screen_destroy_context(__screenContext); return 0; }
int main(int argc, char *argv[]) { int exit_application = 0; bps_initialize(); // Create and set up the app window. if (EXIT_FAILURE == setup_screen()) return EXIT_FAILURE; bbads_set_log_verbosity(2); // Display Banner on screen load_ad(screen_window, WINDOW_GROUP_NAME); screen_request_events(screen_context); navigator_request_events(0); /** * Handle keyboard events and stop playback upon user request. */ for (;;) { bps_event_t *event = 0; if (BPS_SUCCESS != bps_get_event(&event, -1)) { fprintf(stderr, "ERROR: Could not get BPS event!\n"); return EXIT_FAILURE; } if (event) { if (navigator_get_domain() == bps_event_get_domain(event)) { int code = bps_event_get_code(event); if (NAVIGATOR_EXIT == code) { if (BBADS_EOK != bbads_banner_destroy(ad_banner)) { fprintf(stderr, "cannot destroy banner"); } else { fprintf(stderr, "banner destroy"); } exit_application = 1; } } else if (bbads_get_domain() == bps_event_get_domain(event)) { bbads_banner_t* event_banner; bbads_event_get_banner(event, &event_banner); bbads_banner_event_type_t event_type = (bbads_banner_event_type_t)bps_event_get_code(event); banner_event_handler(event_banner, event_type); } else if (screen_get_domain() == bps_event_get_domain(event)) { int screen_val; char buf[1024]; int pos[2]; screen_event_t screen_event = screen_event_get_event(event); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val); screen_get_event_property_cv(screen_event, SCREEN_PROPERTY_ID_STRING, sizeof(buf), buf); screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos); switch (screen_val) { case SCREEN_EVENT_CREATE: fprintf(stderr, "create\n"); if (BBADS_EOK != bbads_banner_is_visible(ad_banner, &ad_is_visible)) { fprintf(stderr, "cannot get banner visibility"); } if (!ad_is_visible) { if (BBADS_EOK != bbads_banner_set_window_visible(ad_banner)) fprintf(stderr, "bbads_banner_set_window_visible has errors\n"); if (BBADS_EOK != bbads_banner_display(ad_banner, screen_context, event)) fprintf(stderr, "create cannot display banner\n"); } break; } if (exit_application) break; } } } screen_stop_events(screen_context); bps_shutdown(); if (screen_destroy_window(screen_window) != 0) return EXIT_FAILURE; if (screen_destroy_context(screen_context) != 0) return EXIT_FAILURE; screen_context = 0; screen_window = 0; return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int rc; int exit_application = 0; //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_cxt, 0); //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for rendering with GL ES 2.0 if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) { fprintf(stderr, "bbutil_init_egl failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Initialize application logic osg::setNotifyLevel(osg::DEBUG_INFO); // node: interesting geometry CTMcontext cContext; CTMuint vertCount,triCount; CTMuint const * indices; CTMfloat const * vertices; CTMfloat const * normals; cContext = ctmNewContext(CTM_IMPORT); ctmLoad(cContext,"app/native/models/cow.ctm"); if(ctmGetError(cContext) == CTM_NONE) { // access the mesh data vertCount = ctmGetInteger(cContext, CTM_VERTEX_COUNT); vertices = ctmGetFloatArray(cContext, CTM_VERTICES); triCount = ctmGetInteger(cContext, CTM_TRIANGLE_COUNT); indices = ctmGetIntegerArray(cContext, CTM_INDICES); std::cout << "# Mesh has " << vertCount << " vertices\n"; std::cout << "# Mesh has " << triCount << " triangles\n"; } else { std::cout << "Error Reading CTM File!" << std::endl; return -1; } // build up openscenegraph geometry osg::ref_ptr<osg::Vec3Array> listVxArray = new osg::Vec3Array(vertCount); unsigned int vxIdx=0; for(int i=0; i < listVxArray->size(); i++) { osg::Vec3 vertex; vertex.x() = vertices[vxIdx]; vxIdx++; vertex.y() = vertices[vxIdx]; vxIdx++; vertex.z() = vertices[vxIdx]; vxIdx++; listVxArray->at(i) = vertex; } osg::ref_ptr<osg::DrawElementsUInt> listIdxs = new osg::DrawElementsUInt(GL_TRIANGLES,triCount*3); for(int i=0; i < listIdxs->size(); i++) { listIdxs->at(i) = indices[i]; } osg::ref_ptr<osg::Geometry> geomMesh = new osg::Geometry; geomMesh->setVertexArray(listVxArray.get()); geomMesh->addPrimitiveSet(listIdxs.get()); osgUtil::SmoothingVisitor::smooth(*geomMesh); osg::ref_ptr<osg::Geode> geodeMesh = new osg::Geode; geodeMesh->addDrawable(geomMesh.get()); osg::ref_ptr<osg::Group> groupRoot = new osg::Group; groupRoot->addChild(geodeMesh.get()); // free ctm memory ctmFreeContext(cContext); // shader osg::StateSet *ss = geodeMesh->getOrCreateStateSet(); osg::ref_ptr<osg::Program> program = new osg::Program; program->setName( "simpleshader" ); program->addShader( new osg::Shader( osg::Shader::VERTEX, gVertexShader ) ); program->addShader( new osg::Shader( osg::Shader::FRAGMENT, gFragmentShader ) ); ss->setAttributeAndModes(program, osg::StateAttribute::ON); // ss->setMode(GL_DEPTH_TEST,osg::StateAttribute::ON); // ss->setAttributeAndModes(new osg::CullFace(osg::CullFace::FRONT), osg::StateAttribute::OFF); // ss->setAttributeAndModes(new osg::CullFace(osg::CullFace::BACK), osg::StateAttribute::ON); // rotate that cube osg::ref_ptr<osg::MatrixTransform> nodeSpin = new osg::MatrixTransform; nodeSpin->addChild(geodeMesh.get()); nodeSpin->addUpdateCallback(new osg::AnimationPathCallback(osg::Vec3(0,0,0), osg::Y_AXIS, osg::inDegrees(45.0f))); // node: root osg::ref_ptr<osg::Group> nodeRoot = new osg::Group; nodeRoot->addChild(nodeSpin.get()); // center point osg::BoundingBox modelBounds = geodeMesh->getBoundingBox(); // viewer osgViewer::Viewer myViewer; myViewer.setSceneData(nodeRoot.get()); myViewer.getCamera()->setViewMatrixAsLookAt(osg::Vec3((modelBounds.xMax()-modelBounds.xMin())*2, (modelBounds.yMax()-modelBounds.yMin())*2, (modelBounds.zMax()-modelBounds.zMin())*2), modelBounds.center(), osg::Vec3(0,1,0)); // graphics window embedded osg::ref_ptr<osgViewer::GraphicsWindowEmbedded> myWindow = new osgViewer::GraphicsWindowEmbedded(0,0,1024,600); myWindow->getState()->setUseModelViewAndProjectionUniforms(true); myWindow->getState()->setUseVertexAttributeAliasing(true); // setup viewer myViewer.getCamera()->setViewport(new osg::Viewport(0,0,1024,600)); myViewer.getCamera()->setGraphicsContext(myWindow.get()); myViewer.setThreadingModel(osgViewer::Viewer::SingleThreaded); //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); bps_shutdown(); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); bps_shutdown(); return 0; } //Signal BPS library that navigator orientation is not to be locked if (BPS_SUCCESS != navigator_rotation_lock(false)) { fprintf(stderr, "navigator_rotation_lock failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); bps_shutdown(); return 0; } while (!exit_application) { //Request and process all available BPS events bps_event_t *event = NULL; for(;;) { rc = bps_get_event(&event, 0); assert(rc == BPS_SUCCESS); if (event) { int domain = bps_event_get_domain(event); if (domain == screen_get_domain()) { handleScreenEvent(event); } else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { exit_application = 1; } } else { break; } } myViewer.frame(); bbutil_swap(); } //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
/** * A sample application that demonstrates the BlackBerry Native APIs for * making in-app purchases. The sample sets the connection mode to local, * allows the purchase of a digital good by using the swipe down gesture, * and displays any existing purchases. */ int main(int argc, char *argv[]) { int exit_application = 0; /* * Before we can listen for events from the BlackBerry Tablet OS platform * services, we need to initialize the BPS infrastructure */ bps_initialize(); /* * Initialize the screen so that the window group Id is properly set, to allow * the Payment Service dialogs to be displayed. */ if (setup_screen() != EXIT_SUCCESS) { fprintf(stderr, "Unable to initialize screen."); exit(0); } /* * Once the BPS infrastructure has been initialized we can register for * events from the various BlackBerry Tablet OS platform services. The * Navigator service manages and delivers application life cycle and * visibility events. * For this sample, we request Navigator events so that we can track when * the system is terminating the application (NAVIGATOR_EXIT event), and as a * convenient way to trigger a purchase request (NAVIGATOR_SWIPE_DOWN). * We request PaymentService events so we can be notified when the payment service * responds to our requests/queries. */ navigator_request_events(0); paymentservice_request_events(0); /* * Set the Payment Service connection mode to local. This allows us to * test the API without the need to contact the AppWorld nor payment servers. */ paymentservice_set_connection_mode(true); /* * Create a set of purchase parameters, which describe the digital good * to be purchased and the application the goods are associated with. */ const char* digital_good_id = "Digital-Good-1-ID"; const char* digital_good_name = "Sample Digital Good 1"; const char* digital_good_sku = "SAMPLE_DIGITAL_GOOD_SKU_1"; const char* metadata = "Sample purchase metadata"; const char* purchase_app_icon = "http://www.rim.com/products/appworld_3col.jpg"; const char* purchase_app_name = "Payment Service Sample App"; /* * Define a request ID to hold the returned value from the purchase request. */ unsigned request_id = 0; /* * initiate the application with a purchase of the sample digital good. */ if (paymentservice_purchase_request(digital_good_id, digital_good_sku, digital_good_name, metadata, purchase_app_name, purchase_app_icon, get_window_group_id(), &request_id) != BPS_SUCCESS) { fprintf(stderr, "Error: purchase request failed.\n"); } /* * Process Payment Service and Navigator events until we receive a NAVIGATOR_EXIT event. */ while (!exit_application) { /* * Using a negative timeout (-1) in the call to bps_get_event(...) * ensures that we don't busy wait by blocking until an event is * available. */ bps_event_t *event = NULL; bps_get_event(&event, -1); if (event) { /* * If it is a Payment Service event, determine the response code * and handle the event accordingly. */ if (bps_event_get_domain(event) == paymentservice_get_domain()) { if (SUCCESS_RESPONSE == paymentservice_event_get_response_code(event)) { if (PURCHASE_RESPONSE == bps_event_get_code(event)) { onPurchaseSuccess(event); unsigned request_id = 0; if (paymentservice_get_existing_purchases_request(false, get_window_group_id(), &request_id) != BPS_SUCCESS) { fprintf(stderr, "Error: get existing purchases failed.\n"); } } else onGetExistingPurchasesSuccess(event); } else { failureCommon(event); } } /* * If it is a NAVIGATOR_EXIT event then set the exit_application * flag so the application will stop processing events, clean up * and exit. * * If it is a NAVIGATOR_SWIPE_DOWN event, initiate the purchase of * the sample digital good. */ if (bps_event_get_domain(event) == navigator_get_domain()) { if (NAVIGATOR_EXIT == bps_event_get_code(event)) { exit_application = 1; } else if (NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) { if (paymentservice_purchase_request(digital_good_id, digital_good_sku, digital_good_name, metadata, purchase_app_name, purchase_app_icon, get_window_group_id(), &request_id) != BPS_SUCCESS) { fprintf(stderr, "Error: purchase request failed.\n"); } } } } } /* * Clean up the BPS infrastructure and exit */ bps_shutdown(); screen_destroy_window(screen_win); screen_destroy_context(screen_ctx); return 0; }
int main(int argc, char **argv) { int rc; #if USE_SKIA_OPENGL RENDERING_API api = GL_ES_2; #else RENDERING_API api = NATIVE; #endif //Create a screen context that will be used to create an EGL surface to to receive libscreen events screen_create_context(&screen_cxt, 0); //Initialize BPS library bps_initialize(); //Use utility code to initialize EGL for 2D rendering with GL ES 1.1 if (EXIT_SUCCESS != bbutil_init(screen_cxt, api)) { fprintf(stderr, "Unable to initialize rendering API\n"); screen_destroy_context(screen_cxt); return 0; } //Initialize app data if (EXIT_SUCCESS != init()) { fprintf(stderr, "Unable to initialize app logic\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator orientation is to be locked if (BPS_SUCCESS != navigator_rotation_lock(true)) { fprintf(stderr, "navigator_rotation_lock failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } //Signal BPS library that navigator and screen events will be requested if (BPS_SUCCESS != screen_request_events(screen_cxt)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } if (BPS_SUCCESS != navigator_request_events(0)) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_cxt); return 0; } static int counter = 0; for (;;) { //Request and process BPS next available event bps_event_t *event = NULL; rc = bps_get_event(&event, 0); assert(rc == BPS_SUCCESS); if (event) { if (bps_event_get_domain(event) == navigator_get_domain()) { if (bps_event_get_code(event) == NAVIGATOR_EXIT) { break; } } else if (bps_event_get_domain(event) == screen_get_domain()) { int type; int screenPos[2]; screen_event_t se = screen_event_get_event(event); screen_get_event_property_iv(se, SCREEN_PROPERTY_TYPE, &type); screen_get_event_property_iv(se, SCREEN_PROPERTY_POSITION, screenPos); /********************** BEGIN USER EVENT HANDLING CODE ***********************/ if (type == SCREEN_EVENT_MTOUCH_RELEASE) { if (screenPos[1] > height - 100) { if (screenPos[0] > width - 80) { currentIndex++; if (currentIndex > DemoFactory::demoCount() - 1) currentIndex = 0; } else if (screenPos[0] < 80) { currentIndex--; if (currentIndex < 0) currentIndex = DemoFactory::demoCount() - 1; } } } /*********************** END USER EVENT HANDLING CODE ************************/ } } render(); } delete canvas; #if USE_SKIA_OPENGL delete device; delete factory; #endif DemoFactory::deleteDemos(demos); //Stop requesting events from libscreen screen_stop_events(screen_cxt); //Shut down BPS library for this process bps_shutdown(); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_cxt); return 0; }
int main(int argc, char **argv) { int rc = 0; //Create a screen context that will be used to create an EGL surface to to receive libscreen events rc = screen_create_context(&screen_ctx, 0); if (BPS_SUCCESS != rc) { fprintf(stderr, "Failed to create context.\n"); return rc; } //Initialize BPS library rc = bps_initialize(); if (BPS_SUCCESS != rc) { fprintf(stderr, "Failed to initialize BPS.\n"); return rc; } //Use utility code to initialize EGL for rendering with GL ES 1.1 rc = bbutil_init_egl(screen_ctx); if (EXIT_SUCCESS != rc) { fprintf(stderr, "Unable to initialize EGL\n"); screen_destroy_context(screen_ctx); return rc; } //Initialize app data rc = init(); if (EXIT_SUCCESS != rc) { fprintf(stderr, "Unable to initialize app logic\n"); bbutil_terminate(); screen_destroy_context(screen_ctx); return rc; } //Signal BPS library that navigator and screen events will be requested rc = screen_request_events(screen_ctx); if (rc != screen_request_events(screen_ctx)) { fprintf(stderr, "screen_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_ctx); return rc; } rc = navigator_request_events(0); if (BPS_SUCCESS != rc) { fprintf(stderr, "navigator_request_events failed\n"); bbutil_terminate(); screen_destroy_context(screen_ctx); return rc; } for (;;) { //Request and process BPS next available event bps_event_t *event = NULL; if (BPS_SUCCESS != bps_get_event(&event, 0)) { fprintf(stderr, "bps_get_event failed\n"); break; } if ((event) && (bps_event_get_domain(event) == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event))) { break; } render(); } //Stop requesting events from libscreen screen_stop_events(screen_ctx); //Shut down BPS library for this process bps_shutdown(); //Destroy the font bbutil_destroy_font(font); //Use utility code to terminate EGL setup bbutil_terminate(); //Destroy libscreen context screen_destroy_context(screen_ctx); return rc; }