Exemple #1
1
void Ctrl::WndUpdate()
{
	GuiLock __;
	LLOG("WndUpdate0");
	gdk_window_process_updates(gdk(), TRUE);
	FetchEvents(FALSE); // Should pickup GDK_EXPOSE and repaint the window
	gdk_flush();
}
Exemple #2
1
bool Ctrl::SetWndFocus()
{
	GuiLock __;
	LLOG("SetWndFocus0 " << Upp::Name(this) << ", top: " << top);
	if(top) {
		LLOG("SetWndFocus0 DO gdk: " << gdk());
		SetWndForeground();
		int t0 = msecs();
		while(!gtk_window_is_active(gtk()) && msecs() - t0 < 500) // Wait up to 500ms for window to become active - not ideal, but only possibility
			FetchEvents(true);
		FocusSync();
	}
	return true;
}
Exemple #3
0
void Ctrl::EventLoop(Ctrl *ctrl)
{
	GuiLock __;
	ASSERT_(IsMainThread(), "EventLoop can only run in the main thread");
	ASSERT(LoopLevel == 0 || ctrl);
	LoopLevel++;
	LLOG("Entering event loop at level " << LoopLevel << LOG_BEGIN);
	if(!GetMouseRight() && !GetMouseMiddle() && !GetMouseLeft())
		ReleaseCtrlCapture();
	Ptr<Ctrl> ploop;
	if(ctrl) {
		ploop = LoopCtrl;
		LoopCtrl = ctrl;
		ctrl->inloop = true;
	}

	while(!IsEndSession() &&
	      (ctrl ? ctrl->IsOpen() && ctrl->InLoop() : GetTopCtrls().GetCount())) {
		FetchEvents(TRUE);
		ProcessEvents();
	}

	if(ctrl)
		LoopCtrl = ploop;
	LoopLevel--;
	LLOG(LOG_END << "Leaving event loop ");
}
Exemple #4
0
void Ctrl::GuiSleep(int ms)
{
	GuiLock __;
	ASSERT_(IsMainThread(), "Only the main thread can perform GuiSleep");
	if(ms < 20) // Periodic timer is each 20ms, so that is the longest possible wait
		g_timeout_add(ms, (GSourceFunc) sOnce, NULL); // otherwise setup shorter timer
	FetchEvents(TRUE);
}
Exemple #5
0
bool Ctrl::ProcessEvents0(bool *quit, bool fetch)
{
	bool r = false;
	while(IsWaitingEvent0(fetch) && (!LoopCtrl || LoopCtrl->InLoop()))
		r = ProcessEvent0(quit, fetch) || r;
	TimerProc(GetTickCount());
	AnimateCaret();
	if(quit)
		*quit = IsEndSession();
	for(int i = 0; i < wins.GetCount(); i++)
		if(wins[i].ctrl)
			wins[i].ctrl->SyncScroll();
	gdk_window_process_all_updates();
	FetchEvents(FALSE); // To perform any pending GDK_EXPOSE
	gdk_flush();
	return r;
}
Exemple #6
0
bool Ctrl::SweepConfigure(bool wait)
{
	Ptr<Ctrl> this_ = this;
	bool r = false;
	FetchEvents(wait);
	for(int i = 0; i < Events.GetCount() && this_; i++) {
		Event& e = Events[i];
		if(e.type == GDK_CONFIGURE && this_ && top->id == e.windowid) {
			Rect rect = e.value;
			LLOG("SweepConfigure " << rect);
			if(GetRect() != rect)
				SetWndRect(rect);
			r = true;
			e.type = EVENT_NONE;
		}
	}
	return r;
}
Exemple #7
0
String Ctrl::DragGet(const char *fmt)
{
	LLOG("DragGet " << fmt << " " << (Ctrl::dnd_targets.Find(fmt) >= 0));
	if(Ctrl::dnd_targets.Find(fmt) < 0)
		return Null;
	dnd_data.Clear();
	dnd_data_wait = true;
	dnd_data_fmt = fmt;
	int t0 = msecs();
	gtk_drag_get_data(dnd_widget, dnd_context,
	                  GAtom(strcmp(fmt, "image") == 0 ? ~dnd_image_target :
	                        strcmp(fmt, "text") == 0 ? ~dnd_text_target :
	                        strcmp(fmt, "files") == 0 ? ~dnd_files_target : fmt),
	                  dnd_time);
	while(msecs() - t0 < 1000 && dnd_data_wait)
		FetchEvents(true);
	LLOG("DragGet data length " << dnd_data.GetLength());
	return dnd_data;
}
bool GPGManager::Initialize(bool ui_login) {
  state_ = kStart;
  do_ui_login_ = ui_login;
  event_data_initialized_ = false;
  achievement_data_initialized_ = false;
  player_data_.reset(nullptr);
#ifdef NO_GPG
  return true;
#endif

  /*
  // This code is here because we may be able to do this part of the
  // initialization here in the future, rather than relying on JNI_OnLoad below.
  auto env = reinterpret_cast<JNIEnv *>(SDL_AndroidGetJNIEnv());
  JavaVM *vm = nullptr;
  auto ret = env->GetJavaVM(&vm);
  assert(ret >= 0);
  gpg::AndroidInitialization::JNI_OnLoad(vm);
  */
  gpg::AndroidPlatformConfiguration platform_configuration;
  platform_configuration.SetActivity((jobject)SDL_AndroidGetActivity());

  // Creates a games_services object that has lambda callbacks.
  game_services_ =
      gpg::GameServices::Builder()
          .SetDefaultOnLog(gpg::LogLevel::VERBOSE)
          .SetOnAuthActionStarted([this](gpg::AuthOperation op) {
            state_ =
                state_ == kAuthUILaunched ? kAuthUIStarted : kAutoAuthStarted;
            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                        "GPG: Sign in started! (%d)", state_);
          })
          .SetOnAuthActionFinished([this](gpg::AuthOperation op,
                                          gpg::AuthStatus status) {
            SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                        "GPG: Sign in finished with a result of %d (%d)",
                        status, state_);
            if (op == gpg::AuthOperation::SIGN_IN) {
              state_ =
                  status == gpg::AuthStatus::VALID
                      ? kAuthed
                      : ((state_ == kAuthUIStarted || state_ == kAuthUILaunched)
                             ? kAuthUIFailed
                             : kAutoAuthFailed);
              if (state_ == kAuthed) {
                // If we just logged in, go fetch our data!
                FetchPlayer();
                FetchEvents();
                FetchAchievements();
              }
            } else if (op == gpg::AuthOperation::SIGN_OUT) {
              state_ = kStart;
              SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                          "GPG: SIGN OUT finished with a result of %d", status);
            } else {
              SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
                          "GPG: unknown auth op %d", op);
            }
          })
          .Create(platform_configuration);

  if (!game_services_) {
    SDL_LogError(SDL_LOG_CATEGORY_ERROR, "GPG: failed to create GameServices!");
    return false;
  }

  SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "GPG: created GameServices");
  return true;
}
Exemple #9
0
bool Ctrl::IsWaitingEvent0(bool fetch)
{
	if(fetch)
		FetchEvents(FALSE);
	return Events.GetCount();
}