diff --git a/extras/Jucer (experimental)/Source/ui/Drawable Editor/jucer_DrawableEditorCanvas.h b/extras/Jucer (experimental)/Source/ui/Drawable Editor/jucer_DrawableEditorCanvas.h index 647a2257a7..9bac07319b 100644 --- a/extras/Jucer (experimental)/Source/ui/Drawable Editor/jucer_DrawableEditorCanvas.h +++ b/extras/Jucer (experimental)/Source/ui/Drawable Editor/jucer_DrawableEditorCanvas.h @@ -722,7 +722,7 @@ public: canvas->handleUpdateNowIfNeeded(); g.fillAll (Colours::white); - const Point origin (canvas->getOrigin()); + const Point origin (canvas->getScale().origin); g.setOrigin (origin.getX(), origin.getY()); if (origin.getX() > 0) diff --git a/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorCanvas.cpp b/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorCanvas.cpp index c2ce593e7d..dc6c2540f6 100644 --- a/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorCanvas.cpp +++ b/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorCanvas.cpp @@ -242,167 +242,6 @@ private: } }; -//============================================================================== -class EditorCanvasBase::MarkerComponent : public EditorCanvasBase::OverlayItemComponent -{ -public: - MarkerComponent (EditorCanvasBase* canvas_, const ValueTree& marker_, bool isX_, int headSize_) - : OverlayItemComponent (canvas_), marker (marker_), isX (isX_), headSize (headSize_ - 2), - dragStartPos (0), isDragging (false) - { - } - - ~MarkerComponent() - { - } - - void paint (Graphics& g) - { - g.setColour (Colours::lightblue.withAlpha (isMouseOverOrDragging() ? 0.9f : 0.5f)); - g.fillPath (path); - } - - void updatePosition() - { - RelativeCoordinate coord (getMarkerList().getCoordinate (marker)); - const int pos = roundToInt (coord.resolve (&getMarkerList())); - const int width = 8; - - if (isX) - setBoundsInTargetSpace (Rectangle (pos - width, -canvas->getOrigin().getY() - headSize, - width * 2, getParentHeight())); - else - setBoundsInTargetSpace (Rectangle (-canvas->getOrigin().getX() - headSize, pos - width, - getParentWidth(), width * 2)); - - labelText = "name: " + getMarkerList().getName (marker) + "\nposition: " + coord.toString(); - updateLabel(); - } - - void updateLabel() - { - if (isMouseOverOrDragging() && (getWidth() > 1 || getHeight() > 1)) - label.update (getParentComponent(), labelText, Colours::darkgreen, - isX ? getBounds().getCentreX() : getX() + headSize, - isX ? getY() + headSize : getBounds().getCentreY(), true, true); - else - label.remove(); - } - - bool hitTest (int x, int y) - { - return (isX ? y : x) < headSize; - } - - void resized() - { - const float lineThickness = 1.0f; - path.clear(); - - if (isX) - { - const float centre = getWidth() / 2 + 0.5f; - path.addLineSegment (Line (centre, 2.0f, centre, getHeight() + 1.0f), lineThickness); - path.addTriangle (1.0f, 0.0f, centre * 2.0f - 1.0f, 0.0f, centre, headSize + 1.0f); - } - else - { - const float centre = getHeight() / 2 + 0.5f; - path.addLineSegment (Line (2.0f, centre, getWidth() + 1.0f, centre), lineThickness); - path.addTriangle (0.0f, centre * 2.0f - 1.0f, 0.0f, 1.0f, headSize + 1.0f, centre); - } - - updateLabel(); - } - - void mouseDown (const MouseEvent& e) - { - mouseDownPos = e.getEventRelativeTo (getParentComponent()).getMouseDownPosition(); - toFront (false); - updateLabel(); - - canvas->getSelection().selectOnly (getMarkerList().getId (marker)); - - if (e.mods.isPopupMenu()) - { - isDragging = false; - } - else - { - isDragging = true; - canvas->getUndoManager().beginNewTransaction(); - - RelativeCoordinate coord (getMarkerList().getCoordinate (marker)); - dragStartPos = coord.resolve (&getMarkerList()); - } - } - - void mouseDrag (const MouseEvent& e) - { - if (isDragging) - { - autoScrollForMouseEvent (e); - const MouseEvent e2 (e.getEventRelativeTo (getParentComponent())); - - canvas->getUndoManager().undoCurrentTransactionOnly(); - - Rectangle axis; - if (isX) - axis.setBounds (0, 0, getParentWidth(), headSize); - else - axis.setBounds (0, 0, headSize, getParentHeight()); - - if (axis.expanded (isX ? 500 : 30, isX ? 30 : 500).contains (e.x, e.y)) - { - RelativeCoordinate coord (getMarkerList().getCoordinate (marker)); - - // (can't use getDistanceFromDragStart() because it doesn't take into account auto-scrolling) - coord.moveToAbsolute (canvas->limitMarkerPosition (dragStartPos + (isX ? e2.x - mouseDownPos.getX() - : e2.y - mouseDownPos.getY())), - &getMarkerList()); - getMarkerList().setCoordinate (marker, coord); - } - else - { - getMarkerList().deleteMarker (marker); - } - } - } - - void mouseUp (const MouseEvent& e) - { - canvas->getUndoManager().beginNewTransaction(); - updateLabel(); - } - - void mouseEnter (const MouseEvent& e) - { - updateLabel(); - repaint(); - } - - void mouseExit (const MouseEvent& e) - { - updateLabel(); - repaint(); - } - - MarkerListBase& getMarkerList() { return canvas->getMarkerList (isX); } - - ValueTree marker; - const bool isX; - -private: - const int headSize; - Path path; - double dragStartPos; - bool isDragging; - FloatingLabelComponent label; - String labelText; - Point mouseDownPos; -}; - - //============================================================================== class EditorCanvasBase::OverlayComponent : public Component, public LassoSource , @@ -421,8 +260,6 @@ public: getSelection().removeChangeListener (this); lasso = 0; resizers.clear(); - markersX.clear(); - markersY.clear(); controlPoints.clear(); deleteAllChildren(); } @@ -526,30 +363,13 @@ public: void mouseDoubleClick (const MouseEvent& e) { - const BorderSize& border = canvas->border; - const Rectangle xAxis (border.getLeft(), 0, getWidth() - border.getLeftAndRight(), border.getTop()); - const Rectangle yAxis (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom()); + const MouseEvent e2 (e.getEventRelativeTo (canvas->getComponentHolder())); + const SelectedItems::ItemType underMouse (canvas->findObjectIdAt (canvas->screenSpaceToObjectSpace (e2.getPosition()))); - if (xAxis.contains (e.x, e.y)) + if (underMouse.isNotEmpty()) { - canvas->getMarkerList (true).createMarker (canvas->getMarkerList (true).getNonexistentMarkerName ("Marker"), - e.x - xAxis.getX()); - } - else if (yAxis.contains (e.x, e.y)) - { - canvas->getMarkerList (false).createMarker (canvas->getMarkerList (false).getNonexistentMarkerName ("Marker"), - e.y - yAxis.getY()); - } - else - { - const MouseEvent e2 (e.getEventRelativeTo (canvas->getComponentHolder())); - const SelectedItems::ItemType underMouse (canvas->findObjectIdAt (canvas->screenSpaceToObjectSpace (e2.getPosition()))); - - if (underMouse.isNotEmpty()) - { - const ValueTree state (canvas->getObjectState (underMouse)); - canvas->objectDoubleClicked (e2, state); - } + const ValueTree state (canvas->getObjectState (underMouse)); + canvas->objectDoubleClicked (e2, state); } } @@ -602,7 +422,6 @@ public: { updateResizeFrames(); updateControlPoints(); - updateMarkers(); } private: @@ -612,7 +431,6 @@ private: bool mouseDownResult, isDraggingClickedComp; SelectedItems::ItemType mouseDownCompUID; OwnedArray resizers; - OwnedArray markersX, markersY; OwnedArray controlPoints; void updateResizeFrames() @@ -678,54 +496,6 @@ private: canvas->updateControlPointComponents (this, controlPoints); } - - void updateMarkers (OwnedArray & markers, const bool isX) - { - MarkerListBase& markerList = canvas->getMarkerList (isX); - const int num = markerList.size(); - - Array requiredMarkers; - requiredMarkers.ensureStorageAllocated (num); - - int i; - for (i = 0; i < num; ++i) - requiredMarkers.add (markerList.getMarker (i)); - - for (i = markers.size(); --i >= 0;) - { - MarkerComponent* marker = markers.getUnchecked (i); - const int index = requiredMarkers.indexOf (marker->marker); - - if (index >= 0) - { - marker->updatePosition(); - requiredMarkers.removeValue (marker->marker); - } - else - { - if (marker->isMouseButtonDown()) - marker->setBounds (-1, -1, 1, 1); - else - markers.remove (i); - } - } - - for (i = requiredMarkers.size(); --i >= 0;) - { - MarkerComponent* marker = new MarkerComponent (canvas, requiredMarkers.getReference(i), - isX, isX ? canvas->border.getTop() - : canvas->border.getLeft()); - markers.add (marker); - addAndMakeVisible (marker); - marker->updatePosition(); - } - } - - void updateMarkers() - { - updateMarkers (markersX, true); - updateMarkers (markersY, false); - } }; //============================================================================== @@ -824,8 +594,7 @@ private: //============================================================================== EditorCanvasBase::EditorCanvasBase() - : border (14), - scaleFactor (1.0) + : border (8, 8, 14, 14) { //setOpaque (true); } @@ -858,32 +627,32 @@ EditorPanelBase* EditorCanvasBase::getPanel() const const Point EditorCanvasBase::screenSpaceToObjectSpace (const Point& p) const { - return p - origin; + return p - scale.origin; } const Point EditorCanvasBase::objectSpaceToScreenSpace (const Point& p) const { - return p + origin; + return p + scale.origin; } const Point EditorCanvasBase::screenSpaceToObjectSpace (const Point& p) const { - return p - origin.toFloat(); + return p - scale.origin.toFloat(); } const Point EditorCanvasBase::objectSpaceToScreenSpace (const Point& p) const { - return p + origin.toFloat(); + return p + scale.origin.toFloat(); } const Rectangle EditorCanvasBase::screenSpaceToObjectSpace (const Rectangle& r) const { - return r - origin; + return r - scale.origin; } const Rectangle EditorCanvasBase::objectSpaceToScreenSpace (const Rectangle& r) const { - return r + origin; + return r + scale.origin; } void EditorCanvasBase::enableResizingMode() @@ -909,47 +678,11 @@ bool EditorCanvasBase::isRotating() const //============================================================================== void EditorCanvasBase::paint (Graphics& g) { - g.setFont (border.getTop() - 5.0f); - g.setColour (Colour::greyLevel (0.9f)); - - //g.drawHorizontalLine (border.getTop() - 1, 2.0f, (float) getWidth() - border.getRight()); - //g.drawVerticalLine (border.getLeft() - 1, 2.0f, (float) getHeight() - border.getBottom()); - - drawXAxis (g, Rectangle (border.getLeft(), 0, componentHolder->getWidth(), border.getTop())); - drawYAxis (g, Rectangle (0, border.getTop(), border.getLeft(), componentHolder->getHeight())); } -void EditorCanvasBase::drawXAxis (Graphics& g, const Rectangle& r) +void EditorCanvasBase::setScale (const Scale& newScale) { - TickIterator ticks (-origin.getX(), r.getWidth(), 1.0, 10, 50); - float pos, tickLength; - String label; - - while (ticks.getNextTick (pos, tickLength, label)) - { - if (pos > 0) - { - g.drawVerticalLine (r.getX() + (int) pos, r.getBottom() - tickLength * r.getHeight(), (float) r.getBottom()); - g.drawSingleLineText (label, r.getX() + (int) pos + 2, (int) r.getBottom() - 6); - } - } -} - -void EditorCanvasBase::drawYAxis (Graphics& g, const Rectangle& r) -{ - TickIterator ticks (-origin.getY(), r.getHeight(), 1.0, 10, 80); - float pos, tickLength; - String label; - - while (ticks.getNextTick (pos, tickLength, label)) - { - if (pos > 0) - { - g.drawHorizontalLine (r.getY() + (int) pos, r.getRight() - tickLength * r.getWidth(), (float) r.getRight()); - g.drawTextAsPath (label, AffineTransform::rotation (float_Pi / -2.0f) - .translated (r.getRight() - 6.0f, r.getY() + pos - 2.0f)); - } - } + jassertfalse; } const Rectangle EditorCanvasBase::getContentArea() const @@ -968,16 +701,20 @@ void EditorCanvasBase::handleAsyncUpdate() const int newWidth = jmax (canvasBounds.getWidth(), canvasBounds.getRight()) + border.getLeftAndRight(); const int newHeight = jmax (canvasBounds.getHeight(), canvasBounds.getBottom()) + border.getTopAndBottom(); - if (origin != newOrigin) + if (scale.origin != newOrigin) { repaint(); - const Point oldOrigin (origin); - origin = newOrigin; + const Point oldOrigin (scale.origin); + scale.origin = newOrigin; - setBounds (jmin (0, getX() + oldOrigin.getX() - origin.getX()), - jmin (0, getY() + oldOrigin.getY() - origin.getY()), + setBounds (jmin (0, getX() + oldOrigin.getX() - scale.origin.getX()), + jmin (0, getY() + oldOrigin.getY() - scale.origin.getY()), newWidth, newHeight); + + EditorPanelBase* panel = getPanel(); + if (panel != 0) + panel->updateRulers(); } else if (getWidth() != newWidth || getHeight() != newHeight) { @@ -986,6 +723,10 @@ void EditorCanvasBase::handleAsyncUpdate() else { overlay->update(); + + EditorPanelBase* panel = getPanel(); + if (panel != 0) + panel->updateMarkers(); } } @@ -1007,7 +748,7 @@ void EditorCanvasBase::hideSizeGuides() { overlay->hideSizeGuides(); } void EditorCanvasBase::beginDrag (const MouseEvent& e, const ResizableBorderComponent::Zone& zone, bool isRotating, const Point& rotationCentre) { - dragger = createDragOperation (e.getEventRelativeTo (overlay).getPosition() - origin, overlay, zone, isRotating); + dragger = createDragOperation (screenSpaceToObjectSpace (e.getEventRelativeTo (overlay).getPosition()), overlay, zone, isRotating); dragger->setRotationCentre (rotationCentre); repaint(); } @@ -1017,7 +758,7 @@ void EditorCanvasBase::continueDrag (const MouseEvent& e) MouseEvent e2 (e.getEventRelativeTo (overlay)); if (dragger != 0) - dragger->drag (e2, e2.getPosition() - origin); + dragger->drag (e2, screenSpaceToObjectSpace (e2.getPosition())); } void EditorCanvasBase::endDrag (const MouseEvent& e) @@ -1025,7 +766,7 @@ void EditorCanvasBase::endDrag (const MouseEvent& e) if (dragger != 0) { MouseEvent e2 (e.getEventRelativeTo (overlay)); - dragger->drag (e2, e2.getPosition() - origin); + dragger->drag (e2, screenSpaceToObjectSpace (e2.getPosition())); dragger = 0; getUndoManager().beginNewTransaction(); @@ -1056,3 +797,9 @@ const Point EditorCanvasBase::OverlayItemComponent::pointToLocalSpace (co + (canvas->getComponentHolder()->relativePositionToOtherComponent (getParentComponent(), Point()) - getPosition()).toFloat(); } + +//============================================================================== +EditorCanvasBase::Scale::Scale() + : scale (1.0) +{ +} diff --git a/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorCanvas.h b/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorCanvas.h index a84fdb1b78..b121108ea5 100644 --- a/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorCanvas.h +++ b/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorCanvas.h @@ -51,8 +51,6 @@ public: void resized(); const Rectangle getContentArea() const; - void drawXAxis (Graphics& g, const Rectangle& r); - void drawYAxis (Graphics& g, const Rectangle& r); //============================================================================== void valueTreePropertyChanged (ValueTree&, const Identifier&) { triggerAsyncUpdate(); } @@ -63,6 +61,17 @@ public: void showSizeGuides(); void hideSizeGuides(); + struct Scale + { + Scale(); + + Point origin; + double scale; + }; + + const Scale& getScale() const throw() { return scale; } + void setScale (const Scale& newScale); + //============================================================================== virtual UndoManager& getUndoManager() = 0; virtual void documentChanged() = 0; @@ -123,7 +132,6 @@ public: Component* getComponentHolder() const { return componentHolder; } EditorPanelBase* getPanel() const; - const Point& getOrigin() const throw() { return origin; } const Point screenSpaceToObjectSpace (const Point& p) const; const Point screenSpaceToObjectSpace (const Point& p) const; const Point objectSpaceToScreenSpace (const Point& p) const; @@ -152,8 +160,7 @@ public: protected: //============================================================================== const BorderSize border; - Point origin; - double scaleFactor; + Scale scale; ValueTree controlPointEditingTarget; friend class OverlayItemComponent; diff --git a/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorPanel.h b/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorPanel.h index e41d754704..be960f63de 100644 --- a/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorPanel.h +++ b/extras/Jucer (experimental)/Source/ui/Editor Base/jucer_EditorPanel.h @@ -26,46 +26,54 @@ #ifndef __JUCER_EDITORPANEL_H_8E192A99__ #define __JUCER_EDITORPANEL_H_8E192A99__ +#include "../../utility/jucer_TickIterator.h" +#include "jucer_EditorCanvas.h" + //============================================================================== class EditorPanelBase : public Component { public: EditorPanelBase() - : infoPanel (0), tree (0), markersVisible (true), snappingEnabled (true) + : rulerX (true), rulerY (false), markersVisible (true), snappingEnabled (true), canvas (0) { - addAndMakeVisible (toolbar = new Toolbar()); - toolbar->setStyle (Toolbar::textOnly); - - addAndMakeVisible (viewport = new CanvasViewport()); - - addChildComponent (tree = new TreeView()); - tree->setRootItemVisible (true); - tree->setMultiSelectEnabled (true); - tree->setDefaultOpenness (true); - tree->setColour (TreeView::backgroundColourId, Colour::greyLevel (0.92f)); - tree->setIndentSize (15); + setOpaque (true); + background = ImageCache::getFromMemory (BinaryData::brushed_aluminium_png, BinaryData::brushed_aluminium_pngSize); + + addAndMakeVisible (&toolbar); + toolbar.setStyle (Toolbar::textOnly); + + addAndMakeVisible (&viewport); + addAndMakeVisible (&rulerX); + addAndMakeVisible (&rulerY); + + addChildComponent (&tree); + tree.setRootItemVisible (true); + tree.setMultiSelectEnabled (true); + tree.setDefaultOpenness (true); + tree.setColour (TreeView::backgroundColourId, Colour::greyLevel (0.92f)); + tree.setIndentSize (15); } ~EditorPanelBase() { jassert (infoPanel == 0); // remember to call shutdown() - deleteAllChildren(); } - void initialise (Component* canvas, ToolbarItemFactory& toolbarFactory, TreeViewItem* treeRootItem) + void initialise (EditorCanvasBase* canvas_, ToolbarItemFactory& toolbarFactory, TreeViewItem* treeRootItem) { - toolbar->addDefaultItems (toolbarFactory); - viewport->setViewedComponent (canvas); + canvas = canvas_; + toolbar.addDefaultItems (toolbarFactory); + viewport.setViewedComponent (canvas); addAndMakeVisible (infoPanel = new InfoPanel (this)); - tree->setRootItem (treeRootItem); + tree.setRootItem (treeRootItem); resized(); } void shutdown() { - tree->deleteRootItem(); - deleteAndZero (infoPanel); + tree.deleteRootItem(); + infoPanel = 0; } //============================================================================== @@ -79,11 +87,11 @@ public: void showOrHideTree() { - tree->setVisible (! tree->isVisible()); + tree.setVisible (! tree.isVisible()); resized(); } - bool isTreeVisible() const { return tree->isVisible(); } + bool isTreeVisible() const { return tree.isVisible(); } void showOrHideMarkers() { @@ -105,27 +113,62 @@ public: virtual SelectedItemSet& getSelection() = 0; virtual void getSelectedItemProperties (Array& newComps) = 0; + void paint (Graphics& g) + { + g.setTiledImageFill (background, 0, 0, 1.0f); + g.fillAll(); + } + void resized() { const int toolbarHeight = 22; - toolbar->setBounds (0, 0, getWidth(), toolbarHeight); + toolbar.setBounds (0, 0, getWidth(), toolbarHeight); int contentL = 0, contentR = getWidth(); if (infoPanel != 0 && infoPanel->isVisible()) { contentR -= 200; - infoPanel->setBounds (contentR, toolbar->getBottom(), getWidth() - contentR, getHeight() - toolbar->getBottom()); + infoPanel->setBounds (contentR, toolbar.getBottom(), getWidth() - contentR, getHeight() - toolbar.getBottom()); } - if (tree->isVisible()) + if (tree.isVisible()) { contentL = 200; - tree->setBounds (0, toolbar->getBottom(), contentL, getHeight() - toolbar->getBottom()); + tree.setBounds (0, toolbar.getBottom(), contentL, getHeight() - toolbar.getBottom()); } - viewport->setBounds (contentL, toolbar->getBottom(), contentR - contentL, getHeight() - toolbar->getBottom()); + const int rulerThickness = 16; + viewport.setBounds (contentL + rulerThickness, toolbar.getBottom() + rulerThickness, + contentR - contentL - rulerThickness, + getHeight() - toolbar.getBottom() - rulerThickness); + + rulerX.setBounds (viewport.getX(), viewport.getY() - rulerThickness, viewport.getWidth(), rulerThickness); + rulerY.setBounds (viewport.getX() - rulerThickness, viewport.getY(), rulerThickness, viewport.getHeight()); + updateRulers(); + } + + void updateRulers() + { + if (canvas != 0) + { + rulerX.update (canvas->getScale(), canvas->getComponentHolder()); + rulerY.update (canvas->getScale(), canvas->getComponentHolder()); + } + + updateMarkers(); + } + + void updateMarkers() + { + if (canvas != 0) + { + const int vw = viewport.getMaximumVisibleWidth(); + const int vh = viewport.getMaximumVisibleHeight(); + rulerX.updateMarkers (canvas->getMarkerList (true), canvas, vw, vh); + rulerY.updateMarkers (canvas->getMarkerList (false), canvas, vw, vh); + } } private: @@ -175,12 +218,315 @@ private: PropertyPanel* props; }; + //============================================================================== + class RulerComponent : public Component + { + public: + RulerComponent (const bool isX_) + : isX (isX_), range (0.0, 100.0), canvas (0) + { + } + + ~RulerComponent() + { + } + + void update (const EditorCanvasBase::Scale& scale, Component* contentHolder) + { + const Point origin (contentHolder->relativePositionToOtherComponent (this, scale.origin)); + const double start = isX ? origin.getX() : origin.getY(); + + const Range newRange (-start * scale.scale, + ((isX ? getWidth() : getHeight()) - start) * scale.scale); + + if (range != newRange) + { + range = newRange; + repaint(); + } + } + + void updateMarkers (MarkerListBase& markerList, EditorCanvasBase* canvas_, const int viewportWidth, const int viewportHeight) + { + canvas = canvas_; + const int num = markerList.size(); + + Array requiredMarkers; + requiredMarkers.ensureStorageAllocated (num); + + int i; + for (i = 0; i < num; ++i) + requiredMarkers.add (markerList.getMarker (i)); + + for (i = markers.size(); --i >= 0;) + { + MarkerComponent* marker = markers.getUnchecked (i); + const int index = requiredMarkers.indexOf (marker->marker); + + if (index >= 0) + { + marker->updatePosition (viewportWidth, viewportHeight); + requiredMarkers.removeValue (marker->marker); + } + else + { + if (marker->isMouseButtonDown()) + marker->setBounds (-1, -1, 1, 1); + else + markers.remove (i); + } + } + + for (i = requiredMarkers.size(); --i >= 0;) + { + MarkerComponent* marker = new MarkerComponent (*this, canvas, requiredMarkers.getReference(i), + isX, isX ? getHeight() : getWidth()); + markers.add (marker); + getParentComponent()->addAndMakeVisible (marker); + marker->updatePosition (viewportWidth, viewportHeight); + } + } + + void paint (Graphics& g) + { + g.setFont (10.0f); + g.setColour (Colour::greyLevel (0.9f)); + + TickIterator ticks (range.getStart(), range.getEnd(), range.getLength() / (isX ? getWidth() : getHeight()), + 10, isX ? 50 : 80); + + float pos, tickLength; + String label; + + while (ticks.getNextTick (pos, tickLength, label)) + { + if (pos > 0) + { + if (isX) + { + g.drawVerticalLine ((int) pos, getHeight() - tickLength * getHeight(), (float) getHeight()); + g.drawSingleLineText (label, (int) pos + 2, getHeight() - 6); + } + else + { + g.drawHorizontalLine ((int) pos, getWidth() - tickLength * getWidth(), (float) getWidth()); + g.drawTextAsPath (label, AffineTransform::rotation (float_Pi / -2.0f) + .translated (getWidth() - 6.0f, pos - 2.0f)); + } + } + } + } + + void mouseDoubleClick (const MouseEvent& e) + { + if (isX) + canvas->getMarkerList (true).createMarker (canvas->getMarkerList (true).getNonexistentMarkerName ("Marker"), + xToPosition (e.x)); + else + canvas->getMarkerList (false).createMarker (canvas->getMarkerList (false).getNonexistentMarkerName ("Marker"), + xToPosition (e.y)); + } + + double xToPosition (const int x) const + { + return range.getStart() + x * range.getLength() / (isX ? getWidth() : getHeight()); + } + + int positionToX (const double position) const + { + const float proportion = (float) ((position - range.getStart()) / range.getLength()); + return isX ? proportionOfWidth (proportion) : proportionOfHeight (proportion); + } + + //============================================================================== + class MarkerComponent : public Component + { + public: + MarkerComponent (RulerComponent& ruler_, EditorCanvasBase* const canvas_, + const ValueTree& marker_, bool isX_, int headSize_) + : ruler (ruler_), canvas (canvas_), marker (marker_), isX (isX_), headSize (headSize_ - 2), + isDragging (false) + { + } + + ~MarkerComponent() + { + } + + void paint (Graphics& g) + { + g.setColour (Colours::lightblue.withAlpha (isMouseOverOrDragging() ? 0.9f : 0.5f)); + g.fillPath (path); + } + + void updatePosition (const int viewportWidth, const int viewportHeight) + { + RelativeCoordinate coord (getMarkerList().getCoordinate (marker)); + const double pos = coord.resolve (&getMarkerList()); + + if (! ruler.range.contains (pos)) + { + setVisible (false); + } + else + { + setVisible (true); + + Point anchorPoint; + if (isX) + anchorPoint.setXY (ruler.positionToX (pos), ruler.getHeight()); + else + anchorPoint.setXY (ruler.getWidth(), ruler.positionToX (pos)); + + Component* const parent = getParentComponent(); + anchorPoint = ruler.relativePositionToOtherComponent (parent, anchorPoint); + + const int width = 8; + if (isX) + setBounds (anchorPoint.getX() - width, anchorPoint.getY() - headSize, width * 2, viewportHeight + headSize); + else + setBounds (anchorPoint.getX() - headSize, anchorPoint.getY() - width, viewportWidth + headSize, width * 2); + } + + labelText = "name: " + getMarkerList().getName (marker) + "\nposition: " + coord.toString(); + updateLabel(); + } + + void updateLabel() + { + if (isMouseOverOrDragging() && isVisible() && (getWidth() > 1 || getHeight() > 1)) + label.update (getParentComponent(), labelText, Colours::darkgreen, + isX ? getBounds().getCentreX() : getX() + headSize, + isX ? getY() + headSize : getBounds().getCentreY(), true, true); + else + label.remove(); + } + + bool hitTest (int x, int y) + { + return (isX ? y : x) < headSize; + } + + void resized() + { + const float lineThickness = 1.0f; + path.clear(); + + if (isX) + { + const float centre = getWidth() / 2 + 0.5f; + path.addLineSegment (Line (centre, 2.0f, centre, getHeight() + 1.0f), lineThickness); + path.addTriangle (1.0f, 0.0f, centre * 2.0f - 1.0f, 0.0f, centre, headSize + 1.0f); + } + else + { + const float centre = getHeight() / 2 + 0.5f; + path.addLineSegment (Line (2.0f, centre, getWidth() + 1.0f, centre), lineThickness); + path.addTriangle (0.0f, centre * 2.0f - 1.0f, 0.0f, 1.0f, headSize + 1.0f, centre); + } + + updateLabel(); + } + + void mouseDown (const MouseEvent& e) + { + mouseDownPos = e.getMouseDownPosition(); + toFront (false); + updateLabel(); + + canvas->getSelection().selectOnly (getMarkerList().getId (marker)); + + if (e.mods.isPopupMenu()) + { + isDragging = false; + } + else + { + isDragging = true; + canvas->getUndoManager().beginNewTransaction(); + } + } + + void mouseDrag (const MouseEvent& e) + { + if (isDragging) + { + autoScrollForMouseEvent (e.getEventRelativeTo (canvas), isX, ! isX); + canvas->getUndoManager().undoCurrentTransactionOnly(); + + Rectangle axis; + if (isX) + axis.setBounds (0, 0, getParentWidth(), headSize); + else + axis.setBounds (0, 0, headSize, getParentHeight()); + + if (axis.expanded (isX ? 500 : 30, isX ? 30 : 500).contains (e.x, e.y)) + { + RelativeCoordinate coord (getMarkerList().getCoordinate (marker)); + + MouseEvent rulerEvent (e.getEventRelativeTo (&ruler)); + int rulerPos = isX ? (rulerEvent.x + getWidth() / 2 - mouseDownPos.getX()) + : (rulerEvent.y + getHeight() / 2 - mouseDownPos.getY()); + + coord.moveToAbsolute (canvas->limitMarkerPosition (ruler.xToPosition (rulerPos)), &getMarkerList()); + getMarkerList().setCoordinate (marker, coord); + } + else + { + getMarkerList().deleteMarker (marker); + } + } + } + + void mouseUp (const MouseEvent& e) + { + canvas->getUndoManager().beginNewTransaction(); + updateLabel(); + } + + void mouseEnter (const MouseEvent& e) + { + updateLabel(); + repaint(); + } + + void mouseExit (const MouseEvent& e) + { + updateLabel(); + repaint(); + } + + MarkerListBase& getMarkerList() { return canvas->getMarkerList (isX); } + + ValueTree marker; + const bool isX; + + private: + RulerComponent& ruler; + EditorCanvasBase* canvas; + const int headSize; + Path path; + bool isDragging; + FloatingLabelComponent label; + String labelText; + Point mouseDownPos; + }; + + Range range; + + private: + const bool isX; + OwnedArray markers; + EditorCanvasBase* canvas; + }; + //============================================================================== class CanvasViewport : public Viewport { public: CanvasViewport() { + background = ImageCache::getFromMemory (BinaryData::brushed_aluminium_png, BinaryData::brushed_aluminium_pngSize); setOpaque (true); } @@ -190,23 +536,36 @@ private: void paint (Graphics& g) { - g.setTiledImageFill (ImageCache::getFromMemory (BinaryData::brushed_aluminium_png, BinaryData::brushed_aluminium_pngSize), - 0, 0, 1.0f); + g.setTiledImageFill (background, 0, 0, 1.0f); g.fillAll(); } void paintOverChildren (Graphics& g) { - drawRecessedShadows (g, getWidth(), getHeight(), 14); + drawRecessedShadows (g, getMaximumVisibleWidth(), getMaximumVisibleHeight(), 14); } + + void visibleAreaChanged (int, int , int, int) + { + EditorPanelBase* p = dynamic_cast (getParentComponent()); + + if (p != 0) + p->updateRulers(); + } + + private: + Image background; }; //============================================================================== - Toolbar* toolbar; - Viewport* viewport; - InfoPanel* infoPanel; - TreeView* tree; + Toolbar toolbar; + CanvasViewport viewport; + RulerComponent rulerX, rulerY; + ScopedPointer infoPanel; + TreeView tree; + EditorCanvasBase* canvas; bool markersVisible, snappingEnabled; + Image background; }; diff --git a/extras/Jucer (experimental)/Source/utility/jucer_MiscUtilities.cpp b/extras/Jucer (experimental)/Source/utility/jucer_MiscUtilities.cpp index 06c7a75d02..5da86de55d 100644 --- a/extras/Jucer (experimental)/Source/utility/jucer_MiscUtilities.cpp +++ b/extras/Jucer (experimental)/Source/utility/jucer_MiscUtilities.cpp @@ -77,14 +77,14 @@ const String createGUID (const String& seed) } //============================================================================== -void autoScrollForMouseEvent (const MouseEvent& e) +void autoScrollForMouseEvent (const MouseEvent& e, bool scrollX, bool scrollY) { Viewport* const viewport = e.eventComponent->findParentComponentOfClass ((Viewport*) 0); if (viewport != 0) { const MouseEvent e2 (e.getEventRelativeTo (viewport)); - viewport->autoScroll (e2.x, e2.y, 8, 16); + viewport->autoScroll (scrollX ? e2.x : 20, scrollY ? e2.y : 20, 8, 16); } } diff --git a/extras/Jucer (experimental)/Source/utility/jucer_MiscUtilities.h b/extras/Jucer (experimental)/Source/utility/jucer_MiscUtilities.h index 36595058cd..b537343935 100644 --- a/extras/Jucer (experimental)/Source/utility/jucer_MiscUtilities.h +++ b/extras/Jucer (experimental)/Source/utility/jucer_MiscUtilities.h @@ -36,7 +36,7 @@ const String createGUID (const String& seed); // Turns a seed into a windows GUI //============================================================================== int indexOfLineStartingWith (const StringArray& lines, const String& text, int startIndex); -void autoScrollForMouseEvent (const MouseEvent& e); +void autoScrollForMouseEvent (const MouseEvent& e, bool scrollX = true, bool scrollY = true); void drawComponentPlaceholder (Graphics& g, int w, int h, const String& text); void drawRecessedShadows (Graphics& g, int w, int h, int shadowSize); diff --git a/juce_amalgamated.cpp b/juce_amalgamated.cpp index e075a03666..412a06b2c2 100644 --- a/juce_amalgamated.cpp +++ b/juce_amalgamated.cpp @@ -1279,7 +1279,7 @@ Logger::~Logger() { } -static Logger* currentLogger = 0; +Logger* Logger::currentLogger = 0; void Logger::setCurrentLogger (Logger* const newLogger, const bool deleteOldLogger) @@ -1653,6 +1653,8 @@ END_JUCE_NAMESPACE /*** Start of inlined file: juce_SystemStats.cpp ***/ BEGIN_JUCE_NAMESPACE +SystemStats::CPUFlags SystemStats::cpuFlags; + const String SystemStats::getJUCEVersion() { return "JUCE v" + String (JUCE_MAJOR_VERSION) @@ -1807,9 +1809,7 @@ void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI() } #if JUCE_WINDOWS - // This is imported from the sockets code.. - typedef int (__stdcall juce_CloseWin32SocketLibCall) (void); - extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib; + extern void juce_shutdownWin32Sockets(); // (defined in the sockets code) #endif #if JUCE_DEBUG @@ -1820,22 +1820,21 @@ void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI() { if (juceInitialisedNonGUI) { -#if JUCE_MAC || JUCE_IPHONE + #if JUCE_MAC || JUCE_IPHONE const ScopedAutoReleasePool pool; -#endif + #endif -#if JUCE_WINDOWS + #if JUCE_WINDOWS // need to shut down sockets if they were used.. - if (juce_CloseWin32SocketLib != 0) - (*juce_CloseWin32SocketLib)(); -#endif + juce_shutdownWin32Sockets(); + #endif LocalisedStrings::setCurrentMappings (0); Thread::stopAllThreads (3000); -#if JUCE_DEBUG + #if JUCE_DEBUG juce_CheckForDanglingStreams(); -#endif + #endif juceInitialisedNonGUI = false; } @@ -3607,8 +3606,7 @@ void MemoryBlock::loadFromHexString (const String& hex) throw() } } -static const char* const encodingTable - = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; +const char* const MemoryBlock::encodingTable = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+"; const String MemoryBlock::toBase64Encoding() const throw() { @@ -5273,7 +5271,7 @@ bool RSAKey::applyToValue (BigInteger& value) const return true; } -static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q) +const BigInteger RSAKey::findBestCommonDivisor (const BigInteger& p, const BigInteger& q) { // try 3, 5, 9, 17, etc first because these only contain 2 bits and so // are fast to divide + multiply @@ -7354,235 +7352,247 @@ BEGIN_JUCE_NAMESPACE #if JUCE_WINDOWS -typedef int (__stdcall juce_CloseWin32SocketLibCall) (void); -juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0; +namespace SocketHelpers +{ + typedef int (__stdcall juce_CloseWin32SocketLibCall) (void); + static juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0; +} static void initWin32Sockets() { static CriticalSection lock; const ScopedLock sl (lock); - if (juce_CloseWin32SocketLib == 0) + if (SocketHelpers::juce_CloseWin32SocketLib == 0) { WSADATA wsaData; const WORD wVersionRequested = MAKEWORD (1, 1); WSAStartup (wVersionRequested, &wsaData); - juce_CloseWin32SocketLib = &WSACleanup; + SocketHelpers::juce_CloseWin32SocketLib = &WSACleanup; } } -#endif - -static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw() +void juce_shutdownWin32Sockets() { - const int sndBufSize = 65536; - const int rcvBufSize = 65536; - const int one = 1; - - return handle > 0 - && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0 - && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0 - && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0) - : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0)); + if (SocketHelpers::juce_CloseWin32SocketLib != 0) + (*SocketHelpers::juce_CloseWin32SocketLib)(); } -static bool bindSocketToPort (const int handle, const int port) throw() +#endif + +namespace SocketHelpers { - if (handle <= 0 || port <= 0) - return false; + static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw() + { + const int sndBufSize = 65536; + const int rcvBufSize = 65536; + const int one = 1; - struct sockaddr_in servTmpAddr; - zerostruct (servTmpAddr); - servTmpAddr.sin_family = PF_INET; - servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY); - servTmpAddr.sin_port = htons ((uint16) port); + return handle > 0 + && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0 + && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0 + && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0) + : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0)); + } - return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0; -} + static bool bindSocketToPort (const int handle, const int port) throw() + { + if (handle <= 0 || port <= 0) + return false; -static int readSocket (const int handle, - void* const destBuffer, const int maxBytesToRead, - bool volatile& connected, - const bool blockUntilSpecifiedAmountHasArrived) throw() -{ - int bytesRead = 0; + struct sockaddr_in servTmpAddr; + zerostruct (servTmpAddr); + servTmpAddr.sin_family = PF_INET; + servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY); + servTmpAddr.sin_port = htons ((uint16) port); - while (bytesRead < maxBytesToRead) - { - int bytesThisTime; + return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0; + } -#if JUCE_WINDOWS - bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0); -#else - while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0 - && errno == EINTR - && connected) - { - } -#endif + static int readSocket (const int handle, + void* const destBuffer, const int maxBytesToRead, + bool volatile& connected, + const bool blockUntilSpecifiedAmountHasArrived) throw() + { + int bytesRead = 0; - if (bytesThisTime <= 0 || ! connected) + while (bytesRead < maxBytesToRead) { - if (bytesRead == 0) - bytesRead = -1; + int bytesThisTime; - break; - } + #if JUCE_WINDOWS + bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0); + #else + while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0 + && errno == EINTR + && connected) + { + } + #endif - bytesRead += bytesThisTime; + if (bytesThisTime <= 0 || ! connected) + { + if (bytesRead == 0) + bytesRead = -1; - if (! blockUntilSpecifiedAmountHasArrived) - break; - } + break; + } - return bytesRead; -} + bytesRead += bytesThisTime; -static int waitForReadiness (const int handle, const bool forReading, - const int timeoutMsecs) throw() -{ - struct timeval timeout; - struct timeval* timeoutp; + if (! blockUntilSpecifiedAmountHasArrived) + break; + } - if (timeoutMsecs >= 0) - { - timeout.tv_sec = timeoutMsecs / 1000; - timeout.tv_usec = (timeoutMsecs % 1000) * 1000; - timeoutp = &timeout; - } - else - { - timeoutp = 0; + return bytesRead; } - fd_set rset, wset; - FD_ZERO (&rset); - FD_SET (handle, &rset); - FD_ZERO (&wset); - FD_SET (handle, &wset); - - fd_set* const prset = forReading ? &rset : 0; - fd_set* const pwset = forReading ? 0 : &wset; - -#if JUCE_WINDOWS - if (select (handle + 1, prset, pwset, 0, timeoutp) < 0) - return -1; -#else + static int waitForReadiness (const int handle, const bool forReading, + const int timeoutMsecs) throw() { - int result; - while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0 - && errno == EINTR) + struct timeval timeout; + struct timeval* timeoutp; + + if (timeoutMsecs >= 0) + { + timeout.tv_sec = timeoutMsecs / 1000; + timeout.tv_usec = (timeoutMsecs % 1000) * 1000; + timeoutp = &timeout; + } + else { + timeoutp = 0; } - if (result < 0) - return -1; - } -#endif + fd_set rset, wset; + FD_ZERO (&rset); + FD_SET (handle, &rset); + FD_ZERO (&wset); + FD_SET (handle, &wset); - { - int opt; - juce_socklen_t len = sizeof (opt); + fd_set* const prset = forReading ? &rset : 0; + fd_set* const pwset = forReading ? 0 : &wset; - if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0 - || opt != 0) + #if JUCE_WINDOWS + if (select (handle + 1, prset, pwset, 0, timeoutp) < 0) return -1; - } + #else + { + int result; + while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0 + && errno == EINTR) + { + } - if ((forReading && FD_ISSET (handle, &rset)) - || ((! forReading) && FD_ISSET (handle, &wset))) - return 1; + if (result < 0) + return -1; + } + #endif - return 0; -} + { + int opt; + juce_socklen_t len = sizeof (opt); -static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw() -{ -#if JUCE_WINDOWS - u_long nonBlocking = shouldBlock ? 0 : 1; + if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0 + || opt != 0) + return -1; + } - if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0) - return false; -#else - int socketFlags = fcntl (handle, F_GETFL, 0); + if ((forReading && FD_ISSET (handle, &rset)) + || ((! forReading) && FD_ISSET (handle, &wset))) + return 1; - if (socketFlags == -1) - return false; + return 0; + } - if (shouldBlock) - socketFlags &= ~O_NONBLOCK; - else - socketFlags |= O_NONBLOCK; + static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw() + { + #if JUCE_WINDOWS + u_long nonBlocking = shouldBlock ? 0 : 1; - if (fcntl (handle, F_SETFL, socketFlags) != 0) - return false; -#endif + if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0) + return false; + #else + int socketFlags = fcntl (handle, F_GETFL, 0); - return true; -} + if (socketFlags == -1) + return false; -static bool connectSocket (int volatile& handle, - const bool isDatagram, - void** serverAddress, - const String& hostName, - const int portNumber, - const int timeOutMillisecs) throw() -{ - struct hostent* const hostEnt = gethostbyname (hostName.toUTF8()); + if (shouldBlock) + socketFlags &= ~O_NONBLOCK; + else + socketFlags |= O_NONBLOCK; - if (hostEnt == 0) - return false; + if (fcntl (handle, F_SETFL, socketFlags) != 0) + return false; + #endif - struct in_addr targetAddress; - memcpy (&targetAddress.s_addr, - *(hostEnt->h_addr_list), - sizeof (targetAddress.s_addr)); + return true; + } - struct sockaddr_in servTmpAddr; - zerostruct (servTmpAddr); - servTmpAddr.sin_family = PF_INET; - servTmpAddr.sin_addr = targetAddress; - servTmpAddr.sin_port = htons ((uint16) portNumber); + static bool connectSocket (int volatile& handle, + const bool isDatagram, + void** serverAddress, + const String& hostName, + const int portNumber, + const int timeOutMillisecs) throw() + { + struct hostent* const hostEnt = gethostbyname (hostName.toUTF8()); - if (handle < 0) - handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0); + if (hostEnt == 0) + return false; - if (handle < 0) - return false; + struct in_addr targetAddress; + memcpy (&targetAddress.s_addr, + *(hostEnt->h_addr_list), + sizeof (targetAddress.s_addr)); - if (isDatagram) - { - *serverAddress = new struct sockaddr_in(); - *((struct sockaddr_in*) *serverAddress) = servTmpAddr; + struct sockaddr_in servTmpAddr; + zerostruct (servTmpAddr); + servTmpAddr.sin_family = PF_INET; + servTmpAddr.sin_addr = targetAddress; + servTmpAddr.sin_port = htons ((uint16) portNumber); - return true; - } + if (handle < 0) + handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0); + + if (handle < 0) + return false; - setSocketBlockingState (handle, false); + if (isDatagram) + { + *serverAddress = new struct sockaddr_in(); + *((struct sockaddr_in*) *serverAddress) = servTmpAddr; - const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)); + return true; + } - if (result < 0) - { -#if JUCE_WINDOWS - if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) -#else - if (errno == EINPROGRESS) -#endif + setSocketBlockingState (handle, false); + + const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)); + + if (result < 0) { - if (waitForReadiness (handle, false, timeOutMillisecs) != 1) + #if JUCE_WINDOWS + if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) + #else + if (errno == EINPROGRESS) + #endif { - setSocketBlockingState (handle, true); - return false; + if (waitForReadiness (handle, false, timeOutMillisecs) != 1) + { + setSocketBlockingState (handle, true); + return false; + } } } - } - setSocketBlockingState (handle, true); - resetSocketOptions (handle, false, false); + setSocketBlockingState (handle, true); + resetSocketOptions (handle, false, false); - return true; + return true; + } } StreamingSocket::StreamingSocket() @@ -7609,7 +7619,7 @@ StreamingSocket::StreamingSocket (const String& hostName_, initWin32Sockets(); #endif - resetSocketOptions (handle_, false, false); + SocketHelpers::resetSocketOptions (handle_, false, false); } StreamingSocket::~StreamingSocket() @@ -7619,7 +7629,7 @@ StreamingSocket::~StreamingSocket() int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived) { - return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived) + return (connected && ! isListener) ? SocketHelpers::readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived) : -1; } @@ -7645,13 +7655,13 @@ int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite) int StreamingSocket::waitUntilReady (const bool readyForReading, const int timeoutMsecs) const { - return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs) + return connected ? SocketHelpers::waitForReadiness (handle, readyForReading, timeoutMsecs) : -1; } bool StreamingSocket::bindToPort (const int port) { - return bindSocketToPort (handle, port); + return SocketHelpers::bindSocketToPort (handle, port); } bool StreamingSocket::connect (const String& remoteHostName, @@ -7671,10 +7681,10 @@ bool StreamingSocket::connect (const String& remoteHostName, portNumber = remotePortNumber; isListener = false; - connected = connectSocket (handle, false, 0, remoteHostName, - remotePortNumber, timeOutMillisecs); + connected = SocketHelpers::connectSocket (handle, false, 0, remoteHostName, + remotePortNumber, timeOutMillisecs); - if (! (connected && resetSocketOptions (handle, false, false))) + if (! (connected && SocketHelpers::resetSocketOptions (handle, false, false))) { close(); return false; @@ -7803,7 +7813,7 @@ DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_, initWin32Sockets(); #endif - resetSocketOptions (handle_, true, allowBroadcast); + SocketHelpers::resetSocketOptions (handle_, true, allowBroadcast); bindToPort (localPortNumber); } @@ -7832,7 +7842,7 @@ void DatagramSocket::close() bool DatagramSocket::bindToPort (const int port) { - return bindSocketToPort (handle, port); + return SocketHelpers::bindSocketToPort (handle, port); } bool DatagramSocket::connect (const String& remoteHostName, @@ -7845,11 +7855,11 @@ bool DatagramSocket::connect (const String& remoteHostName, hostName = remoteHostName; portNumber = remotePortNumber; - connected = connectSocket (handle, true, &serverAddress, - remoteHostName, remotePortNumber, - timeOutMillisecs); + connected = SocketHelpers::connectSocket (handle, true, &serverAddress, + remoteHostName, remotePortNumber, + timeOutMillisecs); - if (! (connected && resetSocketOptions (handle, true, allowBroadcast))) + if (! (connected && SocketHelpers::resetSocketOptions (handle, true, allowBroadcast))) { close(); return false; @@ -7881,13 +7891,13 @@ DatagramSocket* DatagramSocket::waitForNextConnection() const int DatagramSocket::waitUntilReady (const bool readyForReading, const int timeoutMsecs) const { - return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs) + return connected ? SocketHelpers::waitForReadiness (handle, readyForReading, timeoutMsecs) : -1; } int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived) { - return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived) + return connected ? SocketHelpers::readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived) : -1; } @@ -29933,124 +29943,126 @@ BEGIN_JUCE_NAMESPACE #define log(a) #endif -static int insideCallback = 0; - -static const String osTypeToString (OSType type) +namespace AudioUnitFormatHelpers { - char s[4]; - s[0] = (char) (((uint32) type) >> 24); - s[1] = (char) (((uint32) type) >> 16); - s[2] = (char) (((uint32) type) >> 8); - s[3] = (char) ((uint32) type); - return String (s, 4); -} + static int insideCallback = 0; -static OSType stringToOSType (const String& s1) -{ - const String s (s1 + " "); + static const String osTypeToString (OSType type) + { + char s[4]; + s[0] = (char) (((uint32) type) >> 24); + s[1] = (char) (((uint32) type) >> 16); + s[2] = (char) (((uint32) type) >> 8); + s[3] = (char) ((uint32) type); + return String (s, 4); + } - return (((OSType) (unsigned char) s[0]) << 24) - | (((OSType) (unsigned char) s[1]) << 16) - | (((OSType) (unsigned char) s[2]) << 8) - | ((OSType) (unsigned char) s[3]); -} + static OSType stringToOSType (const String& s1) + { + const String s (s1 + " "); -static const char* auIdentifierPrefix = "AudioUnit:"; + return (((OSType) (unsigned char) s[0]) << 24) + | (((OSType) (unsigned char) s[1]) << 16) + | (((OSType) (unsigned char) s[2]) << 8) + | ((OSType) (unsigned char) s[3]); + } -static const String createAUPluginIdentifier (const ComponentDescription& desc) -{ - jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong.. - jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto + static const char* auIdentifierPrefix = "AudioUnit:"; - String s (auIdentifierPrefix); + static const String createAUPluginIdentifier (const ComponentDescription& desc) + { + jassert (osTypeToString ('abcd') == "abcd"); // agh, must have got the endianness wrong.. + jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto - if (desc.componentType == kAudioUnitType_MusicDevice) - s << "Synths/"; - else if (desc.componentType == kAudioUnitType_MusicEffect - || desc.componentType == kAudioUnitType_Effect) - s << "Effects/"; - else if (desc.componentType == kAudioUnitType_Generator) - s << "Generators/"; - else if (desc.componentType == kAudioUnitType_Panner) - s << "Panners/"; + String s (auIdentifierPrefix); - s << osTypeToString (desc.componentType) << "," - << osTypeToString (desc.componentSubType) << "," - << osTypeToString (desc.componentManufacturer); + if (desc.componentType == kAudioUnitType_MusicDevice) + s << "Synths/"; + else if (desc.componentType == kAudioUnitType_MusicEffect + || desc.componentType == kAudioUnitType_Effect) + s << "Effects/"; + else if (desc.componentType == kAudioUnitType_Generator) + s << "Generators/"; + else if (desc.componentType == kAudioUnitType_Panner) + s << "Panners/"; - return s; -} + s << osTypeToString (desc.componentType) << "," + << osTypeToString (desc.componentSubType) << "," + << osTypeToString (desc.componentManufacturer); -static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer) -{ - Handle componentNameHandle = NewHandle (sizeof (void*)); - Handle componentInfoHandle = NewHandle (sizeof (void*)); + return s; + } - if (componentNameHandle != 0 && componentInfoHandle != 0) + static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer) { - ComponentDescription desc; + Handle componentNameHandle = NewHandle (sizeof (void*)); + Handle componentInfoHandle = NewHandle (sizeof (void*)); - if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr) + if (componentNameHandle != 0 && componentInfoHandle != 0) { - ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle); - ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle); + ComponentDescription desc; - if (nameString != 0 && nameString[0] != 0) + if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr) { - const String all ((const char*) nameString + 1, nameString[0]); - DBG ("name: "+ all); + ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle); + ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle); - manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim(); - name = all.fromFirstOccurrenceOf (":", false, false).trim(); - } + if (nameString != 0 && nameString[0] != 0) + { + const String all ((const char*) nameString + 1, nameString[0]); + DBG ("name: "+ all); - if (infoString != 0 && infoString[0] != 0) - { - DBG ("info: " + String ((const char*) infoString + 1, infoString[0])); + manufacturer = all.upToFirstOccurrenceOf (":", false, false).trim(); + name = all.fromFirstOccurrenceOf (":", false, false).trim(); + } + + if (infoString != 0 && infoString[0] != 0) + { + DBG ("info: " + String ((const char*) infoString + 1, infoString[0])); + } + + if (name.isEmpty()) + name = ""; } - if (name.isEmpty()) - name = ""; + DisposeHandle (componentNameHandle); + DisposeHandle (componentInfoHandle); } - - DisposeHandle (componentNameHandle); - DisposeHandle (componentInfoHandle); } -} - -static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc, - String& name, String& version, String& manufacturer) -{ - zerostruct (desc); - if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix)) + static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc, + String& name, String& version, String& manufacturer) { - String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'), - fileOrIdentifier.lastIndexOfChar ('/')) + 1)); - - StringArray tokens; - tokens.addTokens (s, ",", String::empty); - tokens.trim(); - tokens.removeEmptyStrings(); + zerostruct (desc); - if (tokens.size() == 3) + if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix)) { - desc.componentType = stringToOSType (tokens[0]); - desc.componentSubType = stringToOSType (tokens[1]); - desc.componentManufacturer = stringToOSType (tokens[2]); + String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (':'), + fileOrIdentifier.lastIndexOfChar ('/')) + 1)); - ComponentRecord* comp = FindNextComponent (0, &desc); + StringArray tokens; + tokens.addTokens (s, ",", String::empty); + tokens.trim(); + tokens.removeEmptyStrings(); - if (comp != 0) + if (tokens.size() == 3) { - getAUDetails (comp, name, manufacturer); + desc.componentType = stringToOSType (tokens[0]); + desc.componentSubType = stringToOSType (tokens[1]); + desc.componentManufacturer = stringToOSType (tokens[2]); - return true; + ComponentRecord* comp = FindNextComponent (0, &desc); + + if (comp != 0) + { + getAUDetails (comp, name, manufacturer); + return true; + } } } - } - return false; + return false; + } } class AudioUnitPluginWindowCarbon; @@ -30067,7 +30079,7 @@ public: void fillInPluginDescription (PluginDescription& desc) const { desc.name = pluginName; - desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc); + desc.fileOrIdentifier = AudioUnitFormatHelpers::createAUPluginIdentifier (componentDesc); desc.uid = ((int) componentDesc.componentType) ^ ((int) componentDesc.componentSubType) ^ ((int) componentDesc.componentManufacturer); @@ -30227,6 +30239,8 @@ AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier audioUnit (0), currentBuffer (0) { + using namespace AudioUnitFormatHelpers; + try { ++insideCallback; @@ -30258,7 +30272,7 @@ AudioUnitPluginInstance::~AudioUnitPluginInstance() { const ScopedLock sl (lock); - jassert (insideCallback == 0); + jassert (AudioUnitFormatHelpers::insideCallback == 0); if (audioUnit != 0) { @@ -30272,7 +30286,7 @@ bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIden { zerostruct (componentDesc); - if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer)) + if (AudioUnitFormatHelpers::getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer)) return true; const File file (fileOrIdentifier); @@ -31299,7 +31313,7 @@ const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearch || desc.componentType == kAudioUnitType_Generator || desc.componentType == kAudioUnitType_Panner) { - const String s (createAUPluginIdentifier (desc)); + const String s (AudioUnitFormatHelpers::createAUPluginIdentifier (desc)); DBG (s); result.add (s); } @@ -31313,7 +31327,7 @@ bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOr ComponentDescription desc; String name, version, manufacturer; - if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer)) + if (AudioUnitFormatHelpers::getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer)) return FindNextComponent (0, &desc) != 0; const File f (fileOrIdentifier); @@ -31326,7 +31340,7 @@ const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& { ComponentDescription desc; String name, version, manufacturer; - getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer); + AudioUnitFormatHelpers::getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer); if (name.isEmpty()) name = fileOrIdentifier; @@ -31336,7 +31350,7 @@ const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc) { - if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix)) + if (desc.fileOrIdentifier.startsWithIgnoreCase (AudioUnitFormatHelpers::auIdentifierPrefix)) return fileMightContainThisPluginType (desc.fileOrIdentifier); else return File (desc.fileOrIdentifier).exists(); @@ -45588,299 +45602,297 @@ CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser() namespace CppTokeniser { + static bool isIdentifierStart (const juce_wchar c) throw() + { + return CharacterFunctions::isLetter (c) + || c == '_' || c == '@'; + } -static bool isIdentifierStart (const juce_wchar c) throw() -{ - return CharacterFunctions::isLetter (c) - || c == '_' || c == '@'; -} + static bool isIdentifierBody (const juce_wchar c) throw() + { + return CharacterFunctions::isLetterOrDigit (c) + || c == '_' || c == '@'; + } -static bool isIdentifierBody (const juce_wchar c) throw() -{ - return CharacterFunctions::isLetterOrDigit (c) - || c == '_' || c == '@'; -} + static bool isReservedKeyword (const juce_wchar* const token, const int tokenLength) throw() + { + static const juce_wchar* const keywords2Char[] = + { JUCE_T("if"), JUCE_T("do"), JUCE_T("or"), JUCE_T("id"), 0 }; -static bool isReservedKeyword (const juce_wchar* const token, const int tokenLength) throw() -{ - static const juce_wchar* const keywords2Char[] = - { JUCE_T("if"), JUCE_T("do"), JUCE_T("or"), JUCE_T("id"), 0 }; + static const juce_wchar* const keywords3Char[] = + { JUCE_T("for"), JUCE_T("int"), JUCE_T("new"), JUCE_T("try"), JUCE_T("xor"), JUCE_T("and"), JUCE_T("asm"), JUCE_T("not"), 0 }; + + static const juce_wchar* const keywords4Char[] = + { JUCE_T("bool"), JUCE_T("void"), JUCE_T("this"), JUCE_T("true"), JUCE_T("long"), JUCE_T("else"), JUCE_T("char"), + JUCE_T("enum"), JUCE_T("case"), JUCE_T("goto"), JUCE_T("auto"), 0 }; - static const juce_wchar* const keywords3Char[] = - { JUCE_T("for"), JUCE_T("int"), JUCE_T("new"), JUCE_T("try"), JUCE_T("xor"), JUCE_T("and"), JUCE_T("asm"), JUCE_T("not"), 0 }; + static const juce_wchar* const keywords5Char[] = + { JUCE_T("while"), JUCE_T("bitor"), JUCE_T("break"), JUCE_T("catch"), JUCE_T("class"), JUCE_T("compl"), JUCE_T("const"), JUCE_T("false"), + JUCE_T("float"), JUCE_T("short"), JUCE_T("throw"), JUCE_T("union"), JUCE_T("using"), JUCE_T("or_eq"), 0 }; - static const juce_wchar* const keywords4Char[] = - { JUCE_T("bool"), JUCE_T("void"), JUCE_T("this"), JUCE_T("true"), JUCE_T("long"), JUCE_T("else"), JUCE_T("char"), - JUCE_T("enum"), JUCE_T("case"), JUCE_T("goto"), JUCE_T("auto"), 0 }; + static const juce_wchar* const keywords6Char[] = + { JUCE_T("return"), JUCE_T("struct"), JUCE_T("and_eq"), JUCE_T("bitand"), JUCE_T("delete"), JUCE_T("double"), JUCE_T("extern"), + JUCE_T("friend"), JUCE_T("inline"), JUCE_T("not_eq"), JUCE_T("public"), JUCE_T("sizeof"), JUCE_T("static"), JUCE_T("signed"), + JUCE_T("switch"), JUCE_T("typeid"), JUCE_T("wchar_t"), JUCE_T("xor_eq"), 0}; - static const juce_wchar* const keywords5Char[] = - { JUCE_T("while"), JUCE_T("bitor"), JUCE_T("break"), JUCE_T("catch"), JUCE_T("class"), JUCE_T("compl"), JUCE_T("const"), JUCE_T("false"), - JUCE_T("float"), JUCE_T("short"), JUCE_T("throw"), JUCE_T("union"), JUCE_T("using"), JUCE_T("or_eq"), 0 }; + static const juce_wchar* const keywordsOther[] = + { JUCE_T("const_cast"), JUCE_T("continue"), JUCE_T("default"), JUCE_T("explicit"), JUCE_T("mutable"), JUCE_T("namespace"), + JUCE_T("operator"), JUCE_T("private"), JUCE_T("protected"), JUCE_T("register"), JUCE_T("reinterpret_cast"), JUCE_T("static_cast"), + JUCE_T("template"), JUCE_T("typedef"), JUCE_T("typename"), JUCE_T("unsigned"), JUCE_T("virtual"), JUCE_T("volatile"), + JUCE_T("@implementation"), JUCE_T("@interface"), JUCE_T("@end"), JUCE_T("@synthesize"), JUCE_T("@dynamic"), JUCE_T("@public"), + JUCE_T("@private"), JUCE_T("@property"), JUCE_T("@protected"), JUCE_T("@class"), 0 }; - static const juce_wchar* const keywords6Char[] = - { JUCE_T("return"), JUCE_T("struct"), JUCE_T("and_eq"), JUCE_T("bitand"), JUCE_T("delete"), JUCE_T("double"), JUCE_T("extern"), - JUCE_T("friend"), JUCE_T("inline"), JUCE_T("not_eq"), JUCE_T("public"), JUCE_T("sizeof"), JUCE_T("static"), JUCE_T("signed"), - JUCE_T("switch"), JUCE_T("typeid"), JUCE_T("wchar_t"), JUCE_T("xor_eq"), 0}; + const juce_wchar* const* k; - static const juce_wchar* const keywordsOther[] = - { JUCE_T("const_cast"), JUCE_T("continue"), JUCE_T("default"), JUCE_T("explicit"), JUCE_T("mutable"), JUCE_T("namespace"), - JUCE_T("operator"), JUCE_T("private"), JUCE_T("protected"), JUCE_T("register"), JUCE_T("reinterpret_cast"), JUCE_T("static_cast"), - JUCE_T("template"), JUCE_T("typedef"), JUCE_T("typename"), JUCE_T("unsigned"), JUCE_T("virtual"), JUCE_T("volatile"), - JUCE_T("@implementation"), JUCE_T("@interface"), JUCE_T("@end"), JUCE_T("@synthesize"), JUCE_T("@dynamic"), JUCE_T("@public"), - JUCE_T("@private"), JUCE_T("@property"), JUCE_T("@protected"), JUCE_T("@class"), 0 }; + switch (tokenLength) + { + case 2: k = keywords2Char; break; + case 3: k = keywords3Char; break; + case 4: k = keywords4Char; break; + case 5: k = keywords5Char; break; + case 6: k = keywords6Char; break; - const juce_wchar* const* k; + default: + if (tokenLength < 2 || tokenLength > 16) + return false; - switch (tokenLength) - { - case 2: k = keywords2Char; break; - case 3: k = keywords3Char; break; - case 4: k = keywords4Char; break; - case 5: k = keywords5Char; break; - case 6: k = keywords6Char; break; + k = keywordsOther; + break; + } - default: - if (tokenLength < 2 || tokenLength > 16) - return false; + int i = 0; + while (k[i] != 0) + { + if (k[i][0] == token[0] && CharacterFunctions::compare (k[i], token) == 0) + return true; - k = keywordsOther; - break; + ++i; + } + + return false; } - int i = 0; - while (k[i] != 0) + static int parseIdentifier (CodeDocument::Iterator& source) throw() { - if (k[i][0] == token[0] && CharacterFunctions::compare (k[i], token) == 0) - return true; + int tokenLength = 0; + juce_wchar possibleIdentifier [19]; - ++i; - } + while (isIdentifierBody (source.peekNextChar())) + { + const juce_wchar c = source.nextChar(); - return false; -} + if (tokenLength < numElementsInArray (possibleIdentifier) - 1) + possibleIdentifier [tokenLength] = c; -static int parseIdentifier (CodeDocument::Iterator& source) throw() -{ - int tokenLength = 0; - juce_wchar possibleIdentifier [19]; + ++tokenLength; + } - while (isIdentifierBody (source.peekNextChar())) - { - const juce_wchar c = source.nextChar(); + if (tokenLength > 1 && tokenLength <= 16) + { + possibleIdentifier [tokenLength] = 0; - if (tokenLength < numElementsInArray (possibleIdentifier) - 1) - possibleIdentifier [tokenLength] = c; + if (isReservedKeyword (possibleIdentifier, tokenLength)) + return CPlusPlusCodeTokeniser::tokenType_builtInKeyword; + } - ++tokenLength; + return CPlusPlusCodeTokeniser::tokenType_identifier; } - if (tokenLength > 1 && tokenLength <= 16) + static bool skipNumberSuffix (CodeDocument::Iterator& source) { - possibleIdentifier [tokenLength] = 0; + const juce_wchar c = source.peekNextChar(); + if (c == 'l' || c == 'L' || c == 'u' || c == 'U') + source.skip(); - if (isReservedKeyword (possibleIdentifier, tokenLength)) - return CPlusPlusCodeTokeniser::tokenType_builtInKeyword; - } + if (CharacterFunctions::isLetterOrDigit (source.peekNextChar())) + return false; - return CPlusPlusCodeTokeniser::tokenType_identifier; -} + return true; + } -static bool skipNumberSuffix (CodeDocument::Iterator& source) -{ - const juce_wchar c = source.peekNextChar(); - if (c == 'l' || c == 'L' || c == 'u' || c == 'U') - source.skip(); + static bool isHexDigit (const juce_wchar c) throw() + { + return (c >= '0' && c <= '9') + || (c >= 'a' && c <= 'f') + || (c >= 'A' && c <= 'F'); + } - if (CharacterFunctions::isLetterOrDigit (source.peekNextChar())) - return false; + static bool parseHexLiteral (CodeDocument::Iterator& source) throw() + { + if (source.nextChar() != '0') + return false; - return true; -} + juce_wchar c = source.nextChar(); + if (c != 'x' && c != 'X') + return false; -static bool isHexDigit (const juce_wchar c) throw() -{ - return (c >= '0' && c <= '9') - || (c >= 'a' && c <= 'f') - || (c >= 'A' && c <= 'F'); -} + int numDigits = 0; + while (isHexDigit (source.peekNextChar())) + { + ++numDigits; + source.skip(); + } -static bool parseHexLiteral (CodeDocument::Iterator& source) throw() -{ - if (source.nextChar() != '0') - return false; + if (numDigits == 0) + return false; - juce_wchar c = source.nextChar(); - if (c != 'x' && c != 'X') - return false; + return skipNumberSuffix (source); + } - int numDigits = 0; - while (isHexDigit (source.peekNextChar())) + static bool isOctalDigit (const juce_wchar c) throw() { - ++numDigits; - source.skip(); + return c >= '0' && c <= '7'; } - if (numDigits == 0) - return false; - - return skipNumberSuffix (source); -} - -static bool isOctalDigit (const juce_wchar c) throw() -{ - return c >= '0' && c <= '7'; -} - -static bool parseOctalLiteral (CodeDocument::Iterator& source) throw() -{ - if (source.nextChar() != '0') - return false; - - if (! isOctalDigit (source.nextChar())) - return false; + static bool parseOctalLiteral (CodeDocument::Iterator& source) throw() + { + if (source.nextChar() != '0') + return false; - while (isOctalDigit (source.peekNextChar())) - source.skip(); + if (! isOctalDigit (source.nextChar())) + return false; - return skipNumberSuffix (source); -} + while (isOctalDigit (source.peekNextChar())) + source.skip(); -static bool isDecimalDigit (const juce_wchar c) throw() -{ - return c >= '0' && c <= '9'; -} + return skipNumberSuffix (source); + } -static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw() -{ - int numChars = 0; - while (isDecimalDigit (source.peekNextChar())) + static bool isDecimalDigit (const juce_wchar c) throw() { - ++numChars; - source.skip(); + return c >= '0' && c <= '9'; } - if (numChars == 0) - return false; - - return skipNumberSuffix (source); -} + static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw() + { + int numChars = 0; + while (isDecimalDigit (source.peekNextChar())) + { + ++numChars; + source.skip(); + } -static bool parseFloatLiteral (CodeDocument::Iterator& source) throw() -{ - int numDigits = 0; + if (numChars == 0) + return false; - while (isDecimalDigit (source.peekNextChar())) - { - source.skip(); - ++numDigits; + return skipNumberSuffix (source); } - const bool hasPoint = (source.peekNextChar() == '.'); - - if (hasPoint) + static bool parseFloatLiteral (CodeDocument::Iterator& source) throw() { - source.skip(); + int numDigits = 0; while (isDecimalDigit (source.peekNextChar())) { source.skip(); ++numDigits; } - } - if (numDigits == 0) - return false; + const bool hasPoint = (source.peekNextChar() == '.'); - juce_wchar c = source.peekNextChar(); - const bool hasExponent = (c == 'e' || c == 'E'); + if (hasPoint) + { + source.skip(); - if (hasExponent) - { - source.skip(); + while (isDecimalDigit (source.peekNextChar())) + { + source.skip(); + ++numDigits; + } + } - c = source.peekNextChar(); - if (c == '+' || c == '-') - source.skip(); + if (numDigits == 0) + return false; - int numExpDigits = 0; - while (isDecimalDigit (source.peekNextChar())) + juce_wchar c = source.peekNextChar(); + const bool hasExponent = (c == 'e' || c == 'E'); + + if (hasExponent) { source.skip(); - ++numExpDigits; - } - if (numExpDigits == 0) - return false; - } + c = source.peekNextChar(); + if (c == '+' || c == '-') + source.skip(); - c = source.peekNextChar(); - if (c == 'f' || c == 'F') - source.skip(); - else if (! (hasExponent || hasPoint)) - return false; + int numExpDigits = 0; + while (isDecimalDigit (source.peekNextChar())) + { + source.skip(); + ++numExpDigits; + } - return true; -} + if (numExpDigits == 0) + return false; + } -static int parseNumber (CodeDocument::Iterator& source) -{ - const CodeDocument::Iterator original (source); + c = source.peekNextChar(); + if (c == 'f' || c == 'F') + source.skip(); + else if (! (hasExponent || hasPoint)) + return false; - if (parseFloatLiteral (source)) - return CPlusPlusCodeTokeniser::tokenType_floatLiteral; + return true; + } + + static int parseNumber (CodeDocument::Iterator& source) + { + const CodeDocument::Iterator original (source); - source = original; + if (parseFloatLiteral (source)) + return CPlusPlusCodeTokeniser::tokenType_floatLiteral; - if (parseHexLiteral (source)) - return CPlusPlusCodeTokeniser::tokenType_integerLiteral; + source = original; - source = original; + if (parseHexLiteral (source)) + return CPlusPlusCodeTokeniser::tokenType_integerLiteral; - if (parseOctalLiteral (source)) - return CPlusPlusCodeTokeniser::tokenType_integerLiteral; + source = original; - source = original; + if (parseOctalLiteral (source)) + return CPlusPlusCodeTokeniser::tokenType_integerLiteral; - if (parseDecimalLiteral (source)) - return CPlusPlusCodeTokeniser::tokenType_integerLiteral; + source = original; - source = original; - source.skip(); + if (parseDecimalLiteral (source)) + return CPlusPlusCodeTokeniser::tokenType_integerLiteral; - return CPlusPlusCodeTokeniser::tokenType_error; -} + source = original; + source.skip(); -static void skipQuotedString (CodeDocument::Iterator& source) throw() -{ - const juce_wchar quote = source.nextChar(); + return CPlusPlusCodeTokeniser::tokenType_error; + } - for (;;) + static void skipQuotedString (CodeDocument::Iterator& source) throw() { - const juce_wchar c = source.nextChar(); + const juce_wchar quote = source.nextChar(); - if (c == quote || c == 0) - break; + for (;;) + { + const juce_wchar c = source.nextChar(); - if (c == '\\') - source.skip(); - } -} + if (c == quote || c == 0) + break; -static void skipComment (CodeDocument::Iterator& source) throw() -{ - bool lastWasStar = false; + if (c == '\\') + source.skip(); + } + } - for (;;) + static void skipComment (CodeDocument::Iterator& source) throw() { - const juce_wchar c = source.nextChar(); + bool lastWasStar = false; - if (c == 0 || (c == '/' && lastWasStar)) - break; + for (;;) + { + const juce_wchar c = source.nextChar(); - lastWasStar = (c == '*'); - } -} + if (c == 0 || (c == '/' && lastWasStar)) + break; + lastWasStar = (c == '*'); + } + } } int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source) @@ -70124,7 +70136,7 @@ const Point MouseEvent::getMouseDownScreenPosition() const return eventComponent->relativePositionToGlobal (mouseDownPos); } -static int doubleClickTimeOutMs = 400; +int MouseEvent::doubleClickTimeOutMs = 400; void MouseEvent::setDoubleClickTimeout (const int newTime) throw() { @@ -73010,9 +73022,6 @@ END_JUCE_NAMESPACE /*** Start of inlined file: juce_ColourSelector.cpp ***/ BEGIN_JUCE_NAMESPACE -static const int swatchesPerRow = 8; -static const int swatchHeight = 22; - class ColourComponentSlider : public Slider { public: @@ -73482,6 +73491,9 @@ void ColourSelector::paint (Graphics& g) void ColourSelector::resized() { + const int swatchesPerRow = 8; + const int swatchHeight = 22; + const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3; const int numSwatches = getNumSwatches(); @@ -74429,8 +74441,8 @@ int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const return x; } -static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 }; -static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 }; +const uint8 MidiKeyboardComponent::whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 }; +const uint8 MidiKeyboardComponent::blackNotes[] = { 1, 3, 6, 8, 10 }; int MidiKeyboardComponent::xyToNote (const Point& pos, float& mousePositionVelocity) { @@ -80332,8 +80344,6 @@ END_JUCE_NAMESPACE /*** Start of inlined file: juce_Graphics.cpp ***/ BEGIN_JUCE_NAMESPACE -static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality; - template static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h) { @@ -80375,7 +80385,7 @@ void Graphics::resetToDefaultState() saveStateIfPending(); context->setFill (FillType()); context->setFont (Font()); - context->setInterpolationQuality (defaultQuality); + context->setInterpolationQuality (Graphics::mediumResamplingQuality); } bool Graphics::isVectorDevice() const @@ -93633,8 +93643,6 @@ END_JUCE_NAMESPACE /*** Start of inlined file: juce_Image.cpp ***/ BEGIN_JUCE_NAMESPACE -static const int fullAlphaThreshold = 253; - Image::SharedImage::SharedImage (const PixelFormat format_, const int width_, const int height_) : format (format_), width (width_), height (height_) { @@ -236230,36 +236238,6 @@ const String SystemStats::getCpuVendor() } #endif -struct CPUFlags -{ - bool hasMMX : 1; - bool hasSSE : 1; - bool hasSSE2 : 1; - bool has3DNow : 1; -}; - -static CPUFlags cpuFlags; - -bool SystemStats::hasMMX() -{ - return cpuFlags.hasMMX; -} - -bool SystemStats::hasSSE() -{ - return cpuFlags.hasSSE; -} - -bool SystemStats::hasSSE2() -{ - return cpuFlags.hasSSE2; -} - -bool SystemStats::has3DNow() -{ - return cpuFlags.has3DNow; -} - void SystemStats::initialiseStats() { juce_initialiseThreadEvents(); @@ -236273,6 +236251,12 @@ void SystemStats::initialiseStats() cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0; #endif + { + SYSTEM_INFO systemInfo; + GetSystemInfo (&systemInfo); + cpuFlags.numCpus = systemInfo.dwNumberOfProcessors; + } + LARGE_INTEGER f; QueryPerformanceFrequency (&f); hiResTicksPerSecond = f.QuadPart; @@ -236280,12 +236264,9 @@ void SystemStats::initialiseStats() String s (SystemStats::getJUCEVersion()); -#if JUCE_DEBUG const MMRESULT res = timeBeginPeriod (1); + (void) res; jassert (res == TIMERR_NOERROR); -#else - timeBeginPeriod (1); -#endif #if JUCE_DEBUG && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); @@ -236358,14 +236339,6 @@ int SystemStats::getMemorySizeInMegabytes() return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1; } -int SystemStats::getNumCpus() -{ - SYSTEM_INFO systemInfo; - GetSystemInfo (&systemInfo); - - return systemInfo.dwNumberOfProcessors; -} - uint32 juce_millisecondsSinceStartup() throw() { return (uint32) GetTickCount(); @@ -237992,8 +237965,8 @@ void juce_getInternetFileHeaders (void* handle, StringPairArray& headers) for (int i = 0; i < headersArray.size(); ++i) { const String& header = headersArray[i]; - const String key (header.upToFirstOccurrenceOf ("; ", false, false)); - const String value (header.fromFirstOccurrenceOf ("; ", false, false)); + const String key (header.upToFirstOccurrenceOf (": ", false, false)); + const String value (header.fromFirstOccurrenceOf (": ", false, false)); const String previousValue (headers [key]); headers.set (key, previousValue.isEmpty() ? value : (previousValue + "," + value)); @@ -253811,8 +253784,8 @@ void juce_getInternetFileHeaders (void* handle, StringPairArray& headers) for (int i = 0; i < s->headerLines.size(); ++i) { const String& headersEntry = s->headerLines[i]; - const String key (headersEntry.upToFirstOccurrenceOf ("; ", false, false)); - const String value (headersEntry.fromFirstOccurrenceOf ("; ", false, false)); + const String key (headersEntry.upToFirstOccurrenceOf (": ", false, false)); + const String value (headersEntry.fromFirstOccurrenceOf (": ", false, false)); const String previousValue (headers [key]); headers.set (key, previousValue.isEmpty() ? value : (previousValue + "," + value)); } @@ -253872,11 +253845,6 @@ static const String juce_getCpuInfo (const char* const key) return String::empty; } -bool SystemStats::hasMMX() { return juce_getCpuInfo ("flags").contains ("mmx"); } -bool SystemStats::hasSSE() { return juce_getCpuInfo ("flags").contains ("sse"); } -bool SystemStats::hasSSE2() { return juce_getCpuInfo ("flags").contains ("sse2"); } -bool SystemStats::has3DNow() { return juce_getCpuInfo ("flags").contains ("3dnow"); } - const String SystemStats::getCpuVendor() { return juce_getCpuInfo ("vendor_id"); @@ -253902,11 +253870,6 @@ int SystemStats::getPageSize() return sysconf (_SC_PAGESIZE); } -int SystemStats::getNumCpus() -{ - return juce_getCpuInfo ("processor").getIntValue() + 1; -} - const String SystemStats::getLogonName() { const char* user = getenv ("USER"); @@ -253928,6 +253891,13 @@ const String SystemStats::getFullUserName() void SystemStats::initialiseStats() { + const String flags (juce_getCpuInfo ("flags")); + cpuFlags.hasMMX = flags.contains ("mmx"); + cpuFlags.hasSSE = flags.contains ("sse"); + cpuFlags.hasSSE2 = flags.contains ("sse2"); + cpuFlags.has3DNow = flags.contains ("3dnow"); + + cpuFlags.numCpus = juce_getCpuInfo ("processor").getIntValue() + 1; } void PlatformUtilities::fpuReset() @@ -254683,11 +254653,11 @@ namespace LinuxErrorHandling static int ioErrorHandler (Display* display) { DBG ("ERROR: connection to X server broken.. terminating."); - errorOccurred = true; if (JUCEApplication::getInstance() != 0) MessageManager::getInstance()->stopDispatchLoop(); + errorOccurred = true; return 0; } @@ -261266,16 +261236,6 @@ namespace SystemStatsHelpers return cpu; } - struct CPUFlags - { - bool hasMMX : 1; - bool hasSSE : 1; - bool hasSSE2 : 1; - bool has3DNow : 1; - }; - - static CPUFlags cpuFlags; - #endif } @@ -261288,16 +261248,15 @@ void SystemStats::initialiseStats() { initialised = true; -#if JUCE_MAC - // extremely annoying: adding this line stops the apple menu items from working. Of - // course, not adding it means that carbon windows (e.g. in plugins) won't get - // any events. - //NSApplicationLoad(); - [NSApplication sharedApplication]; -#endif + #if JUCE_MAC + // extremely annoying: adding this line stops the apple menu items from working. Of + // course, not adding it means that carbon windows (e.g. in plugins) won't get + // any events. + //NSApplicationLoad(); + [NSApplication sharedApplication]; + #endif -#if JUCE_INTEL - { + #if JUCE_INTEL unsigned int familyModel, extFeatures; const unsigned int features = getCPUIDWord (familyModel, extFeatures); @@ -261305,8 +261264,18 @@ void SystemStats::initialiseStats() cpuFlags.hasSSE = ((features & (1 << 25)) != 0); cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0); cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0); - } -#endif + #else + cpuFlags.hasMMX = false; + cpuFlags.hasSSE = false; + cpuFlags.hasSSE2 = false; + cpuFlags.has3DNow = false; + #endif + + #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) + cpuFlags.numCpus = (int) [[NSProcessInfo processInfo] activeProcessorCount]; + #else + cpuFlags.numCpus = (int) MPProcessors(); + #endif mach_timebase_info_data_t timebase; (void) mach_timebase_info (&timebase); @@ -261351,42 +261320,6 @@ int SystemStats::getMemorySizeInMegabytes() return (int) (mem / (1024 * 1024)); } -bool SystemStats::hasMMX() -{ -#if JUCE_INTEL - return SystemStatsHelpers::cpuFlags.hasMMX; -#else - return false; -#endif -} - -bool SystemStats::hasSSE() -{ -#if JUCE_INTEL - return SystemStatsHelpers::cpuFlags.hasSSE; -#else - return false; -#endif -} - -bool SystemStats::hasSSE2() -{ -#if JUCE_INTEL - return SystemStatsHelpers::cpuFlags.hasSSE2; -#else - return false; -#endif -} - -bool SystemStats::has3DNow() -{ -#if JUCE_INTEL - return SystemStatsHelpers::cpuFlags.has3DNow; -#else - return false; -#endif -} - const String SystemStats::getCpuVendor() { #if JUCE_INTEL @@ -261412,15 +261345,6 @@ int SystemStats::getCpuSpeedInMegaherz() return (int) (speedHz / 1000000); } -int SystemStats::getNumCpus() -{ -#if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) - return (int) [[NSProcessInfo processInfo] activeProcessorCount]; -#else - return MPProcessors(); -#endif -} - const String SystemStats::getLogonName() { return nsStringToJuce (NSUserName()); diff --git a/juce_amalgamated.h b/juce_amalgamated.h index 92724e079b..c230a1a273 100644 --- a/juce_amalgamated.h +++ b/juce_amalgamated.h @@ -64,7 +64,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 16 +#define JUCE_BUILDNUMBER 17 /** Current Juce version number. @@ -2701,6 +2701,9 @@ protected: @see setCurrentLogger */ virtual void logMessage (const String& message) = 0; + +private: + static Logger* currentLogger; }; #endif // __JUCE_LOGGER_JUCEHEADER__ @@ -5027,6 +5030,7 @@ private: HeapBlock data; size_t size; + static const char* const encodingTable; }; #endif // __JUCE_MEMORYBLOCK_JUCEHEADER__ @@ -14530,20 +14534,20 @@ public: static const String getCpuVendor(); /** Checks whether Intel MMX instructions are available. */ - static bool hasMMX(); + static bool hasMMX() throw() { return cpuFlags.hasMMX; } /** Checks whether Intel SSE instructions are available. */ - static bool hasSSE(); + static bool hasSSE() throw() { return cpuFlags.hasSSE; } /** Checks whether Intel SSE2 instructions are available. */ - static bool hasSSE2(); + static bool hasSSE2() throw() { return cpuFlags.hasSSE2; } /** Checks whether AMD 3DNOW instructions are available. */ - static bool has3DNow(); + static bool has3DNow() throw() { return cpuFlags.has3DNow; } /** Returns the number of CPUs. */ - static int getNumCpus(); + static int getNumCpus() throw() { return cpuFlags.numCpus; } /** Finds out how much RAM is in the machine. @@ -14590,6 +14594,17 @@ public: static void initialiseStats(); private: + struct CPUFlags + { + int numCpus; + bool hasMMX : 1; + bool hasSSE : 1; + bool hasSSE2 : 1; + bool has3DNow : 1; + }; + + static CPUFlags cpuFlags; + SystemStats(); SystemStats (const SystemStats&); SystemStats& operator= (const SystemStats&); @@ -14973,6 +14988,9 @@ public: protected: BigInteger part1, part2; + +private: + static const BigInteger findBestCommonDivisor (const BigInteger& p, const BigInteger& q); }; #endif // __JUCE_RSAKEY_JUCEHEADER__ @@ -19419,6 +19437,7 @@ private: const Time mouseDownTime; const int numberOfClicks; const bool wasMovedSinceMouseDown; + static int doubleClickTimeOutMs; MouseEvent& operator= (const MouseEvent&); }; @@ -56235,6 +56254,9 @@ private: int keyMappingOctave; int octaveNumForMiddleC; + static const uint8 whiteNotes[]; + static const uint8 blackNotes[]; + void getKeyPos (int midiNoteNumber, int& x, int& w) const; int xyToNote (const Point& pos, float& mousePositionVelocity); int remappedXYToNote (const Point& pos, float& mousePositionVelocity) const; diff --git a/src/core/juce_StandardHeader.h b/src/core/juce_StandardHeader.h index 66d7e22453..be2d180d41 100644 --- a/src/core/juce_StandardHeader.h +++ b/src/core/juce_StandardHeader.h @@ -33,7 +33,7 @@ */ #define JUCE_MAJOR_VERSION 1 #define JUCE_MINOR_VERSION 52 -#define JUCE_BUILDNUMBER 16 +#define JUCE_BUILDNUMBER 17 /** Current Juce version number. diff --git a/src/native/linux/juce_linux_Messaging.cpp b/src/native/linux/juce_linux_Messaging.cpp index 4953c80a74..f5420d9d98 100644 --- a/src/native/linux/juce_linux_Messaging.cpp +++ b/src/native/linux/juce_linux_Messaging.cpp @@ -254,11 +254,11 @@ namespace LinuxErrorHandling static int ioErrorHandler (Display* display) { DBG ("ERROR: connection to X server broken.. terminating."); - errorOccurred = true; if (JUCEApplication::getInstance() != 0) MessageManager::getInstance()->stopDispatchLoop(); + errorOccurred = true; return 0; } diff --git a/src/native/linux/juce_linux_Network.cpp b/src/native/linux/juce_linux_Network.cpp index e20af264a9..955f03e307 100644 --- a/src/native/linux/juce_linux_Network.cpp +++ b/src/native/linux/juce_linux_Network.cpp @@ -463,8 +463,8 @@ void juce_getInternetFileHeaders (void* handle, StringPairArray& headers) for (int i = 0; i < s->headerLines.size(); ++i) { const String& headersEntry = s->headerLines[i]; - const String key (headersEntry.upToFirstOccurrenceOf ("; ", false, false)); - const String value (headersEntry.fromFirstOccurrenceOf ("; ", false, false)); + const String key (headersEntry.upToFirstOccurrenceOf (": ", false, false)); + const String value (headersEntry.fromFirstOccurrenceOf (": ", false, false)); const String previousValue (headers [key]); headers.set (key, previousValue.isEmpty() ? value : (previousValue + "," + value)); } diff --git a/src/native/windows/juce_win32_Network.cpp b/src/native/windows/juce_win32_Network.cpp index 0c6e1ca31b..7b90a943a9 100644 --- a/src/native/windows/juce_win32_Network.cpp +++ b/src/native/windows/juce_win32_Network.cpp @@ -298,8 +298,8 @@ void juce_getInternetFileHeaders (void* handle, StringPairArray& headers) for (int i = 0; i < headersArray.size(); ++i) { const String& header = headersArray[i]; - const String key (header.upToFirstOccurrenceOf ("; ", false, false)); - const String value (header.fromFirstOccurrenceOf ("; ", false, false)); + const String key (header.upToFirstOccurrenceOf (": ", false, false)); + const String value (header.fromFirstOccurrenceOf (": ", false, false)); const String previousValue (headers [key]); headers.set (key, previousValue.isEmpty() ? value : (previousValue + "," + value));