void VScrollTemplate::OnHandleMouseUp(GuiGraphicsComposition* sender, vl::presentation::compositions::GuiMouseEventArgs& arguments) { if (draggingHandle) { vint totalPixels = handle->GetParent()->GetBounds().Height(); vint currentOffset = handle->GetBounds().Top(); vint newOffset = currentOffset + (arguments.y - draggingStartLocation.y); vint totalSize = GetTotalSize(); double ratio = (double)newOffset / totalPixels; vint newPosition = (vint)(ratio * totalSize); vint offset1 = (vint)(((double)newPosition / totalSize) * totalPixels); vint offset2 = vint(((double)(newPosition + 1) / totalSize) * totalPixels); vint delta1 = abs((int)(offset1 - newOffset)); vint delta2 = abs((int)(offset2 - newOffset)); if(delta1 < delta2) { GetCommands()->SetPosition(newPosition); } else { GetCommands()->SetPosition(newPosition + 1); } } }
void CommandProcessorBase::PopulateLabelledStatesMenu(wxMenu* menu) { wxCHECK_RET(menu, "NULL menu"); for (size_t n = menu->GetMenuItemCount(); n > 0; --n) { // We need to delete any items left over from a previous call wxMenuItem* item = menu->FindItemByPosition(n-1); if (item) { menu->Delete(item); } } if (!GetInitialCommand()->GetUserLabel().empty()) { // First any initial label menu->Append(FIRST_MENU_ID - 1, GetInitialCommand()->GetUserLabel()); // (Ab)use an out-of-range id to avoid confusion } int id = FIRST_MENU_ID; for (CLCommand::Vec_t::const_iterator iter = GetCommands().begin(); iter != GetCommands().end(); ++iter) { CLCommand::Ptr_t command = *iter; if (command && !command->GetUserLabel().empty()) { menu->Append(id, command->GetUserLabel()); } ++id; // It's easier in the handler if the event id is the GetCommands() index, rather than a menu index } menu->Bind(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(CommandProcessorBase::OnLabelledStatesMenuItem), this); }
CVar* CVar::FindCVar(tstring sName) { tmap<tstring, CCommand*>::iterator it = GetCommands().find(sName); if (it == GetCommands().end()) return NULL; CVar* pVar = dynamic_cast<CVar*>(it->second); return pVar; }
CLCommand::Ptr_t CommandProcessorBase::GetOpenCommand() { CLCommand::Ptr_t command(NULL); size_t size = GetCommands().size(); if (size && GetCommands().at(size-1)->IsOpen()) { command = GetCommands().at(size-1); } return command; }
CLCommand::Ptr_t CommandProcessorBase::GetActiveCommand() const { CLCommand::Ptr_t command(NULL); if (GetCurrentCommand() == -1) { command = GetInitialCommand(); } else if (GetCommands().size() > 0) { command = GetCommands().at(GetCurrentCommand()); } return command; }
void CommandProcessorBase::OnLabelledStatesMenuItem(wxCommandEvent& event) { if (GetOpenCommand()) { ProcessOpenCommand(); } int index = event.GetId() - FIRST_MENU_ID; // NB index will be -1 if the selection is the initial-command's label. This will always mean *un*dos (or nothing) wxCHECK_RET(index < (int)GetCommands().size(), "An ID that overruns the command-list"); if (index < GetCurrentCommand()) { const int count = GetCurrentCommand() - index; for (int n=0; n < count; ++n) { if (DoUndo()) { DecrementCurrentCommand(); } } } else { const int count = index - GetCurrentCommand(); for (int n=0; n < count; ++n) { if (DoRedo()) { IncrementCurrentCommand(); } } } }
void CommandProcessorBase::DoPopulateUnRedoMenu(wxMenu& menu, bool undoing) { wxString prefix(undoing ? _("Undo ") : _("Redo ")); int id = FIRST_MENU_ID; int count = 0; if (undoing) { if (GetCommands().size() > 0) { for (CLCommand::Vec_t::const_reverse_iterator iter = GetCommands().rbegin() + GetNextUndoCommand(); iter != GetCommands().rend(); ++iter) { CLCommand::Ptr_t command = *iter; if (command) { wxString label; if (!command->GetUserLabel().empty()) { if (command->GetName().Contains(":")) { label = command->GetName().BeforeFirst(':') + ": "; } label << command->GetUserLabel(); } else { if (command == GetOpenCommand()) { label = GetBestLabel(command); // If the command's still open, there won't otherwise be a name string } else { label = command->GetName(); } } menu.Append(id++, wxString::Format("%i ", ++count) + prefix + label); } } } } else { for (CLCommand::Vec_t::const_iterator iter = GetCommands().begin() + GetCurrentCommand() + 1; iter != GetCommands().end(); ++iter) { CLCommand::Ptr_t command = *iter; if (command) { wxString label; if (!command->GetUserLabel().empty()) { if (command->GetName().Contains(":")) { label = command->GetName().BeforeFirst(':') + ": "; } label << command->GetUserLabel(); } else { label = command->GetName(); } menu.Append(id++, wxString::Format("%i ", ++count) + prefix + label); } } } }
void CCommand::Run(tstring sCommand) { tvector<tstring> asTokens; tstrtok(sCommand, asTokens); if (asTokens.size() == 0) return; tmap<tstring, CCommand*>::iterator it = GetCommands().find(asTokens[0]); if (it == GetCommands().end()) { TMsg("Unrecognized command.\n"); return; } CCommand* pCommand = it->second; pCommand->m_pfnCallback(pCommand, asTokens, sCommand); }
//----------------------------------------------------------------------------- // Purpose: // Input : *name - // Output : ConCommandBase //----------------------------------------------------------------------------- ConCommandBase const *ConCommandBase::FindCommand( char const *name ) { ConCommandBase const *cmd = GetCommands(); for ( ; cmd; cmd = cmd->GetNext() ) { if ( !stricmp( name, cmd->GetName() ) ) return cmd; } return NULL; }
AnimatePoint Animation::EndPosition(unsigned point, const CC_coord& offset) const { auto animation_commands = GetCommands(point); auto position = pts.at(point); for (auto commands = animation_commands.begin(); commands != animation_commands.end(); ++commands) { (*commands)->ApplyForward(position); } position += offset; return position; }
std::vector<CC_DrawCommand> Animation::GenPathToDraw(unsigned point, const CC_coord& offset) const { auto animation_commands = GetCommands(point); auto position = pts.at(point); std::vector<CC_DrawCommand> draw_commands; for (auto commands = animation_commands.begin(); commands != animation_commands.end(); ++commands) { draw_commands.push_back((*commands)->GenCC_DrawCommand(position, offset)); (*commands)->ApplyForward(position); } return draw_commands; }
tvector<tstring> CCommand::GetCommandsBeginningWith(tstring sFragment) { tvector<tstring> sResults; size_t iFragLength = sFragment.length(); tmap<tstring, CCommand*>& sCommands = GetCommands(); for (tmap<tstring, CCommand*>::iterator it = sCommands.begin(); it != sCommands.end(); it++) { if (it->first.substr(0, iFragLength) == sFragment) sResults.push_back(it->first); } return sResults; }
void ConCommandBase::RevertFlaggedCvars( int flag ) { for (const ConCommandBase *var= GetCommands() ; var ; var=var->GetNext()) { if ( var->IsCommand() ) continue; ConVar *cvar = ( ConVar * )var; if ( !cvar->IsBitSet( flag ) ) continue; // It's == to the default value, don't count if ( !Q_strcasecmp( cvar->GetDefault(), cvar->GetString() ) ) continue; cvar->Revert(); // DevMsg( "%s = \"%s\" (reverted)\n", cvar->GetName(), cvar->GetString() ); } }
void CCommand::RegisterCommand(CCommand* pCommand) { GetCommands()[pCommand->m_sName] = pCommand; }
void CommandProcessorBase::IncrementCurrentCommand() { wxCHECK_RET((m_currentCommand + 1) < (int)GetCommands().size(), "Can't increment the current command"); ++m_currentCommand; }
void SourceTASReader::ResetConvars() { #ifndef OE auto icvar = GetCvarInterface(); #ifndef P2 ConCommandBase* cmd = icvar->GetCommands(); // Loops through the console variables and commands while (cmd != NULL) { #else ICvar::Iterator iter(icvar); for (iter.SetFirst(); iter.IsValid(); iter.Next()) { auto cmd = iter.Get(); #endif const char* name = cmd->GetName(); // Reset any variables that have been marked to be reset for TASes if (!cmd->IsCommand() && name != NULL && cmd->IsFlagSet(FCVAR_TAS_RESET)) { auto convar = icvar->FindVar(name); DevMsg("Trying to reset variable %s\n", name); // convar found if (convar != NULL) { DevMsg("Resetting var %s to value %s\n", name, convar->GetDefault()); convar->SetValue(convar->GetDefault()); } else throw std::exception("Unable to find listed console variable!"); } // Issue minus commands to reset any keypresses else if (cmd->IsCommand() && cmd->GetName() != NULL && cmd->GetName()[0] == '-') { DevMsg("Running command %s\n", cmd->GetName()); EngineConCmd(cmd->GetName()); } #ifndef P2 cmd = cmd->GetNext(); #endif } // Reset any variables selected above for (int i = 0; i < RESET_VARS_COUNT; ++i) { auto resetCmd = icvar->FindVar(RESET_VARS[i]); if (resetCmd != NULL) { DevMsg("Resetting var %s to value %s\n", resetCmd->GetName(), resetCmd->GetDefault()); resetCmd->SetValue(resetCmd->GetDefault()); } else DevWarning("Unable to find console variable %s\n", RESET_VARS[i]); } #endif } void SourceTASReader::Reset() { if (!freezeVariables) { variables.Clear(); } ResetIterationState(); } void SourceTASReader::ResetIterationState() { ResetConvars(); conditions.clear(); scriptStream.clear(); lineStream.clear(); line.clear(); currentLine = 0; searchType = SearchType::None; playbackSpeed = 1.0f; demoDelay = 0; demoName.clear(); currentScript.Reset(); }