/****************************************************************************** * Handles the mouse down event. ******************************************************************************/ void SpinnerWidget::mousePressEvent(QMouseEvent* event) { if(event->button() == Qt::LeftButton && !_upperBtnPressed && !_lowerBtnPressed) { // Backup current value. _oldValue = floatValue(); OVITO_ASSERT(_lowerBtnPressed == false && _upperBtnPressed == false); if(event->y() <= height()/2) _upperBtnPressed = true; else _lowerBtnPressed = true; _currentStepSize = unit() ? unit()->stepSize(floatValue(), _upperBtnPressed) : 1; if(textBox()) textBox()->setFocus(Qt::OtherFocusReason); grabMouse(); repaint(); } else if(event->button() == Qt::RightButton) { // restore old value setFloatValue(_oldValue, true); if(_upperBtnPressed == _lowerBtnPressed) { Q_EMIT spinnerDragAbort(); } _upperBtnPressed = false; _lowerBtnPressed = false; releaseMouse(); update(); } }
void Opcode803AHandler::_run() { Logger::debug("SCRIPT") << "[803A] [*] op_sub(a, b) -" << std::endl; auto bValue = _vm->dataStack()->pop(); auto aValue = _vm->dataStack()->pop(); if (!bValue.isNumber() || !aValue.isNumber()) { _error(std::string("op_sub(a, b): Incompatible types: ") + aValue.typeName() + " - " + bValue.typeName()); } if (aValue.type() == VMStackValue::Type::INTEGER) { if (bValue.type() == VMStackValue::Type::INTEGER) { _vm->dataStack()->push(aValue.integerValue() - bValue.integerValue()); } else { _vm->dataStack()->push((float)aValue.integerValue() - bValue.floatValue()); } } else { if (bValue.type() == VMStackValue::Type::INTEGER) { _vm->dataStack()->push(aValue.floatValue() - (float)bValue.integerValue()); } else { _vm->dataStack()->push(aValue.floatValue() - bValue.floatValue()); } } }
/****************************************************************************** * Updates the text of the connected text box after the spinner's value has changed. ******************************************************************************/ void SpinnerWidget::updateTextBox() { if(textBox()) { if(unit()) _originalText = unit()->formatValue(unit()->nativeToUser(floatValue())); else _originalText = QString::number(floatValue()); textBox()->setText(_originalText); } }
void GuiScrollBar::render(RenderDevice* rd, const shared_ptr<GuiTheme>& theme, bool ancestorsEnabled) const { (void)rd; if (m_visible) { const_cast<GuiScrollBar*>(this)->updateScroll(); if (m_vertical) { theme->renderVerticalScrollBar(m_rect, floatValue(), maxValue(), focused()); } else { theme->renderHorizontalScrollBar(m_rect, floatValue(), maxValue(), focused()); } } }
size_t hash() const { Hasher hasher; hasher.add(kind()); switch (kind()) { case NULLVAL: break; case BOOLEAN: hasher.add(boolValue()); break; case INTEGER: hasher.add(integerValue()); break; case FLOATINGPOINT: hasher.add(floatValue()); break; case CHARACTER: hasher.add(characterValue()); break; case STRING: hasher.add(stringValue()); break; } return hasher.get(); }
// ----------------------------------------------------------------------------- // CLandmarksEditDialog::FetchFloatL // // (other items were commented in a header). // ----------------------------------------------------------------------------- // void CLandmarksEditDialog::FetchFloatL( TRealX& aFloat, TInt aEditorResourceId, TInt aErrorResourceId) { const TChar KDecimalPoint = '.'; TBuf<KPosLmMaxTextFieldLength> textFieldValue; TLex fieldLex; TInt result(KErrNone); CEikEdwin* editor = static_cast <CEikEdwin*> (Control(aEditorResourceId)); editor->GetText(textFieldValue); if (textFieldValue == KNullDesC) { // User has indicated that he/she wants this value to be undefined. aFloat.SetNaN(); } else { // Try to extract value fieldLex = textFieldValue; TReal floatValue(0); result = fieldLex.Val(floatValue, KDecimalPoint); if (result != KErrNone) { NotifyErrorToUserL(aErrorResourceId); } // Update output parameter User::LeaveIfError(aFloat.Set(floatValue)); } }
void _GuiSliderBase::render(RenderDevice* rd, const GuiThemeRef& skin) const { (void)rd; if (m_visible) { if (m_horizontal) { skin->renderHorizontalSlider(m_rect, floatValue(), m_enabled, focused() || mouseOver(), m_caption, m_captionSize); } } }
float XmlTools::loadFloatValue(std::string section, std::string variable, float defValue) { coConfigFloat floatValue(config, QString(variable.c_str()), QString(section.c_str())); if (floatValue.hasValidValue()) return floatValue; else return defValue; }
void GuiScrollBar::getAllBounds(Rect2D& top, Rect2D& bottom, Rect2D& barBounds, Rect2D& thumbBounds) const { if(m_vertical) { top = Rect2D::xywh(m_rect.x0y0(), Vector2(BUTTON_HEIGHT_AND_WIDTH, BUTTON_HEIGHT_AND_WIDTH)); bottom = Rect2D::xywh(m_rect.x0y1() - Vector2(0, BUTTON_HEIGHT_AND_WIDTH), Vector2(BUTTON_HEIGHT_AND_WIDTH, BUTTON_HEIGHT_AND_WIDTH)); barBounds = theme()->verticalScrollBarToBarBounds(m_rect); thumbBounds = theme()->verticalScrollBarToThumbBounds(barBounds, floatValue(), maxValue()); } else { top = Rect2D::xywh(m_rect.x0y0(), Vector2(BUTTON_HEIGHT_AND_WIDTH, BUTTON_HEIGHT_AND_WIDTH)); bottom = Rect2D::xywh(m_rect.x1y0() - Vector2(BUTTON_HEIGHT_AND_WIDTH, 0), Vector2(BUTTON_HEIGHT_AND_WIDTH, BUTTON_HEIGHT_AND_WIDTH)); barBounds = theme()->horizontalScrollBarToBarBounds(m_rect); thumbBounds = theme()->horizontalScrollBarToThumbBounds(barBounds, floatValue(), maxValue()); } }
/****************************************************************************** * Handles the mouse move event. ******************************************************************************/ void SpinnerWidget::mouseMoveEvent(QMouseEvent* event) { if(_upperBtnPressed || _lowerBtnPressed) { if(_upperBtnPressed && !_lowerBtnPressed) { if(event->y() > height()/2 || event->y() < 0) { _lowerBtnPressed = true; _lastMouseY = _startMouseY = mapToGlobal(event->pos()).y(); update(); Q_EMIT spinnerDragStart(); } } else if(!_upperBtnPressed && _lowerBtnPressed) { if(event->y() <= height()/2 || event->y() > height()) { _upperBtnPressed = true; _lastMouseY = _startMouseY = mapToGlobal(event->pos()).y(); update(); Q_EMIT spinnerDragStart(); } } else { QPoint cursorPos = QCursor::pos(); int screenY = cursorPos.y(); if(screenY != _lastMouseY) { int screenHeight = QApplication::desktop()->screenGeometry().height(); if(screenY <= 5 && _lastMouseY == screenHeight-1) return; if(screenY >= screenHeight - 5 && _lastMouseY == 0) return; FloatType newVal = _oldValue + _currentStepSize * (FloatType)(_startMouseY - screenY) * 0.1f; if(unit()) newVal = unit()->roundValue(newVal); if(screenY < _lastMouseY && screenY <= 5) { _lastMouseY = screenHeight-1; _startMouseY += _lastMouseY - screenY; QCursor::setPos(cursorPos.x(), _lastMouseY); } else if(screenY > _lastMouseY && screenY >= screenHeight - 5) { _lastMouseY = 0; _startMouseY += _lastMouseY - screenY; QCursor::setPos(cursorPos.x(), _lastMouseY); } else _lastMouseY = screenY; if(newVal != floatValue()) { setFloatValue(newVal, true); // Repaint viewports for immediate visual feedback when changing a parameter. if(MainWindow* mainWindow = qobject_cast<MainWindow*>(window())) mainWindow->processViewportUpdates(); // Also repaint text box for immediate visual updates. if(textBox()) textBox()->repaint(); } } } } }
Value* ValueKey::materialize(Procedure& proc, Origin origin) const { switch (opcode()) { case FramePointer: return proc.add<Value>(opcode(), type(), origin); case Identity: case Sqrt: case SExt8: case SExt16: case SExt32: case ZExt32: case Clz: case Trunc: case IToD: case IToF: case FloatToDouble: case DoubleToFloat: case Check: return proc.add<Value>(opcode(), type(), origin, child(proc, 0)); case Add: case Sub: case Mul: case ChillDiv: case Mod: case BitAnd: case BitOr: case BitXor: case Shl: case SShr: case ZShr: case Equal: case NotEqual: case LessThan: case GreaterThan: case Above: case Below: case AboveEqual: case BelowEqual: case Div: return proc.add<Value>(opcode(), type(), origin, child(proc, 0), child(proc, 1)); case Select: return proc.add<Value>(opcode(), type(), origin, child(proc, 0), child(proc, 1), child(proc, 2)); case Const32: return proc.add<Const32Value>(origin, static_cast<int32_t>(value())); case Const64: return proc.add<Const64Value>(origin, value()); case ConstDouble: return proc.add<ConstDoubleValue>(origin, doubleValue()); case ConstFloat: return proc.add<ConstFloatValue>(origin, floatValue()); case ArgumentReg: return proc.add<ArgumentRegValue>(origin, Reg::fromIndex(static_cast<unsigned>(value()))); case SlotBase: return proc.add<SlotBaseValue>(origin, proc.stackSlots()[value()]); default: return nullptr; } }
/****************************************************************************** * Handles the mouse up event. ******************************************************************************/ void SpinnerWidget::mouseReleaseEvent(QMouseEvent* event) { if(_upperBtnPressed || _lowerBtnPressed) { if(_upperBtnPressed == _lowerBtnPressed) { Q_EMIT spinnerDragStop(); } else { FloatType newValue; if(_upperBtnPressed) { if(unit()) newValue = unit()->roundValue(floatValue() + unit()->stepSize(floatValue(), true)); else newValue = floatValue() + 1.0f; } else { if(unit()) newValue = unit()->roundValue(floatValue() - unit()->stepSize(floatValue(), false)); else newValue = floatValue() - 1.0f; } setFloatValue(newValue, true); } _upperBtnPressed = false; _lowerBtnPressed = false; // Repaint spinner. update(); } releaseMouse(); }
void Opcode8046::_run() { Logger::debug("SCRIPT") << "[8046] [*] op_negate" << std::endl; auto value = _script->dataStack()->pop(); if (value.type() == StackValue::Type::INTEGER) { _script->dataStack()->push(- value.integerValue()); } else if (value.type() == StackValue::Type::FLOAT) { _script->dataStack()->push(- value.floatValue()); } else { _error(std::string("Invalid argument type: ") + value.typeName()); } }
void Opcode8044Handler::_run() { Logger::debug("SCRIPT") << "[8044] [*] op_floor" << std::endl; auto value = _vm->dataStack()->pop(); int result = 0; if (value.type() == VMStackValue::Type::FLOAT) { result = (int)value.floatValue(); // this is how "floor" originally worked.. } else if (value.type() == VMStackValue::Type::INTEGER) { result = value.integerValue(); } else { _error(std::string("op_floor: invalid argument type: ") + value.typeName()); } _vm->dataStack()->push(result); }
std::string toString() const { switch (kind_) { case NULLVAL: return "NullConstant"; case BOOLEAN: return makeString("BoolConstant(%s)", bool_ ? "true" : "false"); case INTEGER: return makeString("IntegerConstant(%s)", integerValue().toString().c_str()); case FLOATINGPOINT: return makeString("FloatConstant(%Lf)", floatValue()); case CHARACTER: return makeString("CharacterConstant(%llu)", static_cast<unsigned long long>(characterValue())); case STRING: return makeString("StringConstant(\"%s\")", escapeString(stringValue().asStdString()).c_str()); } return "[UNKNOWN CONSTANT]"; }
bool operator==(const Constant& other) const { if (kind() != other.kind()) { return false; } switch (kind()) { case NULLVAL: return true; case BOOLEAN: return boolValue() == other.boolValue(); case INTEGER: return integerValue() == other.integerValue(); case FLOATINGPOINT: return floatValue() == other.floatValue(); case CHARACTER: return characterValue() == other.characterValue(); case STRING: return stringValue() == other.stringValue(); } return false; }
void JsonPrinter::floatProperty(Print& printer, char* name, float value) { property(printer, name); floatValue(printer, value); }
void XmlTools::saveFloatValue(float float_value, std::string section, std::string variable) { coConfigFloat floatValue(config, QString(variable.c_str()), QString(section.c_str())); floatValue = float_value; saveToXml(); }
bool _GuiSliderBase::onEvent(const GEvent& event) { if (! m_visible) { return false; } if (event.type == GEventType::MOUSE_BUTTON_DOWN) { Vector2 mouse = Vector2(event.button.x, event.button.y); float v = floatValue(); Rect2D thumbRect = theme()->horizontalSliderToThumbBounds(m_rect, v, m_captionSize); Rect2D trackRect = theme()->horizontalSliderToTrackBounds(m_rect, m_captionSize); if (thumbRect.contains(mouse)) { // Begin drag m_inDrag = true; m_dragStart = mouse; m_dragStartValue = v; GEvent response; response.gui.type = GEventType::GUI_DOWN; response.gui.control = m_eventSource; m_gui->fireEvent(response); response.gui.type = GEventType::GUI_CHANGE; response.gui.control = m_eventSource; m_gui->fireEvent(response); return true; } else if (trackRect.contains(mouse)) { // Jump to this position float p = clamp((mouse.x - trackRect.x0()) / trackRect.width(), 0.0f, 1.0f); setFloatValue(p); m_inDrag = false; GEvent response; response.gui.type = GEventType::GUI_CHANGE; response.gui.control = m_eventSource; m_gui->fireEvent(response); fireEvent(GEventType::GUI_ACTION); return true; } } else if (event.type == GEventType::MOUSE_BUTTON_UP) { if (m_inDrag) { // End the drag m_inDrag = false; fireEvent(GEventType::GUI_DOWN); fireEvent(GEventType::GUI_ACTION); return true; } } else if (m_inDrag && (event.type == GEventType::MOUSE_MOTION)) { // We'll only receive these events if we have the keyFocus, but we can't // help receiving the key focus if the user clicked on the control! Vector2 mouse = Vector2(event.button.x, event.button.y); Rect2D trackRect = theme()->horizontalSliderToTrackBounds(m_rect, m_captionSize); float delta = (mouse.x - m_dragStart.x) / trackRect.width(); float p = clamp(m_dragStartValue + delta, 0.0f, 1.0f); setFloatValue(p); GEvent response; response.gui.type = GEventType::GUI_CHANGE; response.gui.control = m_eventSource; m_gui->fireEvent(response); return true; } return false; }
double FrInteger::real() const { return floatValue() ; }
void OpcodeComparisonHandler::_run() { Logger::debug("SCRIPT") << "[8033-8038] [*] " << _cmpOpcodeName() << std::endl; auto bValue = _vm->dataStack()->pop(); auto aValue = _vm->dataStack()->pop(); int result = 0; switch (aValue.type()) { case VMStackValue::Type::INTEGER: { int arg1 = aValue.integerValue(); switch (bValue.type()) { case VMStackValue::Type::INTEGER: { result = _compare(arg1, bValue.integerValue()); // INTEGER op INTEGER break; } case VMStackValue::Type::FLOAT: { result = _compare(arg1, bValue.floatValue()); // INTEGER op FLOAT break; } case VMStackValue::Type::STRING: { result = _compare(arg1, bValue.toInteger()); // INTEGER op STRING (parsed as int) break; } default: { _error(std::string() + _cmpOpcodeName() + ": invalid right argument type: " + bValue.typeName()); } } break; } case VMStackValue::Type::FLOAT: { float arg1 = aValue.floatValue(); switch (bValue.type()) { case VMStackValue::Type::INTEGER: { result = _compare(arg1, bValue.integerValue()); // FLOAT op INTEGER break; } case VMStackValue::Type::FLOAT: { result = _compare(arg1, bValue.floatValue()); // FLOAT op FLOAT break; } case VMStackValue::Type::STRING: { float arg2 = 0.0; try { arg2 = std::stof(bValue.stringValue()); } catch (std::invalid_argument ex) { } catch (std::out_of_range ex) { } result = _compare(arg1, arg2); // FLOAT op STRING (parsed as float) break; } default: { _error(std::string() + _cmpOpcodeName() + ": invalid right argument type: " + bValue.typeName()); } } break; } case VMStackValue::Type::STRING: { switch (bValue.type()) { case VMStackValue::Type::INTEGER: { result = _compare(aValue.toInteger(), bValue.integerValue()); // STRING (as integer) op INTEGER break; } case VMStackValue::Type::FLOAT: { float arg1 = 0.0; try { arg1 = std::stof(aValue.stringValue()); } catch (std::invalid_argument ex) { } catch (std::out_of_range ex) { } result = _compare(arg1, bValue.floatValue()); // STRING (as float) op FLOAT break; } case VMStackValue::Type::STRING: { result = _compare(aValue.stringValue(), bValue.stringValue()); // STRING op STRING break; } default: { _error(std::string() + _cmpOpcodeName() + ": invalid right argument type: " + bValue.typeName()); } } break; } case VMStackValue::Type::OBJECT: { switch (bValue.type()) { case VMStackValue::Type::INTEGER: { result = _compare((int)aValue.toBoolean(), bValue.integerValue()); // OBJECT op INTEGER break; } case VMStackValue::Type::FLOAT: { result = _compare((float)aValue.toBoolean(), bValue.floatValue()); // OBJECT op FLOAT break; } case VMStackValue::Type::STRING: { result = _compare(aValue.toString(), bValue.stringValue()); // OBJECT op STRING - compare object name break; } default: { _error(std::string() + _cmpOpcodeName() + ": invalid right argument type: " + bValue.typeName()); } } break; } default: { _error(std::string() + _cmpOpcodeName() + ": invalid left argument type: " + aValue.typeName()); } } _vm->dataStack()->push(result); }
void Opcode8039::_run() { auto& debug = Logger::debug("SCRIPT"); debug << "[8039] [*] op_add(aValue, bValue)" << std::endl; auto bValue = _script->dataStack()->pop(); auto aValue = _script->dataStack()->pop(); debug << " types: " << aValue.typeName() << " + " << bValue.typeName() << std::endl; switch (bValue.type()) { case StackValue::Type::INTEGER: // INTEGER { int arg2 = bValue.integerValue(); switch (aValue.type()) { case StackValue::Type::INTEGER: // INTEGER + INTEGER { _script->dataStack()->push(aValue.integerValue() + arg2); break; } case StackValue::Type::FLOAT: // FLOAT + INTEGER { _script->dataStack()->push(aValue.floatValue() + (float)arg2); break; } case StackValue::Type::STRING: // STRING + INTEGER { std::string arg1 = aValue.stringValue(); _script->dataStack()->push(arg1 + bValue.toString()); break; } default: { _error(std::string("op_add - invalid left argument type: ") + aValue.typeName()); } } break; } case StackValue::Type::STRING: { auto arg2 = bValue.stringValue(); switch (aValue.type()) { case StackValue::Type::STRING: // STRING + STRING { _script->dataStack()->push(aValue.stringValue() + arg2); break; } case StackValue::Type::FLOAT: // FLOAT + STRING { _error("op_add - FLOAT+STRING not allowed"); } case StackValue::Type::INTEGER: // INTEGER + STRING { _error("op_add - INTEGER+STRING not allowed"); } default: { _error(std::string("op_add - invalid left argument type: ") + aValue.typeName()); } } break; } case StackValue::Type::FLOAT: // FLOAT { auto arg2 = bValue.floatValue(); switch (aValue.type()) { case StackValue::Type::INTEGER: // INTEGER + FLOAT { _script->dataStack()->push((float)aValue.integerValue() + arg2); break; } case StackValue::Type::FLOAT: // FLOAT + FLOAT { _script->dataStack()->push(aValue.floatValue() + arg2); break; } case StackValue::Type::STRING: // STRING + FLOAT { auto arg1 = aValue.stringValue(); _script->dataStack()->push(arg1 + bValue.toString()); break; } default: { _error(std::string("op_add - invalid left argument type: ") + aValue.typeName()); } } break; } default: { _error(std::string("op_add - invalid right argument type: ") + bValue.typeName()); } } }
// ----------------------------------------------------------------------------- // Reads a UDMF property definition from a parsed tree [node] // ----------------------------------------------------------------------------- void UDMFProperty::parse(ParseTreeNode* node, std::string_view group) { // Set group and property name group_ = group; property_ = node->name(); // Check for basic definition if (node->nChildren() == 0) { name_ = node->stringValue(); return; } // Otherwise, read node data for (unsigned a = 0; a < node->nChildren(); a++) { auto prop = node->childPTN(a); auto pn_lower = StrUtil::lower(prop->name()); // Property type if (pn_lower == "type") { auto val_lower = StrUtil::lower(prop->stringValue()); if (val_lower == "bool") type_ = Type::Boolean; else if (val_lower == "int") type_ = Type::Int; else if (val_lower == "float") type_ = Type::Float; else if (val_lower == "string") type_ = Type::String; else if (val_lower == "colour") type_ = Type::Colour; else if (val_lower == "actionspecial") type_ = Type::ActionSpecial; else if (val_lower == "sectorspecial") type_ = Type::SectorSpecial; else if (val_lower == "thingtype") type_ = Type::ThingType; else if (val_lower == "angle") type_ = Type::Angle; else if (val_lower == "texture_wall") type_ = Type::TextureWall; else if (val_lower == "texture_flat") type_ = Type::TextureFlat; else if (val_lower == "id") type_ = Type::ID; } // Property name else if (pn_lower == "name") name_ = prop->stringValue(); // Default value else if (pn_lower == "default") { switch (type_) { case Type::Boolean: default_value_ = prop->boolValue(); break; case Type::Int: default_value_ = prop->intValue(); break; case Type::Float: default_value_ = prop->floatValue(); break; case Type::String: default_value_ = prop->stringValue(); break; case Type::ActionSpecial: default_value_ = prop->intValue(); break; case Type::SectorSpecial: default_value_ = prop->intValue(); break; case Type::ThingType: default_value_ = prop->intValue(); break; case Type::Angle: default_value_ = prop->intValue(); break; case Type::TextureWall: default_value_ = prop->stringValue(); break; case Type::TextureFlat: default_value_ = prop->stringValue(); break; case Type::ID: default_value_ = prop->intValue(); break; default: default_value_ = prop->stringValue(); break; } // Not sure why I have to do this here, but for whatever reason prop->getIntValue() doesn't work // if the value parsed was hex (or it could be to do with the colour type? who knows) if (type_ == Type::Colour) default_value_ = StrUtil::asInt(prop->stringValue()); has_default_ = true; } // Property is a flag else if (pn_lower == "flag") flag_ = true; // Property is a SPAC trigger else if (pn_lower == "trigger") trigger_ = true; // Possible values else if (pn_lower == "values") { switch (type_) { case Type::Boolean: for (unsigned b = 0; b < prop->nValues(); b++) values_.emplace_back(prop->boolValue(b)); break; case Type::Int: case Type::ActionSpecial: case Type::SectorSpecial: case Type::ThingType: for (unsigned b = 0; b < prop->nValues(); b++) values_.emplace_back(prop->intValue(b)); break; case Type::Float: for (unsigned b = 0; b < prop->nValues(); b++) values_.emplace_back(prop->floatValue(b)); break; default: for (unsigned b = 0; b < prop->nValues(); b++) values_.emplace_back(prop->stringValue(b)); break; } } // Show always else if (pn_lower == "show_always") show_always_ = prop->boolValue(); } }
bool GuiScrollBar::onEvent(const GEvent& event) { if (! m_visible) { return false; } float m = maxValue(); Rect2D topB; Rect2D bottomB; Rect2D barBounds; Rect2D thumbBounds; getAllBounds(topB, bottomB, barBounds, thumbBounds); if (event.type == GEventType::MOUSE_BUTTON_DOWN) { const Vector2& mouse = Vector2(event.button.x, event.button.y); if(bottomB.contains(mouse)) { *m_value = min<float>( m * m_extent, *m_value + m_extent * BUTTON_PRESS_SCROLL); m_state = ARROW_DOWN_SCROLLING; GEvent response; response.gui.type = GEventType::GUI_CHANGE; response.gui.control = m_eventSource; m_gui->fireEvent(response); fireEvent(GEventType::GUI_ACTION); return true; } else if (topB.contains(mouse)) { *m_value = max<float>( 0.0f, *m_value - m_extent*BUTTON_PRESS_SCROLL); m_state = ARROW_UP_SCROLLING; GEvent response; response.gui.type = GEventType::GUI_CHANGE; response.gui.control = m_eventSource; m_gui->fireEvent(response); fireEvent(GEventType::GUI_ACTION); return true; } else if (thumbBounds.contains(mouse)) { m_state = IN_DRAG; m_dragStart = mouse; m_dragStartValue = floatValue(); GEvent response; response.gui.type = GEventType::GUI_DOWN; response.gui.control = m_eventSource; m_gui->fireEvent(response); response.gui.type = GEventType::GUI_CHANGE; response.gui.control = m_eventSource; m_gui->fireEvent(response); return true; } else if (barBounds.contains(mouse)) { // Jump to this position float p; if(m_vertical) { p = ( mouse.y - (float)barBounds.y0() ) / ((float)barBounds.height()/(m + 1)) - .5f; } else { p = ( mouse.x - (float)barBounds.x0() ) / ((float)barBounds.width()/(m + 1)) - .5f; } p = max<float>(0, p); p = min<float>(p, m); setFloatValue(p); m_state = NONE; GEvent response; response.gui.type = GEventType::GUI_CHANGE; response.gui.control = m_eventSource; m_gui->fireEvent(response); fireEvent(GEventType::GUI_ACTION); return true; } return false; } else if (event.type == GEventType::MOUSE_BUTTON_UP) { m_state = NONE; fireEvent(GEventType::GUI_ACTION); if (m_state == IN_DRAG) { // End the drag fireEvent(GEventType::GUI_DOWN); fireEvent(GEventType::GUI_ACTION); return true; } } else if (event.type == GEventType::MOUSE_MOTION) { // We'll only receive these events if we have the keyFocus, but we can't // help receiving the key focus if the user clicked on the control! const Vector2& mouse = Vector2(event.button.x, event.button.y); if (m_state == IN_DRAG) { float delta; if(m_vertical) { delta = (mouse.y - m_dragStart.y) / (barBounds.height()/(m + 1)); } else { delta = (mouse.x - m_dragStart.x) / (barBounds.width()/(m + 1)); } float p = m_dragStartValue + delta; p = max<float>(0, p); p = min<float>(p, m); setFloatValue(p); GEvent response; response.gui.type = GEventType::GUI_CHANGE; response.gui.control = m_eventSource; m_gui->fireEvent(response); return true; } else if (m_state == ARROW_UP_SCROLLING || m_state == ARROW_UP) { if(topB.contains(mouse)) { m_state = ARROW_UP_SCROLLING; } else { m_state = ARROW_UP; } return true; } else if (m_state == ARROW_DOWN_SCROLLING || m_state == ARROW_DOWN) { if(bottomB.contains(mouse)) { m_state = ARROW_DOWN_SCROLLING; } else { m_state = ARROW_DOWN; } return true; } } return false; }
// ----------------------------------------------------------------------------- // Reads a colour configuration from text data [mc] // ----------------------------------------------------------------------------- bool ColourConfiguration::readConfiguration(MemChunk& mc) { // Parse text Parser parser; parser.parseText(mc); // Get 'colours' block auto colours = parser.parseTreeRoot()->childPTN("colours"); if (colours) { // Read all colour definitions for (unsigned a = 0; a < colours->nChildren(); a++) { auto def = colours->childPTN(a); // Read properties for (unsigned b = 0; b < def->nChildren(); b++) { auto prop = def->childPTN(b); auto& col = cc_colours[def->name()]; col.exists = true; // Colour name if (prop->name() == "name") col.name = prop->stringValue(); // Colour group (for config ui) else if (prop->name() == "group") col.group = prop->stringValue(); // Colour else if (prop->name() == "rgb") col.colour.set(prop->intValue(0), prop->intValue(1), prop->intValue(2)); // Alpha else if (prop->name() == "alpha") col.colour.a = prop->intValue(); // Additive else if (prop->name() == "additive") col.blend_additive = prop->boolValue(); else Log::warning(fmt::format("Unknown colour definition property \"{}\"", prop->name())); } } } // Get 'theme' block auto theme = parser.parseTreeRoot()->childPTN("theme"); if (theme) { // Read all theme definitions for (unsigned a = 0; a < theme->nChildren(); a++) { auto prop = theme->childPTN(a); if (prop->name() == "line_hilight_width") line_hilight_width = prop->floatValue(); else if (prop->name() == "line_selection_width") line_selection_width = prop->floatValue(); else if (prop->name() == "flat_alpha") flat_alpha = prop->floatValue(); else Log::warning(fmt::format("Unknown theme property \"{}\"", prop->name())); } } return true; }
void FloatValueParameter::getDisplay(char *outBuffer) const { sprintf(outBuffer, "%3.2f", floatValue()); }