void runTest() override { beginTest ("Basics"); Random r = getRandom(); int randomInt = r.nextInt(); int64 randomInt64 = r.nextInt64(); double randomDouble = r.nextDouble(); String randomString (createRandomWideCharString (r)); MemoryOutputStream mo; mo.writeInt (randomInt); mo.writeIntBigEndian (randomInt); mo.writeCompressedInt (randomInt); mo.writeString (randomString); mo.writeInt64 (randomInt64); mo.writeInt64BigEndian (randomInt64); mo.writeDouble (randomDouble); mo.writeDoubleBigEndian (randomDouble); MemoryInputStream mi (mo.getData(), mo.getDataSize(), false); expect (mi.readInt() == randomInt); expect (mi.readIntBigEndian() == randomInt); expect (mi.readCompressedInt() == randomInt); expectEquals (mi.readString(), randomString); expect (mi.readInt64() == randomInt64); expect (mi.readInt64BigEndian() == randomInt64); expect (mi.readDouble() == randomDouble); expect (mi.readDoubleBigEndian() == randomDouble); }
void CabbageIDELookAndFeel::drawAlertBox (Graphics& g, AlertWindow& alert, const Rectangle<int>& textArea, TextLayout& textLayout) { g.fillAll (CabbageSettings::getColourFromValueTree (colourTree, CabbageColourIds::alertWindowBackground, Colour (Colour::fromString("2ff52636a")))); int iconSpaceUsed = 160; if (alert.getAlertType() != AlertWindow::NoIcon) { Path icon; if (alert.getAlertType() == AlertWindow::WarningIcon) { Rectangle<float> rect (alert.getLocalBounds().removeFromLeft (iconSpaceUsed).toFloat()); const Image warningImage = ImageCache::getFromMemory (CabbageBinaryData::WarningIcon_png, CabbageBinaryData::WarningIcon_pngSize); //g.drawImage(warningImage, rect.reduced(20)); } if (alert.getAlertType() == AlertWindow::QuestionIcon) { Rectangle<float> rect (alert.getLocalBounds().removeFromLeft (iconSpaceUsed - 20).toFloat()); const Image warningImage = ImageCache::getFromMemory (CabbageBinaryData::WarningIcon_png, CabbageBinaryData::WarningIcon_pngSize); //g.drawImage(warningImage, rect.reduced(25)); } MemoryInputStream svgStream (CabbageBinaryData::processstop_svg, CabbageBinaryData::processstop_svgSize, false); ScopedPointer<XmlElement> svg (XmlDocument::parse (svgStream.readString())); if (svg == nullptr) jassert (false); ScopedPointer<Drawable> drawable; if (svg != nullptr) { drawable = Drawable::createFromSVG (*svg); Rectangle<float> rect (20, 20, 80, 80);//alert.getLocalBounds().removeFromLeft (iconSpaceUsed - 20).withHeight(130).toFloat()); drawable->setTransformToFit (rect, RectanglePlacement::stretchToFit); drawable->draw (g, 1.f, AffineTransform()); } } g.setColour (alert.findColour (AlertWindow::textColourId)); textLayout.draw (g, Rectangle<int> (textArea.getX() + iconSpaceUsed - 50, textArea.getY(), textArea.getWidth() - iconSpaceUsed - 40, textArea.getHeight()).toFloat()); g.setColour (alert.findColour (AlertWindow::outlineColourId)); g.drawRect (0, 0, alert.getWidth(), alert.getHeight()); }
bool ValueTreeSynchroniser::applyChange (ValueTree& root, const void* data, size_t dataSize, UndoManager* undoManager) { MemoryInputStream input (data, dataSize, false); const ValueTreeSynchroniserHelpers::ChangeType type = (ValueTreeSynchroniserHelpers::ChangeType) input.readByte(); if (type == ValueTreeSynchroniserHelpers::fullSync) { root = ValueTree::readFromStream (input); return true; } ValueTree v (ValueTreeSynchroniserHelpers::readSubTreeLocation (input, root)); if (! v.isValid()) return false; switch (type) { case ValueTreeSynchroniserHelpers::propertyChanged: { Identifier property (input.readString()); v.setProperty (property, var::readFromStream (input), undoManager); return true; } case ValueTreeSynchroniserHelpers::propertyRemoved: { Identifier property (input.readString()); v.removeProperty (property, undoManager); return true; } case ValueTreeSynchroniserHelpers::childAdded: { const int index = input.readCompressedInt(); v.addChild (ValueTree::readFromStream (input), index, undoManager); return true; } case ValueTreeSynchroniserHelpers::childRemoved: { const int index = input.readCompressedInt(); if (isPositiveAndBelow (index, v.getNumChildren())) { v.removeChild (index, undoManager); return true; } jassertfalse; // Either received some corrupt data, or the trees have drifted out of sync break; } case ValueTreeSynchroniserHelpers::childMoved: { const int oldIndex = input.readCompressedInt(); const int newIndex = input.readCompressedInt(); if (isPositiveAndBelow (oldIndex, v.getNumChildren()) && isPositiveAndBelow (newIndex, v.getNumChildren())) { v.moveChild (oldIndex, newIndex, undoManager); return true; } jassertfalse; // Either received some corrupt data, or the trees have drifted out of sync break; } default: jassertfalse; // Seem to have received some corrupt data? break; } return false; }