void Region::cursorUp(Cursor* c) { if ( c == palette->MostRecentCursorDown() ) { palette->SetMostRecentCursorDown(NULL); } if ( isButton() ) { if ( buttonTooDeep(c) ) { NosuchDebug("Ignoring button up, too deep!"); } else if ( palette->isButtonDown(name) != true ) { NosuchDebug("Ignoring button up, isButtonDown wasn't true!"); } else { NosuchDebug("REGION::BUTTONUP %s %s",name.c_str(),c->DebugBrief().c_str()); buttonUp(name); } } else if ( Palette::selector_check && _graphicBehaviour->isSelectorDown() ) { NosuchDebug(1,"REGION::CURSORUP WITH GRAPHIC SELECTOR %s",c->DebugBrief().c_str()); _graphicBehaviour->cursorUpWithSelector(c); } else if ( Palette::selector_check && _musicBehaviour->isSelectorDown() ) { NosuchDebug(1,"REGION::CURSORUP WITH MUSIC SELECTOR %s",c->DebugBrief().c_str()); _musicBehaviour->cursorUpWithSelector(c); } else { NosuchVector pos = c->curr_pos; palette->cursorUp(c); NosuchDebug(2,"REGION::CURSORUP %s",c->DebugBrief().c_str()); _graphicBehaviour->cursorUp(c); _musicBehaviour->cursorUp(c); } }
void GameInput::zoomOutView(int key, bool isdown) { if (isdown) { buttonDown(TriggerStart + UserInput::Trigger_ZoomOut, key, 0); } else { buttonUp(TriggerStart + UserInput::Trigger_ZoomOut, key, 0); } }
void GameInput::toggleView(int key, bool isdown) { if (isdown) { buttonDown(TriggerStart + UserInput::Trigger_ToggleView, key, 0); } else { buttonUp(TriggerStart + UserInput::Trigger_ToggleView, key, 0); } }
void GameInput::moveRush(int key, bool isdown) { if (isdown) { buttonDown(Rush, key, 0); } else { buttonUp(Rush, key, 0); } }
void GameInput::moveRight(int key, bool isdown) { if (isdown) { buttonDown(MoveRight, key, 0); } else { buttonUp(MoveRight, key, 0); } }
void GameInput::moveBackward(int key, bool isdown) { if (isdown) { buttonDown(MoveBackward, key, 0); } else { buttonUp(MoveBackward, key, 0); } }
//-------------------------------------------------------------- void testApp::keyReleased(int key){ if (((char) key) == '+') { midiMapMode = !midiMapMode; if (freqOutThread.isThreadRunning()) freqOutThread.lock(); freqOutThread.toggleMidiOut(); if (freqOutThread.isThreadRunning()) freqOutThread.unlock(); } if (((char) key) == '1') { midiout.sendControlChange(midiChannel, midiId, midiValue); printf("1"); } if (((char) key) == '2') { midiout.sendControlChange(midiChannel, midiId+1, midiValue); printf("2"); } if (((char) key) == '3') { midiout.sendNoteOn(midiChannel, midiId+1, midiValue); printf("3"); } if (((char) key) == '4') { midiout.sendNoteOff(midiChannel, midiId+1, midiValue); printf("3"); } if ( key == 'f') { ofToggleFullscreen(); } if ( key == 'r') { //absMaxOutDelay = 0; } if ( key == 'p') { isScopePaused = !isScopePaused; } if ( key == 's') { if (showStimuli) { //stimulusPlayer.randomizeStimuli(); //logger.push_back(myGetElapsedTimeMillis(), LoggerData::PARTICIPANT_NUMBER, participantNumber); //logger.push_back(myGetElapsedTimeMillis(), LoggerData::PARTICIPANT_ID, participantID); //logger.unlock(); //if (participantNumber % 2) { // stimulusPlayer.loadStimuli("data/stimuli/text/form4.txt", "stimuli/audio/form1/"); //} else { // stimulusPlayer.loadStimuli("data/stimuli/text/form1.txt", "stimuli/audio/form4/"); //} //stimulusPlayer.start(); } } if ( ((char) key) == 'b') { buttonUp(); } }
void Region::processCursor(SpaceCursor* c, int downdragup) { if ( isButton() ) { DEBUGPRINT(("Region::processCursor BUTTON!")); switch ( downdragup ) { case CURSOR_DOWN: buttonDown(); break; case CURSOR_UP: buttonUp(); break; } } else { DEBUGPRINT(("Region::processCursor SURFACE!")); switch ( downdragup ) { case CURSOR_DOWN: cursorDown(c); break; case CURSOR_DRAG: cursorDrag(c); break; case CURSOR_UP: cursorUp(c); break; } } }
void Region::cursorUp(SpaceCursor* c) { if ( c == palette()->MostRecentSpaceCursorDown() ) { palette()->SetMostRecentSpaceCursorDown(NULL); } if ( isButton() ) { if ( buttonTooDeep(c) ) { NosuchDebug("Ignoring button up, too deep!"); } else if ( palette()->isButtonDown(name) != true ) { NosuchDebug("Ignoring button up, isButtonDown wasn't true!"); } else { buttonUp(); } } else { _graphicBehaviour->cursorUp(c); _musicBehaviour->cursorUp(c); } }
bool Dialog::SelectCount(const std::string &header, u32 min, u32 max, u32 & cur, u8 step) { Display & display = Display::Get(); if(min >= max) min = 0; if(cur > max || cur < min) cur = min; const ICN::icn_t system = Settings::Get().ExtGameEvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; // preload AGG::Cache::PreloadObject(system); // cursor Cursor & cursor = Cursor::Get(); cursor.Hide(); Text text(header, Font::BIG); const u8 spacer = Settings::Get().QVGA() ? 5 : 10; Box box(text.h() + spacer + 30, true); const Rect & pos = box.GetArea(); Point pt; // text pt.x = pos.x + (pos.w - text.w()) / 2; pt.y = pos.y; text.Blit(pt); // sprite edit const Surface & sprite_edit = AGG::GetICN(ICN::TOWNWIND, 4); pt.x = pos.x + 80; pt.y = pos.y + 35; sprite_edit.Blit(pt, display); text.Set(GetString(cur)); pt.x = pos.x + 80 + (sprite_edit.w() - text.w()) / 2; pt.y = pos.y + 36; text.Blit(pt); // buttons pt.x = pos.x + 150; pt.y = pos.y + 31; Button buttonUp(pt, ICN::TOWNWIND, 5, 6); pt.x = pos.x + 150; pt.y = pos.y + 47; Button buttonDn(pt, ICN::TOWNWIND, 7, 8); pt.x = pos.x; pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 1).h(); Button buttonOk(pt, system, 1, 2); pt.x = pos.x + pos.w - AGG::GetICN(system, 3).w(); pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 3).h(); Button buttonCancel(pt, system, 3, 4); text.Set("MAX", Font::SMALL); const Rect rectMax(pos.x + 173, pos.y + 38, text.w(), text.h()); text.Blit(rectMax.x, rectMax.y); LocalEvent & le = LocalEvent::Get(); buttonUp.Draw(); buttonDn.Draw(); buttonOk.Draw(); buttonCancel.Draw(); bool redraw_count = false; cursor.Show(); display.Flip(); // message loop while(le.HandleEvents()) { le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); le.MousePressLeft(buttonUp) ? buttonUp.PressDraw() : buttonUp.ReleaseDraw(); le.MousePressLeft(buttonDn) ? buttonDn.PressDraw() : buttonDn.ReleaseDraw(); if(PressIntKey(min, max, cur)) redraw_count = true; // max if(le.MouseClickLeft(rectMax)) { cur = max; redraw_count = true; } else // up if((le.MouseWheelUp(pos) || le.MouseClickLeft(buttonUp)) && cur < max) { cur += cur + step <= max ? step : max - cur; redraw_count = true; } else // down if((le.MouseWheelDn(pos) || le.MouseClickLeft(buttonDn)) && min < cur) { cur -= min + cur >= step ? step : cur; redraw_count = true; } if(redraw_count) { cursor.Hide(); pt.x = pos.x + 80; pt.y = pos.y + 35; sprite_edit.Blit(pt, display); text.Set(GetString(cur), Font::BIG); pt.x = pos.x + 80 + (sprite_edit.w() - text.w()) / 2; pt.y = pos.y + 36; text.Blit(pt); cursor.Show(); display.Flip(); redraw_count = false; } if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || le.MouseClickLeft(buttonOk)){ return true; } else if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancel)){ cur = 0; break; } } return false; }
UtlBoolean TaoPhoneComponentAdaptor::handleMessage(OsMsg& rMsg) { UtlBoolean handled = FALSE; int msgType = ((TaoMessage&)rMsg).getMsgSubType(); if( TaoMessage::REQUEST_PHONECOMPONENT == msgType) { switch (((TaoMessage&)rMsg).getCmd()) { case TaoMessage::BUTTON_PRESS: if (TAO_SUCCESS == buttonPress((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::BUTTON_UP: if (TAO_SUCCESS == buttonUp((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::BUTTON_DOWN: if (TAO_SUCCESS == buttonDown((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::BUTTON_GET_INFO: if (TAO_SUCCESS == getButtonInfo((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::BUTTON_SET_INFO: if (TAO_SUCCESS == setButtonInfo((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::BUTTON_GET_PHONELAMP: if (TAO_SUCCESS == getAssociatedPhoneLamp((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::HOOKSWITCH_GET_STATE: if (TAO_SUCCESS == getHookswState((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::HOOKSWITCH_SET_STATE: if (TAO_SUCCESS == setHookswState((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::HOOKSWITCH_GET_CALL: if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::LAMP_GET_MODE: if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::LAMP_GET_SUPPORTED_MODES: if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::LAMP_GET_BUTTON: if (TAO_SUCCESS == getHookswCall((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::LAMP_SET_MODE: if (TAO_SUCCESS == setLampMode((TaoMessage&)rMsg)) { handled = TRUE; } break; /* ----------------------------- PHONEDISPALY --------------------------------- */ case TaoMessage::DISPLAY_GET_DISPLAY: if (TAO_SUCCESS == getDisplay((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::DISPLAY_GET_ROWS: if (TAO_SUCCESS == getDisplayRows((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::DISPLAY_GET_COLS: if (TAO_SUCCESS == getDisplayColumns((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::DISPLAY_SET_DISPLAY: if (TAO_SUCCESS == setDisplay((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::DISPLAY_GET_CONTRAST: if (TAO_SUCCESS == getDisplayContrast((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::DISPLAY_SET_CONTRAST: if (TAO_SUCCESS == setDisplayContrast((TaoMessage&)rMsg)) { handled = TRUE; } break; /* ----------------------------- PHONEMIC --------------------------------- */ case TaoMessage::MIC_GET_GAIN: if (TAO_SUCCESS == getMicGain((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::MIC_SET_GAIN: if (TAO_SUCCESS == setMicGain((TaoMessage&)rMsg)) { handled = TRUE; } break; /* ----------------------------- PHONERINGER --------------------------------- */ case TaoMessage::RINGER_SET_INFO: if (TAO_SUCCESS == setRingerInfo((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::RINGER_SET_PATTERN: if (TAO_SUCCESS == setRingerPattern((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::RINGER_SET_VOLUME: if (TAO_SUCCESS == setRingerVolume((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::RINGER_GET_INFO: if (TAO_SUCCESS == getRingerInfo((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::RINGER_GET_PATTERN: if (TAO_SUCCESS == getRingerPattern((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::RINGER_GET_VOLUME: if (TAO_SUCCESS == getRingerVolume((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::RINGER_GET_MAX_PATTERN_INDEX: if (TAO_SUCCESS == getMaxRingPatternIndex((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::RINGER_GET_NUMBER_OF_RINGS: if (TAO_SUCCESS == getNumberOfRings((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::RINGER_IS_ON: if (TAO_SUCCESS == isRingerOn((TaoMessage&)rMsg)) { handled = TRUE; } break; /* ----------------------------- PHONESPEAKER --------------------------------- */ case TaoMessage::SPEAKER_SET_VOLUME: if (TAO_SUCCESS == setSpeakerVolume((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::SPEAKER_GET_VOLUME: if (TAO_SUCCESS == getSpeakerVolume((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::SPEAKER_GET_NOMINAL_VOLUME: if (TAO_SUCCESS == getSpeakerNominalVolume((TaoMessage&)rMsg)) { handled = TRUE; } break; /* ----------------------------- PHONEEXTSPEAKER --------------------------------- */ case TaoMessage::EXTSPEAKER_SET_VOLUME: if (TAO_SUCCESS == setExtSpeakerVolume((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::EXTSPEAKER_GET_VOLUME: if (TAO_SUCCESS == getExtSpeakerVolume((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::EXTSPEAKER_GET_NOMINAL_VOLUME: if (TAO_SUCCESS == getExtSpeakerNominalVolume((TaoMessage&)rMsg)) { handled = TRUE; } break; /* ----------------------------- PHONEGROUP --------------------------------- */ case TaoMessage::PHONEGROUP_ACTIVATE: if (TAO_SUCCESS == activateGroup((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::PHONEGROUP_DEACTIVATE: if (TAO_SUCCESS == deactivateGroup((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::PHONEGROUP_GET_COMPONENTS: if (TAO_SUCCESS == getGroupComponents((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::PHONEGROUP_GET_DESCRIPTION: if (TAO_SUCCESS == getGroupDescription((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::PHONEGROUP_GET_TYPE: if (TAO_SUCCESS == getGroupType((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::PHONEGROUP_IS_ACTIVATED: if (TAO_SUCCESS == isGroupActivated((TaoMessage&)rMsg)) { handled = TRUE; } break; case TaoMessage::COMPONENT_RESULT: if (TAO_SUCCESS == returnResult((TaoMessage&)rMsg)) { handled = TRUE; } break; default: break; } } else if (TaoMessage::RESPONSE_PHONECOMPONENT == msgType) { if (TAO_SUCCESS == returnResult((TaoMessage&)rMsg)) handled = TRUE; } if (!handled) { TaoMessage* pMsg = (TaoMessage*) &rMsg; pMsg->setArgCnt(1); pMsg->setArgList("-1"); if (mpSvrTransport->postMessage(*pMsg)) handled = TRUE; } return handled; }
u16 Dialog::RecruitMonster(const Monster & monster, u16 available) { Display & display = Display::Get(); LocalEvent & le = LocalEvent::Get(); // cursor Cursor & cursor = Cursor::Get(); const Cursor::themes_t oldcursor = cursor.Themes(); cursor.Hide(); cursor.SetThemes(Cursor::POINTER); // calculate max count u32 max = 0; const payment_t paymentMonster = monster.GetCost(); const Kingdom & kingdom = world.GetKingdom(Settings::Get().CurrentColor()); while(kingdom.AllowPayment(paymentMonster * max) && max < available) ++max; u32 result = max; payment_t paymentCosts(paymentMonster * result); const Sprite & box = AGG::GetICN(ICN::RECRBKG, 0); const Rect pos((display.w() - box.w()) / 2, Settings::Get().QVGA() ? (display.h() - box.h()) / 2 - 15 : (display.h() - box.h()) / 2, box.w(), box.h()); Background back(pos); back.Save(); box.Blit(pos.x, pos.y); Point dst_pt; std::string str; Text text; // smear hardcore text "Cost per troop:" const Sprite & smear = AGG::GetICN(ICN::TOWNNAME, 0); dst_pt.x = pos.x + 144; dst_pt.y = pos.y + 55; smear.Blit(Rect(8, 1, 120, 12), dst_pt); text.Set(_("Cost per troop:"), Font::SMALL); dst_pt.x = pos.x + 206 - text.w() / 2; dst_pt.y = pos.y + 55; text.Blit(dst_pt); // text recruit monster str = _("Recruit %{name}"); String::Replace(str, "%{name}", monster.GetMultiName()); text.Set(str, Font::BIG); dst_pt.x = pos.x + (pos.w - text.w()) / 2; dst_pt.y = pos.y + 25; text.Blit(dst_pt); // sprite monster const Sprite & smon = AGG::GetICN(monster.ICNMonh(), 0); dst_pt.x = pos.x + 70 - smon.w() / 2; dst_pt.y = pos.y + 130 - smon.h(); smon.Blit(dst_pt); bool extres = 2 == paymentMonster.GetValidItems(); // info resource // gold const Sprite & sgold = AGG::GetICN(ICN::RESOURCE, 6); dst_pt.x = pos.x + (extres ? 150 : 175); dst_pt.y = pos.y + 75; sgold.Blit(dst_pt); dst_pt.x = pos.x + (extres ? 105 : 130); dst_pt.y = pos.y + 200; sgold.Blit(dst_pt); text.Set(GetString(paymentMonster.gold), Font::SMALL); dst_pt.x = pos.x + (extres ? 183 : 205) - text.w() / 2; dst_pt.y = pos.y + 103; text.Blit(dst_pt); // crystal if(paymentMonster.crystal) { const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 4); RedrawResourceInfo(sres, pos, paymentMonster.crystal, 225, 75, 240, 103); dst_pt.x = pos.x + 180; dst_pt.y = pos.y + 200; sres.Blit(dst_pt); } else // mercury if(paymentMonster.mercury) { const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 1); RedrawResourceInfo(sres, pos, paymentMonster.mercury, 225, 72, 240, 103); dst_pt.x = pos.x + 180; dst_pt.y = pos.y + 197; sres.Blit(dst_pt); } else // wood if(paymentMonster.wood) { const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 0); RedrawResourceInfo(sres, pos, paymentMonster.wood, 225, 72, 240, 103); dst_pt.x = pos.x + 180; dst_pt.y = pos.y + 197; sres.Blit(dst_pt); } else // ore if(paymentMonster.ore) { const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 2); RedrawResourceInfo(sres, pos, paymentMonster.ore, 225, 72, 240, 103); dst_pt.x = pos.x + 180; dst_pt.y = pos.y + 197; sres.Blit(dst_pt); } else // sulfur if(paymentMonster.sulfur) { const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 3); RedrawResourceInfo(sres, pos, paymentMonster.sulfur, 225, 75, 240, 103); dst_pt.x = pos.x + 180; dst_pt.y = pos.y + 200; sres.Blit(dst_pt); } else // gems if(paymentMonster.gems) { const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 5); RedrawResourceInfo(sres, pos, paymentMonster.gems, 225, 75, 240, 103); dst_pt.x = pos.x + 180; dst_pt.y = pos.y + 200; sres.Blit(dst_pt); } // text number buy text.Set(_("Number to buy:")); dst_pt.x = pos.x + 30; dst_pt.y = pos.y + 163; text.Blit(dst_pt); Background static_info(Rect(pos.x + 16, pos.y + 125, pos.w - 32, 122)); static_info.Save(); RedrawCurrentInfo(pos, available, result, paymentMonster, paymentCosts); // buttons dst_pt.x = pos.x + 34; dst_pt.y = pos.y + 249; Button buttonOk(dst_pt, ICN::RECRUIT, 8, 9); dst_pt.x = pos.x + 187; dst_pt.y = pos.y + 249; Button buttonCancel(dst_pt, ICN::RECRUIT, 6, 7); dst_pt.x = pos.x + 230; dst_pt.y = pos.y + 155; Button buttonMax(dst_pt, ICN::RECRUIT, 4, 5); dst_pt.x = pos.x + 208; dst_pt.y = pos.y + 156; Button buttonUp(dst_pt, ICN::RECRUIT, 0, 1); dst_pt.x = pos.x + 208; dst_pt.y = pos.y + 171; Button buttonDn(dst_pt, ICN::RECRUIT, 2, 3); buttonOk.Draw(); buttonCancel.Draw(); buttonMax.Draw(); buttonUp.Draw(); buttonDn.Draw(); cursor.Show(); display.Flip(); bool redraw = false; // str loop while(le.HandleEvents()) { le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); le.MousePressLeft(buttonMax) ? buttonMax.PressDraw() : buttonMax.ReleaseDraw(); le.MousePressLeft(buttonUp) ? buttonUp.PressDraw() : buttonUp.ReleaseDraw(); le.MousePressLeft(buttonDn) ? buttonDn.PressDraw() : buttonDn.ReleaseDraw(); if(PressIntKey(0, max, result)) { paymentCosts = paymentMonster * result; redraw = true; } if(le.MouseClickLeft(buttonUp) && result < max) { ++result; paymentCosts += paymentMonster; redraw = true; } else if(le.MouseClickLeft(buttonDn) && result) { --result; paymentCosts -= paymentMonster; redraw = true; } else if(le.MouseClickLeft(buttonMax) && result != max) { result = max; paymentCosts = paymentMonster * max; redraw = true; } if(redraw) { cursor.Hide(); static_info.Restore(); RedrawCurrentInfo(pos, available, result, paymentMonster, paymentCosts); cursor.Show(); display.Flip(); redraw = false; } if(le.MouseClickLeft(buttonOk) || Game::HotKeyPress(Game::EVENT_DEFAULT_READY)) break; if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)){ result = 0; break; } } cursor.Hide(); back.Restore(); cursor.SetThemes(oldcursor); cursor.Show(); display.Flip(); return result; }
//-------------------------------------------------------------- void testApp::draw(){ #ifdef DEBUG_PRINT printf("draw()\n"); #endif /* if (logData) { freqOutThread.lock(); bool outOn = freqOutThread.getCurrentOutState(); float freq = freqOutThread.getCurrentFreq(); freqOutThread.unlock(); logger.lock(); logger.push_back(myGetElapsedTimeMillis(), LoggerData::IS_ENTRAINMENT_ON, outOn); logger.push_back(myGetElapsedTimeMillis(), LoggerData::ENTRAINMENT_FREQ, freq); logger.unlock(); } */ if (checkButtonPresses) { inputArduino.update(); int input = inputArduino.getAnalog(0); if (input > 512) { buttonDown(); } else { buttonUp(); } } // Draw oscilloscope data if (showOscilloscope) { //if (++eegPlotCounter == rawTimeWindow) { scopeWin.plot(); // eegPlotCounter = 0; //} } experimentGovernor.update(); //if (showInstructions) { // instructionsPlayer.update(); //} //if (showStimuli) { // if (stimulusPlayer.update() <= 0) { // //cout << "stimulus list complete \n"; // } //} if (showScreenEntrainment) { //freqOutThread.lock(); freqOutThread.update(); //freqOutThread.unlock(); } else { ofSleepMillis(1); //sleep(1); } //cout << "time=" << myGetElapsedTimeMillis() << ", diff=" << myGetElapsedTimeMillis() - drawTime << "\n"; drawTime = myGetElapsedTimeMillis(); }
int main() { initialize(); UBRR0H = UBRRH_VALUE; UBRR0L = UBRRL_VALUE; UCSR0B = (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0); UCSR0C = (1<<UCSZ00) | (1<<UCSZ01); // enable interrupts for the timer sei(); /* Timer aufsetzen: nach 1 ms soll der Interrupt ausgelöst werden. */ /* 8 bit counter (TIMER0) */ /* normal mode */ TCCR0A = 0; /* CLK/64 */ TCCR0B = (1 << CS01) | (1 << CS00); /* timer ticks: 250 */ TCNT0 = 5; TIMSK0 = (1 << TOIE0); TIFR0 = (1 << TOV0); adcInit(); int16_t ii = 0; int16_t jj = 0; wdt_enable(WDTO_2S); /* for(;;i++) { uart_bin(PINB); uart_puts(" "); uart_bin(PIND); uart_puts(" "); uart_hex16(i); uart_puts("\r\n"); _delay_ms(1000); wdt_reset(); } */ uart_puts("Starting up\r\n"); for (ii = 0; ii < 4; ii++) { positions[ii] = 0; } // Count the number of cycles the autofocus is stuck in mid-state uint8_t mid_state_counter = 0; // Count the number of successive movements in the same direction before increasing speed uint16_t movement_counter = 0; uint16_t current_delay = INITIAL_DELAY; enum movement{NONE, UP, DOWN, TILT_DOWN, TILT_UP, LEVEL, EMERGENCY} last_movement, movement; last_movement = NONE; movement = NONE; // Reset autofocus position /* while(1) { adc_start_conversion(7); const uint16_t autofocus_result = adc_wait(); uart_hex16(autofocus_result); wdt_reset(); uart_puts("\r\n"); } // */ uint8_t autofocus_hit_counter = 0; movement_counter = 0; current_delay = INITIAL_DELAY; initialize(); adcInit(); adc_start_conversion(); uint16_t autofocus_result = adc_wait(); uint16_t no_movement_counter = 0; autofocusPosition = 2*HEIGHT_LIMIT; for(ii = 0; ; ii++){ wdt_reset(); //* if (current_delay > 1) { for (jj = 0; jj < current_delay; jj++) { _delay_us(1); } } // */ #ifdef DEBUG uart_hex16(current_delay); uart_puts("\r\n"); #endif // True if autofocus endstop not yet hit. const bool autofocus_switch_clear = (autofocus_result <= OPEN_VALUE + INTERVAL_SIZE && autofocus_result >= OPEN_VALUE - INTERVAL_SIZE); bool autofocus_clear = true; if (!autofocus_switch_clear) { if (autofocus_hit_counter > 10) { autofocus_clear = false; if ((ii % 1024) == 0) { uart_puts("Autofocus hit at: "); printPositions(); autofocusPosition = positions[0]; uart_puts("\r\n"); } if (autofocus_result < SHORT_CIRCUIT_VALUE) { uart_puts("Autofocus has short circuit, value is: "); uart_hex16(autofocus_result); uart_puts("\r\n"); } else if (autofocus_result > CABLE_BROKEN_VALUE) { uart_puts("Autofocus cable is broken, value is: "); uart_hex16(autofocus_result); uart_puts("\r\n"); } else if(autofocus_result > OPEN_VALUE + INTERVAL_SIZE && autofocus_result < CLOSED_VALUE - INTERVAL_SIZE) { if (mid_state_counter > 10) { uart_puts("Autofocus stuck in mid-state, value is: 0x"); uart_hex16(autofocus_result); uart_puts("\r\n"); } else { mid_state_counter++; } } } // Increment autofocus_hit_counter in order to detect series of hit autofocus. if (autofocus_hit_counter < 20) { autofocus_hit_counter++; } } else { mid_state_counter = 0; autofocus_hit_counter = 0; } movement = NONE; if (!buttonEmergency()) { if (buttonDown()) { if (!anyStopReached()) { stepAllDown(); movement = DOWN; } _delay_us(2.08); } else if (buttonUp()) { if (!anyHeightLimitReached() && autofocus_clear) { stepAllUp(); movement = UP; } } else if (buttonTiltFrontUp()) { if (!anyStopReached() && !anyHeightLimitReached() && (positions[3]-positions[1] < TILT_LIMIT) && autofocus_clear) { stepUp3(); stepDown1(); movement = TILT_UP; } _delay_us(0.96); } else if (buttonTiltFrontDown()) { if (!anyStopReached() && !anyHeightLimitReached() && (positions[1]-positions[3] < TILT_LIMIT) && autofocus_clear) { stepDown3(); stepUp1(); movement = TILT_DOWN; } _delay_us(1.52); } else if (buttonLevel()) { if (!anyStopReached() && autofocus_clear) { if (positions[1] > positions[3]+1) { stepDown1(); stepUp3(); movement = LEVEL; _delay_us(0.72); } else if (positions[1]+1 < positions[3]) { stepDown3(); stepUp1(); movement = LEVEL; } } _delay_us(2.22); } else if (buttonFocus()) { if ((positions[0] > (autofocusPosition - FOCUS_DISTANCE)) && !anyStopReached()) { stepAllDown(); movement = DOWN; } else if ((positions[0] < (int32_t)(autofocusPosition - FOCUS_DISTANCE)) && autofocus_clear) { stepAllUp(); movement = UP; } // Needed to fulfill the 2us hold constraint of the step pin } } if (movement == last_movement && movement != NONE) { if (movement_counter > 500) { current_delay--; if (current_delay < MIN_DELAY) { current_delay = MIN_DELAY; } movement_counter = 0; } movement_counter += current_delay; } else { current_delay = INITIAL_DELAY; movement_counter = 0; } // Do all the emergency stuff if (buttonEmergency()) { _delay_us(17); movement = EMERGENCY; if (buttonEmergency() && buttonFocus()) { gotoEndstops(); } if (buttonUp()) { if (buttonTiltFrontDown()) { stepUp1(); } if (buttonLevel()) { stepUp2(); } if (buttonTiltFrontUp()) { stepUp3(); } } if (buttonDown()) { if (buttonTiltFrontDown()) { stepDown1(); } if (buttonLevel()) { stepDown2(); } if (buttonTiltFrontUp()) { stepDown3(); } } if (buttonLevel()) { int32_t maxPosition = max(positions[1], max(positions[2], positions[3])); if (positions[1] < maxPosition) { stepUp1(); } if (positions[2] < maxPosition) { stepUp2(); } if (positions[3] < maxPosition) { stepUp3(); } } // In case of emergency, introduce a safe delay for the step hold time _delay_us(2); } last_movement = movement; if (movement == NONE) { no_movement_counter++; if (no_movement_counter > 2e3) { sleep(); no_movement_counter = 0; printPositions(); uart_puts("\r\n"); } } else { no_movement_counter = 0; if (sleeping) { wakeup(); _delay_ms(100); } } if(!(ADCSRA & (1<<ADSC))) { // auf Abschluss der Konvertierung warten autofocus_result = ADCW; adc_start_conversion(); } _delay_us(1.08); unsetStep1; unsetStep2; unsetStep3; } }
void FakeMouse::click(int button) { buttonDown(button); usleep(100000); buttonUp(button); }