Example #1
0
bool ScreenWindow::pollEvent(WinEvent *event)
{
	bps_event_t *bpsEvent;
	bps_get_event(&bpsEvent, 0);
	if (bpsEvent) {
		int domain = bps_event_get_domain(bpsEvent);
		if (domain == navigator_get_domain()) {
			if (bps_event_get_code(bpsEvent) == NAVIGATOR_EXIT) {
				event->type = QUIT;
				return true;
			}
		} else if (domain == screen_get_domain()) {
			screen_event_t se = screen_event_get_event(bpsEvent);
			int type;
			screen_get_event_property_iv(se, SCREEN_PROPERTY_TYPE, &type);
			if (type == SCREEN_EVENT_CLOSE) {
				event->type = QUIT;
				return true;
			} else if (type == SCREEN_EVENT_MTOUCH_TOUCH) {
				event->type = MOUSEBUTTONDOWN;
				return true;
			}
		}
	}
	return false;
}
bool QQnxBpsEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
{
    Q_UNUSED(eventType);
    Q_UNUSED(result);
    bps_event_t *event = static_cast<bps_event_t *>(message);
    const int eventDomain = bps_event_get_domain(event);
    qBpsEventFilterDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << eventDomain;

    if (eventDomain == screen_get_domain()) {
        if (!m_screenEventHandler) {
            qWarning("QQNX: registered for screen events, but no handler provided.");
            return false;
        }

        screen_event_t screenEvent = screen_event_get_event(event);
        return m_screenEventHandler->handleEvent(screenEvent);
    }

    if (eventDomain == dialog_get_domain()) {
        dialog_instance_t nativeDialog = dialog_event_get_dialog_instance(event);
        QQnxFileDialogHelper *dialog = m_dialogMapper.value(nativeDialog, 0);
        if (dialog)
            return dialog->handleEvent(event);
    }

    if (eventDomain == navigator_get_domain())
        return handleNavigatorEvent(event);

    if (m_virtualKeyboard->handleEvent(event))
        return true;

    return false;
}
Example #3
0
File: main.c Project: PamC/VSPlugin
static void handleScreenEvent(bps_event_t *event) {
	int screen_val, buttons;
	int pair[2];

	static bool mouse_pressed = false;

	screen_event_t screen_event = screen_event_get_event(event);

	//Query type of screen event and its location on the screen
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,
			&screen_val);
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION,
			pair);

	//There is a difference between touch screen events and mouse events
	if (screen_val == SCREEN_EVENT_MTOUCH_RELEASE) {
		//This is touch screen event.
		add_cube((float) pair[0], (float) pair[1]);
	} else if (screen_val == SCREEN_EVENT_POINTER) {
		//This is a mouse move event, it is applicable to a device with a usb mouse or simulator
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS,
				&buttons);

		if (buttons == SCREEN_LEFT_MOUSE_BUTTON) {
			//Left mouse button is pressed
			mouse_pressed = true;
		} else {
			if (mouse_pressed) {
				//Left mouse button was released, add a cube
				add_cube((float) pair[0], (float) pair[1]);
				mouse_pressed = false;
			}
		}
	}
}
Example #4
0
void handleScreenEvent(bps_event_t *event) {
	screen_event_t screen_event = screen_event_get_event(event);

	int screen_val;
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,
			&screen_val);

	mtouch_event_t mtouch_event;
	int rc = screen_get_mtouch_event(screen_event, &mtouch_event, 0);
	if (rc) {
		//fprintf(stderr, "Error: failed to get mtouch event\n");
	}

	p = points.begin();
	bool found;
	found = false;

	while (p != points.end()) {
		if (p->id == mtouch_event.contact_id) {
			found = true;
			break;
		}
		p++;
	}

	switch (screen_val) {
	case SCREEN_EVENT_MTOUCH_TOUCH:

		if (!found) {

			Touchpoint *tp = new Touchpoint(mtouch_event.x, mtouch_event.y,
					mtouch_event.contact_id);
			if(mtouch_event.contact_id<4){
				tp->setColor(colors[mtouch_event.contact_id][0],colors[mtouch_event.contact_id][1],colors[mtouch_event.contact_id][2]);
			}
			points.push_back(*tp);
			fprintf(stderr,"neuer touchpoint: %i Orientation: %i \n",mtouch_event.contact_id,tp->startRotation);
		} else {
			p->updatePosition(mtouch_event.x, mtouch_event.y);
		}

		break;
	case SCREEN_EVENT_MTOUCH_MOVE:

		if (found) {
			p->updatePosition(mtouch_event.x, mtouch_event.y);
		} else {
			fprintf(stderr, "ERROR: TOUCH POINT NOT FOUND\n");
		}
		break;
	case SCREEN_EVENT_MTOUCH_RELEASE:
		if (found) {
			p->setInvisible();
		} else {
			fprintf(stderr, "ERROR: TOUCH POINT NOT FOUND\n");
		}
		break;
	}
}
Example #5
0
void handleScreenEvent(bps_event_t *event)
{
    screen_event_t screen_event = screen_event_get_event(event);
	mtouch_event_t mtouch_event;
    int screen_val;
    int position[2];
    int rc;

    screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

    switch (screen_val)
    {
		case SCREEN_EVENT_MTOUCH_TOUCH:
		case SCREEN_EVENT_MTOUCH_MOVE:
		case SCREEN_EVENT_MTOUCH_RELEASE:
            rc = screen_get_mtouch_event(screen_event, &mtouch_event, 0);
            if (rc)
                fprintf(stderr, "Error: failed to get mtouch event\n");

            rc = gestures_set_process_event(set, &mtouch_event, NULL);

            // No gesture detected, pass through
            if (!rc)
            {
            	if (screen_val == SCREEN_EVENT_MTOUCH_TOUCH)
            		MouseDown(mtouch_event.x, mtouch_event.y);
            	else if (screen_val == SCREEN_EVENT_MTOUCH_MOVE)
            		test->MouseMove(ConvertScreenToWorld(mtouch_event.x, mtouch_event.y));
            	else
            		test->MouseUp(ConvertScreenToWorld(mtouch_event.x, mtouch_event.y));
            }

			break;

		case SCREEN_EVENT_KEYBOARD:
			screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &screen_val);

			if (screen_val & KEY_DOWN)
			{
				screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &screen_val);

				if (screen_val >= ' ' && screen_val < '~')
				{
					Keyboard(screen_val, 0, 0);
				}
				else
				{
					screen_val = screen_val - 0xf000;
					Keyboard(screen_val, 0, 0);
				}
			}

			break;
    }
}
Example #6
0
static void
handle_screen_event(bps_event_t *event)
{
    int screen_val;

    screen_event_t screen_event = screen_event_get_event(event);
    screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

    switch (screen_val) {
    case SCREEN_EVENT_MTOUCH_TOUCH:
        fprintf(stderr,"Touch event\n");
        touch = true;
        break;
    case SCREEN_EVENT_MTOUCH_MOVE:
        fprintf(stderr,"Move event\n");
        break;
    case SCREEN_EVENT_MTOUCH_RELEASE:
        fprintf(stderr,"Release event\n");
        break;
    case SCREEN_EVENT_CREATE:
        // in a more involved application, it may be wise to actually check the window name to ensure
        // that we are processing the viewfinder window here, and not some other window
        if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void **)&vf_win) == -1) {
            perror("screen_get_event_property_pv(SCREEN_PROPERTY_WINDOW)");
        } else {
            fprintf(stderr,"viewfinder window found!\n");
            // mirror viewfinder if this is the front-facing camera
            int i = (shouldmirror?1:0);
            screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_MIRROR, &i);
            // place viewfinder in front of the black application background window.
            // note that a child window's ZORDER is relative to it's parent.
            // if we wanted to draw a UI on the application window, we could place the
            // viewfinder behind it and rely on transparency.  or alternately, another
            // child window could be overlaid on top of the viewfinder.
            i = +1;
            screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_ZORDER, &i);
            // make viewfinder window visible
            i = 1;
            screen_set_window_property_iv(vf_win, SCREEN_PROPERTY_VISIBLE, &i);
            screen_flush_context(screen_ctx, 0);
            // we should now have a visible viewfinder
            // other things we could do here include rotating the viewfinder window (screen rotation),
            // or adjusting the size & position of the window.
            // some properties are immutable for security reasons since the window was actually created
            // in another process.  anything related to presentation should be modifiable.
            touch = false;
            state = STATE_VIEWFINDER;
        }
        break;
    default:
        break;
    }
}
Example #7
0
void handleScreenEvent(bps_event_t *event) {
    screen_event_t screen_event = screen_event_get_event(event);

    int screen_val;
    screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

    switch (screen_val) {
    case SCREEN_EVENT_MTOUCH_TOUCH:
    case SCREEN_EVENT_MTOUCH_MOVE:
    case SCREEN_EVENT_MTOUCH_RELEASE:
        break;
    }
}
Example #8
0
void handleScreenEvent(bps_event_t *event)
{
	screen_event_t screen_event = screen_event_get_event(event);

	int screen_val;
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

	switch (screen_val) {
	case SCREEN_EVENT_KEYBOARD:
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &screen_val);

		if (screen_val & KEY_DOWN) {
			screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM,&screen_val);

			printf("The '%c' key was pressed\n", (char)screen_val);
			fflush(stdout);

			switch (screen_val) {
			case KEYCODE_I:
				// Display the email layout with "Send" enter key
				virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_EMAIL, VIRTUALKEYBOARD_ENTER_SEND);
				break;
			case KEYCODE_O:
				// Display the phone layout with "Connect" enter key
				virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_PHONE, VIRTUALKEYBOARD_ENTER_CONNECT);
				break;
			case KEYCODE_P:
				// Display the default layout with default enter key
				virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_DEFAULT, VIRTUALKEYBOARD_ENTER_DEFAULT);
				break;
			case KEYCODE_H:
				// Hide the keyboard
				virtualkeyboard_hide();
				break;
			case KEYCODE_A:
				// Increment rotation angle
				angle = fmod(angle + ANGLE_INCREMENT, CIRCLE_DEGREES );
				break;
			case KEYCODE_Z:
				// Decrement rotation angle
				angle = fmod(angle - ANGLE_INCREMENT, CIRCLE_DEGREES );
				break;
			default:
				break;
			}
		}
		break;
	}
}
void MinutesPerGameRenderer::screenEvent(bps_event_t *event)
{
    screen_event_t screen_event = screen_event_get_event(event);

    int screen_val;
    screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

    switch (screen_val) {
    case SCREEN_EVENT_MTOUCH_TOUCH:
    case SCREEN_EVENT_MTOUCH_RELEASE:
        break;
    case SCREEN_EVENT_MTOUCH_MOVE:
        break;
    }
}
Example #10
0
static void gfx_ctx_check_window(bool *quit,
      bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
   (void)frame_count;
   //Request and process all available BPS events
   bps_event_t *event = NULL;

   bps_get_event(&event, 0);

   *quit = false;

   unsigned new_width, new_height;
   gfx_ctx_get_video_size(&new_width, &new_height);
   if (new_width != *width || new_height != *height)
   {
      *width  = new_width;
      *height = new_height;
      *resize = true;
   }

   if (event)
   {
      int domain = bps_event_get_domain(event);

      if (domain == screen_get_domain())
      {
         screen_event_t screen_event = screen_event_get_event(event);
         int screen_val;
         screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);
         switch (screen_val) {

            case SCREEN_EVENT_MTOUCH_TOUCH:
            case SCREEN_EVENT_MTOUCH_MOVE:
            case SCREEN_EVENT_MTOUCH_RELEASE:

               break;
         }
      }
      else if ((domain == navigator_get_domain()) && (NAVIGATOR_EXIT == bps_event_get_code(event)))
         g_extern.lifecycle_state |= (1ULL << RARCH_QUIT_KEY);
   }

   // Check if we are exiting.
   if (g_extern.lifecycle_state & (1ULL << RARCH_QUIT_KEY))
      *quit = true;
}
Example #11
0
int NativeWindow::screenDisplayAttached(bps_event_t *event, int *size)
{
    screen_display_t eventDisplay;
    int type;
    int attached = -1;

    screen_event_t screen_event = screen_event_get_event(event);

    //Query type of screen event and its location on the screen
    screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,
            &type);

    _displaysMutex.lock();

    if (_screenDisplays) {
    	free (_screenDisplays);
    }

	// try this first as it will fail if an HDMI display is not attached
	screen_get_context_property_iv(_screenContext, SCREEN_PROPERTY_DISPLAY_COUNT, &_numberDisplays);

	_screenDisplays = (screen_display_t *)calloc(_numberDisplays, sizeof(screen_display_t));
	screen_get_context_property_pv(_screenContext, SCREEN_PROPERTY_DISPLAYS, (void **)_screenDisplays);

	switch (type) {
		case SCREEN_EVENT_DISPLAY:
			screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DISPLAY, (void **)&eventDisplay);
			for (int index = 0; index < _numberDisplays; index++) {
				if (eventDisplay == _screenDisplays[index]) {
					screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ATTACHED, &attached);

					if (attached) {
						screen_get_display_property_iv(_screenDisplays[index], SCREEN_PROPERTY_SIZE, size);
						if (size[0] == 0 || size[1] == 0) {
							attached = 0;
						}
					}
				}
			}
			break;
	}

    _displaysMutex.unlock();

	return attached;
}
Example #12
0
static void event(bps_event_t *event, int domain, int code, void *data)
{
  if(domain == screen_get_domain())
  {
    screen_event_t screenEvent = screen_event_get_event(event);

    int eventType;
    screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType);

    if(eventType == SCREEN_EVENT_MTOUCH_TOUCH/* || eventType == SCREEN_EVENT_MTOUCH_MOVE*/)
    {
      int pair[2];
      screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, pair);

      Game::OnScreenTouch(pair[0], pair[1]);
    }
  }
}
void BbVideoWindowControl::bpsEventHandler(bps_event_t *event)
{
    if (event && bps_event_get_domain(event) == screen_get_domain()) {
        const screen_event_t screen_event = screen_event_get_event(event);

        int eventType;
        if (screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType) != 0) {
            perror("BbVideoWindowControl: Failed to query screen event type");
            return;
        }

        if (eventType != SCREEN_EVENT_CREATE)
            return;

        screen_window_t window = 0;
        if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0) {
            perror("BbVideoWindowControl: Failed to query window property");
            return;
        }

        const int maxIdStrLength = 128;
        char idString[maxIdStrLength];
        if (screen_get_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, maxIdStrLength, idString) != 0) {
            perror("BbVideoWindowControl: Failed to query window ID string");
            return;
        }

        if (m_windowName == idString) {
            m_window = window;
            updateVideoPosition();

            const int visibleFlag = 1;
            if (screen_set_window_property_iv(m_window, SCREEN_PROPERTY_VISIBLE, &visibleFlag) != 0) {
                perror("BbVideoWindowControl: Failed to make window visible");
                return;
            }
        }
    }
}
Example #14
0
bool WindowGrabber::nativeEventFilter(const QByteArray&, void *message, long*)
{
    bps_event_t * const event = static_cast<bps_event_t *>(message);

    if (event && bps_event_get_domain(event) == screen_get_domain()) {
        const screen_event_t screen_event = screen_event_get_event(event);

        int eventType;
        if (screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType) != 0) {
            qWarning() << "WindowGrabber: Failed to query screen event type";
            return false;
        }

        if (eventType != SCREEN_EVENT_CREATE)
            return false;

        screen_window_t window = 0;
        if (screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&window) != 0) {
            qWarning() << "WindowGrabber: Failed to query window property";
            return false;
        }

        const int maxIdStrLength = 128;
        char idString[maxIdStrLength];
        if (screen_get_window_property_cv(window, SCREEN_PROPERTY_ID_STRING, maxIdStrLength, idString) != 0) {
            qWarning() << "WindowGrabber: Failed to query window ID string";
            return false;
        }

        if (m_windowId == idString) {
            m_window = window;
            start();
        }
    }

    return false;
}
Example #15
0
void OSBB10::handle_screen_event(bps_event_t *event) {

	screen_event_t screen_event = screen_event_get_event(event);

	int screen_val;
	screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

	int pos[2];

	switch (screen_val) {
	case SCREEN_EVENT_MTOUCH_TOUCH:
	case SCREEN_EVENT_MTOUCH_RELEASE: {

		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos);

		InputEvent ievent;
		ievent.type = InputEvent::SCREEN_TOUCH;
		ievent.ID = ++last_id;
		ievent.device = 0;
		ievent.screen_touch.pressed = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH);
		ievent.screen_touch.x = pos[0];
		ievent.screen_touch.y = pos[1];
		Point2 mpos(ievent.screen_touch.x, ievent.screen_touch.y);

		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pos[0]);
		ievent.screen_touch.index = pos[0];

		last_touch_x[pos[0]] = ievent.screen_touch.x;
		last_touch_y[pos[0]] = ievent.screen_touch.y;

		input->parse_input_event( ievent );

		if (ievent.screen_touch.index == 0) {

			InputEvent ievent;
			ievent.type = InputEvent::MOUSE_BUTTON;
			ievent.ID = ++last_id;
			ievent.device = 0;
			ievent.mouse_button.pressed = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH);
			ievent.mouse_button.button_index = BUTTON_LEFT;
			ievent.mouse_button.doubleclick = 0;
			ievent.mouse_button.x = ievent.mouse_button.global_x = mpos.x;
			ievent.mouse_button.y = ievent.mouse_button.global_y = mpos.y;
			input->parse_input_event( ievent );
		};


	} break;
	case SCREEN_EVENT_MTOUCH_MOVE: {

		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_POSITION, pos);

		InputEvent ievent;
		ievent.type = InputEvent::SCREEN_DRAG;
		ievent.ID = ++last_id;
		ievent.device = 0;
		ievent.screen_drag.x = pos[0];
		ievent.screen_drag.y = pos[1];

		/*
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pos);
		ievent.screen_drag.relative_x = ievent.screen_drag.x - pos[0];
		ievent.screen_drag.relative_y = ievent.screen_drag.y - pos[1];
		*/

		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pos[0]);
		ievent.screen_drag.index = pos[0];


		ievent.screen_drag.relative_x = ievent.screen_drag.x - last_touch_x[ievent.screen_drag.index];
		ievent.screen_drag.relative_y = ievent.screen_drag.y - last_touch_y[ievent.screen_drag.index];

		last_touch_x[ievent.screen_drag.index] = ievent.screen_drag.x;
		last_touch_y[ievent.screen_drag.index] = ievent.screen_drag.y;

		Point2 mpos(ievent.screen_drag.x, ievent.screen_drag.y);
		Point2 mrel(ievent.screen_drag.relative_x, ievent.screen_drag.relative_y);

		input->parse_input_event( ievent );

		if (ievent.screen_touch.index == 0) {

			InputEvent ievent;
			ievent.type = InputEvent::MOUSE_MOTION;
			ievent.ID = ++last_id;
			ievent.device = 0;
			ievent.mouse_motion.x = ievent.mouse_motion.global_x = mpos.x;
			ievent.mouse_motion.y = ievent.mouse_motion.global_y = mpos.y;
			input->set_mouse_pos(Point2(ievent.mouse_motion.x,ievent.mouse_motion.y));
			ievent.mouse_motion.speed_x=input->get_last_mouse_speed().x;
			ievent.mouse_motion.speed_y=input->get_last_mouse_speed().y;
			ievent.mouse_motion.relative_x = mrel.x;
			ievent.mouse_motion.relative_y = mrel.y;
			ievent.mouse_motion.button_mask = 1; // pressed

			input->parse_input_event( ievent );
		};
	} break;

	case SCREEN_EVENT_KEYBOARD: {

		InputEvent ievent;
		ievent.type = InputEvent::KEY;
		ievent.ID = ++last_id;
		ievent.device = 0;
		int val = 0;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SCAN, &val);
		ievent.key.scancode = val;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &val);
		ievent.key.unicode = val;
		if (val == 61448) {
			ievent.key.scancode = KEY_BACKSPACE;
			ievent.key.unicode = KEY_BACKSPACE;
		};
		if (val == 61453) {
			ievent.key.scancode = KEY_ENTER;
			ievent.key.unicode = KEY_ENTER;
		};

		int flags;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &flags);
		ievent.key.pressed = flags & 1; // bit 1 is pressed apparently

		int mod;
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_MODIFIERS, &mod);

		input->parse_input_event( ievent );
	} break;

	default:
		break;

	}
};
Example #16
0
void BlackberryMain::runMain() {
	bool running = true;
	while (running && !g_quitRequested) {
		input_state.mouse_valid = false;
		input_state.accelerometer_valid = false;
		while (true) {
			// Handle Blackberry events
			bps_event_t *event = NULL;
			bps_get_event(&event, 0);
			if (event == NULL)
				break; // Ran out of events
			int domain = bps_event_get_domain(event);
			if (domain == screen_get_domain()) {
				handleInput(screen_event_get_event(event));
			} else if (domain == navigator_get_domain()) {
				switch(bps_event_get_code(event))
				{
				case NAVIGATOR_INVOKE_TARGET:
					{
						const navigator_invoke_invocation_t *invoke = navigator_invoke_event_get_invocation(event);
						if(invoke) {
							boot_filename = navigator_invoke_invocation_get_uri(invoke)+7; // Remove file://
						}
					}
					break;
				case NAVIGATOR_ORIENTATION:
					sensor_remap_coordinates(navigator_event_get_orientation_angle(event));
					break;
				case NAVIGATOR_BACK:
				case NAVIGATOR_SWIPE_DOWN:
					NativeKey(KeyInput(DEVICE_ID_KEYBOARD, NKCODE_ESCAPE, KEY_DOWN));
					break;
				case NAVIGATOR_EXIT:
					return;
				}
			} else if (domain == sensor_get_domain()) {
				if (SENSOR_ACCELEROMETER_READING == bps_event_get_code(event)) {
					sensor_event_get_xyz(event, &(input_state.acc.y), &(input_state.acc.x), &(input_state.acc.z));
					AxisInput axis;
					axis.deviceId = DEVICE_ID_ACCELEROMETER;
					axis.flags = 0;

					axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_X;
					axis.value = input_state.acc.x;
					NativeAxis(axis);

					axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Y;
					axis.value = input_state.acc.y;
					NativeAxis(axis);

					axis.axisId = JOYSTICK_AXIS_ACCELEROMETER_Z;
					axis.value = input_state.acc.z;
					NativeAxis(axis);
				}
			}
		}
		UpdateInputState(&input_state);
		NativeUpdate(input_state);
		// Work in Progress
		// Currently: Render to HDMI port (eg. 1080p) when in game. Render to device when in menu.
		// Idea: Render to all displays. Controls go to internal, game goes to external(s).
		if (GetUIState() == UISTATE_INGAME && !emulating) {
			emulating = true;
			switchDisplay(screen_emu);
			if (g_Config.iShowFPSCounter == 4) {
				int options = SCREEN_DEBUG_STATISTICS;
				screen_set_window_property_iv(screen_win[0], SCREEN_PROPERTY_DEBUG, &options);
			}
		} else if (GetUIState() != UISTATE_INGAME && emulating) {
			emulating = false;
			switchDisplay(screen_ui);
		}
		NativeRender();
		EndInputState(&input_state);
		time_update();
		// This handles VSync
		if (emulating)
			eglSwapBuffers(egl_disp[screen_emu], egl_surf[screen_emu]);
		else
			eglSwapBuffers(egl_disp[screen_ui], egl_surf[screen_ui]);
	}
}
Example #17
0
int main(int argc, char *argv[])
{
    int rc;
    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;
}
Example #18
0
// Entry Point
int main(int argc, char *argv[]) {
	static screen_context_t screen_cxt;
	// Receive events from window manager
	screen_create_context(&screen_cxt, 0);
	//Initialise Blackberry Platform Services
	bps_initialize();

	net::Init();
	init_GLES2(screen_cxt);
#ifdef BLACKBERRY10
	// Dev Alpha: 1280x768, 4.2", 356DPI, 0.6f scale
	int dpi;
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_DPI, &dpi);
#else
	// Playbook: 1024x600, 7", 170DPI, 1.25f scale
	int screen_phys_size[2];
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_PHYSICAL_SIZE, screen_phys_size);
	int screen_resolution[2];
	screen_get_display_property_iv(screen_disp, SCREEN_PROPERTY_SIZE, screen_resolution);
	double diagonal_pixels = sqrt(screen_resolution[0] * screen_resolution[0] + screen_resolution[1] * screen_resolution[1]);
    double diagonal_inches = 0.0393700787 * sqrt(screen_phys_size[0] * screen_phys_size[0] + screen_phys_size[1] * screen_phys_size[1]);
	int dpi = (int)(diagonal_pixels / diagonal_inches + 0.5);
#endif
	float dpi_scale = 213.6f / dpi;
	dp_xres = (int)(pixel_xres * dpi_scale); dp_yres = (int)(pixel_yres * dpi_scale);

	NativeInit(argc, (const char **)argv, "data/", "/accounts/1000/shared", "BADCOFFEE");
	NativeInitGraphics();
	screen_request_events(screen_cxt);
	navigator_request_events(0);
	dialog_request_events(0);
#ifdef BLACKBERRY10
	vibration_request_events(0);
#endif
	BlackberryAudio* audio = new BlackberryAudio();
	InputState input_state;
	bool running = true;
	while (running) {
		input_state.mouse_valid = false;
		input_state.accelerometer_valid = false;
		SimulateGamepad(&input_state);
		while (true) {
			// Handle Blackberry events
			bps_event_t *event = NULL;
			bps_get_event(&event, 0);
			if (event == NULL)
				break; // Ran out of events
			int domain = bps_event_get_domain(event);
			if (domain == screen_get_domain()) {
				int screen_val, buttons, pointerId;
				int pair[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_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pair);
				screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID, &pointerId);

				input_state.mouse_valid = true;
				switch(screen_val)
				{
				// Touchscreen
				case SCREEN_EVENT_MTOUCH_TOUCH:
				case SCREEN_EVENT_MTOUCH_RELEASE: 	// Up, down
					input_state.pointer_down[pointerId] = (screen_val == SCREEN_EVENT_MTOUCH_TOUCH);
				case SCREEN_EVENT_MTOUCH_MOVE:
					input_state.pointer_x[pointerId] = pair[0] * dpi_scale;
					input_state.pointer_y[pointerId] = pair[1] * dpi_scale;
					break;
				// Mouse, Simulator
    			case SCREEN_EVENT_POINTER:
					screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS,
						&buttons);
					if (buttons == SCREEN_LEFT_MOUSE_BUTTON) { 			// Down
						input_state.pointer_x[pointerId] = pair[0] * dpi_scale;
						input_state.pointer_y[pointerId] = pair[1] * dpi_scale;
						input_state.pointer_down[pointerId] = true;
					} else if (input_state.pointer_down[pointerId]) {	// Up
						input_state.pointer_x[pointerId] = pair[0] * dpi_scale;
						input_state.pointer_y[pointerId] = pair[1] * dpi_scale;
						input_state.pointer_down[pointerId] = false;
					}
					break;
				// Keyboard
				case SCREEN_EVENT_KEYBOARD:
					int flags, value;
					screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &flags);
					screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &value);
					if (flags & (KEY_DOWN | KEY_SYM_VALID)) {
						for (int b = 0; b < 14; b++) {
							if (value == buttonMappings[b])
								input_state.pad_buttons |= (1<<b);
						}
					}
					break;
				}
			} else if (domain == navigator_get_domain()) {
				switch(bps_event_get_code(event))
				{
				case NAVIGATOR_BACK:
				case NAVIGATOR_SWIPE_DOWN:
					input_state.pad_buttons |= PAD_BUTTON_MENU;
					break;
				case NAVIGATOR_EXIT:
					running = false;
					break;
				}
			}
		}
		UpdateInputState(&input_state);
		NativeUpdate(input_state);
		EndInputState(&input_state);
		NativeRender();
		// On Blackberry, this handles VSync for us
		eglSwapBuffers(egl_disp, egl_surf);
	}

	screen_stop_events(screen_cxt);
	bps_shutdown();

	NativeShutdownGraphics();
	delete audio;
	NativeShutdown();
	kill_GLES2();
	net::Shutdown();
	screen_destroy_context(screen_cxt);
	exit(0);
	return 0;
}
Example #19
0
static void handle_screen_event(bps_event_t *event)
{
   int type;

   screen_event_t screen_event = screen_event_get_event(event);
   screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &type);

   switch(type)
   {
      case SCREEN_EVENT_MTOUCH_TOUCH:
      case SCREEN_EVENT_MTOUCH_RELEASE:
      case SCREEN_EVENT_MTOUCH_MOVE:
         process_touch_event(screen_event, type);
         break;
      case SCREEN_EVENT_KEYBOARD:
         process_keyboard_event(screen_event, type);
         break;
#ifdef HAVE_BB10
      case SCREEN_EVENT_GAMEPAD:
      case SCREEN_EVENT_JOYSTICK:
         process_gamepad_event(screen_event, type);
         break;
      case SCREEN_EVENT_DEVICE:
         {
            // A device was attached or removed.
            screen_device_t device;
            int attached;
            int type;

            screen_get_event_property_pv(screen_event,
                  SCREEN_PROPERTY_DEVICE, (void**)&device);
            screen_get_event_property_iv(screen_event,
                  SCREEN_PROPERTY_ATTACHED, &attached);

            if (attached)
               screen_get_device_property_iv(device,
                     SCREEN_PROPERTY_TYPE, &type);

            int i;

            if (attached && (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK || type == SCREEN_EVENT_KEYBOARD))
            {
               for (i = 0; i < MAX_PADS; ++i)
               {
                  if (!devices[i].handle)
                  {
                     devices[i].handle = device;
                     loadController(&devices[i]);
                     break;
                  }
               }
            }
            else
            {
               for (i = 0; i < MAX_PADS; ++i)
               {
                  if (device == devices[i].handle)
                  {
                     RARCH_LOG("Device %s: Disconnected.\n", devices[i].id);
                     initController(&devices[i]);
                     break;
                  }
               }
            }
         }
         break;
#endif
      default:
         break;
   }
}
Example #20
0
void zaAppBase::dispatchevent(bps_event_t *event)
{
	int domain = bps_event_get_domain(event);
	if (domain == screen_get_domain())
	{
		int screen_val;
		int pair[2];
		int id;
		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_iv(screen_event,
				SCREEN_PROPERTY_SOURCE_POSITION, pair);
		screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TOUCH_ID,
				&id);

		if (screen_val >= SCREEN_EVENT_MTOUCH_TOUCH
				&& screen_val <= SCREEN_EVENT_MTOUCH_RELEASE
				&& (id == 0 || m_multitouch))
		{
			e.m_id = id;
			e.m_type = screen_val;
			e.m_x = pair[0];
			e.m_y = m_height - pair[1];
			// e.m_obj
			m_active->processEvent(&e);
		}
		else if (screen_val == SCREEN_EVENT_KEYBOARD)
		{
			int key_status;
			screen_get_event_property_iv(screen_event,
					SCREEN_PROPERTY_KEY_FLAGS, &key_status);
			if (key_status & KEY_DOWN)
			{
				int key_code;
				screen_get_event_property_iv(screen_event,
						SCREEN_PROPERTY_KEY_SYM, &key_code);
				e.m_type = screen_val;
				e.m_keycode = key_code;
				m_active->processEvent(&e);
			}
		}
		else if (screen_val == SCREEN_EVENT_POINTER)
		{
			int buttons;
			static int mouse_pressed = false;
			screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS,
					&buttons);
			e.m_event = 0;
			e.m_x = pair[0];
			e.m_y = m_height - pair[1];
			e.m_id = id;

			if (buttons == SCREEN_LEFT_MOUSE_BUTTON && mouse_pressed == false)
			{
				mouse_pressed = true;
				e.m_type = 100; //down
			}
			else if (mouse_pressed && buttons == SCREEN_LEFT_MOUSE_BUTTON)
			{
				e.m_type = 101; //move
			}
			else if (mouse_pressed)
			{
				fprintf(stderr,"2222222  btn %d, x %d ,y  %d \n", buttons,e.m_x ,e.m_y );
				mouse_pressed = false;
				e.m_type = 102; //up
			}
			if (e.m_type >= 100 && e.m_type <= 102)
				m_active->processEvent(&e);
		}
	}
	else if (domain == navigator_get_domain())
	{
		int cod = bps_event_get_code(event);

		if (NAVIGATOR_WINDOW_INACTIVE == cod)
		{
			onInactive();
//				   ZaScreenFlash * l_flash = (ZaScreenFlash *)ZaResLib::getInstance()->getScreen("ZaScreenFlash");
//				   ZaScreenBase * l_src = (ZaScreenBase *)ZaResLib::getInstance()->getScreen("ZaScreenStart");
//				   string p= "";
//				   l_flash->changeScreen(l_src,l_src,l_src,p.c_str(),ZaScreenFlash::NONE);
		}
	}
}
Example #21
0
int ButtonMap::mapNextButtonPressed()
{
   bps_event_t *event = NULL;
   int sym;

   //use in frontend run loop, get key pressed back, and map
   int z = 10;
   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0)
   {
      return -1;
   }

   screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0);

   while(1)
   {
      if (BPS_SUCCESS != bps_get_event(&event, -1))
      {
         fprintf(stderr, "bps_get_event failed\n");
         break;
      }

      if (event)
      {
         int domain = bps_event_get_domain(event);
         int events = bps_event_get_code(event);

         if (events == NAVIGATOR_SWIPE_DOWN)
         {
        	 if(overlayDisplay)
        	 {
        		 *g_settings.input.overlay = '\1';
        	 }

        	 else
        	 {
        		 *g_settings.input.overlay = '\1';
        	 }

        	 overlayDisplay = !overlayDisplay;

         }

         if (domain == screen_get_domain())
         {
            screen_event_t screen_event = screen_event_get_event(event);
            int screen_val;
            screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

            //TODO: Should we only let the buttons through that we are trying to map?
            if(screen_val == SCREEN_EVENT_MTOUCH_TOUCH)
            {
               //This is touch screen event
               sym = NO_BTN;
               break;
            }
            else if(screen_val == SCREEN_EVENT_KEYBOARD)
            {
               screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM, &sym);
               sym &= 0xFF;
               break;
            }
            else if( (screen_val == SCREEN_EVENT_GAMEPAD) || (screen_val == SCREEN_EVENT_JOYSTICK) )
            {
               screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &sym);
               break;
            }
         }
      }
   }

   z = -10;
   if (screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_ZORDER, &z) != 0)
   {
      return -1;
   }

   screen_post_window(screen_win, screen_buf, 1, screen_resolution, 0);

   return (g_settings.input.binds[player][button].joykey = sym);
}
Example #22
0
void PB_HandleEvents(void (*keyHandleFunction)(screen_event_t*)){
	bps_event_t *event = NULL;

	while(1){
		bps_get_event(&event, 0);
		if(event == NULL){
			break;
		}

		if (bps_event_get_domain(event) == screen_get_domain()) {
			int screen_val;

			screen_event_t screen_event = screen_event_get_event(event);

			screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE,
										 &screen_val);

			//Here we should handle menu related functions such as rom switch, etc.
			//Then pass off to input plugin.
			switch(screen_val){
			case SCREEN_EVENT_MTOUCH_TOUCH:
			case SCREEN_EVENT_MTOUCH_MOVE:
			case SCREEN_EVENT_MTOUCH_RELEASE:
				(*keyHandleFunction)((void*)&screen_event);
				break;
			}
		} else if (bps_event_get_domain(event) == navigator_get_domain()) {
			int rc;
			navigator_window_state_t state;
			bps_event_t *activation_event = NULL;
			//int videoPlugin, disableSound;

			switch (bps_event_get_code(event)) {
			case NAVIGATOR_ORIENTATION_CHECK:
				//Signal navigator that we intend to resize
				//navigator_orientation_check_response(event, true);
				break;
			case NAVIGATOR_ORIENTATION:
				//if (EXIT_FAILURE == resize(event)) {
				//	shutdown = true;
				//}
				break;
			case NAVIGATOR_SWIPE_DOWN:
				//Rom picker
				rc = dialog_select_game(romName, "shared/misc/n64/roms/", &videoPlugin, &disableSound);
				if (rc == 0) {
					(*keyHandleFunction)(0);
				}
				break;
			case NAVIGATOR_EXIT:
				break;
			case NAVIGATOR_WINDOW_STATE:
				state = navigator_event_get_window_state(event);

				switch(state){
				case NAVIGATOR_WINDOW_THUMBNAIL:
					for(;;){
						rc = bps_get_event(&activation_event, -1);
						assert(rc==BPS_SUCCESS);

						if(bps_event_get_code(activation_event) == NAVIGATOR_WINDOW_STATE){
							state = navigator_event_get_window_state(activation_event);
							if(state == NAVIGATOR_WINDOW_FULLSCREEN){
								break;
							}
						}
					}
					break;
				}
				break;
			}
		}
	}
}
Example #23
0
int main(int argc, char *argv[])
{
    int rc;

    // Renderer variables
    mmr_connection_t*     mmr_connection = 0;
    mmr_context_t*        mmr_context = 0;
    strm_dict_t*          dict = NULL;

    // I/O variables
    int                    video_device_output_id = -1;
    int                    audio_device_output_id = -1;

    // Position of the play and stop button.
    static int ctrl_x = 0;
    static int ctrl_y = 0;

    EGLint surface_width;
    EGLint surface_height;

    srand(time(0));
    app_id = rand();

    // I/O devices
    static char *audio_device_url    = "audio:default";
    static char video_device_url[PATH_MAX];
    rc = snprintf(video_device_url, PATH_MAX, "screen:?winid=videosamplewindowgroup_%d&wingrp=videosamplewindowgroup_%d", app_id, app_id);
    if (rc >= PATH_MAX) {
        fprintf(stderr, "URL too long\n");
    }

    // Name of video context...with a random number appended.
    static char video_context_name[PATH_MAX];
    rc = snprintf(video_context_name, PATH_MAX, "samplevideocontextname_%d", app_id);
    if (rc >= PATH_MAX) {
        fprintf(stderr, "Video context name too long\n");
    }

    // Window group name...with the same random number appended.
    static char window_group_name[PATH_MAX];
    rc = snprintf(window_group_name, PATH_MAX, "videosamplewindowgroup_%d", app_id);
    if (rc >= PATH_MAX) {
        fprintf(stderr, "Video context name too long\n");
    }

    // Video file bundled with our app
    static const char *video_file_relative_path = "app/native/pb_sample.mp4";


    bps_initialize();

    // Create the Screen Context.
    if (screen_create_context(&g_screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) {
        fprintf(stderr, "screen_create_context failed\n");
        return EXIT_FAILURE;
    }

    // Create the window and initialize EGL for GL_ES_1 rendering
    rc = initialize_egl_window(g_screen_ctx, window_group_name);
    if (rc != EXIT_SUCCESS) {
        fprintf(stderr, "initialize_egl_window failed\n");
        return EXIT_FAILURE;
    }

    // Query width and height of the window surface created by utility code
    eglQuerySurface(g_egl_disp, g_egl_surf, EGL_WIDTH, &surface_width);
    eglQuerySurface(g_egl_disp, g_egl_surf, EGL_HEIGHT, &surface_height);
    EGLint err = eglGetError();
    if (err != EGL_SUCCESS) {
        fprintf(stderr, "Unable to query EGL surface dimensions\n");
        return EXIT_FAILURE;
    }

    // Initialize GL for 2D rendering
    glViewport(0, 0, (int)surface_width, (int) surface_height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Set world coordinates to coincide with screen pixels
    glScalef(1.0f / (float)surface_width, 1.0f / (float)surface_height, 1.0f);

    // We can calculate location and verticies of the controls
    ctrl_x = (float)surface_width  / 2 - ctrl_w / 2;
    ctrl_y = (float)surface_height / 2 - ctrl_h / 2;

    g_triangle_vertices[0] = ctrl_x;
    g_triangle_vertices[1] = ctrl_y;

    g_triangle_vertices[2] = ctrl_x;
    g_triangle_vertices[3] = ctrl_y + ctrl_h;

    g_triangle_vertices[4] = ctrl_x + ctrl_w;
    g_triangle_vertices[5] = ctrl_y + ctrl_h / 2;

    g_square_vertices[0] = ctrl_x;
    g_square_vertices[1] = ctrl_y;
    g_square_vertices[2] = ctrl_x;
    g_square_vertices[3] = ctrl_y + ctrl_h;
    g_square_vertices[4] = ctrl_x + ctrl_w;
    g_square_vertices[5] = ctrl_y + ctrl_h;
    g_square_vertices[6] = ctrl_x + ctrl_w;
    g_square_vertices[7] = ctrl_y;
    g_square_vertices[8] = ctrl_x;
    g_square_vertices[9] = ctrl_y;

    // Configure mm-renderer.
    mmr_connection = mmr_connect(NULL);
    if (mmr_connection == NULL) {
        fprintf(stderr, "mmr_connect failed\n");
        return EXIT_FAILURE;
    }

    mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);
    if (mmr_context == NULL) {
        fprintf(stderr, "mmr_context_create failed\n");
        return EXIT_FAILURE;
    }

    // Configure video and audio output.
    video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video");
    if (video_device_output_id == -1) {
        fprintf(stderr, "mmr_output_attach(video) failed\n");
        return EXIT_FAILURE;
    }

    audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");
    if (audio_device_output_id == -1) {
        fprintf(stderr, "mmr_output_attach(audio) failed\n");
        return EXIT_FAILURE;
    }

    // render 'paused'
    render(true);


    // Build up the path where our bundled resource is.
    char cwd[PATH_MAX];
    char media_file[PATH_MAX];
    getcwd(cwd,PATH_MAX);

    rc = snprintf(media_file, PATH_MAX, "file://%s/%s", cwd, video_file_relative_path);
    if ((rc == -1) || (rc >= PATH_MAX)) {
        fprintf(stderr, "snprintf(media_file) failed\n");
        return EXIT_FAILURE;
    }

    // Attach the input media.
    if (mmr_input_attach(mmr_context, media_file, "track") != 0) {
        fprintf(stderr, "mmr_input_attach(track) failed\n");
        return EXIT_FAILURE;
    }


    int video_speed = 0;

    // Set the speed to 0 to pause the video initially
    if (mmr_speed_set(mmr_context, video_speed) != 0) {
        fprintf(stderr, "mmr_set_speed(0) failed\n");
        return EXIT_FAILURE;
    }

    // Change to the play state, although speed is zero
    if (mmr_play(mmr_context) != 0) {
        fprintf(stderr, "mmr_play failed\n");
        return EXIT_FAILURE;
    }

    /* Do some work to make the aspect ratio correct.
     */
    dict = calculate_rect(surface_width, surface_height);
    if (NULL == dict) {
        fprintf(stderr, "calculate_rect failed\n");
        return EXIT_FAILURE;
    }

    if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) {
        fprintf(stderr, "mmr_output_parameters failed\n");
        return EXIT_FAILURE;
    }

    /* Note that we allocated memory for the dictionary, but the call to 
     * mmr_output_parameters() deallocates that memory even on failure.
     */
    dict = NULL;

    screen_request_events(g_screen_ctx);
    navigator_request_events(0);

    screen_window_t video_window = (screen_window_t)0;
    bool app_window_above = true;
    int screen_val;
    int exit_value = EXIT_SUCCESS;

    // Handle keyboard events and stop playback upon user request.
    for (;;) {
        bps_event_t *event = NULL;
        if (bps_get_event(&event, 0) != BPS_SUCCESS) {
            return EXIT_FAILURE;
        }
        if (event) {
            if (bps_event_get_domain(event) == navigator_get_domain()) {
                if (bps_event_get_code(event) == NAVIGATOR_EXIT) {
                    break;
                } else if(NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) {
                    if ((screen_window_t)0 != video_window) {

                        app_window_above = !app_window_above;
                        if (app_window_above) {
                            screen_val = 1;
                        } else {
                            screen_val = -1;
                        }
                        if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_ZORDER, &screen_val) != 0) {
                            fprintf(stderr, "screen_set_window_property(ZORDER) failed\n");
                            exit_value = EXIT_FAILURE;
                            break;
                        }

                        screen_val = 1;
                        if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_VISIBLE, &screen_val) != 0) {
                            fprintf(stderr, "screen_set_window_property(VISIBLE) failed\n");
                            exit_value = EXIT_FAILURE;
                            break;
                        }

                        rc = screen_flush_context(g_screen_ctx, SCREEN_WAIT_IDLE);
                        if (rc != 0) {
                            fprintf (stderr, "Warning: Failed to flush\n");
                        }
                    }
                }
            } else if (bps_event_get_domain(event) == screen_get_domain()) {
                screen_event_t screen_event = screen_event_get_event(event);
                int event_type;
                screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &event_type);

                if (event_type == SCREEN_EVENT_CREATE && (video_window == (screen_window_t)0)) {
                    char id[256];

                    rc = screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&video_window);
                    if (rc != 0) {
                        fprintf(stderr, "screen_get_event_property(WINDOW) failed\n");
                        exit_value = EXIT_FAILURE;
                        break;
                    }
                    fprintf(stderr, "video_window%d\n",(int)video_window);

                    rc = screen_get_window_property_cv(video_window, SCREEN_PROPERTY_ID_STRING, 256, id);
                    if (rc != 0) {
                        fprintf(stderr, "screen_get_window_property(ID) failed\n");
                        exit_value = EXIT_FAILURE;
                        break;
                    }
                    fprintf(stderr, "window ID is %s\n", id);

                    if (strncmp(id, window_group_name, strlen(window_group_name)) != 0) {
                        fprintf(stderr, "window ID mismatch\n");
                        exit_value = EXIT_FAILURE;
                        break;
                    }
                } else if(event_type == SCREEN_EVENT_MTOUCH_TOUCH) {
                    if (video_speed == 0) {
                        video_speed = 1000;
                        render(false);
                    } else {
                        video_speed = 0;
                        render(true);
                    }

                    if (mmr_speed_set(mmr_context, video_speed) != 0) {
                        fprintf(stderr, "mmr_speed_set(%d) failed\n", video_speed);
                        exit_value = EXIT_FAILURE;
                        break;
                    }
                }
            }
        }
    }

    screen_stop_events(g_screen_ctx);

    if (mmr_stop(mmr_context) != 0) {
        fprintf(stderr, "mmr_stop failed\n");
        exit_value = EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) {
        fprintf(stderr, "mmr_output_detach(audio) failed\n");
        exit_value = EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, video_device_output_id) != 0) {
        fprintf(stderr, "mmr_output_detach(video) failed\n");
        exit_value = EXIT_FAILURE;
    }

    if (mmr_context_destroy(mmr_context) != 0) {
        fprintf(stderr, "mmr_context_destroy failed\n");
        exit_value = EXIT_FAILURE;
    }

    mmr_context = 0;
    video_device_output_id = -1;
    audio_device_output_id = -1;

    mmr_disconnect(mmr_connection);
    mmr_connection = 0;

    bps_shutdown();

    if (screen_destroy_window(g_screen_win) != 0) {
        fprintf(stderr, "screen_destroy_window failed\n");
        exit_value = EXIT_FAILURE;
    }

    if (screen_destroy_context(g_screen_ctx) != 0) {
        fprintf(stderr, "screen_destroy_context failed\n");
        exit_value = EXIT_FAILURE;
    }

    g_screen_ctx = 0;
    g_screen_win = 0;

    return exit_value;
}
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;
}
Example #25
0
static void handleScreenEvent(bps_event_t *event)
{
    int eventType;

    screen_event_t screen_event = screen_event_get_event(event);
    screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &eventType);

    switch (eventType) {
        case SCREEN_EVENT_GAMEPAD:
        case SCREEN_EVENT_JOYSTICK:
        {
            if (!_polling) {
                // Determine which controller this is.
                screen_device_t device;
                SCREEN_API(screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device), "SCREEN_PROPERTY_DEVICE");

                GameController* controller = NULL;
                int i;
                for (i = 0; i < MAX_CONTROLLERS; ++i) {
                    if (device == _controllers[i].handle) {
                        controller = &_controllers[i];
                        break;
                    }
                }

                if (!controller) {
                    break;
                }

                // Store the controller's new state.
                SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_BUTTONS, &controller->buttons), "SCREEN_PROPERTY_BUTTONS");
                SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ANALOG0, controller->analog0), "SCREEN_PROPERTY_ANALOG0");

                if (controller->type == SCREEN_EVENT_GAMEPAD) {
                    SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ANALOG1, controller->analog1), "SCREEN_PROPERTY_ANALOG1");
                }
            }
            break;
        }
        case SCREEN_EVENT_DEVICE:
        {
            // A device was attached or removed.
            screen_device_t device;
            int attached;
            int type;

            SCREEN_API(screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_DEVICE, (void**)&device), "SCREEN_PROPERTY_DEVICE");
            SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_ATTACHED, &attached), "SCREEN_PROPERTY_ATTACHED");

            if (attached) {
                SCREEN_API(screen_get_device_property_iv(device, SCREEN_PROPERTY_TYPE, &type), "SCREEN_PROPERTY_TYPE");
            }

            int i;
            if (attached && (type == SCREEN_EVENT_GAMEPAD || type == SCREEN_EVENT_JOYSTICK)) {
                for (i = 0; i < MAX_CONTROLLERS; ++i) {
                    if (!_controllers[i].handle) {
                        _controllers[i].handle = device;
                        loadController(&_controllers[i]);
                        break;
                    }
                }
            } else {
                for (i = 0; i < MAX_CONTROLLERS; ++i) {
                    if (device == _controllers[i].handle) {
                        initController(&_controllers[i], i);
                        break;
                    }
                }
            }

            break;
        }

        case SCREEN_EVENT_MTOUCH_RELEASE:
        {
            int pos[2];
            SCREEN_API(screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_SOURCE_POSITION, pos), "SCREEN_PROPERTY_SOURCE_POSITION");
            int x = pos[0];
            int y = _surfaceHeight - pos[1];

            int i;
            for (i = 0; i < MAX_CONTROLLERS; ++i) {
                bool buttonTapped = false;

                int j;
                for (j = 0; j < MAX_BUTTONS; ++j) {
                    Button* button = &_buttons[i][j];
                    Quad* quad = button->quad;

                    // Detect that a button was tapped.
                    if (x > quad->x && x < quad->x + quad->width &&
                        y > quad->y && y < quad->y + quad->height) {
                        _activeButton[i] = button;
                        buttonTapped = true;
                        break;
                    }
                }

                if (_activeButton[i] && !buttonTapped) {
                    // Cancel the button's active state.
                    _activeButton[i] = NULL;
                }
            }

            // The polling button is used to switch between handling all device events and polling devices once per frame.
            Quad* quad = _pollingButton.quad;
            if (x > quad->x && x < quad->x + quad->width &&
                y > quad->y && y < quad->y + quad->height) {
                _polling = !_polling;

                // The polling button lights up when polling is enabled.
                if (_polling) {
                    quad->uvs = _triggerDownUVs;
                } else {
                    quad->uvs = _triggerUpUVs;
                }
            }

            break;
        }
    }
}
void fgPlatformProcessSingleEvent ( void )
{
    if(fgStructure.CurrentWindow == NULL) {
        //XXX Is this right? Would this just cause a whole lot of busy looping while we wait for events?
        LOGW("fgPlatformProcessSingleEvent: Missing current window. Skipping event processing");
        return;
    }

    if(fgDisplay.pDisplay.event == NULL)
        /* Nothing to do */
        return;

    int domain;
    do
    {
        SFG_Window* window = fgStructure.CurrentWindow;
#ifdef __PLAYBOOK__
        /* Get the keyboard height before doing anything since we otherwise don't get it until it changes */
        if(window->State.pWState.keyboardHeight == 0) {
            virtualkeyboard_get_height(&window->State.pWState.keyboardHeight);
        }
#endif
        domain = bps_event_get_domain(fgDisplay.pDisplay.event);
        if (domain == screen_get_domain()) {
            int eventType;
            int mod;
            screen_event_t screenEvent = screen_event_get_event(fgDisplay.pDisplay.event);
            screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_TYPE, &eventType);
            switch (eventType) {

            //Mostly from fg_main_android
            case SCREEN_EVENT_MTOUCH_TOUCH:
            case SCREEN_EVENT_MTOUCH_RELEASE:
            case SCREEN_EVENT_MTOUCH_MOVE:
            {
                mtouch_event_t touchEvent;
                screen_get_mtouch_event(screenEvent, &touchEvent, 0);
#ifndef __PLAYBOOK__
                screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod);
#else
                mod = 0;
#endif

                LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_MTOUCH_*: Type: 0x%X, X: %d, Y: %d, Contact Id: %d, Mod: 0x%X", SLOG2_FA_SIGNED(eventType), SLOG2_FA_SIGNED(touchEvent.x), SLOG2_FA_SIGNED(touchEvent.y), SLOG2_FA_SIGNED(touchEvent.contact_id), SLOG2_FA_SIGNED(mod));

                /* Remember the current modifiers state so user can query it from their callback */
                fgState.Modifiers = fgPlatformGetModifiers(mod);

                if(touchEvent.contact_id == 0) {
                    int size[2];
                    screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);
                    handle_left_mouse(touchEvent.x, touchEvent.y, size[1], eventType, window);
                }

                //Now handle mutlitouch (adapted from fg_main_windows)
                if (eventType == SCREEN_EVENT_MTOUCH_TOUCH) {
                    INVOKE_WCB( *window, MultiEntry,  ( touchEvent.contact_id, GLUT_ENTERED ) );
                    INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_DOWN ) );
                } else if (eventType == SCREEN_EVENT_MTOUCH_MOVE) {
                    INVOKE_WCB( *window, MultiMotion, ( touchEvent.contact_id, touchEvent.x, touchEvent.y ) );
                    //XXX No motion is performed without contact, thus MultiPassive is never used
                } else if (eventType == SCREEN_EVENT_MTOUCH_RELEASE) {
                    INVOKE_WCB( *window, MultiButton, ( touchEvent.contact_id, touchEvent.x, touchEvent.y, 0, GLUT_UP ) );
                    INVOKE_WCB( *window, MultiEntry,  ( touchEvent.contact_id, GLUT_LEFT ) );
                }

                fgState.Modifiers = INVALID_MODIFIERS;
                break;
            }

            case SCREEN_EVENT_POINTER:
            {
                //Based off/part taken from GamePlay3d PlatformBlackBerry
                static int mouse_pressed = 0;
                int buttons;
                int position[2];
                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);
#ifndef __PLAYBOOK__
                screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel);
                screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod);
#else
                wheel = mod = 0;
#endif
                int size[2];
                screen_get_window_property_iv(window->Window.Handle, SCREEN_PROPERTY_BUFFER_SIZE, size);

                LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_POINTER: Buttons: 0x%X, X: %d, Y: %d, Wheel: %d, Mod: 0x%X", SLOG2_FA_SIGNED(buttons), SLOG2_FA_SIGNED(position[0]), SLOG2_FA_SIGNED(position[1]), SLOG2_FA_SIGNED(wheel), SLOG2_FA_SIGNED(mod));

                //XXX Is multitouch be handled in a good way?

                /* Remember the current modifiers state so user can query it from their callback */
                fgState.Modifiers = fgPlatformGetModifiers(mod);

                // 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;
                        handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_TOUCH, window);
                    }
                } else if (mouse_pressed & SCREEN_LEFT_MOUSE_BUTTON) {
                    move = false;
                    mouse_pressed &= ~SCREEN_LEFT_MOUSE_BUTTON;
                    handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_RELEASE, window);
                }

                // 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;
                        INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_DOWN, position[0], position[1]));
                    }
                } else if (mouse_pressed & SCREEN_RIGHT_MOUSE_BUTTON) {
                    move = false;
                    mouse_pressed &= ~SCREEN_RIGHT_MOUSE_BUTTON;
                    INVOKE_WCB(*window, Mouse, (GLUT_RIGHT_BUTTON, GLUT_UP, position[0], position[1]));
                }

                // 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;
                        INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_DOWN, position[0], position[1]));
                    }
                } else if (mouse_pressed & SCREEN_MIDDLE_MOUSE_BUTTON) {
                    move = false;
                    mouse_pressed &= ~SCREEN_MIDDLE_MOUSE_BUTTON;
                    INVOKE_WCB(*window, Mouse, (GLUT_MIDDLE_BUTTON, GLUT_UP, position[0], position[1]));
                }

                // Fire a move event if none of the buttons changed.
                if (left_move || move) {
                    handle_left_mouse(position[0], position[1], size[1], SCREEN_EVENT_MTOUCH_MOVE, window);
                }

                if (wheel) {
                    /* Very slightly modified from fg_main_mswin.
                     * Because we don't want MouseWheel to be called every. single. time.
                     * That the action occurs, we mimic the Windows version with "wheel deltas"
                     * XXX Do we even want this?
                     * XXX If we want this, it's possible to get horizontal scroll as well.
                     * XXX -Vertical scroll=wheel 0, horizontal=wheel 1? */
                    fgState.MouseWheelTicks -= wheel;
                    if (abs(fgState.MouseWheelTicks) >= WHEEL_DELTA)
                    {
                        int wheel_number = 0;
                        int direction = (fgState.MouseWheelTicks > 0) ? -1 : 1;

                        if (!FETCH_WCB(*window, MouseWheel) && !FETCH_WCB(*window, Mouse))
                            break;

                        //XXX fgSetWindow(window);

                        while(abs(fgState.MouseWheelTicks) >= WHEEL_DELTA)
                        {
                            if (FETCH_WCB(*window, MouseWheel))
                                INVOKE_WCB(*window, MouseWheel, (wheel_number, direction, window->State.MouseX, window->State.MouseY));
                            else /* No mouse wheel, call the mouse button callback twice */
                            {
                                /*
                                 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
                                 *  "    "   one                     +1 to 5, -1 to 6, ...
                                 *
                                 * XXX The below assumes that you have no more than 3 mouse
                                 * XXX buttons.  Sorry.
                                 */
                                int button = wheel_number * 2 + 3;
                                if (direction < 0)
                                    ++button;
                                INVOKE_WCB(*window, Mouse, (button, GLUT_DOWN, window->State.MouseX, window->State.MouseY));
                                INVOKE_WCB(*window, Mouse, (button, GLUT_UP, window->State.MouseX, window->State.MouseY));
                            }

                            fgState.MouseWheelTicks -= WHEEL_DELTA * direction;
                        }
                    }
                }

                fgState.Modifiers = INVALID_MODIFIERS;
                break;
            }

            //Based off fg_main_android
            case SCREEN_EVENT_KEYBOARD:
            {
                int flags;
                int value;
                screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &flags);
                screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_SYM, &value);
                screen_get_event_property_iv(screenEvent, SCREEN_PROPERTY_KEY_MODIFIERS, &mod);

                LOGI("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Flags: 0x%X, Sym: 0x%X, Mod: 0x%X", SLOG2_FA_SIGNED(flags), SLOG2_FA_SIGNED(value), SLOG2_FA_SIGNED(mod));

                /* Suppress key repeats if desired. Based off fg_main_mswin */
                if ((flags & KEY_REPEAT) == 0 || (fgState.KeyRepeat == GLUT_KEY_REPEAT_OFF && fgStructure.CurrentWindow->State.IgnoreKeyRepeat == GL_TRUE)) {
                    unsigned int keypress = 0;
                    unsigned char ascii = 0;

                    /* Remember the current modifiers state so user can query it from their callback */
                    fgState.Modifiers = fgPlatformGetModifiers(mod);

                    /* Process keys */
                    if ((keypress = key_special(value))) {
                        if(flags & KEY_DOWN) {
                            INVOKE_WCB(*window, Special, (keypress, window->State.MouseX, window->State.MouseY));
                        } else {
                            INVOKE_WCB(*window, SpecialUp, (keypress, window->State.MouseX, window->State.MouseY));
                        }
                    } else if((flags & KEY_SYM_VALID) && (ascii = key_ascii(value))) {
                        if(flags & KEY_DOWN) {
                            INVOKE_WCB(*window, Keyboard, (ascii, window->State.MouseX, window->State.MouseY));
                        } else {
                            INVOKE_WCB(*window, KeyboardUp, (ascii, window->State.MouseX, window->State.MouseY));
                        }
                    } else {
                        LOGW("fgPlatformProcessSingleEvent: SCREEN_EVENT_KEYBOARD. Unhandled key event");
                    }

                    fgState.Modifiers = INVALID_MODIFIERS;
                }
                break;
            }

            case SCREEN_EVENT_PROPERTY:
            case SCREEN_EVENT_IDLE:
                break;

            default:
                LOGW("fgPlatformProcessSingleEvent: unknown screen event: 0x%X", SLOG2_FA_SIGNED(eventType));
                break;
            }
        } else if (domain == navigator_get_domain()) {
            unsigned int eventType = bps_event_get_code(fgDisplay.pDisplay.event);
            switch (eventType) {

            case NAVIGATOR_WINDOW_STATE:
            {
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE");

                /* Covered only happens due to keyboard. When the app is minimized, the keyboard is closed.
                   When the keyboard is open, and the app is fullscreened, the keyboard is also closed.
                   If a window is covered and the app is minimized, the state will be set and the keyboard event
                   will adjust the screen size and change window status. */
                navigator_window_state_t state = navigator_event_get_window_state(fgDisplay.pDisplay.event);
                if(window->State.pWState.windowCovered == GL_FALSE)
                {
                    switch (state)
                    {
                    case NAVIGATOR_WINDOW_FULLSCREEN:
                        LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_FULLSCREEN");
                        window->State.Visible = GL_TRUE;
                        INVOKE_WCB(*window, WindowStatus, (GLUT_FULLY_RETAINED));
                        break;
                    case NAVIGATOR_WINDOW_THUMBNAIL:
                        LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_THUMBNAIL");
                        window->State.Visible = GL_TRUE;
                        INVOKE_WCB(*window, WindowStatus, (GLUT_PARTIALLY_RETAINED));
                        break;
                    case NAVIGATOR_WINDOW_INVISIBLE:
                        LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE-NAVIGATOR_WINDOW_INVISIBLE");
                        window->State.Visible = GL_FALSE;
                        INVOKE_WCB(*window, WindowStatus, (GLUT_HIDDEN));
                        break;
                    default:
                        LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state));
                        break;
                    }
                }
                window->State.pWState.windowState = state;
                break;
            }

            case NAVIGATOR_EXIT:
            {
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_EXIT");

                fgPlatformMainLoopPostWork();

                /* User closed the application for good, let's kill the window */
                SFG_Window* window = fgStructure.CurrentWindow;
                if (window != NULL) {
                    fgDestroyWindow(window);
                } else {
                    LOGW("NAVIGATOR_EXIT: No current window");
                }

                //XXX Should this be a bit more "forceful" so that it doesn't continue to loop through events?
                break;
            }

            case NAVIGATOR_SWIPE_DOWN:
                /* XXX Open app menu */
                break;

            /* Orientation is a bunch of handshakes.
               - First the app get's asked if it wants to rotate (NAVIGATOR_ORIENTATION_CHECK)
               - If the app wants to rotate, then it will be told what size it will be after rotate (NAVIGATOR_ORIENTATION_SIZE).
               - Once the OS confirms that it's ready to rotate, it tells the app to handle rotation (NAVIGATOR_ORIENTATION).
               - Once rotation is complete, the OS tells the app it's done (NAVIGATOR_ORIENTATION_DONE) */
            case NAVIGATOR_ORIENTATION_CHECK:
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_CHECK");

                /* Reset sizes */
                window->State.pWState.newWidth = 0;
                window->State.pWState.newHeight = 0;

#ifdef __PLAYBOOK__
                /* On rotation, the keyboard is closed. This prevents two resize calls */
                window->State.pWState.keyboardOpen = GL_FALSE;
#endif

                /* Notify that we want to rotate */
                navigator_orientation_check_response(fgDisplay.pDisplay.event, true);
                break;

            case NAVIGATOR_ORIENTATION:
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION");

                /* NAVIGATOR_ORIENTATION occurs before NAVIGATOR_KEYBOARD_POSITION */

                /* Rotate and resize the window */
                fgPlatformRotateWindow(window, navigator_event_get_orientation_angle(fgDisplay.pDisplay.event));
                fgPlatformFlushCommands();
#ifdef __PLAYBOOK__
                /* PlayBook doesn't indicate what the new size will be, so we need to retrieve it from the window itself */
                window->State.pWState.newWidth = glutGet(GLUT_WINDOW_WIDTH);
                window->State.pWState.newHeight = glutGet(GLUT_WINDOW_HEIGHT);
#endif
                fghOnReshapeNotify(window, window->State.pWState.newWidth, window->State.pWState.newHeight, GL_FALSE);

                /* Reset sizes */
                window->State.pWState.newWidth = 0;
                window->State.pWState.newHeight = 0;

                /* Done rotating */
                navigator_done_orientation(fgDisplay.pDisplay.event);
                break;

            case NAVIGATOR_BACK:
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_BACK");
                INVOKE_WCB(*window, Keyboard, (ESCAPE_BUTTON_KEY, window->State.MouseX, window->State.MouseY));
                INVOKE_WCB(*window, KeyboardUp, (ESCAPE_BUTTON_KEY, window->State.MouseX, window->State.MouseY));
                break;

            case NAVIGATOR_WINDOW_ACTIVE:
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_ACTIVE");
                INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_RESUME));
                break;

            case NAVIGATOR_WINDOW_INACTIVE:
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_WINDOW_INACTIVE");
                INVOKE_WCB(*window, AppStatus, (GLUT_APPSTATUS_PAUSE));
                break;

            case NAVIGATOR_ORIENTATION_DONE:
            case NAVIGATOR_ORIENTATION_RESULT:
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_DONE/NAVIGATOR_ORIENTATION_RESULT");
                break;

#ifndef __PLAYBOOK__
            case NAVIGATOR_KEYBOARD_STATE:
            {
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE");

                navigator_keyboard_state_t state = navigator_event_get_keyboard_state(fgDisplay.pDisplay.event);
                switch (state)
                {
                case NAVIGATOR_KEYBOARD_CLOSED:
                    LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE-NAVIGATOR_KEYBOARD_CLOSED");
                    /* NAVIGATOR_KEYBOARD_POSITION only occurs on open, so on keyboard close we need to reset the keyboard height */
                    fgPlatformHandleKeyboardHeight(window, 0);
                    break;
                case NAVIGATOR_KEYBOARD_OPENING:
                case NAVIGATOR_KEYBOARD_OPENED:
                case NAVIGATOR_KEYBOARD_CLOSING:
                    break;
                case NAVIGATOR_KEYBOARD_UNRECOGNIZED:
                    LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE-NAVIGATOR_KEYBOARD_UNRECOGNIZED");
                    break;
                default:
                    LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_STATE unknown: 0x%X", SLOG2_FA_SIGNED(state));
                    break;
                }
                break;
            }

            case NAVIGATOR_KEYBOARD_POSITION:
            {
                /* Occurs only when keyboard has opened or resizes */
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_POSITION");

                int keyboardOffset = navigator_event_get_keyboard_position(fgDisplay.pDisplay.event);
                if(keyboardOffset == BPS_FAILURE) {
                    LOGW("fgPlatformProcessSingleEvent: NAVIGATOR_KEYBOARD_POSITION: getting keyboard offset failed");
                } else {
                    /* keyboardOffset is the offset from the top of the screen to the top of the keyboard, AKA the size of the uncovered screen
                       We want the height of the keyboard. So instead of determining the orientation, getting the right display size, and subtracting;
                       we just get the keyboard height which may be slower but easier to understand and work with */
                    virtualkeyboard_get_height(&keyboardOffset);
                    fgPlatformHandleKeyboardHeight(window, keyboardOffset);
                }
                break;
            }

            case NAVIGATOR_DEVICE_LOCK_STATE:
                break;

            case NAVIGATOR_WINDOW_COVER:
            case NAVIGATOR_WINDOW_COVER_ENTER:
            case NAVIGATOR_WINDOW_COVER_EXIT:
                /* BlackBerry specific. Let app status and window status take care of everything */
                break;

            case NAVIGATOR_APP_STATE:
                /* Can do the same as NAVIGATOR_WINDOW_ACTIVE/NAVIGATOR_WINDOW_INACTIVE but
                   seems like it doesn't work when the app comes to the foreground. Might be a bug */
                break;

            case NAVIGATOR_ORIENTATION_SIZE:
                LOGI("fgPlatformProcessSingleEvent: NAVIGATOR_ORIENTATION_SIZE");

                /* Get new window size */
                window->State.pWState.newWidth = navigator_event_get_orientation_size_width(fgDisplay.pDisplay.event);
                window->State.pWState.newHeight = navigator_event_get_orientation_size_height(fgDisplay.pDisplay.event);
                break;
#endif

            case 0: //Doesn't exist in header, but shows up when keyboard shows and resizes
                break;

            default:
                LOGW("fgPlatformProcessSingleEvent: unknown navigator event: 0x%X", SLOG2_FA_SIGNED(eventType));
                break;
            }
        }
#ifdef __PLAYBOOK__
        /* While this could be used for non-PlayBook, BlackBerry 10 will still get navigator events, so use those. They are a bit more exact. */
        else if(domain == virtualkeyboard_get_domain()) {
            unsigned int eventType = bps_event_get_code(fgDisplay.pDisplay.event);
            switch (eventType) {
            case VIRTUALKEYBOARD_EVENT_VISIBLE:
                LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_VISIBLE");
                if(window->State.pWState.keyboardOpen != GL_TRUE) {
                    window->State.pWState.keyboardOpen = GL_TRUE;
                    fgPlatformHandleKeyboardHeight(window, window->State.pWState.keyboardHeight);
                }
                break;

            case VIRTUALKEYBOARD_EVENT_HIDDEN:
                LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_HIDDEN");
                if(window->State.pWState.keyboardOpen != GL_FALSE) {
                    window->State.pWState.keyboardOpen = GL_FALSE;
                    fgPlatformHandleKeyboardHeight(window, 0);
                }
                break;

            case VIRTUALKEYBOARD_EVENT_INFO:
                LOGI("fgPlatformProcessSingleEvent: VIRTUALKEYBOARD_EVENT_INFO");
                window->State.pWState.keyboardHeight = virtualkeyboard_event_get_height(fgDisplay.pDisplay.event);
                if(window->State.pWState.keyboardOpen == GL_TRUE) {
                    fgPlatformHandleKeyboardHeight(window, window->State.pWState.keyboardHeight);
                }
                break;

            default:
                LOGW("fgPlatformProcessSingleEvent: unknown virtualkeyboard event: 0x%X", eventType);
                break;
            }
        }
#endif
    } while(bps_get_event(&fgDisplay.pDisplay.event, 1) == BPS_SUCCESS && fgDisplay.pDisplay.event != NULL);

    /* Reset event to reduce chances of triggering something */
    fgDisplay.pDisplay.event = NULL;
}
void ConfigWindow::runEventLoop(TCOContext *emuContext)
{
	screen_buffer_t buffer = draw(emuContext);

	bool showingWindow = true;
	bps_initialize();
	screen_request_events(m_context);
	bps_event_t *event; /* FIXME: How do we verify they ran bps_initialize? */
	screen_event_t se;
	int eventType;
	int contactId;
	bool touching = false;
	bool releasedThisRound = false;
	int startPos[2] = {0,0};
	int endPos[2] = {0,0};
	bool scaling = false;

	while (showingWindow)
	{
		const int dirtyRects[4] = {0, 0, m_size[0], m_size[1]};

		releasedThisRound = false;
		bps_get_event(&event, 0);
		while (showingWindow && event)
		{
			int domain = bps_event_get_domain(event);
			if (domain == navigator_get_domain())
			{
				if (bps_event_get_code(event) == NAVIGATOR_SWIPE_DOWN)
					showingWindow = false;
				else if (bps_event_get_code(event) == NAVIGATOR_EXIT) {
					showingWindow = false;
				}
			} else if (domain == screen_get_domain()) {
				se = screen_event_get_event(event);
				screen_get_event_property_iv(se, SCREEN_PROPERTY_TYPE, &eventType);
				screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId);
				switch (eventType)
				{
				case SCREEN_EVENT_MTOUCH_TOUCH:
					screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId);
					if (contactId == 0 && !touching && !releasedThisRound) {
						touching = true;
						screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, startPos);
						endPos[0] = startPos[0];
						endPos[1] = startPos[1];
					}
					break;
				case SCREEN_EVENT_MTOUCH_MOVE:
					screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId);
					if (contactId == 0 && touching) {
						screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, endPos);
					}
					break;
				case SCREEN_EVENT_MTOUCH_RELEASE:
					screen_get_event_property_iv(se, SCREEN_PROPERTY_TOUCH_ID, &contactId);
					if (contactId == 0 && touching) {
						touching = false;
						releasedThisRound = true;
						screen_get_event_property_iv(se, SCREEN_PROPERTY_SOURCE_POSITION, endPos);
					}
					break;
				case SCREEN_EVENT_PROPERTY:
					break;
				default:
#ifdef _DEBUG
					fprintf(stderr, "Unknown screen event: %d\n", eventType);
#endif
					break;
				}
			}

			bps_get_event(&event, 0);
		}

		if (releasedThisRound) {
			m_selected = 0;
		} else if (touching) {
			if (!m_selected)
				m_selected = emuContext->controlAt(startPos);
			if (m_selected && (endPos[0] != startPos[0] || endPos[1] != startPos[1])) {
				m_selected->move(endPos[0] - startPos[0], endPos[1] - startPos[1], (unsigned*)m_size);
				buffer = draw(emuContext);
				startPos[0] = endPos[0];
				startPos[1] = endPos[1];
			}
		}

		if (buffer)
			post(buffer);
	}
}
Example #28
0
bool CCEGLView::handleEvents()
{
	bps_event_t*    event = NULL;
	mtouch_event_t  mtouch_event;
	int				touch_id = 0;
	int				val = 0;
	int				rc = 0;
	int 			domain = 0;
	char 			buf[4] = {0};

	for (;;)
	{
		rc = bps_get_event(&event, 1);
		assert(rc == BPS_SUCCESS);

		// break if no more events
		if (event == NULL)
			break;

		domain = bps_event_get_domain(event);

		if (domain == navigator_get_domain())
		{
			switch (bps_event_get_code(event))
			{
				case NAVIGATOR_SWIPE_DOWN:
					CCDirector::sharedDirector()->getKeypadDispatcher()->dispatchKeypadMSG(kTypeMenuClicked);
					break;

				case NAVIGATOR_EXIT:
					// exit the application
				//	release();
					end();
					break;

				case NAVIGATOR_WINDOW_INACTIVE:
					if (m_isWindowActive)
					{
						CCApplication::sharedApplication()->applicationDidEnterBackground();
						m_isWindowActive = false;
					}
					break;

				case NAVIGATOR_WINDOW_ACTIVE:
					if (!m_isWindowActive)
					{
						CCApplication::sharedApplication()->applicationWillEnterForeground();
						m_isWindowActive = true;
					}
					break;

				case NAVIGATOR_WINDOW_STATE:
				{
					switch(navigator_event_get_window_state(event))
					{
						case NAVIGATOR_WINDOW_FULLSCREEN:
							if (!m_isWindowActive)
							{
								CCApplication::sharedApplication()->applicationWillEnterForeground();
								m_isWindowActive = true;
							}
							break;
						case NAVIGATOR_WINDOW_THUMBNAIL:
							if (m_isWindowActive)
							{
								CCApplication::sharedApplication()->applicationDidEnterBackground();
								m_isWindowActive = false;
							}
							break;
					}
					break;
				}

				default:
					break;
			}
		}
		else if (domain == screen_get_domain())
		{
			m_screenEvent = screen_event_get_event(event);
			rc = screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_TYPE, &val);
			if (rc || val == SCREEN_EVENT_NONE)
				break;

			float x, y;

			switch (val)
			{
				case SCREEN_EVENT_CLOSE:
					fprintf(stderr, "SCREEN CLOSE EVENT!\n");
					break;

				case SCREEN_EVENT_MTOUCH_RELEASE:
					screen_get_mtouch_event(m_screenEvent, &mtouch_event, 0);
					touch_id = mtouch_event.contact_id;
					x = mtouch_event.x;
					y = mtouch_event.y;

					handleTouchesEnd(1, &touch_id, &x, &y);

					break;

				case SCREEN_EVENT_MTOUCH_TOUCH:
					screen_get_mtouch_event(m_screenEvent, &mtouch_event, 0);
					touch_id = mtouch_event.contact_id;
					x = mtouch_event.x;
					y = mtouch_event.y;

					handleTouchesBegin(1, &touch_id, &x, &y);

					break;

				case SCREEN_EVENT_MTOUCH_MOVE:
					screen_get_mtouch_event(m_screenEvent, &mtouch_event, 0);
					touch_id = mtouch_event.contact_id;
					x = mtouch_event.x;
					y = mtouch_event.y;

					handleTouchesMove(1, &touch_id, &x, &y);

					break;

				case SCREEN_EVENT_POINTER:
					{
						int buttons = 0;
						int pair_[2] = {0};
						float pair[2] = {0.0f};
						static bool mouse_pressed = false;

						// this is a mouse move event, it is applicable to a device with a usb mouse or simulator
						screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_BUTTONS, &buttons);
						screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_SOURCE_POSITION, pair_);
						pair[0] = (float)pair_[0];
						pair[1] = (float)pair_[1];
						if (buttons & SCREEN_LEFT_MOUSE_BUTTON)
						{
							if (mouse_pressed)
							{
								handleTouchesMove(1, &touch_id, &pair[0], &pair[1]);
							}
							else
							{
								// Left mouse button is pressed
								mouse_pressed = true;

								handleTouchesBegin(1, &touch_id, &pair[0], &pair[1]);
							}
						}
						else
						{
							if (mouse_pressed)
							{
								mouse_pressed = false;
								handleTouchesEnd(1, &touch_id, &pair[0], &pair[1]);
							}
						}
					}
					break;

				case SCREEN_EVENT_KEYBOARD:
					screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_KEY_FLAGS, &val);
					if (val & KEY_DOWN)
					{
						screen_get_event_property_iv(m_screenEvent, SCREEN_PROPERTY_KEY_SYM, &val);

						if (val >= ' ' && val < '~')
						{
							buf[0] = val;
							buf[1]=  '\0';
							CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(buf, 1);
						}
						else
						{
							val = val - 0xf000;
							buf[0] = val;
							buf[1]=  '\0';

							switch (val)
							{
								case 8: // backspace
									//		CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(kTypeBackClicked);
									CCIMEDispatcher::sharedDispatcher()->dispatchDeleteBackward();
									break;

								default:
									CCIMEDispatcher::sharedDispatcher()->dispatchInsertText(buf, 1);
									break;
							}
						}
					}

					break;

				default:
					break;
			}
		}
        else if (domain == sensor_get_domain())
        {
            if (bps_event_get_code(event) == SENSOR_ACCELEROMETER_READING)
            {
            	struct timespec time_struct;
            	long current_time;
                float x, y, z;

                clock_gettime(CLOCK_REALTIME, &time_struct);
                current_time = time2millis(&time_struct);

                sensor_event_get_xyz(event, &x, &y, &z);
                CCDirector::sharedDirector()->getAccelerometer()->update(current_time, -x, -y, z);
            }
        }
	}

	return true;
}
Example #29
0
static void qnx_handle_screen_event(qnx_input_t *qnx, bps_event_t *event)
{
   int type;
   screen_event_t screen_event = screen_event_get_event(event);

   screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &type);

   switch(type)
   {
      case SCREEN_EVENT_MTOUCH_TOUCH:
      case SCREEN_EVENT_MTOUCH_RELEASE:
      case SCREEN_EVENT_MTOUCH_MOVE:
         qnx_process_touch_event(qnx, screen_event, type);
         break;
      case SCREEN_EVENT_KEYBOARD:
         qnx_process_keyboard_event(qnx, screen_event, type);
         break;
#ifdef HAVE_BB10
      case SCREEN_EVENT_GAMEPAD:
         qnx_process_gamepad_event(qnx, screen_event, type);
          break;
      case SCREEN_EVENT_JOYSTICK:
         qnx_process_joystick_event(qnx, screen_event, type);
         break;
      case SCREEN_EVENT_DEVICE:
         {
            /* A device was attached or removed. */
            screen_device_t device;
            int attached, type, i;

            screen_get_event_property_pv(screen_event,
                  SCREEN_PROPERTY_DEVICE, (void**)&device);
            screen_get_event_property_iv(screen_event,
                  SCREEN_PROPERTY_ATTACHED, &attached);

            if (attached)
               screen_get_device_property_iv(device,
                     SCREEN_PROPERTY_TYPE, &type);

            if (attached &&
                  (
                   type == SCREEN_EVENT_GAMEPAD ||
                   type == SCREEN_EVENT_JOYSTICK ||
                   type == SCREEN_EVENT_KEYBOARD)
               )
            {
               for (i = 0; i < MAX_PADS; ++i)
               {
                  if (!qnx->devices[i].handle)
                  {
                     qnx->devices[i].handle = device;
                     qnx_handle_device(qnx, &qnx->devices[i]);
                     break;
                  }
               }
            }
            else
            {
               for (i = 0; i < MAX_PADS; ++i)
               {
                  if (device == qnx->devices[i].handle)
                  {
                     RARCH_LOG("Device %s: Disconnected.\n",
                           qnx->devices[i].id);
                     qnx_init_controller(qnx, &qnx->devices[i]);
                     break;
                  }
               }
            }
         }
         break;
#endif
      default:
         break;
   }
}
Example #30
0
static void
event(bps_event_t *event, int domain, int code, void *p)
{
    if (virtualkeyboard_get_domain() == domain) {
        switch (code) {
        case VIRTUALKEYBOARD_EVENT_VISIBLE:
            keyboard_visible = true;
            break;
        case VIRTUALKEYBOARD_EVENT_HIDDEN:
            keyboard_visible = false;
            break;
        }
    } else if (screen_get_domain() == domain) {

        screen_event_t screen_event = screen_event_get_event(event);

        int screen_val;
        screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &screen_val);

        switch (screen_val) {
        case SCREEN_EVENT_MTOUCH_TOUCH:
            if (!keyboard_visible) {
                virtualkeyboard_show();
            }
            break;
        case SCREEN_EVENT_KEYBOARD:
            screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_FLAGS, &screen_val);

            if (screen_val & KEY_DOWN) {
                screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_KEY_SYM,&screen_val);

                fprintf(stderr, "The '%c' key was pressed\n", (char)screen_val);

                switch (screen_val) {
                case KEYCODE_I:
                    // Display the email layout with "Send" enter key
                    virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_EMAIL, VIRTUALKEYBOARD_ENTER_SEND);
                    break;
                case KEYCODE_O:
                    // Display the phone layout with "Connect" enter key
                    virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_PHONE, VIRTUALKEYBOARD_ENTER_CONNECT);
                    break;
                case KEYCODE_P:
                    // Display the default layout with default enter key
                    virtualkeyboard_change_options(VIRTUALKEYBOARD_LAYOUT_DEFAULT, VIRTUALKEYBOARD_ENTER_DEFAULT);
                    break;
                case KEYCODE_H:
                    // Hide the keyboard
                    virtualkeyboard_hide();
                    break;
                case KEYCODE_A:
                    // Increment rotation angle
                    angle = fmod(angle + ANGLE_INCREMENT, CIRCLE_DEGREES );
                    break;
                case KEYCODE_Z:
                    // Decrement rotation angle
                    angle = fmod(angle - ANGLE_INCREMENT, CIRCLE_DEGREES );
                    break;
                default:
                    break;
                }
            }
            break;
        }
    }
}