Exemplo n.º 1
0
void RunMenu(unsigned char Menu_Index)
{
  unsigned char key = 0xFF , menu_index  , SubMenuIndex                   ;
  unsigned char First_Item , Active_Item , Active_Item_Index              ;
  unsigned char CallBackIndex                                             ;

  Clear_LCD(Color_BK)                                                     ;
  DrawRectFill(0,0,240,25,Blue)                                           ;
  DrawRectFill(0,295,240,25,Blue)                                         ;
  Color    = 0xFFFF                                                       ;
  Color_BK = Blue                                                         ;
  PutStringCN16(4,4,Menus[Menu_Index].MenuTitle)                          ;
  Color    = Black                                                        ;
  Color_BK = WINDOW_BK_COLOR                                              ;  
  
  Clear_LCD(STATUS_BK_COLOR)                                              ;
  Color_BK = STATUS_BK_COLOR                                              ;
  PutStringCN24(10,294,"确认")                                            ; // 底栏
  PutStringCN24(185,294,"取消")                                           ; 
  LoadMenu(MAIN_MENU,PERMISSION)                                          ;
  Initial_Menu()                                                          ;
  for(;;)
  {
    key = GetKeyPress()                                                   ;
    switch(key)
    {
    case Up: case Down: case Left: case Right:
      MenuMessage(key)                                                    ;
      break                                                               ;
    case  8:
      MenuMessage(Up)                                                     ;
      break                                                               ;
    case  0:
      MenuMessage(Down)                                                   ;
      break                                                               ;
    case Esc:
      {
//        if(Current_Menu[0][6]!=EMPTY)
//          Item_OP[Current_Menu[0][6]](0,0)                                ; // 菜单执行函数
        menu_index = GetMenuIndex()                                       ;
        if(Menus[menu_index].MasterMenu!=EMPTY)
//          return Menus[menu_index].MasterMenu                             ;
        {
          LoadMenu(Menus[menu_index].MasterMenu,PERMISSION)               ;
          Initial_Menu()                                                  ;
        }
        break                                                             ;
      }
    case OK: case Enter:
      {
        First_Item          = GetFirstItem()                              ;
        Active_Item         = GetActiveItem()                             ;
        Active_Item_Index   = GetActiveItemIndex()                        ;        
        if(MENU_ITEM[Active_Item_Index].CallBackFuncIndex!=EMPTY)           // 有操作函数
        {
          CallBackIndex= MENU_ITEM[Active_Item_Index].CallBackFuncIndex   ;
          SubMenuIndex = MENU_ITEM[Active_Item_Index].SubMenuIndex        ;
          if(SubMenuIndex!=EMPTY)                                           // 有操作函数且有动态子菜单
          {
            SubMenuIndex = MENU_ITEM[Active_Item_Index].SubMenuIndex      ; 
            if(Item_OP[CallBackIndex](0,Active_Item_Index  )==0x00)         // 生成子菜单成功
              Initial_Menu()                                              ; // 初始化动态子菜单
            else
              Redraw_Menu(First_Item,Active_Item)                         ; // 未生成子菜单,重画原菜单
          }
          else
          {
            Item_OP[CallBackIndex](0,Active_Item_Index  )                 ; // 无动态子菜单
            Redraw_Menu(First_Item,Active_Item)                           ; // 重画菜单
          }
        }
        
/*        
        if(MENU_ITEM[Item_Index].CallBackFuncIndex!=EMPTY)
        {
          Item_OP[MENU_ITEM[Item_Index].CallBackFuncIndex](0,Active_Index);
          if(  (MENU_ITEM[Item_Index].SubMenuIndex!=EMPTY)
             &&(Master_Or_Sub==GOTO_SUB                  ))
            return MENU_ITEM[Item_Index].SubMenuIndex                     ;
          Redraw_Menu(First_Index,Active_Index,(UCHAR**)P_Current_Menu)   ;          
        }
        else
*/      
        else  
        if(MENU_ITEM[Active_Item_Index].SubMenuIndex!=EMPTY)
//          return MENU_ITEM[Item_Index].SubMenuIndex                       ;
        {
          LoadMenu(MENU_ITEM[Active_Item_Index].SubMenuIndex,PERMISSION)  ;
          Initial_Menu()                                                  ;
        }
        break                                                             ;          
      }
    case Power:
      return                                                              ;
    default:
      break                                                               ;
    }
  }
}  
Exemplo n.º 2
0
int Game(int port, const char *ApplicationPath) {

	// Variabeln definieren
    char Name[20];		// Array für Spielername
    int Zeichen;		// Variable zur Verarbeitung der eingelesenen Zeichen
	int key;			// Variable zum einlesen der Zeichen von der Tastatur
	int dir = 0;		// Variable zum speichern der Richtung
	int dir_old = 0;	// Variable zum speichern der letzten Richtung
	int score;			// Variable für den Score
	int winner;			// Variable für Rückgabewert der Highscorefunktion
						// Wird 1 wenn Highscore geknackt wurde, sonst 0
	int i = 0;


	// Bildschirm löschen
	ClearWindow();

	// Spielernamen einlesen
	SelectFont("Arial MS", 15, FONT_NORMAL);
	DrawTextXY (50, 50, COL_GREEN, "Bitte Namen eingeben:");
	while((key = GetKeyPress()) != W_KEY_RETURN ){
		Zeichen = key;
		// Anzahl der Zeichen begrenzen, Leertaste unterdrücken
		if ((Zeichen >= ' ')&&(i < 19) && (Zeichen != 0x20) ){
			Name[i] = Zeichen;
			Name[i+1] = '\0';
			i++;
		}

		// Möglichkeit Zeichen zu löschen
		if( Zeichen == '\b'){
			if(i>0){
				i--;
				Name[i]='\0';
				DrawFilledRectangle(270, 25, 300, 40, COL_BLACK, 1);
			}
		}

		// Bisherige Eingabe anzeigen
		DrawTextXY (270, 50, COL_RED, Name);
	}

	DrawTextXY (50, 80, COL_GREEN, "Now playing! [ESC] to escape");

	 if (InitSerialPort(port, Bd9600, P_NONE, 8, 1) == 0)	// COM1
	 {
		 printf("\nPort opened: COM%d", port);
		 do
	     {
			 if(IsKeyPressReady())	// Wenn Taste gedrückt
			 {
	        	key = GetKeyPress();

				switch(key)
				{
				case W_KEY_CURSOR_UP:
					if(dir_old != 'd')
					{
						dir = 'u';
					}
					break;
				case W_KEY_CURSOR_DOWN:
					if(dir_old != 'u')
					{
						dir = 'd';
					}
					break;
				case W_KEY_CURSOR_LEFT:
					if(dir_old != 'r')
					{
						dir = 'l';
					}
					break;
				case W_KEY_CURSOR_RIGHT:
					if(dir_old != 'l')
					{
						dir = 'r';
					}
					break;
				case W_KEY_ESCAPE:
				case W_KEY_CLOSE_WINDOW:
					ShutdownSerialPort();
					return 0;
					break;
				default:
					key = NO_VALID_KEY;
					break;
				}
				// Nur wenn Key gültig ist und der Wert geändert hat ein Zeichen ans Carmekit senden
				if(dir != dir_old)
                {
					 SendByteToSerialPort(dir);
					 // Alter Wert speichern
					 dir_old = dir;
				}

	         }

	        score = GetByteFromSerialPort();
	     } while (score == -1);



	     ShutdownSerialPort();

	     winner=highscore(Name , score , ApplicationPath);
	     SelectFont("Arial MS", 20, FONT_ITALIC);

	     if(winner == 1)
	     {
	    	 DrawTextXY (220, 200, COL_GREEN, "Du hast den High Score geknackt!");
	     }
	     else
	     {
	    	 DrawTextXY (220, 200, COL_GREEN, "Game over.");
	     }

	     SelectFont("Arial MS", 15, FONT_NORMAL);
	     DrawTextXY (220, 230, COL_GREEN, "Press any key to continue.");

	     while(!IsKeyPressReady())
	    	 ;
	  }

	return 0;
}
Exemplo n.º 3
0
NS_IMETHODIMP
nsSoftKeyBoard::HandleEvent(nsIDOMEvent* aEvent)
{
  if (!aEvent)
    return NS_OK;

  nsCOMPtr<nsIDOMNSEvent> nsevent(do_QueryInterface(aEvent));

  nsCOMPtr<nsIDOMEventTarget> target;
  nsevent->GetOriginalTarget(getter_AddRefs(target));
  nsCOMPtr<nsIContent> targetContent = do_QueryInterface(target);


  if (!targetContent || !targetContent->IsNodeOfType(nsINode::eHTML_FORM_CONTROL))
    return NS_OK;

  nsCOMPtr<nsIFormControl> formControl(do_QueryInterface(targetContent));
  if (!formControl)
    return NS_OK;


  PRInt32 controlType = formControl->GetType();
      
  if (controlType != NS_FORM_TEXTAREA       &&  controlType != NS_FORM_INPUT_TEXT &&
      controlType != NS_FORM_INPUT_PASSWORD &&  controlType != NS_FORM_INPUT_FILE) 
  {
    return NS_OK;
  }

  nsAutoString eventType;
  aEvent->GetType(eventType);

  if (eventType.EqualsLiteral("keypress"))
  {
    PRUint32 keyCode;
    nsCOMPtr<nsIDOMKeyEvent> keyEvent(do_QueryInterface(aEvent));
    
    if (!keyEvent)
      return NS_OK;
    
    if (NS_FAILED(keyEvent->GetKeyCode(&keyCode)))
      return NS_OK;
    
    if (keyCode == nsIDOMKeyEvent::DOM_VK_RETURN && controlType != NS_FORM_TEXTAREA)
    {
      nsSoftKeyBoardService::CloseSIP();
    }

#ifdef WINCE

    if (IsSmartphone())
    {

      PRUint32 charCode;
      keyEvent->GetCharCode(&charCode);

#if 0
      char buffer[2];
      sprintf(buffer, "%d = %d", keyCode, charCode);
      MessageBox(0, buffer, buffer, 0);
#endif
     
      /* value determined by inspection */
      if (keyCode == 120)
      {
        // We're using this key, no one else should
        aEvent->StopPropagation();
        aEvent->PreventDefault();

        if (mTimer)
          mTimer->Cancel(); 

        keybd_event(VK_SPACE, 0, 0, 0);
        keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);

        return NS_OK;
      }

      /* value determined by inspection */
      if (keyCode == 119)
      {
        // We're using this key, no one else should
        aEvent->StopPropagation();
        aEvent->PreventDefault();

        if (mTimer)
          mTimer->Cancel(); 
        
        mUsage++;
        if (mUsage>eUpperCase) 
          mUsage=eNumbers;

        return NS_OK;
      }

      if (mUsage == eNumbers)
        return NS_OK;

      if ( charCode > nsIDOMKeyEvent::DOM_VK_0 && charCode <= nsIDOMKeyEvent::DOM_VK_9) // [0-9)
      {
        // We're using this key, no one else should
        aEvent->StopPropagation();
        aEvent->PreventDefault();

        if (mTimer)
          mTimer->Cancel();
        
        if (mCurrentDigit != charCode)
        {
          mCurrentDigit = charCode;
          mCurrentDigitCount = 1;
        }
        else
        {
          mCurrentDigitCount++;
        }

        mTimer = do_CreateInstance("@mozilla.org/timer;1");
        if (!mTimer)
          return NS_OK;

        BYTE key = GetKeyPress(mCurrentDigit, mCurrentDigitCount);

        if (mUsage == eUpperCase)
          key = _toupper(key);

        PRUint32 closure = key;
        
        mTimer->InitWithFuncCallback(SoftKeyboardTimerCB,
                                     (void*)closure,
                                     700, 
                                     nsITimer::TYPE_ONE_SHOT);
        return NS_OK;
      }
      else
      {
        mCurrentDigit = 0;
        mCurrentDigitCount = 0;
      }
      
    }
#endif

    return NS_OK;
  }

  if (eventType.EqualsLiteral("click"))
  {
    nsSoftKeyBoardService::OpenSIP();
    return NS_OK;
  }

  PRBool popupConditions = PR_FALSE;
  nsCOMPtr<nsPIDOMWindow> privateWindow = do_QueryInterface(mTopWindow);
  if (!privateWindow)
    return NS_OK;

  nsIDOMWindowInternal *rootWindow = privateWindow->GetPrivateRoot();
  if (!rootWindow)
    return NS_OK;

  nsCOMPtr<nsIDOMWindow> windowContent;
  rootWindow->GetContent(getter_AddRefs(windowContent));
  privateWindow = do_QueryInterface(windowContent);

  if (privateWindow)
    popupConditions = privateWindow->IsLoadingOrRunningTimeout();
  
  if (eventType.EqualsLiteral("focus"))
  {
    //    if (popupConditions == PR_FALSE)
    nsSoftKeyBoardService::OpenSIP();
  }
  else
    nsSoftKeyBoardService::CloseSIP();
  
  return NS_OK;
}
Exemplo n.º 4
0
//キーボードとパッドの両方から入力を取得する
int MyInput::GetInputPress(const int KeyCode, State par, int _padnum){
	if (par == PRESSED_NOT){
		return  min(GetKeyPress(KeyCode, par), GetPadPress(KeyCode, _padnum, par));
	}
	return max(GetKeyPress(KeyCode, par), GetPadPress(KeyCode, _padnum, par));
}
Exemplo n.º 5
0
int Edit(SpielerName *Spieler)
{

	// Buffervariablen definieren

	char spielername1[15]; //lokaler string name1
	char spielername2[15];	// Lokaler string name2
	char spielerbuffer[15];	// Name buffer fuer loeschfunktion

	int key;
	int i=0;			//Countervariable



	// Buffervariablen "leeren"

	strncpy(spielername1,"              ",15);
	strncpy(spielername2,"              ",15);

	// Grundbild zeichen

	DrawFilledRectangle(0, 0, 1300, 750, COL_BLACK,1) ;		// Hintergrund
	DrawEmptyRectangle(0, 0, 1300, 750, COL_GREEN, 4) ;		// Umrandung
	DrawTextXY(550,51,COL_GREEN,"Level-Modus");
	DrawEmptyRectangle(150,90,1000,50, COL_GREEN, 2) ;
	DrawTextXY(350,130,COL_GREEN,"Name von Spieler 1 eingeben");
	DrawTextXY(550,200,COL_GREEN,spielername1);
	DrawEmptyRectangle(150, 440,1000,50, COL_GREEN, 2) ;
	DrawTextXY(550,480,COL_GREEN,"0: Beenden");
	// Spieler 1

	// Durchlauf 14 mal, bis das array voll ist

	for(i=0;i<14;i++)
	{
		key=GetKeyPress(); // Tastendruck auslesen

		if((key>=32) && (key<=128)) // Nur Gross- und Kleinbuchstaben beruecksichtigen
		{
			// Hintergrundbild aktualisieren
			DrawFilledRectangle(0, 0, 1300, 750, COL_BLACK,1) ;
			DrawEmptyRectangle(0, 0, 1300, 750, COL_GREEN, 4) ;
			DrawTextXY(550,51,COL_GREEN,"Level-Modus");
			DrawEmptyRectangle(150,90,1000,50, COL_GREEN, 2) ;
			DrawTextXY(350,130,COL_GREEN,"Name von Spieler 1 eingeben");

			spielername1[i]=key;	// Zeichenzuweisung
			DrawTextXY(550,200,COL_GREEN,spielername1);
			DrawEmptyRectangle(150, 440,1000,50, COL_GREEN, 2) ;
			DrawTextXY(550,480,COL_GREEN,"0: Beenden");
		}


		if (key==8) // 8 entspricht backspace
		{
			DrawFilledRectangle(0, 0, 1300, 750, COL_BLACK,1) ;
			strncpy(spielerbuffer,spielername1,15);		// aktueller Name zwischenspeichern
			strncpy(spielername1,"              ",15); 	// Spielername reseten
			strncpy(spielername1,spielerbuffer,i-1);	// Name zurückschreiben mit länge -1
			strncpy(spielerbuffer,"              ",15);	// Buffer löschen
			DrawEmptyRectangle(0, 0, 1300, 750, COL_GREEN, 4) ;
			DrawTextXY(550,51,COL_GREEN,"Level-Modus");
			DrawEmptyRectangle(150,90,1000,50, COL_GREEN, 2) ;
			DrawTextXY(350,130,COL_GREEN,"Name von Spieler 1 eingeben");
			DrawEmptyRectangle(150, 440,1000,50, COL_GREEN, 2) ;
			DrawTextXY(550,200,COL_GREEN,spielername1);	// Name erneut schreiben
			DrawTextXY(550,480,COL_GREEN,"0: Beenden");
			i=i-2; // Counter auf Start reseten
		}
		if (key== 13)// wenn Enter gedrückt wird (Enter = ASCII 13)
		{	i=14;		// Counter auf "voll" setzten, Schlaufe wird verlassen
		}

		if (key== '0') // Abbruch
		{
			return 0;
		}

	}





	// Spieler 2

	i=0; //Zähler reseten

	//Hintergrund zeichen
	DrawFilledRectangle(0, 0, 1300, 750, COL_BLACK,1) ;
	DrawEmptyRectangle(0, 0, 1300, 750, COL_GREEN, 4) ;
	DrawTextXY(550,51,COL_GREEN,"Level-Modus");
	DrawEmptyRectangle(150,90,1000,50, COL_GREEN, 2) ;
	DrawTextXY(350,130,COL_GREEN,"Name von Spieler 1 eingeben");
	DrawEmptyRectangle(150,250,1000,50, COL_GREEN, 2) ;
	DrawTextXY(350,290,COL_GREEN,"Name von Spieler 2 eingeben");
	DrawEmptyRectangle(150, 440,1000,50, COL_GREEN, 2) ;
	DrawTextXY(550,480,COL_GREEN,"0: Beenden");


	spielername2[i]=key;	// Zeichenzuweisung
	DrawTextXY(550,200,COL_GREEN,spielername1);
	DrawTextXY(550,360,COL_GREEN,spielername2);

	// durchlaufen bis array voll
	for(i=0;i<14;i++)
	{
		key=GetKeyPress(); // Tastendruck auslesen
		if((key>=32) && (key<=128)) // Nur Gross- und Kleinbuchstaben beruecksichtigen
		{
			//Hintergrund aktualisieren
			DrawFilledRectangle(0, 0, 1300, 750, COL_BLACK,1) ;
			DrawEmptyRectangle(0, 0, 1300, 750, COL_GREEN, 4) ;
			DrawTextXY(550,51,COL_GREEN,"Level-Modus");
			DrawEmptyRectangle(150,90,1000,50, COL_GREEN, 2) ;
			DrawTextXY(350,130,COL_GREEN,"Name von Spieler 1 eingeben");
			DrawEmptyRectangle(150,250,1000,50, COL_GREEN, 2) ;
			DrawTextXY(350,290,COL_GREEN,"Name von Spieler 2 eingeben");
			DrawEmptyRectangle(150, 440,1000,50, COL_GREEN, 2) ;
			DrawTextXY(550,480,COL_GREEN,"0: Beenden");


			spielername2[i]=key;	// Zeichenzuweisung
			DrawTextXY(550,200,COL_GREEN,spielername1);
			DrawTextXY(550,360,COL_GREEN,spielername2);
		}

		if (key==8) // 8 entspricht backspace
		{
			DrawFilledRectangle(0, 0, 1300, 750, COL_BLACK,1) ;
			strncpy(spielerbuffer,spielername2,15);		// aktueller Name zwischenspeichern
			strncpy(spielername2,"              ",15); 	// Spielername reseten
			strncpy(spielername2,spielerbuffer,i-1);	// Name zurückschreiben mit länge -1
			strncpy(spielerbuffer,"              ",15);	// Buffer löschen
			DrawEmptyRectangle(0, 0, 1300, 750, COL_GREEN, 4) ;
			DrawTextXY(550,51,COL_GREEN,"Level-Modus");
			DrawEmptyRectangle(150,90,1000,50, COL_GREEN, 2) ;
			DrawTextXY(350,130,COL_GREEN,"Name von Spieler 1 eingeben");
			DrawEmptyRectangle(150,250,1000,50, COL_GREEN, 2) ;
			DrawTextXY(350,290,COL_GREEN,"Name von Spieler 2 eingeben");
			DrawTextXY(550,200,COL_GREEN,spielername1);
			DrawTextXY(550,360,COL_GREEN,spielername2);
			DrawEmptyRectangle(150, 440,1000,50, COL_GREEN, 2) ;
			DrawTextXY(550,480,COL_GREEN,"0: Beenden");

			i=i-2; // Counter reseten
		}

		if (key== 13) // Wenn Enter, counter auf "voll", schlaufe wird verlassen
		{
			i=14;
		}

		if (key== '0') // Abbruch
		{
			return 0;
		}

	}


	// Übertrag aus buffer auf Counter übertragen

	strncpy(Spieler->Spieler1,spielername1,15);
	strncpy(Spieler->Spieler2,spielername2,15);

	return 1;
}