void onMouseDrag(float _x, float _y, int _button) { if( _button == 1 ){ Tangram::handlePanGesture( _x-getMouseVelX()*1.0, _y+getMouseVelY()*1.0, _x, _y); } else if( _button == 2 ){ if ( getKeyPressed() == 'r') { float scale = -0.05; float rot = atan2(getMouseVelY(),getMouseVelX()); if( _x < getWindowWidth()/2.0 ) { scale *= -1.0; } Tangram::handleRotateGesture(getWindowWidth()/2.0, getWindowHeight()/2.0, rot*scale); } else if ( getKeyPressed() == 't') { Tangram::handleShoveGesture(getMouseVelY()*0.005); } else { Tangram::handlePinchGesture(getWindowWidth()/2.0, getWindowHeight()/2.0, 1.0 + getMouseVelY()*0.001, 0.f); } } requestRender(); }
int main( void ) { enum BUTTON_TYPE press; unsigned char cnt; while( 1 ) { press = getKeyPressed(); if( press >= B1 && press <= B9 ) { for( cnt = 0 ; cnt < press ; cnt ++ ) { bibber = 0; //trun on the bibber delay_ms( 1000 ); bibber = 1; delay_ms( 1000 ); } } } return 0; }
void fun2( void ) { enum BUTTON_TYPE button; buff[0] = 0; buff[1] = 9; buff[2] = 0; buff[3] = 0; buff[4] = 3; buff[5] = 0; buff[6] = 2; buff[7] = 0; ms50count=0; setTimer2_50ms(); EA = 1; while( 1 ) { button = getKeyPressed(); handleUserInput( button ); updateSEGLED(); } }
void fun1( void ) { enum BUTTON_TYPE button; short cnt; while( 1 ) { button = getKeyPressed(); if( button != NON ) { LedConPort= 0x00; DataPort = comNegative[button]; } /* for( cnt=0 ; cnt<8; cnt++ ) { LedConPort = cnt; DataPort = ch[cnt]; delay_ms( 5 ); } */ } }
/** polling method. Call every frame. */ int readPads() { int i; oldpaddata = paddata; paddata = 0; // in ms. u32 newtime = cpu_ticks() / CLOCKS_PER_MILISEC; time_since_last = newtime - curtime; curtime = newtime; int rslt = 0; for (i = 0; i < pad_count; ++i) { rslt |= readPad(&pad_data[i]); } for (i = 0; i < 16; ++i) { if (getKeyPressed(i + 1)) delaycnt[i] -= time_since_last; else delaycnt[i] = getKeyDelay(i + 1, 0); } return rslt; }
bool TouchKeyboard::getScanCode(uint8_t &scanCode, bool wait, Point &pressPt) { uint8_t row, key; bool result = getKeyPressed(row, key, wait, pressPt); if (result) { uint16_t scanCodes = pgm_read_word_near(&keyboardRow[row].codes); scanCode = pgm_read_byte_near(scanCodes + key); } return result; }
eKeys SfmlHandler::modalShow(std::string msg){ // Black transparent overlay sf::RectangleShape background(sf::Vector2f(_w, _h)); background.setFillColor(sf::Color(0, 0, 0, 180)); // Box containing the msg sf::RectangleShape box(sf::Vector2f(_w / 4, _h / 4)); box.setFillColor(sf::Color(255, 255, 255, 150)); box.setOrigin((_w / 4) / 2, (_h / 4) / 2); box.setPosition(_w / 2, _h / 2 + 22); // Message sf::Text txt; txt.setFont(_font); txt.setString(msg); txt.setCharacterSize(44); txt.setColor(sf::Color(55, 55, 55)); sf::FloatRect bounds = txt.getGlobalBounds(); txt.setOrigin(bounds.width / 2, bounds.height / 2); txt.setPosition(_w / 2, _h / 2); // Available Commands sf::Text commands; commands.setFont(_font); commands.setString("ESC, SPACE or RETURN : close, R : re-run the game"); commands.setCharacterSize(34); commands.setColor(sf::Color(255, 255, 255)); bounds = commands.getGlobalBounds(); commands.setOrigin(bounds.width / 2, bounds.height / 2); commands.setPosition(_w / 2, _h - (_h / 4)); // Draw items _window->draw(background); _window->draw(box); _window->draw(txt); _window->draw(commands); // Display the modal show(); while (42) { eKeys key = getKeyPressed(); if (key == eKeys::ESC || key == eKeys::SPACE || key == eKeys::RETURN || key == eKeys::R) return key; } }
void Game::Update(long gameTime) { if(firstUpdate && drawnOnce) { if(Preferences::newVersion) { Preferences::newVersion = false; Game::showMessage((String)"iSSB "+Preferences::version, Preferences::versionMessage); } firstUpdate = false; } if(getKeyPressed(Keys::ESCAPE) && !getPrevKeyPressed(Keys::ESCAPE)) { Exit(); } ScreenManager::Update(gameTime); }
/** Key getter with key repeats. * @param id The button ID * @return nonzero if button is being pressed just now */ int getKey(int id) { if ( (id <= 0) || (id >= 17) ) return 0; int kid = id - 1; // either the button was not pressed this frame, then reset counter and return // or it was, then handle the repetition if (getKeyOn(id)) { delaycnt[kid] = getKeyDelay(id, 0); return 1; } if(!getKeyPressed(id)) return 0; if(delaycnt[kid] <= 0) { delaycnt[kid] = getKeyDelay(id, 1); return 1; } return 0; }
/* ======================================================================== Name: initFtaLib Description: Initialize all IO peripherals related to FTA ======================================================================== */ void initFtaLib(void) { U32 flag = 0; I8 *env; I8 selftest = SELFTEST_ON; I8 selfstart = SELFSTART_V2F; I8 *arg[] = {"run", "bootcmd"}; /* We are "saving" the current configuration, because it is not valid after a setenv() */ env = getenv("selftest"); if(env) selftest = env[0]; env = getenv("selfstart"); if(env) selfstart = env[0]; #if defined(USE_DISPLAY) /* Init the use of the video */ init_display(); setVideoPio(); /* Display something on screen */ init_osd(); display = TRUE; #endif splash_update(64); /* Go to the prompt (Do not start automatically any application) */ if( (getKeyPressed() & FP_KEY_DOWN) || (selfstart == SELFSTART_UBOOT) ) { setenv("bootcmd", NULL); return; } splash_update(128); /* U-Boot Self test */ if(selftest == SELFTEST_ON) { if( test_fta() ) { hang(); } else { setenv("selftest","0"); saveenv(); } } if( getKeyPressed() & FP_KEY_POWER ) { usbApp(); } splash_update(256); if(selfstart == SELFSTART_NFS) { /* Set the Kernel (DEV) as the main application */ setenv("bootcmd","bootm 0x80000"); } else { /* Set the V2F as the main application * The address provided is in the RAM, so clear it to avoid confusion * (in case of some remaining data) */ memset((void *)0x80801000, 0, sizeof(ssa_header_t)); setenv("bootcmd","bootm 0x80801000"); } /* Set the Loader as the main application */ if( getKeyPressed() & FP_KEY_UP ) { setenv("bootcmd","bootm 0x2C0000"); } /* Set the Loader as the main application */ if (!eeprom_read(CFG_I2C_EEPROM_ADDR, EEPROM_SSD_REG, (unsigned char*)&flag, sizeof(flag))) { if(flag == FORCE_UPDATE_CODE) { setenv("bootcmd","bootm 0x2C0000"); } } do_run (NULL, 0, 2, arg); }
eChoice SfmlHandler::drawMenu(void) { _isMenu = true; eChoice choice = eChoice::QUIT; eChoice newChoice = eChoice::HUMAN; // Loop until a choice is made while (_isMenu) { // Get the pressed Key obviously eKeys key = getKeyPressed(); // Handle the key if (key == eKeys::ESC) return eChoice::QUIT; else if (key == eKeys::DOWN || key == eKeys::UP) newChoice = (newChoice == eChoice::HUMAN ? eChoice::IA : eChoice::HUMAN); else if (key == eKeys::RETURN){ return choice; } // If choice has changed, we cacn draw if (choice != newChoice){ // Draw the background clearWindow(); _drawBackground(); _window->draw(_logoSprite); // Configure first choice sf::Text choice_1; choice_1.setFont(_font); choice_1.setString("1 - Human vs Human"); choice_1.setCharacterSize(54); choice_1.setColor(sf::Color(255, 255, 255)); choice_1.setPosition(_w / 3, _h / 2); // Configure second choice sf::Text choice_2; choice_2.setFont(_font); choice_2.setString("2 - Human vs AI"); choice_2.setCharacterSize(54); choice_2.setColor(sf::Color(255, 255, 255)); choice_2.setPosition(_w / 3, (_h / 2) + SPACING_RATIO); // Draw choices _window->draw(choice_1); _window->draw(choice_2); // Draw the line pointing on the selected choice if (newChoice == eChoice::HUMAN) _drawSelectedChoice(choice_1); else _drawSelectedChoice(choice_2); // Display our beautiful drawings show(); // Update choice value to the actual value choice = newChoice; } } return eChoice::QUIT; }
bool TouchKeyboard::getKeyPressed(uint8_t &row, uint8_t &key, bool wait) { Point pressPt; return getKeyPressed(row, key, wait, pressPt); }