diff --git a/src/audio/audio_file_formats/juce_AudioFormat.cpp b/src/audio/audio_file_formats/juce_AudioFormat.cpp index e801dc14a1..88a818cb87 100644 --- a/src/audio/audio_file_formats/juce_AudioFormat.cpp +++ b/src/audio/audio_file_formats/juce_AudioFormat.cpp @@ -297,7 +297,7 @@ int64 AudioFormatReader::searchForLevel (int64 startSample, if (usesFloatingPointData) { - const float sample1 = fabsf (((float*) tempBuffer[0]) [index]); + const float sample1 = std::abs (((float*) tempBuffer[0]) [index]); if (sample1 >= magnitudeRangeMinimum && sample1 <= magnitudeRangeMaximum) @@ -306,7 +306,7 @@ int64 AudioFormatReader::searchForLevel (int64 startSample, } else if (numChannels > 1) { - const float sample2 = fabsf (((float*) tempBuffer[1]) [index]); + const float sample2 = std::abs (((float*) tempBuffer[1]) [index]); matches = (sample2 >= magnitudeRangeMinimum && sample2 <= magnitudeRangeMaximum); diff --git a/src/audio/audio_sources/juce_ResamplingAudioSource.cpp b/src/audio/audio_sources/juce_ResamplingAudioSource.cpp index e1c657e42f..06d2e9d69b 100644 --- a/src/audio/audio_sources/juce_ResamplingAudioSource.cpp +++ b/src/audio/audio_sources/juce_ResamplingAudioSource.cpp @@ -205,14 +205,14 @@ void ResamplingAudioSource::createLowPass (const double frequencyRatio) const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate)); const double nSquared = n * n; - const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared); + const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); setFilterCoefficients (c1, c1 * 2.0f, c1, 1.0, c1 * 2.0 * (1.0 - nSquared), - c1 * (1.0 - sqrt (2.0) * n + nSquared)); + c1 * (1.0 - std::sqrt (2.0) * n + nSquared)); } void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6) diff --git a/src/audio/audio_sources/juce_ToneGeneratorAudioSource.cpp b/src/audio/audio_sources/juce_ToneGeneratorAudioSource.cpp index d254ecfc3c..abefbb9c71 100644 --- a/src/audio/audio_sources/juce_ToneGeneratorAudioSource.cpp +++ b/src/audio/audio_sources/juce_ToneGeneratorAudioSource.cpp @@ -76,7 +76,7 @@ void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& for (int i = 0; i < info.numSamples; ++i) { - const float sample = amplitude * (float) sin (currentPhase); + const float sample = amplitude * (float) std::sin (currentPhase); currentPhase += phasePerSample; for (int j = info.buffer->getNumChannels(); --j >= 0;) diff --git a/src/audio/devices/juce_AudioDeviceManager.cpp b/src/audio/devices/juce_AudioDeviceManager.cpp index 7975319d8d..14fd5b39c6 100644 --- a/src/audio/devices/juce_AudioDeviceManager.cpp +++ b/src/audio/devices/juce_AudioDeviceManager.cpp @@ -645,7 +645,7 @@ void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelDat float s = 0; for (int i = 0; i < numInputChannels; ++i) - s += fabsf (inputChannelData[i][j]); + s += std::abs (inputChannelData[i][j]); s /= numInputChannels; @@ -946,7 +946,7 @@ void AudioDeviceManager::playTestSound() const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency); for (int i = 0; i < soundLength; ++i) - samples[i] = amplitude * (float) sin (i * phasePerSample); + samples[i] = amplitude * (float) std::sin (i * phasePerSample); newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f); newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f); diff --git a/src/audio/dsp/juce_AudioSampleBuffer.cpp b/src/audio/dsp/juce_AudioSampleBuffer.cpp index 47fdb74d59..5976ba63d1 100644 --- a/src/audio/dsp/juce_AudioSampleBuffer.cpp +++ b/src/audio/dsp/juce_AudioSampleBuffer.cpp @@ -566,7 +566,7 @@ float AudioSampleBuffer::getRMSLevel (const int channel, sum += sample * sample; } - return (float) sqrt (sum / numSamples); + return (float) std::sqrt (sum / numSamples); } void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader, diff --git a/src/audio/dsp/juce_IIRFilter.cpp b/src/audio/dsp/juce_IIRFilter.cpp index 18fb9455a1..f8dcc4cd87 100644 --- a/src/audio/dsp/juce_IIRFilter.cpp +++ b/src/audio/dsp/juce_IIRFilter.cpp @@ -122,14 +122,14 @@ void IIRFilter::makeLowPass (const double sampleRate, const double n = 1.0 / tan (double_Pi * frequency / sampleRate); const double nSquared = n * n; - const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared); + const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); setCoefficients (c1, c1 * 2.0f, c1, 1.0, c1 * 2.0 * (1.0 - nSquared), - c1 * (1.0 - sqrt (2.0) * n + nSquared)); + c1 * (1.0 - std::sqrt (2.0) * n + nSquared)); } void IIRFilter::makeHighPass (const double sampleRate, @@ -137,14 +137,14 @@ void IIRFilter::makeHighPass (const double sampleRate, { const double n = tan (double_Pi * frequency / sampleRate); const double nSquared = n * n; - const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared); + const double c1 = 1.0 / (1.0 + std::sqrt (2.0) * n + nSquared); setCoefficients (c1, c1 * -2.0f, c1, 1.0, c1 * 2.0 * (nSquared - 1.0), - c1 * (1.0 - sqrt (2.0) * n + nSquared)); + c1 * (1.0 - std::sqrt (2.0) * n + nSquared)); } void IIRFilter::makeLowShelf (const double sampleRate, @@ -159,8 +159,8 @@ void IIRFilter::makeLowShelf (const double sampleRate, const double aminus1 = A - 1.0; const double aplus1 = A + 1.0; const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate; - const double coso = cos (omega); - const double beta = sin (omega) * sqrt (A) / Q; + const double coso = std::cos (omega); + const double beta = std::sin (omega) * std::sqrt (A) / Q; const double aminus1TimesCoso = aminus1 * coso; setCoefficients (A * (aplus1 - aminus1TimesCoso + beta), @@ -183,8 +183,8 @@ void IIRFilter::makeHighShelf (const double sampleRate, const double aminus1 = A - 1.0; const double aplus1 = A + 1.0; const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate; - const double coso = cos (omega); - const double beta = sin (omega) * sqrt (A) / Q; + const double coso = std::cos (omega); + const double beta = std::sin (omega) * std::sqrt (A) / Q; const double aminus1TimesCoso = aminus1 * coso; setCoefficients (A * (aplus1 + aminus1TimesCoso + beta), @@ -205,8 +205,8 @@ void IIRFilter::makeBandPass (const double sampleRate, const double A = jmax (0.0f, gainFactor); const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate; - const double alpha = 0.5 * sin (omega) / Q; - const double c2 = -2.0 * cos (omega); + const double alpha = 0.5 * std::sin (omega) / Q; + const double c2 = -2.0 * std::cos (omega); const double alphaTimesA = alpha * A; const double alphaOverA = alpha / A; diff --git a/src/containers/juce_ValueTree.cpp b/src/containers/juce_ValueTree.cpp index 814773d79d..366dbeddce 100644 --- a/src/containers/juce_ValueTree.cpp +++ b/src/containers/juce_ValueTree.cpp @@ -804,7 +804,7 @@ void ValueTree::writeToStream (OutputStream& output) ValueTree ValueTree::readFromStream (InputStream& input) { - String type (input.readString()); + const String type (input.readString()); if (type.isEmpty()) return ValueTree::invalid; diff --git a/src/core/juce_Logger.h b/src/core/juce_Logger.h index f855ce5133..00aae7df8f 100644 --- a/src/core/juce_Logger.h +++ b/src/core/juce_Logger.h @@ -76,7 +76,7 @@ public: This can be called directly, or by using the DBG() macro in juce_PlatformDefs.h (which will avoid calling the method in non-debug builds). */ - static void JUCE_CALLTYPE outputDebugString (const String& text) throw(); + static void JUCE_CALLTYPE outputDebugString (const String& text); protected: diff --git a/src/core/juce_SystemStats.cpp b/src/core/juce_SystemStats.cpp index b9aecca124..bd77fa3bf2 100644 --- a/src/core/juce_SystemStats.cpp +++ b/src/core/juce_SystemStats.cpp @@ -40,7 +40,7 @@ BEGIN_JUCE_NAMESPACE //============================================================================== -const String SystemStats::getJUCEVersion() throw() +const String SystemStats::getJUCEVersion() { return "JUCE v" + String (JUCE_MAJOR_VERSION) + "." + String (JUCE_MINOR_VERSION) diff --git a/src/core/juce_SystemStats.h b/src/core/juce_SystemStats.h index c8481bb6b9..bf2df96541 100644 --- a/src/core/juce_SystemStats.h +++ b/src/core/juce_SystemStats.h @@ -43,7 +43,7 @@ public: See also the JUCE_VERSION, JUCE_MAJOR_VERSION and JUCE_MINOR_VERSION macros. */ - static const String getJUCEVersion() throw(); + static const String getJUCEVersion(); //============================================================================== /** The set of possible results of the getOperatingSystemType() method. @@ -75,18 +75,18 @@ public: @returns one of the values from the OperatingSystemType enum. @see getOperatingSystemName */ - static OperatingSystemType getOperatingSystemType() throw(); + static OperatingSystemType getOperatingSystemType(); /** Returns the name of the type of operating system we're running on. @returns a string describing the OS type. @see getOperatingSystemType */ - static const String getOperatingSystemName() throw(); + static const String getOperatingSystemName(); /** Returns true if the OS is 64-bit, or false for a 32-bit OS. */ - static bool isOperatingSystem64Bit() throw(); + static bool isOperatingSystem64Bit(); //============================================================================== /** Returns the current user's name, if available. @@ -108,39 +108,29 @@ public: @returns the speed in megahertz, e.g. 1500, 2500, 32000 (depending on what year you're reading this...) */ - static int getCpuSpeedInMegaherz() throw(); + static int getCpuSpeedInMegaherz(); /** Returns a string to indicate the CPU vendor. Might not be known on some systems. */ - static const String getCpuVendor() throw(); + static const String getCpuVendor(); /** Checks whether Intel MMX instructions are available. */ - static bool hasMMX() throw(); + static bool hasMMX(); /** Checks whether Intel SSE instructions are available. */ - static bool hasSSE() throw(); + static bool hasSSE(); /** Checks whether Intel SSE2 instructions are available. */ - static bool hasSSE2() throw(); + static bool hasSSE2(); /** Checks whether AMD 3DNOW instructions are available. */ - static bool has3DNow() throw(); + static bool has3DNow(); /** Returns the number of CPUs. */ - static int getNumCpus() throw(); - - /** Returns a clock-cycle tick counter, if available. - - If the machine can do it, this will return a tick-count - where each tick is one cpu clock cycle - used for profiling - code. - - @returns the tick count, or zero if not available. - */ - static int64 getClockCycleCounter() throw(); + static int getNumCpus(); //============================================================================== /** Finds out how much RAM is in the machine. @@ -148,13 +138,13 @@ public: @returns the approximate number of megabytes of memory, or zero if something goes wrong when finding out. */ - static int getMemorySizeInMegabytes() throw(); + static int getMemorySizeInMegabytes(); /** Returns the system page-size. This is only used by programmers with beards. */ - static int getPageSize() throw(); + static int getPageSize(); //============================================================================== /** Returns a list of MAC addresses found on this machine. @@ -188,7 +178,7 @@ public: //============================================================================== // not-for-public-use platform-specific method gets called at startup to initialise things. - static void initialiseStats() throw(); + static void initialiseStats(); private: SystemStats(); diff --git a/src/core/juce_Time.h b/src/core/juce_Time.h index 98b95bfd28..e0529dd597 100644 --- a/src/core/juce_Time.h +++ b/src/core/juce_Time.h @@ -281,7 +281,7 @@ public: @returns true if this succeeds, although depending on the system, the application might not have sufficient privileges to do this. */ - bool setSystemTimeToThisTime() const throw(); + bool setSystemTimeToThisTime() const; //============================================================================== /** Returns the name of a day of the week. diff --git a/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.cpp b/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.cpp index 7e6c94dd27..061d5e04af 100644 --- a/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.cpp +++ b/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.cpp @@ -51,39 +51,70 @@ static bool isIdentifierStart (const juce_wchar c) throw() static bool isIdentifierBody (const juce_wchar c) throw() { - return CharacterFunctions::isLetter (c) - || CharacterFunctions::isDigit (c) + return CharacterFunctions::isLetterOrDigit (c) || c == '_' || c == '@'; } -static int parseIdentifier (CodeDocument::Iterator& source) throw() +static bool isReservedKeyword (const juce_wchar* const token, const int tokenLength) throw() { - static const juce_wchar* keywords2Char[] = - { T("if"), T("do"), T("or"), 0 }; + static const juce_wchar* const keywords2Char[] = + { T("if"), T("do"), T("or"), T("id"), 0 }; - static const juce_wchar* keywords3Char[] = + static const juce_wchar* const keywords3Char[] = { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 }; - static const juce_wchar* keywords4Char[] = + static const juce_wchar* const keywords4Char[] = { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"), T("enum"), T("case"), T("goto"), T("auto"), 0 }; - static const juce_wchar* keywords5Char[] = + static const juce_wchar* const keywords5Char[] = { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"), T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 }; - static const juce_wchar* keywords6Char[] = + static const juce_wchar* const keywords6Char[] = { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"), T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"), T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0}; - static const juce_wchar* keywordsOther[] = + static const juce_wchar* const keywordsOther[] = { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"), T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"), T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"), T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"), T("@private"), T("@property"), T("@protected"), T("@class"), 0 }; + const juce_wchar* const* k; + + 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; + + default: + if (tokenLength < 2 || tokenLength > 16) + return false; + + k = keywordsOther; + break; + } + + int i = 0; + while (k[i] != 0) + { + if (k[i][0] == token[0] && CharacterFunctions::compare (k[i], token) == 0) + return true; + + ++i; + } + + return false; +} + +static int parseIdentifier (CodeDocument::Iterator& source) throw() +{ int tokenLength = 0; juce_wchar possibleIdentifier [19]; @@ -100,26 +131,9 @@ static int parseIdentifier (CodeDocument::Iterator& source) throw() if (tokenLength > 1 && tokenLength <= 16) { possibleIdentifier [tokenLength] = 0; - const juce_wchar** k; - - 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; - default: k = keywordsOther; break; - } - - int i = 0; - while (k[i] != 0) - { - if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0) - return CPlusPlusCodeTokeniser::tokenType_builtInKeyword; - ++i; - } + if (isReservedKeyword (possibleIdentifier, tokenLength)) + return CPlusPlusCodeTokeniser::tokenType_builtInKeyword; } return CPlusPlusCodeTokeniser::tokenType_identifier; @@ -551,25 +565,28 @@ int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source) break; } - //jassert (result != tokenType_unknown); return result; } const StringArray CPlusPlusCodeTokeniser::getTokenTypes() { - StringArray s; - s.add ("Error"); - s.add ("Comment"); - s.add ("C++ keyword"); - s.add ("Identifier"); - s.add ("Integer literal"); - s.add ("Float literal"); - s.add ("String literal"); - s.add ("Operator"); - s.add ("Bracket"); - s.add ("Punctuation"); - s.add ("Preprocessor line"); - return s; + const char* const types[] = + { + "Error", + "Comment", + "C++ keyword", + "Identifier", + "Integer literal", + "Float literal", + "String literal", + "Operator", + "Bracket", + "Punctuation", + "Preprocessor line", + 0 + }; + + return StringArray (types); } const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType) @@ -595,5 +612,9 @@ const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType) return Colours::black; } +bool CPlusPlusCodeTokeniser::isReservedKeyword (const String& token) throw() +{ + return CppTokeniser::isReservedKeyword (token, token.length()); +} END_JUCE_NAMESPACE diff --git a/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.h b/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.h index ec691795ef..b295215518 100644 --- a/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.h +++ b/src/gui/components/code_editor/juce_CPlusPlusCodeTokeniser.h @@ -63,6 +63,9 @@ public: const StringArray getTokenTypes(); const Colour getDefaultColour (int tokenType); + /** This is a handy method for checking whether a string is a c++ reserved keyword. */ + static bool isReservedKeyword (const String& token) throw(); + //============================================================================== juce_UseDebuggingNewOperator }; diff --git a/src/gui/components/controls/juce_Slider.cpp b/src/gui/components/controls/juce_Slider.cpp index 0e03980b3c..42acd11353 100644 --- a/src/gui/components/controls/juce_Slider.cpp +++ b/src/gui/components/controls/juce_Slider.cpp @@ -742,7 +742,7 @@ void Slider::buttonClicked (Button* button) double Slider::constrainedValue (double value) const { if (interval > 0) - value = minimum + interval * floor ((value - minimum) / interval + 0.5); + value = minimum + interval * std::floor ((value - minimum) / interval + 0.5); if (value <= minimum || maximum <= minimum) value = minimum; @@ -1053,9 +1053,9 @@ void Slider::mouseDown (const MouseEvent& e) { const float mousePos = (float) (isVertical() ? e.y : e.x); - const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos); - const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos); - const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos); + const float normalPosDistance = std::abs (getLinearSliderPos (currentValue.getValue()) - mousePos); + const float minPosDistance = std::abs (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos); + const float maxPosDistance = std::abs (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos); if (style == TwoValueHorizontal || style == TwoValueVertical) { @@ -1187,9 +1187,9 @@ void Slider::modifierKeysChanged (const ModifierKeys& modifiers) static double smallestAngleBetween (double a1, double a2) { - return jmin (fabs (a1 - a2), - fabs (a1 + double_Pi * 2.0 - a2), - fabs (a2 + double_Pi * 2.0 - a1)); + return jmin (std::abs (a1 - a2), + std::abs (a1 + double_Pi * 2.0 - a2), + std::abs (a2 + double_Pi * 2.0 - a1)); } void Slider::mouseDrag (const MouseEvent& e) @@ -1205,13 +1205,13 @@ void Slider::mouseDrag (const MouseEvent& e) if (dx * dx + dy * dy > 25) { - double angle = atan2 ((double) dx, (double) -dy); + double angle = std::atan2 ((double) dx, (double) -dy); while (angle < 0.0) angle += double_Pi * 2.0; if (rotaryStop && ! e.mouseWasClicked()) { - if (fabs (angle - lastAngle) > double_Pi) + if (std::abs (angle - lastAngle) > double_Pi) { if (angle >= lastAngle) angle -= double_Pi * 2.0; @@ -1314,7 +1314,7 @@ void Slider::mouseDrag (const MouseEvent& e) if (speed != 0) { speed = 0.2 * velocityModeSensitivity - * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset + * (1.0 + std::sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset + jmax (0.0, (double) (speed - velocityModeThreshold)) / maxSpeed)))); @@ -1401,7 +1401,7 @@ void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float w const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta)); double delta = (newValue != value) - ? jmax (fabs (newValue - value), interval) : 0; + ? jmax (std::abs (newValue - value), interval) : 0; if (value > newValue) delta = -delta; diff --git a/src/gui/components/controls/juce_TableHeaderComponent.cpp b/src/gui/components/controls/juce_TableHeaderComponent.cpp index 98c1ebd822..349df32a5f 100644 --- a/src/gui/components/controls/juce_TableHeaderComponent.cpp +++ b/src/gui/components/controls/juce_TableHeaderComponent.cpp @@ -357,7 +357,7 @@ void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetT if (ci->isVisible()) { const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth, - (int) floor (sor.getItemSize (visIndex++))); + (int) std::floor (sor.getItemSize (visIndex++))); if (newWidth != ci->width) { diff --git a/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp b/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp index 172586d743..c1e48181c8 100644 --- a/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp +++ b/src/gui/components/layout/juce_ComponentBoundsConstrainer.cpp @@ -246,8 +246,8 @@ void ComponentBoundsConstrainer::checkBounds (Rectangle& bounds, } else { - const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0; - const double newRatio = fabs (w / (double) h); + const double oldRatio = (old.getHeight() > 0) ? std::abs (old.getWidth() / (double) old.getHeight()) : 0.0; + const double newRatio = std::abs (w / (double) h); adjustWidth = (oldRatio > newRatio); } diff --git a/src/gui/components/layout/juce_Viewport.cpp b/src/gui/components/layout/juce_Viewport.cpp index 924b390b35..41074eab31 100644 --- a/src/gui/components/layout/juce_Viewport.cpp +++ b/src/gui/components/layout/juce_Viewport.cpp @@ -253,9 +253,15 @@ void Viewport::setSingleStepSizes (const int stepX, const int stepY) void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded, const bool showHorizontalScrollbarIfNeeded) { - showVScrollbar = showVerticalScrollbarIfNeeded; - showHScrollbar = showHorizontalScrollbarIfNeeded; - updateVisibleRegion(); + if (showVScrollbar != showVerticalScrollbarIfNeeded + || showHScrollbar != showHorizontalScrollbarIfNeeded) + { + showVScrollbar = showVerticalScrollbarIfNeeded; + showHScrollbar = showHorizontalScrollbarIfNeeded; + horizontalScrollBar->setVisible (true); + verticalScrollBar->setVisible (true); + updateVisibleRegion(); + } } void Viewport::setScrollBarThickness (const int thickness) diff --git a/src/gui/components/mouse/juce_DragAndDropContainer.cpp b/src/gui/components/mouse/juce_DragAndDropContainer.cpp index 90520d903e..a51e2f8c1f 100644 --- a/src/gui/components/mouse/juce_DragAndDropContainer.cpp +++ b/src/gui/components/mouse/juce_DragAndDropContainer.cpp @@ -368,7 +368,7 @@ void DragAndDropContainer::startDragging (const String& sourceDescription, for (int x = dragImage->getWidth(); --x >= 0;) { const int dx = x - clipped.getX(); - const int distance = roundToInt (sqrt (dx * dx + dy)); + const int distance = roundToInt (std::sqrt (dx * dx + dy)); if (distance > lo) { diff --git a/src/gui/components/special/juce_AudioDeviceSelectorComponent.cpp b/src/gui/components/special/juce_AudioDeviceSelectorComponent.cpp index 1b855b0e69..6264307094 100644 --- a/src/gui/components/special/juce_AudioDeviceSelectorComponent.cpp +++ b/src/gui/components/special/juce_AudioDeviceSelectorComponent.cpp @@ -57,7 +57,7 @@ public: { const float newLevel = (float) manager->getCurrentInputLevel(); - if (fabsf (level - newLevel) > 0.005f) + if (std::abs (level - newLevel) > 0.005f) { level = newLevel; repaint(); diff --git a/src/gui/components/windows/juce_AlertWindow.cpp b/src/gui/components/windows/juce_AlertWindow.cpp index c1cf280f86..64a4e91456 100644 --- a/src/gui/components/windows/juce_AlertWindow.cpp +++ b/src/gui/components/windows/juce_AlertWindow.cpp @@ -283,7 +283,7 @@ public: setFont (font); setText (message, false); - bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message)); + bestWidth = 2 * (int) std::sqrt (font.getHeight() * font.getStringWidth (message)); setColour (TextEditor::backgroundColourId, Colours::transparentBlack); setColour (TextEditor::outlineColourId, Colours::transparentBlack); @@ -421,7 +421,7 @@ void AlertWindow::updateLayout (const bool onlyIncreaseSize) const int wid = jmax (font.getStringWidth (text), font.getStringWidth (getName())); - const int sw = (int) sqrt (font.getHeight() * wid); + const int sw = (int) std::sqrt (font.getHeight() * wid); int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f)); const int edgeGap = 10; const int labelHeight = 18; diff --git a/src/gui/graphics/colour/juce_Colour.cpp b/src/gui/graphics/colour/juce_Colour.cpp index 11f4f8a827..abcac2e3fc 100644 --- a/src/gui/graphics/colour/juce_Colour.cpp +++ b/src/gui/graphics/colour/juce_Colour.cpp @@ -55,8 +55,8 @@ namespace ColourHelpers { s = jmin (1.0f, s); h = jlimit (0.0f, 1.0f, h); - h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors - const float f = h - floorf (h); + h = (h - std::floor (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors + const float f = h - std::floor (h); const uint8 x = (uint8) roundToInt (v * (1.0f - s)); const float y = v * (1.0f - s * f); @@ -405,7 +405,7 @@ const Colour Colour::withRotatedHue (const float amountToRotate) const throw() getHSB (h, s, b); h += amountToRotate; - h -= floorf (h); + h -= std::floor (h); return Colour (h, s, b, getAlpha()); } @@ -511,8 +511,8 @@ const Colour Colour::contrasting (const Colour& colour1, for (float i = 0.0f; i < 1.0f; i += 0.02f) { - const float d1 = fabsf (i - b1); - const float d2 = fabsf (i - b2); + const float d1 = std::abs (i - b1); + const float d2 = std::abs (i - b2); const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2); if (dist > bestDist) diff --git a/src/gui/graphics/contexts/juce_EdgeTable.cpp b/src/gui/graphics/contexts/juce_EdgeTable.cpp index 5dddc06967..bade51c873 100644 --- a/src/gui/graphics/contexts/juce_EdgeTable.cpp +++ b/src/gui/graphics/contexts/juce_EdgeTable.cpp @@ -1,755 +1,757 @@ -/* - ============================================================================== - - This file is part of the JUCE library - "Jules' Utility Class Extensions" - Copyright 2004-10 by Raw Material Software Ltd. - - ------------------------------------------------------------------------------ - - JUCE can be redistributed and/or modified under the terms of the GNU General - Public License (Version 2), as published by the Free Software Foundation. - A copy of the license is included in the JUCE distribution, or can be found - online at www.gnu.org/licenses. - - JUCE is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - ------------------------------------------------------------------------------ - - To release a closed-source product which uses JUCE, commercial licenses are - available: visit www.rawmaterialsoftware.com/juce for more information. - - ============================================================================== -*/ - -#include "../../../core/juce_StandardHeader.h" - -BEGIN_JUCE_NAMESPACE - -#include "juce_EdgeTable.h" -#include "../geometry/juce_PathIterator.h" -#include "../imaging/juce_Image.h" -#include "../geometry/juce_RectangleList.h" - -const int juce_edgeTableDefaultEdgesPerLine = 32; - -//============================================================================== -EdgeTable::EdgeTable (const Rectangle& bounds_, - const Path& path, const AffineTransform& transform) - : bounds (bounds_), - maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), - lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), - needToCheckEmptinesss (true) -{ - table.malloc ((bounds.getHeight() + 1) * lineStrideElements); - int* t = table; - - for (int i = bounds.getHeight(); --i >= 0;) - { - *t = 0; - t += lineStrideElements; - } - - const int topLimit = bounds.getY() << 8; - const int heightLimit = bounds.getHeight() << 8; - const int leftLimit = bounds.getX() << 8; - const int rightLimit = bounds.getRight() << 8; - - PathFlatteningIterator iter (path, transform); - - while (iter.next()) - { - int y1 = roundToInt (iter.y1 * 256.0f); - int y2 = roundToInt (iter.y2 * 256.0f); - - if (y1 != y2) - { - y1 -= topLimit; - y2 -= topLimit; - - const int startY = y1; - int direction = -1; - - if (y1 > y2) - { - swapVariables (y1, y2); - direction = 1; - } - - if (y1 < 0) - y1 = 0; - - if (y2 > heightLimit) - y2 = heightLimit; - - if (y1 < y2) - { - const double startX = 256.0f * iter.x1; - const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1); - const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier))); - - do - { - const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255)); - int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY)); - - if (x < leftLimit) - x = leftLimit; - else if (x >= rightLimit) - x = rightLimit - 1; - - addEdgePoint (x, y1 >> 8, direction * step); - y1 += step; - } - while (y1 < y2); - } - } - } - - sanitiseLevels (path.isUsingNonZeroWinding()); -} - -EdgeTable::EdgeTable (const Rectangle& rectangleToAdd) - : bounds (rectangleToAdd), - maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), - lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), - needToCheckEmptinesss (true) -{ - table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements); - table[0] = 0; - - const int x1 = rectangleToAdd.getX() << 8; - const int x2 = rectangleToAdd.getRight() << 8; - - int* t = table; - for (int i = rectangleToAdd.getHeight(); --i >= 0;) - { - t[0] = 2; - t[1] = x1; - t[2] = 255; - t[3] = x2; - t[4] = 0; - t += lineStrideElements; - } -} - -EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) - : bounds (rectanglesToAdd.getBounds()), - maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), - lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), - needToCheckEmptinesss (true) -{ - table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements); - - int* t = table; - for (int i = bounds.getHeight(); --i >= 0;) - { - *t = 0; - t += lineStrideElements; - } - - for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();) - { - const Rectangle* const r = iter.getRectangle(); - - const int x1 = r->getX() << 8; - const int x2 = r->getRight() << 8; - int y = r->getY() - bounds.getY(); - - for (int j = r->getHeight(); --j >= 0;) - { - addEdgePoint (x1, y, 255); - addEdgePoint (x2, y, -255); - ++y; - } - } - - sanitiseLevels (true); -} - -EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) - : bounds (Rectangle ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)), - maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), - lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), - needToCheckEmptinesss (true) -{ - jassert (w > 0 && h > 0); - table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements); - table[0] = 0; - - const int x1 = roundToInt (x * 256.0f); - const int x2 = roundToInt ((x + w) * 256.0f); - - int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8); - jassert (y1 < 256); - int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8); - - if (x2 <= x1 || y2 <= y1) - { - bounds.setHeight (0); - return; - } - - int lineY = 0; - int* t = table; - - if ((y1 >> 8) == (y2 >> 8)) - { - t[0] = 2; - t[1] = x1; - t[2] = y2 - y1; - t[3] = x2; - t[4] = 0; - ++lineY; - t += lineStrideElements; - } - else - { - t[0] = 2; - t[1] = x1; - t[2] = 255 - (y1 & 255); - t[3] = x2; - t[4] = 0; - ++lineY; - t += lineStrideElements; - - while (lineY < (y2 >> 8)) - { - t[0] = 2; - t[1] = x1; - t[2] = 255; - t[3] = x2; - t[4] = 0; - ++lineY; - t += lineStrideElements; - } - - jassert (lineY < bounds.getHeight()); - t[0] = 2; - t[1] = x1; - t[2] = y2 & 255; - t[3] = x2; - t[4] = 0; - ++lineY; - t += lineStrideElements; - } - - while (lineY < bounds.getHeight()) - { - t[0] = 0; - t += lineStrideElements; - ++lineY; - } -} - -EdgeTable::EdgeTable (const EdgeTable& other) - : table (0) -{ - operator= (other); -} - -EdgeTable& EdgeTable::operator= (const EdgeTable& other) -{ - bounds = other.bounds; - maxEdgesPerLine = other.maxEdgesPerLine; - lineStrideElements = other.lineStrideElements; - needToCheckEmptinesss = other.needToCheckEmptinesss; - - table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements); - copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight()); - return *this; -} - -EdgeTable::~EdgeTable() -{ -} - -//============================================================================== -void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw() -{ - while (--numLines >= 0) - { - memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int)); - src += srcLineStride; - dest += destLineStride; - } -} - -void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw() -{ - // Convert the table from relative windings to absolute levels.. - int* lineStart = table; - - for (int i = bounds.getHeight(); --i >= 0;) - { - int* line = lineStart; - lineStart += lineStrideElements; - - int num = *line; - if (num == 0) - continue; - - int level = 0; - - if (useNonZeroWinding) - { - while (--num > 0) - { - line += 2; - level += *line; - int corrected = abs (level); - if (corrected >> 8) - corrected = 255; - - *line = corrected; - } - } - else - { - while (--num > 0) - { - line += 2; - level += *line; - int corrected = abs (level); - if (corrected >> 8) - { - corrected &= 511; - if (corrected >> 8) - corrected = 511 - corrected; - } - - *line = corrected; - } - } - - line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table - } -} - -void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw() -{ - if (newNumEdgesPerLine != maxEdgesPerLine) - { - maxEdgesPerLine = newNumEdgesPerLine; - - jassert (bounds.getHeight() > 0); - const int newLineStrideElements = maxEdgesPerLine * 2 + 1; - - HeapBlock newTable (bounds.getHeight() * newLineStrideElements); - - copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight()); - - table.swapWith (newTable); - lineStrideElements = newLineStrideElements; - } -} - -void EdgeTable::optimiseTable() throw() -{ - int maxLineElements = 0; - - for (int i = bounds.getHeight(); --i >= 0;) - maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]); - - remapTableForNumEdges (maxLineElements); -} - -void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw() -{ - jassert (y >= 0 && y < bounds.getHeight()); - - int* line = table + lineStrideElements * y; - const int numPoints = line[0]; - int n = numPoints << 1; - - if (n > 0) - { - while (n > 0) - { - const int cx = line [n - 1]; - - if (cx <= x) - { - if (cx == x) - { - line [n] += winding; - return; - } - - break; - } - - n -= 2; - } - - if (numPoints >= maxEdgesPerLine) - { - remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine); - jassert (numPoints < maxEdgesPerLine); - line = table + lineStrideElements * y; - } - - memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n)); - } - - line [n + 1] = x; - line [n + 2] = winding; - line[0]++; -} - -void EdgeTable::translate (float dx, int dy) throw() -{ - bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy); - - int* lineStart = table; - const int intDx = (int) (dx * 256.0f); - - for (int i = bounds.getHeight(); --i >= 0;) - { - int* line = lineStart; - lineStart += lineStrideElements; - int num = *line++; - - while (--num >= 0) - { - *line += intDx; - line += 2; - } - } -} - -void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw() -{ - jassert (y >= 0 && y < bounds.getHeight()); - - int* dest = table + lineStrideElements * y; - if (dest[0] == 0) - return; - - int otherNumPoints = *otherLine; - if (otherNumPoints == 0) - { - *dest = 0; - return; - } - - const int right = bounds.getRight() << 8; - - // optimise for the common case where our line lies entirely within a - // single pair of points, as happens when clipping to a simple rect. - if (otherNumPoints == 2 && otherLine[2] >= 255) - { - clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3])); - return; - } - - ++otherLine; - const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int); - int* temp = (int*) alloca (lineSizeBytes); - memcpy (temp, dest, lineSizeBytes); - - const int* src1 = temp; - int srcNum1 = *src1++; - int x1 = *src1++; - - const int* src2 = otherLine; - int srcNum2 = otherNumPoints; - int x2 = *src2++; - - int destIndex = 0, destTotal = 0; - int level1 = 0, level2 = 0; - int lastX = std::numeric_limits::min(), lastLevel = 0; - - while (srcNum1 > 0 && srcNum2 > 0) - { - int nextX; - - if (x1 < x2) - { - nextX = x1; - level1 = *src1++; - x1 = *src1++; - --srcNum1; - } - else if (x1 == x2) - { - nextX = x1; - level1 = *src1++; - level2 = *src2++; - x1 = *src1++; - x2 = *src2++; - --srcNum1; - --srcNum2; - } - else - { - nextX = x2; - level2 = *src2++; - x2 = *src2++; - --srcNum2; - } - - if (nextX > lastX) - { - if (nextX >= right) - break; - - lastX = nextX; - - const int nextLevel = (level1 * (level2 + 1)) >> 8; - jassert (((unsigned int) nextLevel) < (unsigned int) 256); - - if (nextLevel != lastLevel) - { - if (destTotal >= maxEdgesPerLine) - { - dest[0] = destTotal; - remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine); - dest = table + lineStrideElements * y; - } - - ++destTotal; - lastLevel = nextLevel; - dest[++destIndex] = nextX; - dest[++destIndex] = nextLevel; - } - } - } - - if (lastLevel > 0) - { - if (destTotal >= maxEdgesPerLine) - { - dest[0] = destTotal; - remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine); - dest = table + lineStrideElements * y; - } - - ++destTotal; - dest[++destIndex] = right; - dest[++destIndex] = 0; - } - - dest[0] = destTotal; - -#if JUCE_DEBUG - int last = std::numeric_limits::min(); - for (int i = 0; i < dest[0]; ++i) - { - jassert (dest[i * 2 + 1] > last); - last = dest[i * 2 + 1]; - } - - jassert (dest [dest[0] * 2] == 0); -#endif -} - -void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw() -{ - int* lastItem = dest + (dest[0] * 2 - 1); - - if (x2 < lastItem[0]) - { - if (x2 <= dest[1]) - { - dest[0] = 0; - return; - } - - while (x2 < lastItem[-2]) - { - --(dest[0]); - lastItem -= 2; - } - - lastItem[0] = x2; - lastItem[1] = 0; - } - - if (x1 > dest[1]) - { - while (lastItem[0] > x1) - lastItem -= 2; - - const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2; - - if (itemsRemoved > 0) - { - dest[0] -= itemsRemoved; - memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2)); - } - - dest[1] = x1; - } -} - - -//============================================================================== -void EdgeTable::clipToRectangle (const Rectangle& r) throw() -{ - const Rectangle clipped (r.getIntersection (bounds)); - - if (clipped.isEmpty()) - { - needToCheckEmptinesss = false; - bounds.setHeight (0); - } - else - { - const int top = clipped.getY() - bounds.getY(); - const int bottom = clipped.getBottom() - bounds.getY(); - - if (bottom < bounds.getHeight()) - bounds.setHeight (bottom); - - if (clipped.getRight() < bounds.getRight()) - bounds.setRight (clipped.getRight()); - - for (int i = top; --i >= 0;) - table [lineStrideElements * i] = 0; - - if (clipped.getX() > bounds.getX()) - { - const int x1 = clipped.getX() << 8; - const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8; - int* line = table + lineStrideElements * top; - - for (int i = bottom - top; --i >= 0;) - { - if (line[0] != 0) - clipEdgeTableLineToRange (line, x1, x2); - - line += lineStrideElements; - } - } - - needToCheckEmptinesss = true; - } -} - -void EdgeTable::excludeRectangle (const Rectangle& r) throw() -{ - const Rectangle clipped (r.getIntersection (bounds)); - - if (! clipped.isEmpty()) - { - const int top = clipped.getY() - bounds.getY(); - const int bottom = clipped.getBottom() - bounds.getY(); - - //XXX optimise here by shortening the table if it fills top or bottom - - const int rectLine[] = { 4, std::numeric_limits::min(), 255, - clipped.getX() << 8, 0, - clipped.getRight() << 8, 255, - std::numeric_limits::max(), 0 }; - - for (int i = top; i < bottom; ++i) - intersectWithEdgeTableLine (i, rectLine); - - needToCheckEmptinesss = true; - } -} - -void EdgeTable::clipToEdgeTable (const EdgeTable& other) -{ - const Rectangle clipped (other.bounds.getIntersection (bounds)); - - if (clipped.isEmpty()) - { - needToCheckEmptinesss = false; - bounds.setHeight (0); - } - else - { - const int top = clipped.getY() - bounds.getY(); - const int bottom = clipped.getBottom() - bounds.getY(); - - if (bottom < bounds.getHeight()) - bounds.setHeight (bottom); - - if (clipped.getRight() < bounds.getRight()) - bounds.setRight (clipped.getRight()); - - int i = 0; - for (i = top; --i >= 0;) - table [lineStrideElements * i] = 0; - - const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY()); - - for (i = top; i < bottom; ++i) - { - intersectWithEdgeTableLine (i, otherLine); - otherLine += other.lineStrideElements; - } - - needToCheckEmptinesss = true; - } -} - -void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw() -{ - y -= bounds.getY(); - - if (y < 0 || y >= bounds.getHeight()) - return; - - needToCheckEmptinesss = true; - - if (numPixels <= 0) - { - table [lineStrideElements * y] = 0; - return; - } - - int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int)); - int destIndex = 0, lastLevel = 0; - - while (--numPixels >= 0) - { - const int alpha = *mask; - mask += maskStride; - - if (alpha != lastLevel) - { - tempLine[++destIndex] = (x << 8); - tempLine[++destIndex] = alpha; - lastLevel = alpha; - } - - ++x; - } - - if (lastLevel > 0) - { - tempLine[++destIndex] = (x << 8); - tempLine[++destIndex] = 0; - } - - tempLine[0] = destIndex >> 1; - - intersectWithEdgeTableLine (y, tempLine); -} - -bool EdgeTable::isEmpty() throw() -{ - if (needToCheckEmptinesss) - { - needToCheckEmptinesss = false; - int* t = table; - - for (int i = bounds.getHeight(); --i >= 0;) - { - if (t[0] > 1) - return false; - - t += lineStrideElements; - } - - bounds.setHeight (0); - } - - return bounds.getHeight() == 0; -} - -END_JUCE_NAMESPACE +/* + ============================================================================== + + This file is part of the JUCE library - "Jules' Utility Class Extensions" + Copyright 2004-10 by Raw Material Software Ltd. + + ------------------------------------------------------------------------------ + + JUCE can be redistributed and/or modified under the terms of the GNU General + Public License (Version 2), as published by the Free Software Foundation. + A copy of the license is included in the JUCE distribution, or can be found + online at www.gnu.org/licenses. + + JUCE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + ------------------------------------------------------------------------------ + + To release a closed-source product which uses JUCE, commercial licenses are + available: visit www.rawmaterialsoftware.com/juce for more information. + + ============================================================================== +*/ + +#include "../../../core/juce_StandardHeader.h" + +BEGIN_JUCE_NAMESPACE + +#include "juce_EdgeTable.h" +#include "../geometry/juce_PathIterator.h" +#include "../imaging/juce_Image.h" +#include "../geometry/juce_RectangleList.h" + +const int juce_edgeTableDefaultEdgesPerLine = 32; + +//============================================================================== +EdgeTable::EdgeTable (const Rectangle& bounds_, + const Path& path, const AffineTransform& transform) + : bounds (bounds_), + maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), + lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), + needToCheckEmptinesss (true) +{ + table.malloc ((bounds.getHeight() + 1) * lineStrideElements); + int* t = table; + + for (int i = bounds.getHeight(); --i >= 0;) + { + *t = 0; + t += lineStrideElements; + } + + const int topLimit = bounds.getY() << 8; + const int heightLimit = bounds.getHeight() << 8; + const int leftLimit = bounds.getX() << 8; + const int rightLimit = bounds.getRight() << 8; + + PathFlatteningIterator iter (path, transform); + + while (iter.next()) + { + int y1 = roundToInt (iter.y1 * 256.0f); + int y2 = roundToInt (iter.y2 * 256.0f); + + if (y1 != y2) + { + y1 -= topLimit; + y2 -= topLimit; + + const int startY = y1; + int direction = -1; + + if (y1 > y2) + { + swapVariables (y1, y2); + direction = 1; + } + + if (y1 < 0) + y1 = 0; + + if (y2 > heightLimit) + y2 = heightLimit; + + if (y1 < y2) + { + const double startX = 256.0f * iter.x1; + const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1); + const int stepSize = jlimit (1, 256, 256 / (1 + (int) std::abs (multiplier))); + + do + { + const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255)); + int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY)); + + if (x < leftLimit) + x = leftLimit; + else if (x >= rightLimit) + x = rightLimit - 1; + + addEdgePoint (x, y1 >> 8, direction * step); + y1 += step; + } + while (y1 < y2); + } + } + } + + sanitiseLevels (path.isUsingNonZeroWinding()); +} + +EdgeTable::EdgeTable (const Rectangle& rectangleToAdd) + : bounds (rectangleToAdd), + maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), + lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), + needToCheckEmptinesss (true) +{ + table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements); + table[0] = 0; + + const int x1 = rectangleToAdd.getX() << 8; + const int x2 = rectangleToAdd.getRight() << 8; + + int* t = table; + for (int i = rectangleToAdd.getHeight(); --i >= 0;) + { + t[0] = 2; + t[1] = x1; + t[2] = 255; + t[3] = x2; + t[4] = 0; + t += lineStrideElements; + } +} + +EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) + : bounds (rectanglesToAdd.getBounds()), + maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), + lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), + needToCheckEmptinesss (true) +{ + table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements); + + int* t = table; + for (int i = bounds.getHeight(); --i >= 0;) + { + *t = 0; + t += lineStrideElements; + } + + for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();) + { + const Rectangle* const r = iter.getRectangle(); + + const int x1 = r->getX() << 8; + const int x2 = r->getRight() << 8; + int y = r->getY() - bounds.getY(); + + for (int j = r->getHeight(); --j >= 0;) + { + addEdgePoint (x1, y, 255); + addEdgePoint (x2, y, -255); + ++y; + } + } + + sanitiseLevels (true); +} + +EdgeTable::EdgeTable (const Rectangle& rectangleToAdd) + : bounds (Rectangle ((int) std::floor (rectangleToAdd.getX()), + roundToInt (rectangleToAdd.getY() * 256.0f) >> 8, + 2 + (int) rectangleToAdd.getWidth(), + 2 + (int) rectangleToAdd.getHeight())), + maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine), + lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1), + needToCheckEmptinesss (true) +{ + jassert (! rectangleToAdd.isEmpty()); + table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements); + table[0] = 0; + + const int x1 = roundToInt (rectangleToAdd.getX() * 256.0f); + const int x2 = roundToInt (rectangleToAdd.getRight() * 256.0f); + + int y1 = roundToInt (rectangleToAdd.getY() * 256.0f) - (bounds.getY() << 8); + jassert (y1 < 256); + int y2 = roundToInt (rectangleToAdd.getBottom() * 256.0f) - (bounds.getY() << 8); + + if (x2 <= x1 || y2 <= y1) + { + bounds.setHeight (0); + return; + } + + int lineY = 0; + int* t = table; + + if ((y1 >> 8) == (y2 >> 8)) + { + t[0] = 2; + t[1] = x1; + t[2] = y2 - y1; + t[3] = x2; + t[4] = 0; + ++lineY; + t += lineStrideElements; + } + else + { + t[0] = 2; + t[1] = x1; + t[2] = 255 - (y1 & 255); + t[3] = x2; + t[4] = 0; + ++lineY; + t += lineStrideElements; + + while (lineY < (y2 >> 8)) + { + t[0] = 2; + t[1] = x1; + t[2] = 255; + t[3] = x2; + t[4] = 0; + ++lineY; + t += lineStrideElements; + } + + jassert (lineY < bounds.getHeight()); + t[0] = 2; + t[1] = x1; + t[2] = y2 & 255; + t[3] = x2; + t[4] = 0; + ++lineY; + t += lineStrideElements; + } + + while (lineY < bounds.getHeight()) + { + t[0] = 0; + t += lineStrideElements; + ++lineY; + } +} + +EdgeTable::EdgeTable (const EdgeTable& other) +{ + operator= (other); +} + +EdgeTable& EdgeTable::operator= (const EdgeTable& other) +{ + bounds = other.bounds; + maxEdgesPerLine = other.maxEdgesPerLine; + lineStrideElements = other.lineStrideElements; + needToCheckEmptinesss = other.needToCheckEmptinesss; + + table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements); + copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight()); + return *this; +} + +EdgeTable::~EdgeTable() +{ +} + +//============================================================================== +void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw() +{ + while (--numLines >= 0) + { + memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int)); + src += srcLineStride; + dest += destLineStride; + } +} + +void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw() +{ + // Convert the table from relative windings to absolute levels.. + int* lineStart = table; + + for (int i = bounds.getHeight(); --i >= 0;) + { + int* line = lineStart; + lineStart += lineStrideElements; + + int num = *line; + if (num == 0) + continue; + + int level = 0; + + if (useNonZeroWinding) + { + while (--num > 0) + { + line += 2; + level += *line; + int corrected = abs (level); + if (corrected >> 8) + corrected = 255; + + *line = corrected; + } + } + else + { + while (--num > 0) + { + line += 2; + level += *line; + int corrected = abs (level); + if (corrected >> 8) + { + corrected &= 511; + if (corrected >> 8) + corrected = 511 - corrected; + } + + *line = corrected; + } + } + + line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table + } +} + +void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw() +{ + if (newNumEdgesPerLine != maxEdgesPerLine) + { + maxEdgesPerLine = newNumEdgesPerLine; + + jassert (bounds.getHeight() > 0); + const int newLineStrideElements = maxEdgesPerLine * 2 + 1; + + HeapBlock newTable (bounds.getHeight() * newLineStrideElements); + + copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight()); + + table.swapWith (newTable); + lineStrideElements = newLineStrideElements; + } +} + +void EdgeTable::optimiseTable() throw() +{ + int maxLineElements = 0; + + for (int i = bounds.getHeight(); --i >= 0;) + maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]); + + remapTableForNumEdges (maxLineElements); +} + +void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw() +{ + jassert (y >= 0 && y < bounds.getHeight()); + + int* line = table + lineStrideElements * y; + const int numPoints = line[0]; + int n = numPoints << 1; + + if (n > 0) + { + while (n > 0) + { + const int cx = line [n - 1]; + + if (cx <= x) + { + if (cx == x) + { + line [n] += winding; + return; + } + + break; + } + + n -= 2; + } + + if (numPoints >= maxEdgesPerLine) + { + remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine); + jassert (numPoints < maxEdgesPerLine); + line = table + lineStrideElements * y; + } + + memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n)); + } + + line [n + 1] = x; + line [n + 2] = winding; + line[0]++; +} + +void EdgeTable::translate (float dx, const int dy) throw() +{ + bounds.translate ((int) std::floor (dx), dy); + + int* lineStart = table; + const int intDx = (int) (dx * 256.0f); + + for (int i = bounds.getHeight(); --i >= 0;) + { + int* line = lineStart; + lineStart += lineStrideElements; + int num = *line++; + + while (--num >= 0) + { + *line += intDx; + line += 2; + } + } +} + +void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw() +{ + jassert (y >= 0 && y < bounds.getHeight()); + + int* dest = table + lineStrideElements * y; + if (dest[0] == 0) + return; + + int otherNumPoints = *otherLine; + if (otherNumPoints == 0) + { + *dest = 0; + return; + } + + const int right = bounds.getRight() << 8; + + // optimise for the common case where our line lies entirely within a + // single pair of points, as happens when clipping to a simple rect. + if (otherNumPoints == 2 && otherLine[2] >= 255) + { + clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3])); + return; + } + + ++otherLine; + const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int); + int* temp = (int*) alloca (lineSizeBytes); + memcpy (temp, dest, lineSizeBytes); + + const int* src1 = temp; + int srcNum1 = *src1++; + int x1 = *src1++; + + const int* src2 = otherLine; + int srcNum2 = otherNumPoints; + int x2 = *src2++; + + int destIndex = 0, destTotal = 0; + int level1 = 0, level2 = 0; + int lastX = std::numeric_limits::min(), lastLevel = 0; + + while (srcNum1 > 0 && srcNum2 > 0) + { + int nextX; + + if (x1 < x2) + { + nextX = x1; + level1 = *src1++; + x1 = *src1++; + --srcNum1; + } + else if (x1 == x2) + { + nextX = x1; + level1 = *src1++; + level2 = *src2++; + x1 = *src1++; + x2 = *src2++; + --srcNum1; + --srcNum2; + } + else + { + nextX = x2; + level2 = *src2++; + x2 = *src2++; + --srcNum2; + } + + if (nextX > lastX) + { + if (nextX >= right) + break; + + lastX = nextX; + + const int nextLevel = (level1 * (level2 + 1)) >> 8; + jassert (((unsigned int) nextLevel) < (unsigned int) 256); + + if (nextLevel != lastLevel) + { + if (destTotal >= maxEdgesPerLine) + { + dest[0] = destTotal; + remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine); + dest = table + lineStrideElements * y; + } + + ++destTotal; + lastLevel = nextLevel; + dest[++destIndex] = nextX; + dest[++destIndex] = nextLevel; + } + } + } + + if (lastLevel > 0) + { + if (destTotal >= maxEdgesPerLine) + { + dest[0] = destTotal; + remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine); + dest = table + lineStrideElements * y; + } + + ++destTotal; + dest[++destIndex] = right; + dest[++destIndex] = 0; + } + + dest[0] = destTotal; + +#if JUCE_DEBUG + int last = std::numeric_limits::min(); + for (int i = 0; i < dest[0]; ++i) + { + jassert (dest[i * 2 + 1] > last); + last = dest[i * 2 + 1]; + } + + jassert (dest [dest[0] * 2] == 0); +#endif +} + +void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw() +{ + int* lastItem = dest + (dest[0] * 2 - 1); + + if (x2 < lastItem[0]) + { + if (x2 <= dest[1]) + { + dest[0] = 0; + return; + } + + while (x2 < lastItem[-2]) + { + --(dest[0]); + lastItem -= 2; + } + + lastItem[0] = x2; + lastItem[1] = 0; + } + + if (x1 > dest[1]) + { + while (lastItem[0] > x1) + lastItem -= 2; + + const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2; + + if (itemsRemoved > 0) + { + dest[0] -= itemsRemoved; + memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2)); + } + + dest[1] = x1; + } +} + + +//============================================================================== +void EdgeTable::clipToRectangle (const Rectangle& r) throw() +{ + const Rectangle clipped (r.getIntersection (bounds)); + + if (clipped.isEmpty()) + { + needToCheckEmptinesss = false; + bounds.setHeight (0); + } + else + { + const int top = clipped.getY() - bounds.getY(); + const int bottom = clipped.getBottom() - bounds.getY(); + + if (bottom < bounds.getHeight()) + bounds.setHeight (bottom); + + if (clipped.getRight() < bounds.getRight()) + bounds.setRight (clipped.getRight()); + + for (int i = top; --i >= 0;) + table [lineStrideElements * i] = 0; + + if (clipped.getX() > bounds.getX()) + { + const int x1 = clipped.getX() << 8; + const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8; + int* line = table + lineStrideElements * top; + + for (int i = bottom - top; --i >= 0;) + { + if (line[0] != 0) + clipEdgeTableLineToRange (line, x1, x2); + + line += lineStrideElements; + } + } + + needToCheckEmptinesss = true; + } +} + +void EdgeTable::excludeRectangle (const Rectangle& r) throw() +{ + const Rectangle clipped (r.getIntersection (bounds)); + + if (! clipped.isEmpty()) + { + const int top = clipped.getY() - bounds.getY(); + const int bottom = clipped.getBottom() - bounds.getY(); + + //XXX optimise here by shortening the table if it fills top or bottom + + const int rectLine[] = { 4, std::numeric_limits::min(), 255, + clipped.getX() << 8, 0, + clipped.getRight() << 8, 255, + std::numeric_limits::max(), 0 }; + + for (int i = top; i < bottom; ++i) + intersectWithEdgeTableLine (i, rectLine); + + needToCheckEmptinesss = true; + } +} + +void EdgeTable::clipToEdgeTable (const EdgeTable& other) +{ + const Rectangle clipped (other.bounds.getIntersection (bounds)); + + if (clipped.isEmpty()) + { + needToCheckEmptinesss = false; + bounds.setHeight (0); + } + else + { + const int top = clipped.getY() - bounds.getY(); + const int bottom = clipped.getBottom() - bounds.getY(); + + if (bottom < bounds.getHeight()) + bounds.setHeight (bottom); + + if (clipped.getRight() < bounds.getRight()) + bounds.setRight (clipped.getRight()); + + int i = 0; + for (i = top; --i >= 0;) + table [lineStrideElements * i] = 0; + + const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY()); + + for (i = top; i < bottom; ++i) + { + intersectWithEdgeTableLine (i, otherLine); + otherLine += other.lineStrideElements; + } + + needToCheckEmptinesss = true; + } +} + +void EdgeTable::clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw() +{ + y -= bounds.getY(); + + if (y < 0 || y >= bounds.getHeight()) + return; + + needToCheckEmptinesss = true; + + if (numPixels <= 0) + { + table [lineStrideElements * y] = 0; + return; + } + + int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int)); + int destIndex = 0, lastLevel = 0; + + while (--numPixels >= 0) + { + const int alpha = *mask; + mask += maskStride; + + if (alpha != lastLevel) + { + tempLine[++destIndex] = (x << 8); + tempLine[++destIndex] = alpha; + lastLevel = alpha; + } + + ++x; + } + + if (lastLevel > 0) + { + tempLine[++destIndex] = (x << 8); + tempLine[++destIndex] = 0; + } + + tempLine[0] = destIndex >> 1; + + intersectWithEdgeTableLine (y, tempLine); +} + +bool EdgeTable::isEmpty() throw() +{ + if (needToCheckEmptinesss) + { + needToCheckEmptinesss = false; + int* t = table; + + for (int i = bounds.getHeight(); --i >= 0;) + { + if (t[0] > 1) + return false; + + t += lineStrideElements; + } + + bounds.setHeight (0); + } + + return bounds.getHeight() == 0; +} + +END_JUCE_NAMESPACE diff --git a/src/gui/graphics/contexts/juce_EdgeTable.h b/src/gui/graphics/contexts/juce_EdgeTable.h index 62f154bad4..25b41c28b5 100644 --- a/src/gui/graphics/contexts/juce_EdgeTable.h +++ b/src/gui/graphics/contexts/juce_EdgeTable.h @@ -1,211 +1,211 @@ -/* - ============================================================================== - - This file is part of the JUCE library - "Jules' Utility Class Extensions" - Copyright 2004-10 by Raw Material Software Ltd. - - ------------------------------------------------------------------------------ - - JUCE can be redistributed and/or modified under the terms of the GNU General - Public License (Version 2), as published by the Free Software Foundation. - A copy of the license is included in the JUCE distribution, or can be found - online at www.gnu.org/licenses. - - JUCE is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - ------------------------------------------------------------------------------ - - To release a closed-source product which uses JUCE, commercial licenses are - available: visit www.rawmaterialsoftware.com/juce for more information. - - ============================================================================== -*/ - -#ifndef __JUCE_EDGETABLE_JUCEHEADER__ -#define __JUCE_EDGETABLE_JUCEHEADER__ - -#include "../geometry/juce_AffineTransform.h" -#include "../geometry/juce_Rectangle.h" -#include "../../../containers/juce_MemoryBlock.h" -class Path; -class RectangleList; -class Image; - - -//============================================================================== -/** - A table of horizontal scan-line segments - used for rasterising Paths. - - @see Path, Graphics -*/ -class JUCE_API EdgeTable -{ -public: - //============================================================================== - /** Creates an edge table containing a path. - - A table is created with a fixed vertical range, and only sections of the path - which lie within this range will be added to the table. - - @param clipLimits only the region of the path that lies within this area will be added - @param pathToAdd the path to add to the table - @param transform a transform to apply to the path being added - */ - EdgeTable (const Rectangle& clipLimits, - const Path& pathToAdd, - const AffineTransform& transform); - - /** Creates an edge table containing a rectangle. - */ - EdgeTable (const Rectangle& rectangleToAdd); - - /** Creates an edge table containing a rectangle list. - */ - EdgeTable (const RectangleList& rectanglesToAdd); - - /** Creates an edge table containing a rectangle. - */ - EdgeTable (float x, float y, float w, float h); - - /** Creates a copy of another edge table. */ - EdgeTable (const EdgeTable& other); - - /** Copies from another edge table. */ - EdgeTable& operator= (const EdgeTable& other); - - /** Destructor. */ - ~EdgeTable(); - - //============================================================================== - void clipToRectangle (const Rectangle& r) throw(); - void excludeRectangle (const Rectangle& r) throw(); - void clipToEdgeTable (const EdgeTable& other); - void clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw(); - bool isEmpty() throw(); - const Rectangle& getMaximumBounds() const throw() { return bounds; } - void translate (float dx, int dy) throw(); - - /** Reduces the amount of space the table has allocated. - - This will shrink the table down to use as little memory as possible - useful for - read-only tables that get stored and re-used for rendering. - */ - void optimiseTable() throw(); - - - //============================================================================== - /** Iterates the lines in the table, for rendering. - - This function will iterate each line in the table, and call a user-defined class - to render each pixel or continuous line of pixels that the table contains. - - @param iterationCallback this templated class must contain the following methods: - @code - inline void setEdgeTableYPos (int y); - inline void handleEdgeTablePixel (int x, int alphaLevel) const; - inline void handleEdgeTableLine (int x, int width, int alphaLevel) const; - @endcode - (these don't necessarily have to be 'const', but it might help it go faster) - */ - template - void iterate (EdgeTableIterationCallback& iterationCallback) const throw() - { - const int* lineStart = table; - - for (int y = 0; y < bounds.getHeight(); ++y) - { - const int* line = lineStart; - lineStart += lineStrideElements; - int numPoints = line[0]; - - if (--numPoints > 0) - { - int x = *++line; - jassert ((x >> 8) >= bounds.getX() && (x >> 8) < bounds.getRight()); - int levelAccumulator = 0; - - iterationCallback.setEdgeTableYPos (bounds.getY() + y); - - while (--numPoints >= 0) - { - const int level = *++line; - jassert (((unsigned int) level) < (unsigned int) 256); - const int endX = *++line; - jassert (endX >= x); - const int endOfRun = (endX >> 8); - - if (endOfRun == (x >> 8)) - { - // small segment within the same pixel, so just save it for the next - // time round.. - levelAccumulator += (endX - x) * level; - } - else - { - // plot the fist pixel of this segment, including any accumulated - // levels from smaller segments that haven't been drawn yet - levelAccumulator += (0xff - (x & 0xff)) * level; - levelAccumulator >>= 8; - x >>= 8; - - if (levelAccumulator > 0) - { - if (levelAccumulator >> 8) - levelAccumulator = 0xff; - - iterationCallback.handleEdgeTablePixel (x, levelAccumulator); - } - - // if there's a run of similar pixels, do it all in one go.. - if (level > 0) - { - jassert (endOfRun <= bounds.getRight()); - const int numPix = endOfRun - ++x; - - if (numPix > 0) - iterationCallback.handleEdgeTableLine (x, numPix, level); - } - - // save the bit at the end to be drawn next time round the loop. - levelAccumulator = (endX & 0xff) * level; - } - - x = endX; - } - - if (levelAccumulator > 0) - { - levelAccumulator >>= 8; - if (levelAccumulator >> 8) - levelAccumulator = 0xff; - - x >>= 8; - jassert (x >= bounds.getX() && x < bounds.getRight()); - iterationCallback.handleEdgeTablePixel (x, levelAccumulator); - } - } - } - } - - //============================================================================== - juce_UseDebuggingNewOperator - -private: - // table line format: number of points; point0 x, point0 levelDelta, point1 x, point1 levelDelta, etc - HeapBlock table; - Rectangle bounds; - int maxEdgesPerLine, lineStrideElements; - bool needToCheckEmptinesss; - - void addEdgePoint (int x, int y, int winding) throw(); - void remapTableForNumEdges (int newNumEdgesPerLine) throw(); - void intersectWithEdgeTableLine (int y, const int* otherLine) throw(); - void clipEdgeTableLineToRange (int* line, int x1, int x2) throw(); - void sanitiseLevels (bool useNonZeroWinding) throw(); - static void copyEdgeTableData (int* dest, int destLineStride, const int* src, int srcLineStride, int numLines) throw(); -}; - - -#endif // __JUCE_EDGETABLE_JUCEHEADER__ +/* + ============================================================================== + + This file is part of the JUCE library - "Jules' Utility Class Extensions" + Copyright 2004-10 by Raw Material Software Ltd. + + ------------------------------------------------------------------------------ + + JUCE can be redistributed and/or modified under the terms of the GNU General + Public License (Version 2), as published by the Free Software Foundation. + A copy of the license is included in the JUCE distribution, or can be found + online at www.gnu.org/licenses. + + JUCE is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + ------------------------------------------------------------------------------ + + To release a closed-source product which uses JUCE, commercial licenses are + available: visit www.rawmaterialsoftware.com/juce for more information. + + ============================================================================== +*/ + +#ifndef __JUCE_EDGETABLE_JUCEHEADER__ +#define __JUCE_EDGETABLE_JUCEHEADER__ + +#include "../geometry/juce_AffineTransform.h" +#include "../geometry/juce_Rectangle.h" +#include "../geometry/juce_RectangleList.h" +#include "../../../containers/juce_MemoryBlock.h" +class Path; +class Image; + + +//============================================================================== +/** + A table of horizontal scan-line segments - used for rasterising Paths. + + @see Path, Graphics +*/ +class JUCE_API EdgeTable +{ +public: + //============================================================================== + /** Creates an edge table containing a path. + + A table is created with a fixed vertical range, and only sections of the path + which lie within this range will be added to the table. + + @param clipLimits only the region of the path that lies within this area will be added + @param pathToAdd the path to add to the table + @param transform a transform to apply to the path being added + */ + EdgeTable (const Rectangle& clipLimits, + const Path& pathToAdd, + const AffineTransform& transform); + + /** Creates an edge table containing a rectangle. + */ + EdgeTable (const Rectangle& rectangleToAdd); + + /** Creates an edge table containing a rectangle list. + */ + EdgeTable (const RectangleList& rectanglesToAdd); + + /** Creates an edge table containing a rectangle. + */ + EdgeTable (const Rectangle& rectangleToAdd); + + /** Creates a copy of another edge table. */ + EdgeTable (const EdgeTable& other); + + /** Copies from another edge table. */ + EdgeTable& operator= (const EdgeTable& other); + + /** Destructor. */ + ~EdgeTable(); + + //============================================================================== + void clipToRectangle (const Rectangle& r) throw(); + void excludeRectangle (const Rectangle& r) throw(); + void clipToEdgeTable (const EdgeTable& other); + void clipLineToMask (int x, int y, const uint8* mask, int maskStride, int numPixels) throw(); + bool isEmpty() throw(); + const Rectangle& getMaximumBounds() const throw() { return bounds; } + void translate (float dx, int dy) throw(); + + /** Reduces the amount of space the table has allocated. + + This will shrink the table down to use as little memory as possible - useful for + read-only tables that get stored and re-used for rendering. + */ + void optimiseTable() throw(); + + + //============================================================================== + /** Iterates the lines in the table, for rendering. + + This function will iterate each line in the table, and call a user-defined class + to render each pixel or continuous line of pixels that the table contains. + + @param iterationCallback this templated class must contain the following methods: + @code + inline void setEdgeTableYPos (int y); + inline void handleEdgeTablePixel (int x, int alphaLevel) const; + inline void handleEdgeTableLine (int x, int width, int alphaLevel) const; + @endcode + (these don't necessarily have to be 'const', but it might help it go faster) + */ + template + void iterate (EdgeTableIterationCallback& iterationCallback) const throw() + { + const int* lineStart = table; + + for (int y = 0; y < bounds.getHeight(); ++y) + { + const int* line = lineStart; + lineStart += lineStrideElements; + int numPoints = line[0]; + + if (--numPoints > 0) + { + int x = *++line; + jassert ((x >> 8) >= bounds.getX() && (x >> 8) < bounds.getRight()); + int levelAccumulator = 0; + + iterationCallback.setEdgeTableYPos (bounds.getY() + y); + + while (--numPoints >= 0) + { + const int level = *++line; + jassert (((unsigned int) level) < (unsigned int) 256); + const int endX = *++line; + jassert (endX >= x); + const int endOfRun = (endX >> 8); + + if (endOfRun == (x >> 8)) + { + // small segment within the same pixel, so just save it for the next + // time round.. + levelAccumulator += (endX - x) * level; + } + else + { + // plot the fist pixel of this segment, including any accumulated + // levels from smaller segments that haven't been drawn yet + levelAccumulator += (0xff - (x & 0xff)) * level; + levelAccumulator >>= 8; + x >>= 8; + + if (levelAccumulator > 0) + { + if (levelAccumulator >> 8) + levelAccumulator = 0xff; + + iterationCallback.handleEdgeTablePixel (x, levelAccumulator); + } + + // if there's a run of similar pixels, do it all in one go.. + if (level > 0) + { + jassert (endOfRun <= bounds.getRight()); + const int numPix = endOfRun - ++x; + + if (numPix > 0) + iterationCallback.handleEdgeTableLine (x, numPix, level); + } + + // save the bit at the end to be drawn next time round the loop. + levelAccumulator = (endX & 0xff) * level; + } + + x = endX; + } + + if (levelAccumulator > 0) + { + levelAccumulator >>= 8; + if (levelAccumulator >> 8) + levelAccumulator = 0xff; + + x >>= 8; + jassert (x >= bounds.getX() && x < bounds.getRight()); + iterationCallback.handleEdgeTablePixel (x, levelAccumulator); + } + } + } + } + + //============================================================================== + juce_UseDebuggingNewOperator + +private: + // table line format: number of points; point0 x, point0 levelDelta, point1 x, point1 levelDelta, etc + HeapBlock table; + Rectangle bounds; + int maxEdgesPerLine, lineStrideElements; + bool needToCheckEmptinesss; + + void addEdgePoint (int x, int y, int winding) throw(); + void remapTableForNumEdges (int newNumEdgesPerLine) throw(); + void intersectWithEdgeTableLine (int y, const int* otherLine) throw(); + void clipEdgeTableLineToRange (int* line, int x1, int x2) throw(); + void sanitiseLevels (bool useNonZeroWinding) throw(); + static void copyEdgeTableData (int* dest, int destLineStride, const int* src, int srcLineStride, int numLines) throw(); +}; + + +#endif // __JUCE_EDGETABLE_JUCEHEADER__ diff --git a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp index 7361a22a65..c3ef974fd5 100644 --- a/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp +++ b/src/gui/graphics/contexts/juce_LowLevelGraphicsSoftwareRenderer.cpp @@ -193,8 +193,8 @@ public: p2 = l2.getPointAlongLineProportionally (l2.findNearestPointTo (p1)); } - vertical = fabs (p1.getX() - p2.getX()) < 0.001f; - horizontal = fabs (p1.getY() - p2.getY()) < 0.001f; + vertical = std::abs (p1.getX() - p2.getX()) < 0.001f; + horizontal = std::abs (p1.getY() - p2.getY()) < 0.001f; if (vertical) { @@ -257,8 +257,8 @@ public: const float gdx = gradient.x1 - gradient.x2; const float gdy = gradient.y1 - gradient.y2; maxDist = gdx * gdx + gdy * gdy; - invScale = numEntries / sqrt (maxDist); - jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries); + invScale = numEntries / std::sqrt (maxDist); + jassert (roundToInt (std::sqrt (maxDist) * invScale) <= numEntries); } forcedinline void setY (const int y) throw() @@ -273,7 +273,7 @@ public: x *= x; x += dy; - return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)]; + return lookupTable [x >= maxDist ? numEntries : roundToInt (std::sqrt (x) * invScale)]; } protected: @@ -316,7 +316,7 @@ public: if (x >= maxDist) return lookupTable [numEntries]; else - return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))]; + return lookupTable [jmin (numEntries, roundToInt (std::sqrt (x) * invScale))]; } private: @@ -888,6 +888,7 @@ private: TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&); }; + //============================================================================== class LLGCSavedState { @@ -1475,7 +1476,10 @@ void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top { if (bottom > top) { - EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top)); + EdgeTable et (Rectangle ((float) (x + currentState->xOffset), + (float) (top + currentState->yOffset), + 1.0f, (float) (bottom - top))); + currentState->fillEdgeTable (image, et); } } @@ -1484,8 +1488,10 @@ void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double l { if (right > left) { - EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset), - (float) (right - left), 1.0f); + EdgeTable et (Rectangle ((float) (left + currentState->xOffset), + (float) (y + currentState->yOffset), + (float) (right - left), 1.0f)); + currentState->fillEdgeTable (image, et); } } diff --git a/src/gui/graphics/drawables/juce_SVGParser.cpp b/src/gui/graphics/drawables/juce_SVGParser.cpp index 1678c83b06..4720b80118 100644 --- a/src/gui/graphics/drawables/juce_SVGParser.cpp +++ b/src/gui/graphics/drawables/juce_SVGParser.cpp @@ -1180,13 +1180,13 @@ private: } else if (t.startsWithIgnoreCase ("skewX")) { - trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f, + trans = AffineTransform (1.0f, std::tan (numbers[0] * (float_Pi / 180.0f)), 0.0f, 0.0f, 1.0f, 0.0f); } else if (t.startsWithIgnoreCase ("skewY")) { trans = AffineTransform (1.0f, 0.0f, 0.0f, - tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f); + std::tan (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f); } result = trans.followedBy (result); @@ -1222,15 +1222,15 @@ private: if (s <= 1.0) { - c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2)) - / (( rx2 * yp2) + (ry2 * xp2)))); + c = std::sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2)) + / (( rx2 * yp2) + (ry2 * xp2)))); if (largeArc == sweep) c = -c; } else { - const double s2 = sqrt (s); + const double s2 = std::sqrt (s); rx *= s2; ry *= s2; rx2 = rx * rx; diff --git a/src/gui/graphics/geometry/juce_AffineTransform.cpp b/src/gui/graphics/geometry/juce_AffineTransform.cpp index 9ddedd73e2..6a3d73e05f 100644 --- a/src/gui/graphics/geometry/juce_AffineTransform.cpp +++ b/src/gui/graphics/geometry/juce_AffineTransform.cpp @@ -150,8 +150,8 @@ const AffineTransform AffineTransform::translation (const float dx, const AffineTransform AffineTransform::rotated (const float rad) const throw() { - const float cosRad = cosf (rad); - const float sinRad = sinf (rad); + const float cosRad = std::cos (rad); + const float sinRad = std::sin (rad); return followedBy (cosRad, -sinRad, 0, sinRad, cosRad, 0); @@ -159,8 +159,8 @@ const AffineTransform AffineTransform::rotated (const float rad) const throw() const AffineTransform AffineTransform::rotation (const float rad) throw() { - const float cosRad = cosf (rad); - const float sinRad = sinf (rad); + const float cosRad = std::cos (rad); + const float sinRad = std::sin (rad); return AffineTransform (cosRad, -sinRad, 0, sinRad, cosRad, 0); diff --git a/src/gui/graphics/geometry/juce_Path.cpp b/src/gui/graphics/geometry/juce_Path.cpp index 22072a3137..bbc4be0cbf 100644 --- a/src/gui/graphics/geometry/juce_Path.cpp +++ b/src/gui/graphics/geometry/juce_Path.cpp @@ -489,8 +489,8 @@ void Path::addCentredArc (const float centreX, const float centreY, if (startAsNewSubPath) { - float x = centreX + radiusX * sinf (angle); - float y = centreY - radiusY * cosf (angle); + float x = centreX + radiusX * std::sin (angle); + float y = centreY - radiusY * std::cos (angle); if (rotationOfEllipse != 0) rotation.transformPoint (x, y); @@ -505,8 +505,8 @@ void Path::addCentredArc (const float centreX, const float centreY, while (angle < toRadians) { - float x = centreX + radiusX * sinf (angle); - float y = centreY - radiusY * cosf (angle); + float x = centreX + radiusX * std::sin (angle); + float y = centreY - radiusY * std::cos (angle); if (rotationOfEllipse != 0) rotation.transformPoint (x, y); @@ -523,8 +523,8 @@ void Path::addCentredArc (const float centreX, const float centreY, while (angle > toRadians) { - float x = centreX + radiusX * sinf (angle); - float y = centreY - radiusY * cosf (angle); + float x = centreX + radiusX * std::sin (angle); + float y = centreY - radiusY * std::cos (angle); if (rotationOfEllipse != 0) rotation.transformPoint (x, y); @@ -535,8 +535,8 @@ void Path::addCentredArc (const float centreX, const float centreY, } } - float x = centreX + radiusX * sinf (toRadians); - float y = centreY - radiusY * cosf (toRadians); + float x = centreX + radiusX * std::sin (toRadians); + float y = centreY - radiusY * std::cos (toRadians); if (rotationOfEllipse != 0) rotation.transformPoint (x, y); @@ -556,12 +556,12 @@ void Path::addPieSegment (const float x, const float y, const float centreX = x + hw; const float centreY = y + hh; - startNewSubPath (centreX + hw * sinf (fromRadians), - centreY - hh * cosf (fromRadians)); + startNewSubPath (centreX + hw * std::sin (fromRadians), + centreY - hh * std::cos (fromRadians)); addArc (x, y, width, height, fromRadians, toRadians); - if (fabs (fromRadians - toRadians) > float_Pi * 1.999f) + if (std::abs (fromRadians - toRadians) > float_Pi * 1.999f) { closeSubPath(); @@ -570,8 +570,8 @@ void Path::addPieSegment (const float x, const float y, hw *= innerCircleProportionalSize; hh *= innerCircleProportionalSize; - startNewSubPath (centreX + hw * sinf (toRadians), - centreY - hh * cosf (toRadians)); + startNewSubPath (centreX + hw * std::sin (toRadians), + centreY - hh * std::cos (toRadians)); addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f, toRadians, fromRadians); @@ -685,8 +685,8 @@ void Path::addStar (const float centreX, { float angle = startAngle + i * angleBetweenPoints; - const float x = centreX + outerRadius * sinf (angle); - const float y = centreY - outerRadius * cosf (angle); + const float x = centreX + outerRadius * std::sin (angle); + const float y = centreY - outerRadius * std::cos (angle); if (i == 0) startNewSubPath (x, y); @@ -695,8 +695,8 @@ void Path::addStar (const float centreX, angle += angleBetweenPoints * 0.5f; - lineTo (centreX + innerRadius * sinf (angle), - centreY - innerRadius * cosf (angle)); + lineTo (centreX + innerRadius * std::sin (angle), + centreY - innerRadius * std::cos (angle)); } closeSubPath(); diff --git a/src/gui/graphics/geometry/juce_Path.h b/src/gui/graphics/geometry/juce_Path.h index 13cd443b5b..c158dd7482 100644 --- a/src/gui/graphics/geometry/juce_Path.h +++ b/src/gui/graphics/geometry/juce_Path.h @@ -30,7 +30,6 @@ #include "juce_Line.h" #include "juce_Rectangle.h" #include "../contexts/juce_Justification.h" -#include "../contexts/juce_EdgeTable.h" #include "../../../containers/juce_Array.h" #include "../../../io/streams/juce_InputStream.h" #include "../../../io/streams/juce_OutputStream.h" diff --git a/src/gui/graphics/geometry/juce_PathStrokeType.cpp b/src/gui/graphics/geometry/juce_PathStrokeType.cpp index d9530ad723..4015e4ddd3 100644 --- a/src/gui/graphics/geometry/juce_PathStrokeType.cpp +++ b/src/gui/graphics/geometry/juce_PathStrokeType.cpp @@ -240,13 +240,13 @@ namespace PathFunctions else { // curved joints - float angle1 = atan2f (x2 - midX, y2 - midY); - float angle2 = atan2f (x3 - midX, y3 - midY); + float angle1 = std::atan2 (x2 - midX, y2 - midY); + float angle2 = std::atan2 (x3 - midX, y3 - midY); const float angleIncrement = 0.1f; destPath.lineTo (x2, y2); - if (fabs (angle1 - angle2) > angleIncrement) + if (std::abs (angle1 - angle2) > angleIncrement) { if (angle2 > angle1 + float_Pi || (angle2 < angle1 && angle2 >= angle1 - float_Pi)) @@ -259,8 +259,8 @@ namespace PathFunctions angle1 -= angleIncrement; while (angle1 > angle2) { - destPath.lineTo (midX + width * sinf (angle1), - midY + width * cosf (angle1)); + destPath.lineTo (midX + width * std::sin (angle1), + midY + width * std::cos (angle1)); angle1 -= angleIncrement; } @@ -275,8 +275,8 @@ namespace PathFunctions angle1 += angleIncrement; while (angle1 < angle2) { - destPath.lineTo (midX + width * sinf (angle1), - midY + width * cosf (angle1)); + destPath.lineTo (midX + width * std::sin (angle1), + midY + width * std::cos (angle1)); angle1 += angleIncrement; } @@ -532,7 +532,7 @@ void PathStrokeType::createStrokedPath (Path& destPath, if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath()) { - const float len = sqrtf (hypotSquared); + const float len = std::sqrt (hypotSquared); if (len == 0) { diff --git a/src/gui/graphics/geometry/juce_Point.h b/src/gui/graphics/geometry/juce_Point.h index e14beeb3a9..826be96e50 100644 --- a/src/gui/graphics/geometry/juce_Point.h +++ b/src/gui/graphics/geometry/juce_Point.h @@ -121,7 +121,7 @@ public: The return value is the number of radians clockwise from the 3 o'clock direction, where this point is the centre and the other point is on the radius. */ - ValueType getAngleToPoint (const Point& other) const throw() { return (ValueType) atan2 (other.x - x, other.y - y); } + ValueType getAngleToPoint (const Point& other) const throw() { return (ValueType) std::atan2 (other.x - x, other.y - y); } /** Uses a transform to change the point's co-ordinates. This will only compile if ValueType = float! diff --git a/src/gui/graphics/geometry/juce_Rectangle.h b/src/gui/graphics/geometry/juce_Rectangle.h index 50fb25cdc1..bf53b38d7f 100644 --- a/src/gui/graphics/geometry/juce_Rectangle.h +++ b/src/gui/graphics/geometry/juce_Rectangle.h @@ -496,10 +496,10 @@ public: */ const Rectangle getSmallestIntegerContainer() const throw() { - const int x1 = (int) floorf ((float) x); - const int y1 = (int) floorf ((float) y); - const int x2 = (int) floorf ((float) (x + w + 0.9999f)); - const int y2 = (int) floorf ((float) (y + h + 0.9999f)); + const int x1 = (int) std::floor (static_cast (x)); + const int y1 = (int) std::floor (static_cast (y)); + const int x2 = (int) std::floor (static_cast (x + w + 0.9999f)); + const int y2 = (int) std::floor (static_cast (y + h + 0.9999f)); return Rectangle (x1, y1, x2 - x1, y2 - y1); } diff --git a/src/native/linux/juce_linux_Clipboard.cpp b/src/native/linux/juce_linux_Clipboard.cpp index 2d7b978161..12af4f5328 100644 --- a/src/native/linux/juce_linux_Clipboard.cpp +++ b/src/native/linux/juce_linux_Clipboard.cpp @@ -35,114 +35,105 @@ extern Display* display; extern Window juce_messageWindowHandle; -static String localClipboardContent; -static Atom atom_UTF8_STRING; -static Atom atom_CLIPBOARD; -static Atom atom_TARGETS; - -//============================================================================== -static void initSelectionAtoms() +namespace ClipboardHelpers { - static bool isInitialised = false; - if (! isInitialised) - { - atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False); - atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False); - atom_TARGETS = XInternAtom (display, "TARGETS", False); - } -} + static String localClipboardContent; + static Atom atom_UTF8_STRING; + static Atom atom_CLIPBOARD; + static Atom atom_TARGETS; -//============================================================================== -// Read the content of a window property as either a locale-dependent string or an utf8 string -// works only for strings shorter than 1000000 bytes -static String juce_readWindowProperty (Window window, Atom prop, - Atom fmt, // XA_STRING or UTF8_STRING - bool deleteAfterReading) -{ - String returnData; - char* clipData; - Atom actualType; - int actualFormat; - unsigned long numItems, bytesLeft; - - if (XGetWindowProperty (display, window, prop, - 0L /* offset */, 1000000 /* length (max) */, False, - AnyPropertyType /* format */, - &actualType, &actualFormat, &numItems, &bytesLeft, - (unsigned char**) &clipData) == Success) + //============================================================================== + static void initSelectionAtoms() { - if (actualType == atom_UTF8_STRING && actualFormat == 8) + static bool isInitialised = false; + if (! isInitialised) { - returnData = String::fromUTF8 (clipData, numItems); + atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False); + atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False); + atom_TARGETS = XInternAtom (display, "TARGETS", False); } - else if (actualType == XA_STRING && actualFormat == 8) + } + + //============================================================================== + // Read the content of a window property as either a locale-dependent string or an utf8 string + // works only for strings shorter than 1000000 bytes + static String readWindowProperty (Window window, Atom prop, Atom fmt) + { + String returnData; + char* clipData; + Atom actualType; + int actualFormat; + unsigned long numItems, bytesLeft; + + if (XGetWindowProperty (display, window, prop, + 0L /* offset */, 1000000 /* length (max) */, False, + AnyPropertyType /* format */, + &actualType, &actualFormat, &numItems, &bytesLeft, + (unsigned char**) &clipData) == Success) { - returnData = String (clipData, numItems); - } + if (actualType == atom_UTF8_STRING && actualFormat == 8) + returnData = String::fromUTF8 (clipData, numItems); + else if (actualType == XA_STRING && actualFormat == 8) + returnData = String (clipData, numItems); - if (clipData != 0) - XFree (clipData); + if (clipData != 0) + XFree (clipData); - jassert (bytesLeft == 0 || numItems == 1000000); - } + jassert (bytesLeft == 0 || numItems == 1000000); + } - if (deleteAfterReading) XDeleteProperty (display, window, prop); + return returnData; + } - return returnData; -} - -//============================================================================== -// Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */ -static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format) -{ - Atom property_name = XInternAtom (display, "JUCE_SEL", false); + //============================================================================== + // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */ + static bool requestSelectionContent (String& selectionContent, Atom selection, Atom requestedFormat) + { + Atom property_name = XInternAtom (display, "JUCE_SEL", false); - // The selection owner will be asked to set the JUCE_SEL property on the - // juce_messageWindowHandle with the selection content - XConvertSelection (display, selection, requested_format, property_name, - juce_messageWindowHandle, CurrentTime); + // The selection owner will be asked to set the JUCE_SEL property on the + // juce_messageWindowHandle with the selection content + XConvertSelection (display, selection, requestedFormat, property_name, + juce_messageWindowHandle, CurrentTime); - int timeoutMs = 200; // will wait at most for 200 ms + int count = 50; // will wait at most for 200 ms - do - { - XEvent event; - - if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event)) + while (--count >= 0) { - if (event.xselection.property == property_name) - { - jassert (event.xselection.requestor == juce_messageWindowHandle); - - selection_content = juce_readWindowProperty (event.xselection.requestor, - event.xselection.property, - requested_format, true); - return true; - } - else + XEvent event; + if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event)) { - return false; // the format we asked for was denied.. (event.xselection.property == None) + if (event.xselection.property == property_name) + { + jassert (event.xselection.requestor == juce_messageWindowHandle); + + selectionContent = readWindowProperty (event.xselection.requestor, + event.xselection.property, + requestedFormat); + return true; + } + else + { + return false; // the format we asked for was denied.. (event.xselection.property == None) + } } + + // not very elegant.. we could do a select() or something like that... + // however clipboard content requesting is inherently slow on x11, it + // often takes 50ms or more so... + Thread::sleep (4); } - // not very elegant.. we could do a select() or something like that... - // however clipboard content requesting is inherently slow on x11, it - // often takes 50ms or more so... - Thread::sleep (4); - timeoutMs -= 4; + return false; } - while (timeoutMs > 0); - - DBG("timeout for juce_requestSelectionContent"); - return false; } //============================================================================== // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events void juce_handleSelectionRequest (XSelectionRequestEvent &evt) { - initSelectionAtoms(); + ClipboardHelpers::initSelectionAtoms(); // the selection content is sent to the target window as a window property XSelectionEvent reply; @@ -157,32 +148,32 @@ void juce_handleSelectionRequest (XSelectionRequestEvent &evt) HeapBlock data; int propertyFormat = 0, numDataItems = 0; - if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD) + if (evt.selection == XA_PRIMARY || evt.selection == ClipboardHelpers::atom_CLIPBOARD) { if (evt.target == XA_STRING) { // format data according to system locale - numDataItems = localClipboardContent.getNumBytesAsCString() + 1; + numDataItems = ClipboardHelpers::localClipboardContent.getNumBytesAsCString() + 1; data.calloc (numDataItems + 1); - localClipboardContent.copyToCString (data, numDataItems); + ClipboardHelpers::localClipboardContent.copyToCString (data, numDataItems); propertyFormat = 8; // bits/item } - else if (evt.target == atom_UTF8_STRING) + else if (evt.target == ClipboardHelpers::atom_UTF8_STRING) { // translate to utf8 - numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1; + numDataItems = ClipboardHelpers::localClipboardContent.getNumBytesAsUTF8() + 1; data.calloc (numDataItems + 1); - localClipboardContent.copyToUTF8 (data, numDataItems); + ClipboardHelpers::localClipboardContent.copyToUTF8 (data, numDataItems); propertyFormat = 8; // bits/item } - else if (evt.target == atom_TARGETS) + else if (evt.target == ClipboardHelpers::atom_TARGETS) { // another application wants to know what we are able to send numDataItems = 2; propertyFormat = 32; // atoms are 32-bit data.calloc (numDataItems * 4); Atom* atoms = reinterpret_cast (data.getData()); - atoms[0] = atom_UTF8_STRING; + atoms[0] = ClipboardHelpers::atom_UTF8_STRING; atoms[1] = XA_STRING; } } @@ -212,16 +203,16 @@ void juce_handleSelectionRequest (XSelectionRequestEvent &evt) //============================================================================== void SystemClipboard::copyTextToClipboard (const String& clipText) { - initSelectionAtoms(); - localClipboardContent = clipText; + ClipboardHelpers::initSelectionAtoms(); + ClipboardHelpers::localClipboardContent = clipText; XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime); - XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime); + XSetSelectionOwner (display, ClipboardHelpers::atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime); } const String SystemClipboard::getTextFromClipboard() { - initSelectionAtoms(); + ClipboardHelpers::initSelectionAtoms(); /* 1) try to read from the "CLIPBOARD" selection first (the "high level" clipboard that is supposed to be filled by ctrl-C @@ -238,7 +229,7 @@ const String SystemClipboard::getTextFromClipboard() if ((selectionOwner = XGetSelectionOwner (display, selection)) == None) { - selection = atom_CLIPBOARD; + selection = ClipboardHelpers::atom_CLIPBOARD; selectionOwner = XGetSelectionOwner (display, selection); } @@ -246,17 +237,17 @@ const String SystemClipboard::getTextFromClipboard() { if (selectionOwner == juce_messageWindowHandle) { - content = localClipboardContent; + content = ClipboardHelpers::localClipboardContent; } else { // first try: we want an utf8 string - bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING); + bool ok = ClipboardHelpers::requestSelectionContent (content, selection, ClipboardHelpers::atom_UTF8_STRING); if (! ok) { // second chance, ask for a good old locale-dependent string .. - ok = juce_requestSelectionContent (content, selection, XA_STRING); + ok = ClipboardHelpers::requestSelectionContent (content, selection, XA_STRING); } } } diff --git a/src/native/linux/juce_linux_Fonts.cpp b/src/native/linux/juce_linux_Fonts.cpp index 8e2d313d73..caf5f9c007 100644 --- a/src/native/linux/juce_linux_Fonts.cpp +++ b/src/native/linux/juce_linux_Fonts.cpp @@ -145,7 +145,7 @@ public: return faces[i]; if (! create) - return NULL; + return 0; FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName); faces.add (newFace); diff --git a/src/native/linux/juce_linux_Messaging.cpp b/src/native/linux/juce_linux_Messaging.cpp index 94298cd631..606209b764 100644 --- a/src/native/linux/juce_linux_Messaging.cpp +++ b/src/native/linux/juce_linux_Messaging.cpp @@ -32,9 +32,8 @@ #define JUCE_DEBUG_XERRORS 1 #endif -Display* display = 0; // This is also referenced from WindowDriver.cpp +Display* display = 0; Window juce_messageWindowHandle = None; - XContext windowHandleXContext; // This is referenced from Windowing.cpp extern void juce_windowMessageReceive (XEvent* event); // Defined in Windowing.cpp @@ -246,15 +245,15 @@ void MessageManager::doPlatformSpecificInitialisation() saction.sa_handler = signalHandler; saction.sa_mask = maskSet; saction.sa_flags = 0; - sigaction (SIGINT, &saction, NULL); + sigaction (SIGINT, &saction, 0); #ifndef _DEBUG // Setup signal handlers for various fatal errors - sigaction (SIGILL, &saction, NULL); - sigaction (SIGBUS, &saction, NULL); - sigaction (SIGFPE, &saction, NULL); - sigaction (SIGSEGV, &saction, NULL); - sigaction (SIGSYS, &saction, NULL); + sigaction (SIGILL, &saction, 0); + sigaction (SIGBUS, &saction, 0); + sigaction (SIGFPE, &saction, 0); + sigaction (SIGSEGV, &saction, 0); + sigaction (SIGSYS, &saction, 0); #endif // Create the internal message queue diff --git a/src/native/linux/juce_linux_SystemStats.cpp b/src/native/linux/juce_linux_SystemStats.cpp index a36868a013..a4797ef9d4 100644 --- a/src/native/linux/juce_linux_SystemStats.cpp +++ b/src/native/linux/juce_linux_SystemStats.cpp @@ -29,22 +29,23 @@ //============================================================================== -void Logger::outputDebugString (const String& text) throw() +void Logger::outputDebugString (const String& text) { std::cerr << text << std::endl; } -SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw() +//============================================================================== +SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() { return Linux; } -const String SystemStats::getOperatingSystemName() throw() +const String SystemStats::getOperatingSystemName() { return "Linux"; } -bool SystemStats::isOperatingSystem64Bit() throw() +bool SystemStats::isOperatingSystem64Bit() { #if JUCE_64BIT return true; @@ -54,84 +55,84 @@ bool SystemStats::isOperatingSystem64Bit() throw() #endif } -static const String getCpuInfo (const char* key, bool lastOne = false) throw() +//============================================================================== +static const String juce_getCpuInfo (const char* const key) { - String info; - char buf [256]; - - FILE* f = fopen ("/proc/cpuinfo", "r"); + StringArray lines; + lines.addLines (File ("/proc/cpuinfo").loadFileAsString()); - while (f != 0 && fgets (buf, sizeof(buf), f)) - { - if (strncmp (buf, key, strlen (key)) == 0) - { - char* p = buf; + for (int i = lines.size(); --i >= 0;) // (NB - it's important that this runs in reverse order) + if (lines[i].startsWithIgnoreCase (key)) + return lines[i].fromFirstOccurrenceOf (":", false, false).trim(); - while (*p && *p != '\n') - ++p; + return String::empty; +} - if (*p != 0) - *p = 0; +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"); } - p = buf; +const String SystemStats::getCpuVendor() +{ + return juce_getCpuInfo ("vendor_id"); +} - while (*p != 0 && *p != ':') - ++p; +int SystemStats::getCpuSpeedInMegaherz() +{ + return roundToInt (juce_getCpuInfo ("cpu MHz").getFloatValue()); +} - if (*p != 0 && *(p + 1) != 0) - info = p + 2; +int SystemStats::getMemorySizeInMegabytes() +{ + struct sysinfo sysi; - if (! lastOne) - break; - } - } + if (sysinfo (&sysi) == 0) + return (sysi.totalram * sysi.mem_unit / (1024 * 1024)); - fclose (f); - return info; + return 0; } -bool SystemStats::hasMMX() throw() +int SystemStats::getPageSize() { - return getCpuInfo ("flags").contains ("mmx"); + return sysconf (_SC_PAGESIZE); } -bool SystemStats::hasSSE() throw() +int SystemStats::getNumCpus() { - return getCpuInfo ("flags").contains ("sse"); + return juce_getCpuInfo ("processor").getIntValue() + 1; } -bool SystemStats::hasSSE2() throw() +//============================================================================== +const String SystemStats::getLogonName() { - return getCpuInfo ("flags").contains ("sse2"); -} + const char* user = getenv ("USER"); -bool SystemStats::has3DNow() throw() -{ - return getCpuInfo ("flags").contains ("3dnow"); + if (user == 0) + { + struct passwd* const pw = getpwuid (getuid()); + if (pw != 0) + user = pw->pw_name; + } + + return String::fromUTF8 (user); } -const String SystemStats::getCpuVendor() throw() +const String SystemStats::getFullUserName() { - return getCpuInfo ("vendor_id"); + return getLogonName(); } -int SystemStats::getCpuSpeedInMegaherz() throw() +//============================================================================== +void SystemStats::initialiseStats() { - const String speed (getCpuInfo ("cpu MHz")); - - return (int) (speed.getFloatValue() + 0.5f); } -int SystemStats::getMemorySizeInMegabytes() throw() +void PlatformUtilities::fpuReset() { - struct sysinfo sysi; - - if (sysinfo (&sysi) == 0) - return (sysi.totalram * sysi.mem_unit / (1024 * 1024)); - - return 0; } +//============================================================================== uint32 juce_millisecondsSinceStartup() throw() { static unsigned int calibrate = 0; @@ -174,67 +175,17 @@ int64 Time::getHighResolutionTicks() throw() int64 Time::getHighResolutionTicksPerSecond() throw() { - // Microseconds - return 1000000; + return 1000000; // (microseconds) } -bool Time::setSystemTimeToThisTime() const throw() +bool Time::setSystemTimeToThisTime() const { timeval t; t.tv_sec = millisSinceEpoch % 1000000; t.tv_usec = millisSinceEpoch - t.tv_sec; - return settimeofday (&t, NULL) ? false : true; -} - -int SystemStats::getPageSize() throw() -{ - static int systemPageSize = 0; - - if (systemPageSize == 0) - systemPageSize = sysconf (_SC_PAGESIZE); - - return systemPageSize; -} - -int SystemStats::getNumCpus() throw() -{ - const int lastCpu = getCpuInfo ("processor", true).getIntValue(); - - return lastCpu + 1; + return settimeofday (&t, 0) ? false : true; } -//============================================================================== -const String SystemStats::getLogonName() -{ - const char* user = getenv ("USER"); - - if (user == 0) - { - struct passwd* const pw = getpwuid (getuid()); - if (pw != 0) - user = pw->pw_name; - } - - return String::fromUTF8 (user); -} - -const String SystemStats::getFullUserName() -{ - return getLogonName(); -} - -//============================================================================== -void SystemStats::initialiseStats() throw() -{ - // Process starts off as root when running suid - Process::lowerPrivilege(); - - String s (SystemStats::getJUCEVersion()); -} - -void PlatformUtilities::fpuReset() -{ -} #endif diff --git a/src/native/linux/juce_linux_Threads.cpp b/src/native/linux/juce_linux_Threads.cpp index a32760b1b0..02813854b7 100644 --- a/src/native/linux/juce_linux_Threads.cpp +++ b/src/native/linux/juce_linux_Threads.cpp @@ -37,9 +37,6 @@ void JUCE_API juce_threadEntryPoint (void*); void* threadEntryProc (void* value) { - // New threads start off as root when running suid - Process::lowerPrivilege(); - juce_threadEntryPoint (value); return 0; } @@ -60,7 +57,7 @@ void* juce_createThread (void* userData) void juce_killThread (void* handle) { if (handle != 0) - pthread_cancel ((pthread_t)handle); + pthread_cancel ((pthread_t) handle); } void juce_setCurrentThreadName (const String& /*name*/) @@ -72,26 +69,25 @@ Thread::ThreadID Thread::getCurrentThreadId() return (ThreadID) pthread_self(); } -/* - * This is all a bit non-ideal... the trouble is that on Linux you - * need to call setpriority to affect the dynamic priority for - * non-realtime processes, but this requires the pid, which is not - * accessible from the pthread_t. We could get it by calling getpid - * once each thread has started, but then we would need a list of - * running threads etc etc. - * Also there is no such thing as IDLE priority on Linux. - * For the moment, map idle, low and normal process priorities to - * SCHED_OTHER, with the thread priority ignored for these classes. - * Map high priority processes to the lower half of the SCHED_RR - * range, and realtime to the upper half - */ - -// priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the -// priority of the current thread +/* This is all a bit non-ideal... the trouble is that on Linux you + need to call setpriority to affect the dynamic priority for + non-realtime processes, but this requires the pid, which is not + accessible from the pthread_t. We could get it by calling getpid + once each thread has started, but then we would need a list of + running threads etc etc. + Also there is no such thing as IDLE priority on Linux. + For the moment, map idle, low and normal process priorities to + SCHED_OTHER, with the thread priority ignored for these classes. + Map high priority processes to the lower half of the SCHED_RR + range, and realtime to the upper half. + + priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the + priority of the current thread +*/ bool juce_setThreadPriority (void* handle, int priority) { struct sched_param param; - int policy, maxp, minp, pri; + int policy; if (handle == 0) handle = (void*) pthread_self(); @@ -99,20 +95,17 @@ bool juce_setThreadPriority (void* handle, int priority) if (pthread_getschedparam ((pthread_t) handle, &policy, ¶m) == 0 && policy != SCHED_OTHER) { - minp = sched_get_priority_min(policy); - maxp = sched_get_priority_max(policy); + int minp = sched_get_priority_min (policy); + int maxp = sched_get_priority_max (policy); - pri = ((maxp - minp) / 2) * (priority - 1) / 9; + int pri = ((maxp - minp) / 2) * (priority - 1) / 9; if (param.__sched_priority >= (minp + (maxp - minp) / 2)) - // Realtime process priority - param.__sched_priority = minp + ((maxp - minp) / 2) + pri; + param.__sched_priority = minp + ((maxp - minp) / 2) + pri; // (realtime) else - // High process priority - param.__sched_priority = minp + pri; + param.__sched_priority = minp + pri; // (high) param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11); - return pthread_setschedparam ((pthread_t) handle, policy, ¶m) == 0; } diff --git a/src/native/mac/juce_mac_Debugging.mm b/src/native/mac/juce_mac_Debugging.mm index ed60cb857e..74a0d8e303 100644 --- a/src/native/mac/juce_mac_Debugging.mm +++ b/src/native/mac/juce_mac_Debugging.mm @@ -28,7 +28,7 @@ #if JUCE_INCLUDED_FILE //============================================================================== -void Logger::outputDebugString (const String& text) throw() +void Logger::outputDebugString (const String& text) { std::cerr << text << std::endl; } diff --git a/src/native/mac/juce_mac_Fonts.mm b/src/native/mac/juce_mac_Fonts.mm index 20d1e6ccc7..2b508183a5 100644 --- a/src/native/mac/juce_mac_Fonts.mm +++ b/src/native/mac/juce_mac_Fonts.mm @@ -117,8 +117,8 @@ public: [nsFont retain]; - ascent = fabsf ((float) [nsFont ascender]); - float totalSize = ascent + fabsf ((float) [nsFont descender]); + ascent = std::abs ((float) [nsFont ascender]); + float totalSize = ascent + std::abs ((float) [nsFont descender]); ascent /= totalSize; pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize); @@ -137,7 +137,7 @@ public: fontRef = CGFontCreateWithPlatformFont (&atsFont); - const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]); + const float totalHeight = std::abs ([nsFont ascender]) + std::abs ([nsFont descender]); unitsToHeightScaleFactor = 1.0f / totalHeight; fontHeightToCGSizeFactor = 1024.0f / totalHeight; #else @@ -151,7 +151,7 @@ public: fontRef = CGFontCreateWithPlatformFont (&atsFont); - const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]); + const float totalHeight = std::abs ([nsFont ascender]) + std::abs ([nsFont descender]); unitsToHeightScaleFactor = 1.0f / totalHeight; fontHeightToCGSizeFactor = 1024.0f / totalHeight; } diff --git a/src/native/mac/juce_mac_SystemStats.mm b/src/native/mac/juce_mac_SystemStats.mm index bc4eec85ff..4576055bf6 100644 --- a/src/native/mac/juce_mac_SystemStats.mm +++ b/src/native/mac/juce_mac_SystemStats.mm @@ -79,7 +79,7 @@ namespace SystemStatsHelpers } //============================================================================== -void SystemStats::initialiseStats() throw() +void SystemStats::initialiseStats() { using namespace SystemStatsHelpers; static bool initialised = false; @@ -123,17 +123,17 @@ void SystemStats::initialiseStats() throw() } //============================================================================== -SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw() +SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() { return MacOSX; } -const String SystemStats::getOperatingSystemName() throw() +const String SystemStats::getOperatingSystemName() { return "Mac OS X"; } -bool SystemStats::isOperatingSystem64Bit() throw() +bool SystemStats::isOperatingSystem64Bit() { #if JUCE_64BIT return true; @@ -143,7 +143,7 @@ bool SystemStats::isOperatingSystem64Bit() throw() #endif } -int SystemStats::getMemorySizeInMegabytes() throw() +int SystemStats::getMemorySizeInMegabytes() { uint64 mem = 0; size_t memSize = sizeof (mem); @@ -152,7 +152,7 @@ int SystemStats::getMemorySizeInMegabytes() throw() return (int) (mem / (1024 * 1024)); } -bool SystemStats::hasMMX() throw() +bool SystemStats::hasMMX() { #if JUCE_INTEL return SystemStatsHelpers::cpuFlags.hasMMX; @@ -161,7 +161,7 @@ bool SystemStats::hasMMX() throw() #endif } -bool SystemStats::hasSSE() throw() +bool SystemStats::hasSSE() { #if JUCE_INTEL return SystemStatsHelpers::cpuFlags.hasSSE; @@ -170,7 +170,7 @@ bool SystemStats::hasSSE() throw() #endif } -bool SystemStats::hasSSE2() throw() +bool SystemStats::hasSSE2() { #if JUCE_INTEL return SystemStatsHelpers::cpuFlags.hasSSE2; @@ -179,7 +179,7 @@ bool SystemStats::hasSSE2() throw() #endif } -bool SystemStats::has3DNow() throw() +bool SystemStats::has3DNow() { #if JUCE_INTEL return SystemStatsHelpers::cpuFlags.has3DNow; @@ -188,7 +188,7 @@ bool SystemStats::has3DNow() throw() #endif } -const String SystemStats::getCpuVendor() throw() +const String SystemStats::getCpuVendor() { #if JUCE_INTEL char v [16]; @@ -199,7 +199,7 @@ const String SystemStats::getCpuVendor() throw() #endif } -int SystemStats::getCpuSpeedInMegaherz() throw() +int SystemStats::getCpuSpeedInMegaherz() { uint64 speedHz = 0; size_t speedSize = sizeof (speedHz); @@ -213,7 +213,7 @@ int SystemStats::getCpuSpeedInMegaherz() throw() return (int) (speedHz / 1000000); } -int SystemStats::getNumCpus() throw() +int SystemStats::getNumCpus() { #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5) return (int) [[NSProcessInfo processInfo] activeProcessorCount]; @@ -254,19 +254,14 @@ int64 Time::getHighResolutionTicksPerSecond() throw() return SystemStatsHelpers::highResTimerFrequency; } -int64 SystemStats::getClockCycleCounter() throw() -{ - return (int64) mach_absolute_time(); -} - -bool Time::setSystemTimeToThisTime() const throw() +bool Time::setSystemTimeToThisTime() const { jassertfalse return false; } //============================================================================== -int SystemStats::getPageSize() throw() +int SystemStats::getPageSize() { return (int) NSPageSize(); } diff --git a/src/native/windows/juce_win32_SystemStats.cpp b/src/native/windows/juce_win32_SystemStats.cpp index f94fbe36db..0ac79bb436 100644 --- a/src/native/windows/juce_win32_SystemStats.cpp +++ b/src/native/windows/juce_win32_SystemStats.cpp @@ -31,7 +31,7 @@ extern void juce_initialiseThreadEvents(); //============================================================================== -void Logger::outputDebugString (const String& text) throw() +void Logger::outputDebugString (const String& text) { OutputDebugString (text + "\n"); } @@ -49,7 +49,7 @@ static double hiResTicksScaleFactor; #pragma intrinsic (__cpuid) #pragma intrinsic (__rdtsc) -const String SystemStats::getCpuVendor() throw() +const String SystemStats::getCpuVendor() { int info [4]; __cpuid (info, 0); @@ -103,7 +103,7 @@ static void juce_getCpuVendor (char* const v) memcpy (v, vendor, 16); } -const String SystemStats::getCpuVendor() throw() +const String SystemStats::getCpuVendor() { char v [16]; juce_getCpuVendor (v); @@ -123,27 +123,27 @@ struct CPUFlags static CPUFlags cpuFlags; -bool SystemStats::hasMMX() throw() +bool SystemStats::hasMMX() { return cpuFlags.hasMMX; } -bool SystemStats::hasSSE() throw() +bool SystemStats::hasSSE() { return cpuFlags.hasSSE; } -bool SystemStats::hasSSE2() throw() +bool SystemStats::hasSSE2() { return cpuFlags.hasSSE2; } -bool SystemStats::has3DNow() throw() +bool SystemStats::has3DNow() { return cpuFlags.has3DNow; } -void SystemStats::initialiseStats() throw() +void SystemStats::initialiseStats() { juce_initialiseThreadEvents(); @@ -176,7 +176,7 @@ void SystemStats::initialiseStats() throw() } //============================================================================== -SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw() +SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() { OSVERSIONINFO info; info.dwOSVersionInfoSize = sizeof (info); @@ -200,7 +200,7 @@ SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw() return UnknownOS; } -const String SystemStats::getOperatingSystemName() throw() +const String SystemStats::getOperatingSystemName() { const char* name = "Unknown OS"; @@ -217,7 +217,7 @@ const String SystemStats::getOperatingSystemName() throw() return name; } -bool SystemStats::isOperatingSystem64Bit() throw() +bool SystemStats::isOperatingSystem64Bit() { #ifdef _WIN64 return true; @@ -236,7 +236,7 @@ bool SystemStats::isOperatingSystem64Bit() throw() //============================================================================== -int SystemStats::getMemorySizeInMegabytes() throw() +int SystemStats::getMemorySizeInMegabytes() { MEMORYSTATUSEX mem; mem.dwLength = sizeof (mem); @@ -244,7 +244,7 @@ int SystemStats::getMemorySizeInMegabytes() throw() return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1; } -int SystemStats::getNumCpus() throw() +int SystemStats::getNumCpus() { SYSTEM_INFO systemInfo; GetSystemInfo (&systemInfo); @@ -287,7 +287,7 @@ int64 Time::getHighResolutionTicksPerSecond() throw() return hiResTicksPerSecond; } -int64 SystemStats::getClockCycleCounter() throw() +static int64 juce_getClockCycleCounter() throw() { #if JUCE_USE_INTRINSICS // MS intrinsics version... @@ -326,9 +326,9 @@ int64 SystemStats::getClockCycleCounter() throw() #endif } -int SystemStats::getCpuSpeedInMegaherz() throw() +int SystemStats::getCpuSpeedInMegaherz() { - const int64 cycles = SystemStats::getClockCycleCounter(); + const int64 cycles = juce_getClockCycleCounter(); const uint32 millis = Time::getMillisecondCounter(); int lastResult = 0; @@ -338,7 +338,7 @@ int SystemStats::getCpuSpeedInMegaherz() throw() while (--n > 0) {} const uint32 millisElapsed = Time::getMillisecondCounter() - millis; - const int64 cyclesNow = SystemStats::getClockCycleCounter(); + const int64 cyclesNow = juce_getClockCycleCounter(); if (millisElapsed > 80) { @@ -354,7 +354,7 @@ int SystemStats::getCpuSpeedInMegaherz() throw() //============================================================================== -bool Time::setSystemTimeToThisTime() const throw() +bool Time::setSystemTimeToThisTime() const { SYSTEMTIME st; @@ -373,7 +373,7 @@ bool Time::setSystemTimeToThisTime() const throw() && SetLocalTime (&st) != 0; } -int SystemStats::getPageSize() throw() +int SystemStats::getPageSize() { SYSTEM_INFO systemInfo; GetSystemInfo (&systemInfo); diff --git a/src/text/juce_String.cpp b/src/text/juce_String.cpp index ce7c767f40..ab1ce6488e 100644 --- a/src/text/juce_String.cpp +++ b/src/text/juce_String.cpp @@ -367,7 +367,7 @@ namespace NumberToStringConverters { juce_wchar* const end = buffer + numChars; juce_wchar* t = end; - int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5); + int64 v = (int64) (pow (10.0, numDecPlaces) * std::abs (n) + 0.5); *--t = (juce_wchar) 0; while (numDecPlaces >= 0 || v > 0)