bool MCommandBuilder::Read(char* pBuffer, int nBufferLen) { MPacketHeader* pPacket = (MPacketHeader*)pBuffer; if (CheckBufferEmpty() == true) { if ( (nBufferLen < sizeof(MPacketHeader)) || (nBufferLen < _CalcPacketSize(pPacket)) ) { AddBuffer(pBuffer, nBufferLen); } else { int nSpareData = MakeCommand(pBuffer, nBufferLen); if (nSpareData > 0) { AddBuffer(pBuffer+(nBufferLen-nSpareData), nSpareData); } else if (nSpareData < 0) return false; } } else { AddBuffer(pBuffer, nBufferLen); if (EstimateBufferToCmd() == true) { int nSpareData = MakeCommand(m_Buffer, m_nBufferNext); // m_nBufferNext == nBufferSize if (nSpareData >= 0) MoveBufferToFront(m_nBufferNext-nSpareData, nSpareData); else return false; } } return true; }
asi::runtimecommandengine::Tree GetTree() { Range<double> add_left_value("left value", -100.0, 100.0); Range<double> add_right_value("right value", -100.0, 100.0); std::vector<std::string> const add_sig{"add"}; static auto add_cmd(MakeCommand(add_sig, "add the left to the right", bind(&printf, "%f\n", bind(&simplemath::Add, _1, _2)), add_left_value, add_right_value)); Range<double> sub_left_value("left value", -100.0, 100.0); Range<double> sub_right_value("right value", -100.0, 100.0); std::vector<std::string> const sub_sig{"subtract"}; static auto sub_cmd(MakeCommand(sub_sig, "subtract the left form the right", bind(&printf, "%f\n", bind(&simplemath::Subtract, _1, _2)), sub_left_value, sub_right_value)); Range<double> mult_left_value("left value", -100.0, 100.0); Range<double> mult_right_value("right value", -100.0, 100.0); std::vector<std::string> const mult_sig{"multiply"}; static auto mult_cmd(MakeCommand(mult_sig, "multiply the left and the right", bind(&printf, "%f\n", bind(&simplemath::Multiply, _1, _2)), mult_left_value, mult_right_value)); Range<double> div_left_value("left value", -100.0, 100.0); Range<double> div_right_value("right value", 0.001, 100.0); std::vector<std::string> const div_sig{"divide"}; static auto div_cmd(MakeCommand(div_sig, "divide the left from the right", bind(&printf, "%f\n", bind(&simplemath::Divide, _1, _2)), div_left_value, div_right_value)); std::vector<asi::runtimecommandengine::CommandInterface *> cmds{&add_cmd, &sub_cmd, &mult_cmd, &div_cmd}; asi::runtimecommandengine::Tree output(cmds); return output; }
// NudgeBy void TransformBox::NudgeBy(BPoint offset) { if (!fNudging && !fCurrentCommand) { fCurrentCommand = MakeCommand("Move", 0/*MOVE*/); fNudging = true; } if (fNudging) { TranslateBy(offset); } }
// MouseDown bool TransformBox::MouseDown(BPoint where) { fView->FilterMouse(&where); // NOTE: filter mouse here and in MouseMoved only TransformToCanvas(where); fDragging = true; if (fCurrentState) { fCurrentState->SetOrigin(where); delete fCurrentCommand; fCurrentCommand = MakeCommand(fCurrentState->ActionName(), fCurrentState->ActionNameIndex()); } return true; }
// HandleKeyDown bool TransformBox::HandleKeyDown(uint32 key, uint32 modifiers, Command** _command) { bool handled = true; BPoint translation(B_ORIGIN); float offset = 1.0; if (modifiers & B_SHIFT_KEY) offset /= ZoomLevel(); switch (key) { case B_UP_ARROW: translation.y = -offset; break; case B_DOWN_ARROW: translation.y = offset; break; case B_LEFT_ARROW: translation.x = -offset; break; case B_RIGHT_ARROW: translation.x = offset; break; default: handled = false; break; } if (!handled) return false; if (!fCurrentCommand) { fCurrentCommand = MakeCommand("Translate", -1); } TranslateBy(translation); return true; }