/*
 * Show snapshot select UI
 */
void Engine::ShowSnapshotSelectUI() {
  service_->Snapshots().ShowSelectUIOperation(
      ALLOW_CREATE_SNAPSHOT_INUI,
      ALLOW_DELETE_SNAPSHOT_INUI,
      MAX_SNAPSHOTS,
      SNAPSHOT_UI_TITLE,
      [this](gpg::SnapshotManager::SnapshotSelectUIResponse const & response) {
    LOGI("Snapshot selected");
    if (IsSuccess(response.status)) {
      if (response.data.Valid()) {
        LOGI("Description: %s", response.data.Description().c_str());
        LOGI("FileName %s", response.data.FileName().c_str());

        //Opening the snapshot data
        current_snapshot_ = response.data;
        LoadFromSnapshot();
      } else {
        LOGI("Creating new snapshot");
        SaveSnapshot();
      }
    } else {
      LOGI("ShowSelectUIOperation returns an error %d", response.status);
      EnableUI(true);
    }
  });
}
Beispiel #2
0
MainWindow::MainWindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{

	iSelfS= this;
	iOpenGLInitialized = false;
	ui.setupUi(this);

	QObject::connect(ui.actionExit , SIGNAL(triggered()), 
		this, SLOT(Exit())); 
	//
	QObject::connect(ui.actionOtev_t , SIGNAL(triggered()), 
		this, SLOT(OpenFile())); 

	QObject::connect(ui.actionSaveSnapshot , SIGNAL(triggered()), 
		this, SLOT(SaveSnapshot())); 
	QObject::connect(ui.actionSaveSequence , SIGNAL(triggered()), 
		this, SLOT(SaveSequence())); 
	QObject::connect(ui.actionPlugins , SIGNAL(triggered()), 
		this, SLOT(runPlugins())); 		
	iWidget  = CWidget::InitInstance(this);
	//iAnimationManager = CAnimationManager::InitInstance();
	setCentralWidget(iWidget);
	//continues in openglinitialized function
	iDock = new QDockWidget(QString("Properties"),this);
	iDock->setFeatures(QDockWidget::DockWidgetMovable|QDockWidget::DockWidgetFloatable);
	iDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
	addDockWidget(Qt::RightDockWidgetArea,iDock);
	Init();
}
Beispiel #3
0
static void ReallySnap(void)
{
	int x=SaveSnapshot();
	if(!x)
		FCEU_DispMessage("Error saving screen snapshot.",0);
	else
		FCEU_DispMessage("Screen snapshot %d saved.",0,x-1);
}
Beispiel #4
0
LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
	switch (msg) {
	case WM_CLOSE:
		return TRUE;

	case WM_KEYDOWN:
		switch (LOWORD(wParam)) {
		case VK_F9:
		{
			u8 *buf = malloc(width * height * 3);
			getSnapshot(buf);
			SaveSnapshot(buf, width * height * 3);
			free(buf);
		}
		}

	default:
		return DefWindowProc(hWnd, msg, wParam, lParam);
	}

	return FALSE;
}
Beispiel #5
0
void FCEU_PutImage(void)
{
	if(dosnapsave==2)	//Save screenshot as, currently only flagged & run by the Win32 build. //TODO SDL: implement this?
	{
		char nameo[512];
		strcpy(nameo,FCEUI_GetSnapshotAsName().c_str());
		if (nameo[0])
		{
			SaveSnapshot(nameo);
			FCEU_DispMessage("Snapshot Saved.",0);
		}
		dosnapsave=0;
	}
	if(GameInfo->type==GIT_NSF)
	{
		DrawNSF(XBuf);

		//Save snapshot after NSF screen is drawn.  Why would we want to do it before?
		if(dosnapsave==1)
		{
			ReallySnap();
			dosnapsave=0;
		}
	}
	else
	{
		//Save backbuffer before overlay stuff is written.
		if(!FCEUI_EmulationPaused())
			memcpy(XBackBuf, XBuf, 256*256);

		//Some messages need to be displayed before the avi is dumped
		DrawMessage(true);

#ifdef _S9XLUA_H
		// Lua gui should draw before the avi is dumped.
		FCEU_LuaGui(XBuf);
#endif

		//Save snapshot
		if(dosnapsave==1)
		{
			ReallySnap();
			dosnapsave=0;
		}

		if (!FCEUI_AviEnableHUDrecording()) snapAVI();

		if(GameInfo->type==GIT_VSUNI)
			FCEU_VSUniDraw(XBuf);

		FCEU_DrawSaveStates(XBuf);
		FCEU_DrawMovies(XBuf);
		FCEU_DrawLagCounter(XBuf);
		FCEU_DrawNTSCControlBars(XBuf);
		FCEU_DrawRecordingStatus(XBuf);
		ShowFPS();
	}

	if(FCEUD_ShouldDrawInputAids())
		FCEU_DrawInput(XBuf);

	//Fancy input display code
	if(input_display)
	{
		extern uint32 JSAutoHeld;
		uint32 held;

		int controller, c, ci, color;
		int i, j;
		uint32 on  = FCEUMOV_Mode(MOVIEMODE_PLAY) ? 0x90:0xA7;	//Standard, or Gray depending on movie mode
		uint32 oni = 0xA0;		//Color for immediate keyboard buttons
		uint32 blend = 0xB6;		//Blend of immiate and last held buttons
		uint32 ahold = 0x87;		//Auto hold
		uint32 off = 0xCF;

		uint8 *t = XBuf+(FSettings.LastSLine-9)*256 + 20;		//mbg merge 7/17/06 changed t to uint8*
		if(input_display > 4) input_display = 4;
		for(controller = 0; controller < input_display; controller++, t += 56)
		{
			for(i = 0; i < 34;i++)
				for(j = 0; j <9 ; j++)
					t[i+j*256] = (t[i+j*256] & 0x30) | 0xC1;
			for(i = 3; i < 6; i++)
				for(j = 3; j< 6; j++)
					t[i+j*256] = 0xCF;
			c = cur_input_display >> (controller * 8);

			// This doesn't work in anything except windows for now.
			// It doesn't get set anywhere in other ports.
#if defined(WIN32) && !defined(DINGUX)
			if (!oldInputDisplay) ci = FCEUMOV_Mode(MOVIEMODE_PLAY) ? 0:GetGamepadPressedImmediate() >> (controller * 8);
			else ci = 0;

			if (!oldInputDisplay && !FCEUMOV_Mode(MOVIEMODE_PLAY)) held = (JSAutoHeld >> (controller * 8));
			else held = 0;
#else
			// Put other port info here
			ci = 0;
			held = 0;
#endif

			//adelikat: I apologize to anyone who ever sifts through this color assignment
			//A
			if (held&1)	{ //If auto-hold
				if (!(ci&1) ) color = ahold;
				else
					color = (c&1) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed!
			}
			else {
				if (c&1) color = (ci&1) ? blend : on;	//If immedaite buttons are pressed and they match the previous frame, blend the colors
				else color = (ci&1) ? oni : off;
			}
			for(i=0; i < 4; i++)
			{
				for(j = 0; j < 4; j++)
				{
					if(i%3==0 && j %3 == 0)
						continue;
					t[30+4*256+i+j*256] = color;
				}
			}
			//B
			if (held&2)	{ //If auto-hold
				if (!(ci&2) ) color = ahold;
				else
					color = (c&2) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed!
			}
			else {
				if (c&2) color = (ci&2) ? blend : on;	//If immedaite buttons are pressed and they match the previous frame, blend the colors
				else color = (ci&2) ? oni : off;
			}
			for(i=0; i < 4; i++)
			{
				for(j = 0; j < 4; j++)
				{
					if(i%3==0 && j %3 == 0)
						continue;
					t[24+4*256+i+j*256] = color;
				}
			}
			//Select
			if (held&4)	{ //If auto-hold
				if (!(ci&4) ) color = ahold;
				else
					color = (c&4) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed!
			}
			else {
				if (c&4) color = (ci&4) ? blend : on;	//If immedaite buttons are pressed and they match the previous frame, blend the colors
				else color = (ci&4) ? oni : off;
			}
			for(i = 0; i < 4; i++)
			{
				t[11+5*256+i] = color;
				t[11+6*256+i] = color;
			}
			//Start
			if (held&8)	{ //If auto-hold
				if (!(ci&8) ) color = ahold;
				else
					color = (c&8) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed!
			}
			else {
				if (c&8) color = (ci&8) ? blend : on;	//If immedaite buttons are pressed and they match the previous frame, blend the colors
				else color = (ci&8) ? oni : off;
			}
			for(i = 0; i < 4; i++)
			{
				t[17+5*256+i] = color;
				t[17+6*256+i] = color;
			}
			//Up
			if (held&16)	{ //If auto-hold
				if (!(ci&16) ) color = ahold;
				else
					color = (c&16) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed!
			}
			else {
				if (c&16) color = (ci&16) ? blend : on;	//If immedaite buttons are pressed and they match the previous frame, blend the colors
				else color = (ci&16) ? oni : off;
			}
			for(i = 0; i < 3; i++)
			{
				for(j = 0; j < 3; j++)
				{
					t[3+i+256*j] = color;
				}
			}
			//Down
			if (held&32)	{ //If auto-hold
				if (!(ci&32) ) color = ahold;
				else
					color = (c&32) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed!
			}
			else {
				if (c&32) color = (ci&32) ? blend : on;	//If immedaite buttons are pressed and they match the previous frame, blend the colors
				else color = (ci&32) ? oni : off;
			}
			for(i = 0; i < 3; i++)
			{
				for(j = 0; j < 3; j++)
				{
					t[3+i+256*j+6*256] = color;
				}
			}
			//Left
			if (held&64)	{ //If auto-hold
				if (!(ci&64) ) color = ahold;
				else
					color = (c&64) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed!
			}
			else {
				if (c&64) color = (ci&64) ? blend : on;	//If immedaite buttons are pressed and they match the previous frame, blend the colors
				else color = (ci&64) ? oni : off;
			}
			for(i = 0; i < 3; i++)
			{
				for(j = 0; j < 3; j++)
				{
					t[3*256+i+256*j] = color;
				}
			}
			//Right
			if (held&128)	{ //If auto-hold
				if (!(ci&128) ) color = ahold;
				else
					color = (c&128) ? on : off; //If the button is pressed down (immediate) that negates auto hold, however it is only off if the previous frame the button wasn't pressed!
			}
			else {
				if (c&128) color = (ci&128) ? blend : on;	//If immedaite buttons are pressed and they match the previous frame, blend the colors
				else color = (ci&128) ? oni : off;
			}
			for(i = 0; i < 3; i++)
			{
				for(j = 0; j < 3; j++)
				{
					t[6+3*256+i+256*j] = color;
				}
			}
		}
Beispiel #6
0
void CScreenSpyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	CMenu* pSysMenu = GetSystemMenu(FALSE);
	switch (nID)
	{
	case IDM_CONTROL:
		{
			m_bIsCtrl = !m_bIsCtrl;
			pSysMenu->CheckMenuItem(IDM_CONTROL, m_bIsCtrl ? MF_CHECKED : MF_UNCHECKED);

			if (m_bIsCtrl)
			{
				if (m_bIsTraceCursor)
					SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)AfxGetApp()->LoadCursor(IDC_DOT));
				else
					SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hRemoteCursor);
			}
			else
				SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_NO));
		}
		break;
	case IDM_SEND_CTRL_ALT_DEL:
		{
			BYTE	bToken = COMMAND_SCREEN_CTRL_ALT_DEL;
			m_iocpServer->Send(m_pContext, &bToken, sizeof(bToken));
		}
		break;
	case IDM_TRACE_CURSOR: // 跟踪服务端鼠标
		{	
			m_bIsTraceCursor = !m_bIsTraceCursor;	
			pSysMenu->CheckMenuItem(IDM_TRACE_CURSOR, m_bIsTraceCursor ? MF_CHECKED : MF_UNCHECKED);
			if (m_bIsCtrl)
			{
				if (!m_bIsTraceCursor)
					SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hRemoteCursor);
				else
					SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)AfxGetApp()->LoadCursor(IDC_DOT));
			}
			// 重绘消除或显示鼠标
			OnPaint();
		}
		break;
	case IDM_BLOCK_INPUT: // 锁定服务端鼠标和键盘
		{
			bool bIsChecked = pSysMenu->GetMenuState(IDM_BLOCK_INPUT, MF_BYCOMMAND) & MF_CHECKED;
			pSysMenu->CheckMenuItem(IDM_BLOCK_INPUT, bIsChecked ? MF_UNCHECKED : MF_CHECKED);
			
			BYTE	bToken[2];
			bToken[0] = COMMAND_SCREEN_BLOCK_INPUT;
			bToken[1] = !bIsChecked;
			m_iocpServer->Send(m_pContext, bToken, sizeof(bToken));
		}
		break;
	case IDM_BLANK_SCREEN: // 服务端黑屏
		{
			bool bIsChecked = pSysMenu->GetMenuState(IDM_BLANK_SCREEN, MF_BYCOMMAND) & MF_CHECKED;
			pSysMenu->CheckMenuItem(IDM_BLANK_SCREEN, bIsChecked ? MF_UNCHECKED : MF_CHECKED);

			BYTE	bToken[2];
			bToken[0] = COMMAND_SCREEN_BLANK;
			bToken[1] = !bIsChecked;
			m_iocpServer->Send(m_pContext, bToken, sizeof(bToken));
		}
		break;
	case IDM_CAPTURE_LAYER: // 捕捉层
		{
			bool bIsChecked = pSysMenu->GetMenuState(IDM_CAPTURE_LAYER, MF_BYCOMMAND) & MF_CHECKED;
			pSysMenu->CheckMenuItem(IDM_CAPTURE_LAYER, bIsChecked ? MF_UNCHECKED : MF_CHECKED);
			
			BYTE	bToken[2];
			bToken[0] = COMMAND_SCREEN_CAPTURE_LAYER;
			bToken[1] = !bIsChecked;
			m_iocpServer->Send(m_pContext, bToken, sizeof(bToken));			
		}
		break;
	case IDM_SAVEDIB:
		SaveSnapshot();
		break;
	case IDM_GET_CLIPBOARD: // 获取剪贴板
		{
			BYTE	bToken = COMMAND_SCREEN_GET_CLIPBOARD;
			m_iocpServer->Send(m_pContext, &bToken, sizeof(bToken));
		}
		break;
	case IDM_SET_CLIPBOARD: // 设置剪贴板
		{
			SendLocalClipboard();
		}
		break;
	case IDM_ALGORITHM_SCAN: // 隔行扫描算法
		{
			SendResetAlgorithm(ALGORITHM_SCAN);
			pSysMenu->CheckMenuRadioItem(IDM_ALGORITHM_SCAN, IDM_ALGORITHM_DIFF, IDM_ALGORITHM_SCAN, MF_BYCOMMAND);
		}
		break;
	case IDM_ALGORITHM_DIFF: // 差异比较算法
		{
			SendResetAlgorithm(ALGORITHM_DIFF);
			pSysMenu->CheckMenuRadioItem(IDM_ALGORITHM_SCAN, IDM_ALGORITHM_DIFF, IDM_ALGORITHM_DIFF, MF_BYCOMMAND);
		}
		break;
	case IDM_DEEP_1:
		{
			SendResetScreen(1);
			pSysMenu->CheckMenuRadioItem(IDM_DEEP_1, IDM_DEEP_32, IDM_DEEP_1, MF_BYCOMMAND);
		}
		break;
	case IDM_DEEP_4_GRAY:
		{
			SendResetScreen(3);
			pSysMenu->CheckMenuRadioItem(IDM_DEEP_1, IDM_DEEP_32, IDM_DEEP_4_GRAY, MF_BYCOMMAND);
		}
		break;
	case IDM_DEEP_4_COLOR:
		{
			SendResetScreen(4);
			pSysMenu->CheckMenuRadioItem(IDM_DEEP_1, IDM_DEEP_32, IDM_DEEP_4_COLOR, MF_BYCOMMAND);
		}
		break;
	case IDM_DEEP_8_GRAY:
		{
			SendResetScreen(7);
			pSysMenu->CheckMenuRadioItem(IDM_DEEP_1, IDM_DEEP_32, IDM_DEEP_8_GRAY, MF_BYCOMMAND);
		}
		break;
	case IDM_DEEP_8_COLOR:
		{
			SendResetScreen(8);
			pSysMenu->CheckMenuRadioItem(IDM_DEEP_1, IDM_DEEP_32, IDM_DEEP_8_COLOR, MF_BYCOMMAND);
		}
		break;
	case IDM_DEEP_16:
		{
			SendResetScreen(16);
			pSysMenu->CheckMenuRadioItem(IDM_DEEP_1, IDM_DEEP_32, IDM_DEEP_16, MF_BYCOMMAND);
		}
		break;
	case IDM_DEEP_32:
		{
			SendResetScreen(32);
			pSysMenu->CheckMenuRadioItem(IDM_DEEP_4_GRAY, IDM_DEEP_32, IDM_DEEP_32, MF_BYCOMMAND);
		}
		break;
	default:
		CDialog::OnSysCommand(nID, lParam);
	}
}
Beispiel #7
0
void CScreenSpyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	switch (nID)
	{
	case IDM_CONTROL:
		{
			m_bIsCtrl = !m_bIsCtrl;
			pSysMenu->CheckMenuItem(IDM_CONTROL, m_bIsCtrl ? MF_CHECKED : MF_UNCHECKED);

			if (m_bIsCtrl)
			{
				if (m_bIsTraceCursor)
					SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)AfxGetApp()->LoadCursor(IDC_DOT));
				else
					SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)m_hRemoteCursor);
			}
			else
			{
				SetClassLong(m_hWnd, GCL_HCURSOR, (LONG)LoadCursor(NULL, IDC_NO));
			}


			break;
		}
	
	case IDM_TRACE_CURSOR: // 跟踪被控端鼠标
		{	
			m_bIsTraceCursor = !m_bIsTraceCursor;	                               //这里在改变数据
			pSysMenu->CheckMenuItem(IDM_TRACE_CURSOR, m_bIsTraceCursor ? MF_CHECKED : MF_UNCHECKED);    //在菜单打钩不打钩
		
			// 重绘消除或显示鼠标
			OnPaint();

			break;
		}

	case IDM_BLOCK_INPUT: // 锁定服务端鼠标和键盘
		{
			bool bIsChecked = pSysMenu->GetMenuState(IDM_BLOCK_INPUT, MF_BYCOMMAND) & MF_CHECKED;
			pSysMenu->CheckMenuItem(IDM_BLOCK_INPUT, bIsChecked ? MF_UNCHECKED : MF_CHECKED);

			BYTE	bToken[2];
			bToken[0] = COMMAND_SCREEN_BLOCK_INPUT;
			bToken[1] = !bIsChecked;
			m_iocpServer->Send(m_pContext, bToken, sizeof(bToken));

			break;
		}
	case IDM_SAVEDIB:    // 快照保存
		{
			SaveSnapshot();
			break;
		}

	case IDM_GET_CLIPBOARD: // 获取剪贴板
		{
			BYTE	bToken = COMMAND_SCREEN_GET_CLIPBOARD;
			m_iocpServer->Send(m_pContext, &bToken, sizeof(bToken));

			break;
		}
		
	case IDM_SET_CLIPBOARD: // 设置剪贴板
		{
			SendLocalClipboard();

			break;
		}
	

	default:
		CDialog::OnSysCommand(nID, lParam);
	}

	CDialog::OnSysCommand(nID, lParam);
}
/*
 * Initialize main sample UI,
 * invoking jui_helper functions to create java UIs
 */
void Engine::InitUI() {
  const int32_t buttonWidth = 600;
    // Show toast with app label
  ndk_helper::JNIHelper::GetInstance()->RunOnUiThread([]() {
    jui_helper::JUIToast toast(
        ndk_helper::JNIHelper::GetInstance()->GetAppLabel());
    toast.Show();
  });

  // The window initialization
  jui_helper::JUIWindow::Init(app_->activity, JUIHELPER_CLASS_NAME);

  //
  // Buttons
  //
  // Setting up game UI
  int32_t index = 0;
  jui_helper::JUILinearLayout *masterLayout = new jui_helper::JUILinearLayout();
  masterLayout->SetAttribute("Orientation",
                             jui_helper::LAYOUT_ORIENTATION_VERTICAL);
  masterLayout->SetAttribute("Gravity",
                             jui_helper::ATTRIBUTE_GRAVITY_CENTER_VERTICAL);
  masterLayout->SetLayoutParams(jui_helper::ATTRIBUTE_SIZE_MATCH_PARENT,
                                jui_helper::ATTRIBUTE_SIZE_WRAP_CONTENT);

  //Select stage
  jui_helper::JUILinearLayout *layout = new jui_helper::JUILinearLayout();
  layout->SetLayoutParams(jui_helper::ATTRIBUTE_SIZE_MATCH_PARENT,
                          jui_helper::ATTRIBUTE_SIZE_WRAP_CONTENT);
  layout->SetMargins(0, 50, 0, 50);
  layout->SetAttribute("Orientation",
                       jui_helper::LAYOUT_ORIENTATION_HORIZONTAL);
  layout->SetAttribute("Gravity", jui_helper::ATTRIBUTE_GRAVITY_CENTER);
  buttonLeft_ = new jui_helper::JUIButton("<<");
  buttonRight_ = new jui_helper::JUIButton(">>");
  labelWorld_ = new jui_helper::JUITextView("Stage 1");
  buttonLeft_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      //Change game world
      if (current_world_ > 0) {
        current_world_--;
        UpdateGameUI();
      }
    }
  });
  buttonRight_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      //Change game world
      if (current_world_ < NUM_GAME_WORLD - 1) {
        current_world_++;
        UpdateGameUI();
      }
    }
  });

  layout->AddView(buttonLeft_);
  layout->AddView(labelWorld_);
  layout->AddView(buttonRight_);
  masterLayout->AddView(layout);

  for (int32_t i = 0; i < 4; ++i) {
    button_games_[index + 0] = CreateButton(index + 0);
    button_games_[index + 1] = CreateButton(index + 1);
    button_games_[index + 2] = CreateButton(index + 2);

    //Center element
    button_games_[index + 1]
        ->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                  jui_helper::LAYOUT_PARAMETER_TRUE);
    button_games_[index + 1]->SetMargins(50, 50, 50, 50);

    jui_helper::JUILinearLayout *layout = new jui_helper::JUILinearLayout();
    layout->SetLayoutParams(jui_helper::ATTRIBUTE_SIZE_MATCH_PARENT,
                            jui_helper::ATTRIBUTE_SIZE_WRAP_CONTENT);
    layout->SetMargins(0, 50, 0, 50);
    layout->SetAttribute("Orientation",
                         jui_helper::LAYOUT_ORIENTATION_HORIZONTAL);
    layout->SetAttribute("Gravity", jui_helper::ATTRIBUTE_GRAVITY_CENTER);
    layout->AddView(button_games_[index + 0]);
    layout->AddView(button_games_[index + 1]);
    layout->AddView(button_games_[index + 2]);
    masterLayout->AddView(layout);

    index += 3;
  }
  jui_helper::JUIWindow::GetInstance()->AddView(masterLayout);

  status_text_ = new jui_helper::JUITextView(
      service_->IsAuthorized() ? "Signed In." : "Signed Out.");

  status_text_->AddRule(jui_helper::LAYOUT_PARAMETER_ALIGN_PARENT_BOTTOM,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  status_text_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  jui_helper::JUIWindow::GetInstance()->AddView(status_text_);

  // Sign in button.
  button_sign_in_ = new jui_helper::JUIButton(
      service_->IsAuthorized() ? "Sign Out" : "Sign In");
  button_sign_in_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, status_text_);
  button_sign_in_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                           jui_helper::LAYOUT_PARAMETER_TRUE);
  button_sign_in_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    LOGI("button_sign_in_ click: %d", message);
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      if (service_->IsAuthorized()) {
        service_->SignOut();
      } else {
        service_->StartAuthorizationUI();
      }
    }
  });
  button_sign_in_->SetAttribute("MinimumWidth", buttonWidth);
  button_sign_in_->SetMargins(0, 50, 0, 0);

  // Select button.
  button_select_ = new jui_helper::JUIButton("Select");
  button_select_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, button_sign_in_);
  button_select_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                          jui_helper::LAYOUT_PARAMETER_TRUE);
  button_select_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    LOGI("button_select_ click: %d", message);
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      EnableUI(false);
      ShowSnapshotSelectUI();
    }
  });
  button_select_->SetAttribute("MinimumWidth", buttonWidth);

  // Save button.
  button_save_ = new jui_helper::JUIButton("Save");
  button_save_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, button_select_);
  button_save_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  button_save_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    LOGI("button_save_ click: %d", message);
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      //Save snapshot
      SaveSnapshot();
    }
  });
  button_save_->SetAttribute("MinimumWidth", buttonWidth);

  // Load button.
  button_load_ = new jui_helper::JUIButton("Load");
  button_load_->AddRule(jui_helper::LAYOUT_PARAMETER_ABOVE, button_save_);
  button_load_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  button_load_->SetCallback(
      [this](jui_helper::JUIView * view, const int32_t message) {
    LOGI("button_load_ click: %d", message);
    if (message == jui_helper::JUICALLBACK_BUTTON_UP) {
      EnableUI(false);
      LoadFromSnapshot();
    }
  });
  button_load_->SetAttribute("MinimumWidth", buttonWidth);

  jui_helper::JUIWindow::GetInstance()->AddView(button_sign_in_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_select_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_save_);
  jui_helper::JUIWindow::GetInstance()->AddView(button_load_);

  textViewFPS_ = new jui_helper::JUITextView("0.0FPS");
  textViewFPS_->SetAttribute("Gravity", jui_helper::ATTRIBUTE_GRAVITY_LEFT);
  textViewFPS_->SetAttribute("TextColor", 0xffffffff);
  textViewFPS_->SetAttribute("TextSize", jui_helper::ATTRIBUTE_UNIT_SP, 18.f);
  textViewFPS_->SetAttribute("Padding", 10, 10, 10, 10);
  jui_helper::JUIWindow::GetInstance()->AddView(textViewFPS_);

  // Progress bar
  progressBar_ = new jui_helper::JUIProgressBar();
  progressBar_->AddRule(jui_helper::LAYOUT_PARAMETER_CENTER_IN_PARENT,
                        jui_helper::LAYOUT_PARAMETER_TRUE);
  jui_helper::JUIWindow::GetInstance()->AddView(progressBar_);
  progressBar_->SetAttribute("Hidden", true);

  //Update game ui
  UpdateGameUI();

  if (authorizing_)
    EnableUI(false);
  return;
}
bool
Engine::ResolveConflicts(gpg::SnapshotManager::OpenResponse const &openResponse,
                         const int32_t retry) {
  if (openResponse.conflict_id == "") {
    LOGI("No conflict detected");
    return true;
  }
  //
  // Note: Expecting ResolveConflicts() is called within callback, we are using
  // blocking read here
  //
  gpg::SnapshotManager &manager = service_->Snapshots();
  gpg::SnapshotManager::OpenResponse responseBase =
      manager.OpenBlocking(openResponse.conflict_base.FileName(),
                           gpg::SnapshotConflictPolicy::MANUAL);
  gpg::SnapshotManager::ReadResponse responseReadBase =
      manager.ReadBlocking(responseBase.data);
  ParseSnapshotData(responseReadBase.data);

  // Temporary store data,
  int32_t temp_scores[NUM_GAME_WORLD][NUM_GAME_STAGES]; //960 bytes
  for (int32_t i = 0; i < NUM_GAME_WORLD; ++i)
    for (int32_t j = 0; j < NUM_GAME_STAGES; ++j) {
      temp_scores[i][j] = scores_[i][j];
    }

  gpg::SnapshotManager::OpenResponse responseRemote =
      manager.OpenBlocking(openResponse.conflict_remote.FileName(),
                           gpg::SnapshotConflictPolicy::MANUAL);
  gpg::SnapshotManager::ReadResponse responseReadRemote =
      manager.ReadBlocking(responseRemote.data);
  ParseSnapshotData(responseReadRemote.data);

  // Merging them
  for (int32_t i = 0; i < NUM_GAME_WORLD; ++i)
    for (int32_t j = 0; j < NUM_GAME_STAGES; ++j) {
      if (temp_scores[i][j] > scores_[i][j])
        scores_[i][j] = temp_scores[i][j];
    }

  //Create image to represent the snapshot
  //Reading png from asset for now
  std::vector<uint8_t> pngData;
  if (!ndk_helper::JNIHelper::GetInstance()->ReadFile("gps.png", &pngData)) {
    LOGI("Can not open a file:%s", "gps.png");
    return false;
  }

  gpg::SnapshotMetadataChange::Builder builder;
  gpg::SnapshotMetadataChange metadata_change =
      builder.SetDescription("CollectAllTheStar savedata ")
          .SetCoverImageFromPngData(pngData).Create();

  //Resolve conflict
  gpg::SnapshotManager::CommitResponse commitResponse =
      manager.ResolveConflictBlocking(openResponse.data, metadata_change,
                                      openResponse.conflict_id);
  if (IsSuccess(commitResponse.status)) {
    LOGI("Conflict resolution succeeded");
  } else {
    LOGI("Conflict resolution failed error: %d", commitResponse.status);
  }

  //Try to re-open,
  gpg::SnapshotManager::OpenResponse retryResponse =
      manager.OpenBlocking(current_snapshot_.FileName(),
                         gpg::SnapshotConflictPolicy::MANUAL);
  if (IsSuccess(retryResponse.status)) {
    if (retryResponse.conflict_id != "") {
      if (retry > MAX_RETRY)
        return false;
      LOGI("Need conflict resolution again..");
      return ResolveConflicts(retryResponse, retry + 1);
    }
  }

  SaveSnapshot();  //Currently, we need to save data again.
                          //We will have convenient API to resolve conflicts and save data
                          //In upcoming release
  return true;
}
Beispiel #10
0
void DecodeKey( word keyCode, word keyFlags )
{
    static bool resetState = false;

    bool flagKeyRelease = ( keyFlags & fKeyRelease ) != 0;

    bool reset1 = ( keyFlags & ( fKeyCtrlLeft | fKeyCtrlRight ) ) == ( fKeyCtrlLeft | fKeyCtrlRight );

    static bool reset2 = false;
    if( keyCode == KEY_POWER && !flagKeyRelease ) reset2 = true;
    if( keyCode == KEY_POWER && flagKeyRelease ) reset2 = false;

    static bool reset3 = false;
    if( keyCode == KEY_PRNTSCR && !flagKeyRelease ) reset3 = true;
    if( keyCode == KEY_PRNTSCR && flagKeyRelease ) reset3 = false;

    if( ( reset1 || reset2 || reset3 ) != resetState )
    {
        resetState = reset1 || reset2 || reset3;
        CPU_Reset( resetState );
        DelayMs( 100 );
    }

    //------------------------------------------------------

    if( !flagKeyRelease )
    {
        if( ( keyFlags & fKeyCtrl ) != 0 )
        {
            switch( keyCode )
            {
                case KEY_1 :
                    specConfig.specVideoMode = 0;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_2 :
                    specConfig.specVideoMode = 1;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_3 :
                    specConfig.specVideoMode = 2;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_4 :
                    specConfig.specVideoMode = 3;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_5 :
                    specConfig.specVideoMode = 4;
                    Spectrum_UpdateConfig();
                    SaveConfig();
                    break;
                case KEY_F12 :
                    CPU_NMI();
                    break;
            }
        }
        else if ( fKeyAlt & keyFlags )
        {
            int kc;

            switch ( keyCode )
            {
                case KEY_0:
                    kc = 0;
                    break;
                case KEY_1:
                    kc = 1;
                    break;
                case KEY_2:
                    kc = 2;
                    break;
                case KEY_3:
                    kc = 3;
                    break;
                case KEY_4:
                    kc = 4;
                    break;
                case KEY_5:
                    kc = 5;
                    break;
                case KEY_6:
                    kc = 6;
                    break;
                case KEY_7:
                    kc = 7;
                    break;
                case KEY_8:
                    kc = 8;
                    break;
                case KEY_9:
                    kc = 9;
                    break;
                default:
                    kc = -1;
                    break;
            }
            if ( kc >= 0 )
            {
                char snaName[ 0x10 ];
                sniprintf( snaName, sizeof(snaName), "!slot_%.1d.sna", kc );
                SaveSnapshot( snaName );
            }
        }

        else
        {
            switch( keyCode )
            {
                case KEY_ESC :
                    Debugger_Enter();
                    break;

                case KEY_PAUSE :
                    Shell_Pause();
                    break;

                case KEY_F1 :
                    specConfig.specTurbo = 0;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F2 :
                    specConfig.specTurbo = 1;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F3 :
                    specConfig.specTurbo = 2;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;
                case KEY_F4 :
                    specConfig.specTurbo = 3;
                    Spectrum_UpdateConfig();
                    //SaveConfig();
                    break;

                case KEY_F5 :
                    SystemBus_Write( 0xc00000, 0x00004 );
                    break;
                case KEY_F6 :
                    {
                        CPU_Stop();

                        byte specPort7ffd = SystemBus_Read( 0xc00017 );

                        byte page = ( specPort7ffd & ( 1 << 3 ) ) != 0 ? 7 : 5;
                        dword addr = 0x800000 | ( page << 13 );

                        SystemBus_Write( 0xc00020, 0 );  // use bank 0

                        for( int i = 0x1800; i < 0x1b00; i += 2 )
                        {
                            SystemBus_Write( addr + ( i >> 1 ), 0x3838 );
                        }

                        CPU_Start();
                    }
                    break;

                case KEY_F9 :
                    Shell_SettingsMenu();
                    break;

                case KEY_F10 :
                    Shell_DisksMenu();
                    break;

                case KEY_F11 :
                    if( ( keyFlags & fKeyShift ) != 0 ) Shell_SaveSnapshot();
                    else SaveSnapshot( UpdateSnaName() );
                    break;

                case KEY_F12 :
                    Shell_Browser();
                    break;

                case KEY_EQUALS :
                case KEY_KP_PLUS :
                    if( !Tape_Started() ) Tape_Restart();
                    break;

                case KEY_MINUS :
                case KEY_KP_MINUS :
                    if( !Tape_Started() ) Tape_Start();
                    else Tape_Stop();
                    break;

                case KEY_INSERT :
                    specConfig.specMouseSwap = !specConfig.specMouseSwap;
                    break;
            }
        }
    }
}