| @@ -257,7 +257,7 @@ AudioDemoRecordPage::AudioDemoRecordPage (AudioDeviceManager& deviceManager_) | |||||
| recordButton->setButtonText (T("Record")); | recordButton->setButtonText (T("Record")); | ||||
| recordButton->addButtonListener (this); | recordButton->addButtonListener (this); | ||||
| recordButton->setColour (TextButton::buttonColourId, Colour (0xffff5c5c)); | recordButton->setColour (TextButton::buttonColourId, Colour (0xffff5c5c)); | ||||
| recordButton->setColour (TextButton::textColourId, Colours::black); | |||||
| recordButton->setColour (TextButton::textColourOffId, Colours::black); | |||||
| //[UserPreSize] | //[UserPreSize] | ||||
| @@ -263,7 +263,7 @@ public: | |||||
| ColourSelector colourSelector2; | ColourSelector colourSelector2; | ||||
| colourSelector2.setName (T("text")); | colourSelector2.setName (T("text")); | ||||
| colourSelector2.setCurrentColour (findColour (TextButton::textColourId)); | |||||
| colourSelector2.setCurrentColour (findColour (TextButton::textColourOffId)); | |||||
| colourSelector2.addChangeListener (this); | colourSelector2.addChangeListener (this); | ||||
| // and add the selectors as custom menu items to a PopupMenu, putting | // and add the selectors as custom menu items to a PopupMenu, putting | ||||
| @@ -285,7 +285,7 @@ public: | |||||
| ColourSelector* cs = (ColourSelector*) source; | ColourSelector* cs = (ColourSelector*) source; | ||||
| if (cs->getName() == T("text")) | if (cs->getName() == T("text")) | ||||
| setColour (TextButton::textColourId, cs->getCurrentColour()); | |||||
| setColour (TextButton::textColourOffId, cs->getCurrentColour()); | |||||
| else | else | ||||
| setColour (TextButton::buttonColourId, cs->getCurrentColour()); | setColour (TextButton::buttonColourId, cs->getCurrentColour()); | ||||
| } | } | ||||
| @@ -42,7 +42,8 @@ public: | |||||
| { | { | ||||
| registerColour (TextButton::buttonColourId, "background (normal)", "bgColOff"); | registerColour (TextButton::buttonColourId, "background (normal)", "bgColOff"); | ||||
| registerColour (TextButton::buttonOnColourId, "background (on)", "bgColOn"); | registerColour (TextButton::buttonOnColourId, "background (on)", "bgColOn"); | ||||
| registerColour (TextButton::textColourId, "text colour", "textCol"); | |||||
| registerColour (TextButton::textColourOnId, "text colour (normal)", "textCol"); | |||||
| registerColour (TextButton::textColourOffId, "text colour (on)", "textColOn"); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -32,24 +32,24 @@ BEGIN_JUCE_NAMESPACE | |||||
| //============================================================================== | //============================================================================== | ||||
| MidiBuffer::MidiBuffer() throw() | MidiBuffer::MidiBuffer() throw() | ||||
| : ArrayAllocationBase <uint8> (32), | |||||
| : data (32), | |||||
| bytesUsed (0) | bytesUsed (0) | ||||
| { | { | ||||
| } | } | ||||
| MidiBuffer::MidiBuffer (const MidiMessage& message) throw() | MidiBuffer::MidiBuffer (const MidiMessage& message) throw() | ||||
| : ArrayAllocationBase <uint8> (32), | |||||
| : data (32), | |||||
| bytesUsed (0) | bytesUsed (0) | ||||
| { | { | ||||
| addEvent (message, 0); | addEvent (message, 0); | ||||
| } | } | ||||
| MidiBuffer::MidiBuffer (const MidiBuffer& other) throw() | MidiBuffer::MidiBuffer (const MidiBuffer& other) throw() | ||||
| : ArrayAllocationBase <uint8> (32), | |||||
| : data (32), | |||||
| bytesUsed (other.bytesUsed) | bytesUsed (other.bytesUsed) | ||||
| { | { | ||||
| ensureAllocatedSize (bytesUsed); | |||||
| memcpy (elements, other.elements, bytesUsed); | |||||
| data.ensureAllocatedSize (bytesUsed); | |||||
| memcpy (data.elements, other.data.elements, bytesUsed); | |||||
| } | } | ||||
| const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() | const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() | ||||
| @@ -57,10 +57,10 @@ const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() | |||||
| if (this != &other) | if (this != &other) | ||||
| { | { | ||||
| bytesUsed = other.bytesUsed; | bytesUsed = other.bytesUsed; | ||||
| ensureAllocatedSize (bytesUsed); | |||||
| data.ensureAllocatedSize (bytesUsed); | |||||
| if (bytesUsed > 0) | if (bytesUsed > 0) | ||||
| memcpy (elements, other.elements, bytesUsed); | |||||
| memcpy (data.elements, other.data.elements, bytesUsed); | |||||
| } | } | ||||
| return *this; | return *this; | ||||
| @@ -68,9 +68,9 @@ const MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw() | |||||
| void MidiBuffer::swap (MidiBuffer& other) | void MidiBuffer::swap (MidiBuffer& other) | ||||
| { | { | ||||
| swapVariables <uint8*> (this->elements, other.elements); | |||||
| swapVariables <int> (this->numAllocated, other.numAllocated); | |||||
| swapVariables <int> (this->bytesUsed, other.bytesUsed); | |||||
| swapVariables <uint8*> (data.elements, other.data.elements); | |||||
| swapVariables <int> (data.numAllocated, other.data.numAllocated); | |||||
| swapVariables <int> (bytesUsed, other.bytesUsed); | |||||
| } | } | ||||
| MidiBuffer::~MidiBuffer() throw() | MidiBuffer::~MidiBuffer() throw() | ||||
| @@ -85,12 +85,12 @@ void MidiBuffer::clear() throw() | |||||
| void MidiBuffer::clear (const int startSample, | void MidiBuffer::clear (const int startSample, | ||||
| const int numSamples) throw() | const int numSamples) throw() | ||||
| { | { | ||||
| uint8* const start = findEventAfter (elements, startSample - 1); | |||||
| uint8* const start = findEventAfter (data.elements, startSample - 1); | |||||
| uint8* const end = findEventAfter (start, startSample + numSamples - 1); | uint8* const end = findEventAfter (start, startSample + numSamples - 1); | ||||
| if (end > start) | if (end > start) | ||||
| { | { | ||||
| const size_t bytesToMove = (size_t) (bytesUsed - (end - elements)); | |||||
| const size_t bytesToMove = (size_t) (bytesUsed - (end - data.elements)); | |||||
| if (bytesToMove > 0) | if (bytesToMove > 0) | ||||
| memmove (start, end, bytesToMove); | memmove (start, end, bytesToMove); | ||||
| @@ -144,10 +144,10 @@ void MidiBuffer::addEvent (const uint8* const newData, | |||||
| if (numBytes > 0) | if (numBytes > 0) | ||||
| { | { | ||||
| ensureAllocatedSize (bytesUsed + numBytes + 6); | |||||
| data.ensureAllocatedSize (bytesUsed + numBytes + 6); | |||||
| uint8* d = findEventAfter (elements, sampleNumber); | |||||
| const size_t bytesToMove = (size_t) (bytesUsed - (d - elements)); | |||||
| uint8* d = findEventAfter (data.elements, sampleNumber); | |||||
| const size_t bytesToMove = (size_t) (bytesUsed - (d - data.elements)); | |||||
| if (bytesToMove > 0) | if (bytesToMove > 0) | ||||
| memmove (d + numBytes + 6, | memmove (d + numBytes + 6, | ||||
| @@ -191,8 +191,8 @@ bool MidiBuffer::isEmpty() const throw() | |||||
| int MidiBuffer::getNumEvents() const throw() | int MidiBuffer::getNumEvents() const throw() | ||||
| { | { | ||||
| int n = 0; | int n = 0; | ||||
| const uint8* d = elements; | |||||
| const uint8* const end = elements + bytesUsed; | |||||
| const uint8* d = data.elements; | |||||
| const uint8* const end = data.elements + bytesUsed; | |||||
| while (d < end) | while (d < end) | ||||
| { | { | ||||
| @@ -206,7 +206,7 @@ int MidiBuffer::getNumEvents() const throw() | |||||
| int MidiBuffer::getFirstEventTime() const throw() | int MidiBuffer::getFirstEventTime() const throw() | ||||
| { | { | ||||
| return (bytesUsed > 0) ? *(const int*) elements : 0; | |||||
| return (bytesUsed > 0) ? *(const int*) data.elements : 0; | |||||
| } | } | ||||
| int MidiBuffer::getLastEventTime() const throw() | int MidiBuffer::getLastEventTime() const throw() | ||||
| @@ -214,7 +214,7 @@ int MidiBuffer::getLastEventTime() const throw() | |||||
| if (bytesUsed == 0) | if (bytesUsed == 0) | ||||
| return 0; | return 0; | ||||
| const uint8* d = elements; | |||||
| const uint8* d = data.elements; | |||||
| const uint8* const endData = d + bytesUsed; | const uint8* const endData = d + bytesUsed; | ||||
| for (;;) | for (;;) | ||||
| @@ -230,7 +230,7 @@ int MidiBuffer::getLastEventTime() const throw() | |||||
| uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw() | uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw() | ||||
| { | { | ||||
| const uint8* const endData = elements + bytesUsed; | |||||
| const uint8* const endData = data.elements + bytesUsed; | |||||
| while (d < endData && *(int*) d <= samplePosition) | while (d < endData && *(int*) d <= samplePosition) | ||||
| { | { | ||||
| @@ -244,7 +244,7 @@ uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const thr | |||||
| //============================================================================== | //============================================================================== | ||||
| MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw() | MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw() | ||||
| : buffer (buffer_), | : buffer (buffer_), | ||||
| data (buffer_.elements) | |||||
| data (buffer_.data.elements) | |||||
| { | { | ||||
| } | } | ||||
| @@ -255,8 +255,8 @@ MidiBuffer::Iterator::~Iterator() throw() | |||||
| //============================================================================== | //============================================================================== | ||||
| void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw() | void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw() | ||||
| { | { | ||||
| data = buffer.elements; | |||||
| const uint8* dataEnd = buffer.elements + buffer.bytesUsed; | |||||
| data = buffer.data.elements; | |||||
| const uint8* dataEnd = buffer.data.elements + buffer.bytesUsed; | |||||
| while (data < dataEnd && *(int*) data < samplePosition) | while (data < dataEnd && *(int*) data < samplePosition) | ||||
| { | { | ||||
| @@ -269,7 +269,7 @@ bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, | |||||
| int& numBytes, | int& numBytes, | ||||
| int& samplePosition) throw() | int& samplePosition) throw() | ||||
| { | { | ||||
| if (data >= buffer.elements + buffer.bytesUsed) | |||||
| if (data >= buffer.data.elements + buffer.bytesUsed) | |||||
| return false; | return false; | ||||
| samplePosition = *(int*) data; | samplePosition = *(int*) data; | ||||
| @@ -285,7 +285,7 @@ bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData, | |||||
| bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, | bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result, | ||||
| int& samplePosition) throw() | int& samplePosition) throw() | ||||
| { | { | ||||
| if (data >= buffer.elements + buffer.bytesUsed) | |||||
| if (data >= buffer.data.elements + buffer.bytesUsed) | |||||
| return false; | return false; | ||||
| samplePosition = *(int*) data; | samplePosition = *(int*) data; | ||||
| @@ -39,7 +39,7 @@ | |||||
| @see MidiMessage | @see MidiMessage | ||||
| */ | */ | ||||
| class JUCE_API MidiBuffer : private ArrayAllocationBase <uint8> | |||||
| class JUCE_API MidiBuffer | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -226,6 +226,7 @@ public: | |||||
| private: | private: | ||||
| friend class MidiBuffer::Iterator; | friend class MidiBuffer::Iterator; | ||||
| ArrayAllocationBase <uint8> data; | |||||
| int bytesUsed; | int bytesUsed; | ||||
| uint8* findEventAfter (uint8* d, const int samplePosition) const throw(); | uint8* findEventAfter (uint8* d, const int samplePosition) const throw(); | ||||
| @@ -52,7 +52,7 @@ | |||||
| @see OwnedArray, ReferenceCountedArray, StringArray, CriticalSection | @see OwnedArray, ReferenceCountedArray, StringArray, CriticalSection | ||||
| */ | */ | ||||
| template <class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection> | template <class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection> | ||||
| class Array : private ArrayAllocationBase <ElementType> | |||||
| class Array | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -61,11 +61,9 @@ public: | |||||
| @param granularity this is the size of increment by which the internal storage | @param granularity this is the size of increment by which the internal storage | ||||
| used by the array will grow. Only change it from the default if you know the | used by the array will grow. Only change it from the default if you know the | ||||
| array is going to be very big and needs to be able to grow efficiently. | array is going to be very big and needs to be able to grow efficiently. | ||||
| @see ArrayAllocationBase | |||||
| */ | */ | ||||
| Array (const int granularity_ = juceDefaultArrayGranularity) throw() | Array (const int granularity_ = juceDefaultArrayGranularity) throw() | ||||
| : ArrayAllocationBase <ElementType> (granularity_), | |||||
| : data (granularity_), | |||||
| numUsed (0) | numUsed (0) | ||||
| { | { | ||||
| } | } | ||||
| @@ -74,12 +72,12 @@ public: | |||||
| @param other the array to copy | @param other the array to copy | ||||
| */ | */ | ||||
| Array (const Array<ElementType, TypeOfCriticalSectionToUse>& other) throw() | Array (const Array<ElementType, TypeOfCriticalSectionToUse>& other) throw() | ||||
| : ArrayAllocationBase <ElementType> (other.granularity) | |||||
| : data (other.data.granularity) | |||||
| { | { | ||||
| other.lockArray(); | other.lockArray(); | ||||
| numUsed = other.numUsed; | numUsed = other.numUsed; | ||||
| this->setAllocatedSize (other.numUsed); | |||||
| memcpy (this->elements, other.elements, numUsed * sizeof (ElementType)); | |||||
| data.setAllocatedSize (other.numUsed); | |||||
| memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); | |||||
| other.unlockArray(); | other.unlockArray(); | ||||
| } | } | ||||
| @@ -88,7 +86,7 @@ public: | |||||
| @param values the array to copy from | @param values the array to copy from | ||||
| */ | */ | ||||
| Array (const ElementType* values) throw() | Array (const ElementType* values) throw() | ||||
| : ArrayAllocationBase <ElementType> (juceDefaultArrayGranularity), | |||||
| : data (juceDefaultArrayGranularity), | |||||
| numUsed (0) | numUsed (0) | ||||
| { | { | ||||
| while (*values != 0) | while (*values != 0) | ||||
| @@ -101,11 +99,11 @@ public: | |||||
| @param numValues the number of values in the array | @param numValues the number of values in the array | ||||
| */ | */ | ||||
| Array (const ElementType* values, int numValues) throw() | Array (const ElementType* values, int numValues) throw() | ||||
| : ArrayAllocationBase <ElementType> (juceDefaultArrayGranularity), | |||||
| : data (juceDefaultArrayGranularity), | |||||
| numUsed (numValues) | numUsed (numValues) | ||||
| { | { | ||||
| this->setAllocatedSize (numValues); | |||||
| memcpy (this->elements, values, numValues * sizeof (ElementType)); | |||||
| data.setAllocatedSize (numValues); | |||||
| memcpy (data.elements, values, numValues * sizeof (ElementType)); | |||||
| } | } | ||||
| /** Destructor. */ | /** Destructor. */ | ||||
| @@ -123,10 +121,10 @@ public: | |||||
| other.lockArray(); | other.lockArray(); | ||||
| lock.enter(); | lock.enter(); | ||||
| this->granularity = other.granularity; | |||||
| this->ensureAllocatedSize (other.size()); | |||||
| data.granularity = other.data.granularity; | |||||
| data.ensureAllocatedSize (other.size()); | |||||
| numUsed = other.numUsed; | numUsed = other.numUsed; | ||||
| memcpy (this->elements, other.elements, this->numUsed * sizeof (ElementType)); | |||||
| memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -147,7 +145,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| if (this->numUsed != other.numUsed) | |||||
| if (numUsed != other.numUsed) | |||||
| { | { | ||||
| lock.exit(); | lock.exit(); | ||||
| return false; | return false; | ||||
| @@ -155,7 +153,7 @@ public: | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (this->elements [i] != other.elements [i]) | |||||
| if (data.elements [i] != other.data.elements [i]) | |||||
| { | { | ||||
| lock.exit(); | lock.exit(); | ||||
| return false; | return false; | ||||
| @@ -188,7 +186,7 @@ public: | |||||
| void clear() throw() | void clear() throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| this->setAllocatedSize (0); | |||||
| data.setAllocatedSize (0); | |||||
| numUsed = 0; | numUsed = 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -226,7 +224,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ElementType result = (((unsigned int) index) < (unsigned int) numUsed) | const ElementType result = (((unsigned int) index) < (unsigned int) numUsed) | ||||
| ? this->elements [index] | |||||
| ? data.elements [index] | |||||
| : ElementType(); | : ElementType(); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -246,7 +244,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| jassert (((unsigned int) index) < (unsigned int) numUsed); | jassert (((unsigned int) index) < (unsigned int) numUsed); | ||||
| const ElementType result = this->elements [index]; | |||||
| const ElementType result = data.elements [index]; | |||||
| lock.exit(); | lock.exit(); | ||||
| return result; | return result; | ||||
| @@ -265,7 +263,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| jassert (((unsigned int) index) < (unsigned int) numUsed); | jassert (((unsigned int) index) < (unsigned int) numUsed); | ||||
| ElementType& result = this->elements [index]; | |||||
| ElementType& result = data.elements [index]; | |||||
| lock.exit(); | lock.exit(); | ||||
| return result; | return result; | ||||
| } | } | ||||
| @@ -277,7 +275,7 @@ public: | |||||
| inline ElementType getFirst() const throw() | inline ElementType getFirst() const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ElementType result = (numUsed > 0) ? this->elements [0] | |||||
| const ElementType result = (numUsed > 0) ? data.elements [0] | |||||
| : ElementType(); | : ElementType(); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -291,7 +289,7 @@ public: | |||||
| inline ElementType getLast() const throw() | inline ElementType getLast() const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ElementType result = (numUsed > 0) ? this->elements [numUsed - 1] | |||||
| const ElementType result = (numUsed > 0) ? data.elements [numUsed - 1] | |||||
| : ElementType(); | : ElementType(); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -312,13 +310,13 @@ public: | |||||
| int result = -1; | int result = -1; | ||||
| lock.enter(); | lock.enter(); | ||||
| const ElementType* e = this->elements; | |||||
| const ElementType* e = data.elements; | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (elementToLookFor == *e) | if (elementToLookFor == *e) | ||||
| { | { | ||||
| result = (int) (e - this->elements); | |||||
| result = (int) (e - data.elements); | |||||
| break; | break; | ||||
| } | } | ||||
| @@ -338,7 +336,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ElementType* e = this->elements; | |||||
| const ElementType* e = data.elements; | |||||
| int num = numUsed; | int num = numUsed; | ||||
| while (num >= 4) | while (num >= 4) | ||||
| @@ -381,8 +379,8 @@ public: | |||||
| void add (const ElementType newElement) throw() | void add (const ElementType newElement) throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| this->elements [numUsed++] = newElement; | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| data.elements [numUsed++] = newElement; | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -401,11 +399,11 @@ public: | |||||
| void insert (int indexToInsertAt, const ElementType newElement) throw() | void insert (int indexToInsertAt, const ElementType newElement) throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) | if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) | ||||
| { | { | ||||
| ElementType* const insertPos = this->elements + indexToInsertAt; | |||||
| ElementType* const insertPos = data.elements + indexToInsertAt; | |||||
| const int numberToMove = numUsed - indexToInsertAt; | const int numberToMove = numUsed - indexToInsertAt; | ||||
| if (numberToMove > 0) | if (numberToMove > 0) | ||||
| @@ -416,7 +414,7 @@ public: | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| this->elements [numUsed++] = newElement; | |||||
| data.elements [numUsed++] = newElement; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -440,11 +438,11 @@ public: | |||||
| if (numberOfTimesToInsertIt > 0) | if (numberOfTimesToInsertIt > 0) | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| this->ensureAllocatedSize (numUsed + numberOfTimesToInsertIt); | |||||
| data.ensureAllocatedSize (numUsed + numberOfTimesToInsertIt); | |||||
| if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) | if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) | ||||
| { | { | ||||
| ElementType* insertPos = this->elements + indexToInsertAt; | |||||
| ElementType* insertPos = data.elements + indexToInsertAt; | |||||
| const int numberToMove = numUsed - indexToInsertAt; | const int numberToMove = numUsed - indexToInsertAt; | ||||
| memmove (insertPos + numberOfTimesToInsertIt, insertPos, numberToMove * sizeof (ElementType)); | memmove (insertPos + numberOfTimesToInsertIt, insertPos, numberToMove * sizeof (ElementType)); | ||||
| @@ -456,7 +454,7 @@ public: | |||||
| else | else | ||||
| { | { | ||||
| while (--numberOfTimesToInsertIt >= 0) | while (--numberOfTimesToInsertIt >= 0) | ||||
| this->elements [numUsed++] = newElement; | |||||
| data.elements [numUsed++] = newElement; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -482,11 +480,11 @@ public: | |||||
| if (numberOfElements > 0) | if (numberOfElements > 0) | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| this->ensureAllocatedSize (numUsed + numberOfElements); | |||||
| data.ensureAllocatedSize (numUsed + numberOfElements); | |||||
| if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) | if (((unsigned int) indexToInsertAt) < (unsigned int) numUsed) | ||||
| { | { | ||||
| ElementType* insertPos = this->elements + indexToInsertAt; | |||||
| ElementType* insertPos = data.elements + indexToInsertAt; | |||||
| const int numberToMove = numUsed - indexToInsertAt; | const int numberToMove = numUsed - indexToInsertAt; | ||||
| memmove (insertPos + numberOfElements, insertPos, numberToMove * sizeof (ElementType)); | memmove (insertPos + numberOfElements, insertPos, numberToMove * sizeof (ElementType)); | ||||
| @@ -498,7 +496,7 @@ public: | |||||
| else | else | ||||
| { | { | ||||
| while (--numberOfElements >= 0) | while (--numberOfElements >= 0) | ||||
| this->elements [numUsed++] = *newElements++; | |||||
| data.elements [numUsed++] = *newElements++; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -543,12 +541,12 @@ public: | |||||
| if (indexToChange < numUsed) | if (indexToChange < numUsed) | ||||
| { | { | ||||
| this->elements [indexToChange] = newValue; | |||||
| data.elements [indexToChange] = newValue; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| this->elements [numUsed++] = newValue; | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| data.elements [numUsed++] = newValue; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -569,7 +567,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| jassert (((unsigned int) indexToChange) < (unsigned int) numUsed); | jassert (((unsigned int) indexToChange) < (unsigned int) numUsed); | ||||
| this->elements [indexToChange] = newValue; | |||||
| data.elements [indexToChange] = newValue; | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -586,10 +584,10 @@ public: | |||||
| if (numElementsToAdd > 0) | if (numElementsToAdd > 0) | ||||
| { | { | ||||
| this->ensureAllocatedSize (numUsed + numElementsToAdd); | |||||
| data.ensureAllocatedSize (numUsed + numElementsToAdd); | |||||
| while (--numElementsToAdd >= 0) | while (--numElementsToAdd >= 0) | ||||
| this->elements [numUsed++] = *elementsToAdd++; | |||||
| data.elements [numUsed++] = *elementsToAdd++; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -605,9 +603,9 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| otherArray.lock.enter(); | otherArray.lock.enter(); | ||||
| swapVariables <int> (this->numUsed, otherArray.numUsed); | |||||
| swapVariables <ElementType*> (this->elements, otherArray.elements); | |||||
| swapVariables <int> (this->numAllocated, otherArray.numAllocated); | |||||
| swapVariables <int> (numUsed, otherArray.numUsed); | |||||
| swapVariables <ElementType*> (data.elements, otherArray.data.elements); | |||||
| swapVariables <int> (data.numAllocated, otherArray.data.numAllocated); | |||||
| otherArray.lock.exit(); | otherArray.lock.exit(); | ||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -639,7 +637,7 @@ public: | |||||
| if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size()) | if (numElementsToAdd < 0 || startIndex + numElementsToAdd > arrayToAddFrom.size()) | ||||
| numElementsToAdd = arrayToAddFrom.size() - startIndex; | numElementsToAdd = arrayToAddFrom.size() - startIndex; | ||||
| this->addArray ((const ElementType*) (arrayToAddFrom.elements + startIndex), numElementsToAdd); | |||||
| addArray ((const ElementType*) (arrayToAddFrom.data.elements + startIndex), numElementsToAdd); | |||||
| lock.exit(); | lock.exit(); | ||||
| arrayToAddFrom.unlockArray(); | arrayToAddFrom.unlockArray(); | ||||
| @@ -661,7 +659,7 @@ public: | |||||
| const ElementType newElement) throw() | const ElementType newElement) throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| insert (findInsertIndexInSortedArray (comparator, this->elements, newElement, 0, numUsed), newElement); | |||||
| insert (findInsertIndexInSortedArray (comparator, data.elements, newElement, 0, numUsed), newElement); | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -695,7 +693,7 @@ public: | |||||
| lock.exit(); | lock.exit(); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| else if (comparator.compareElements (elementToLookFor, this->elements [start]) == 0) | |||||
| else if (comparator.compareElements (elementToLookFor, data.elements [start]) == 0) | |||||
| { | { | ||||
| lock.exit(); | lock.exit(); | ||||
| return start; | return start; | ||||
| @@ -709,7 +707,7 @@ public: | |||||
| lock.exit(); | lock.exit(); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| else if (comparator.compareElements (elementToLookFor, this->elements [halfway]) >= 0) | |||||
| else if (comparator.compareElements (elementToLookFor, data.elements [halfway]) >= 0) | |||||
| start = halfway; | start = halfway; | ||||
| else | else | ||||
| end = halfway; | end = halfway; | ||||
| @@ -736,14 +734,14 @@ public: | |||||
| { | { | ||||
| --numUsed; | --numUsed; | ||||
| ElementType* const e = this->elements + indexToRemove; | |||||
| ElementType* const e = data.elements + indexToRemove; | |||||
| ElementType const removed = *e; | ElementType const removed = *e; | ||||
| const int numberToShift = numUsed - indexToRemove; | const int numberToShift = numUsed - indexToRemove; | ||||
| if (numberToShift > 0) | if (numberToShift > 0) | ||||
| memmove (e, e + 1, numberToShift * sizeof (ElementType)); | memmove (e, e + 1, numberToShift * sizeof (ElementType)); | ||||
| if ((numUsed << 1) < this->numAllocated) | |||||
| if ((numUsed << 1) < data.numAllocated) | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -767,13 +765,13 @@ public: | |||||
| void removeValue (const ElementType valueToRemove) throw() | void removeValue (const ElementType valueToRemove) throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| ElementType* e = this->elements; | |||||
| ElementType* e = data.elements; | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (valueToRemove == *e) | if (valueToRemove == *e) | ||||
| { | { | ||||
| remove ((int) (e - this->elements)); | |||||
| remove ((int) (e - data.elements)); | |||||
| break; | break; | ||||
| } | } | ||||
| @@ -805,7 +803,7 @@ public: | |||||
| if (endIndex > startIndex) | if (endIndex > startIndex) | ||||
| { | { | ||||
| const int rangeSize = endIndex - startIndex; | const int rangeSize = endIndex - startIndex; | ||||
| ElementType* e = this->elements + startIndex; | |||||
| ElementType* e = data.elements + startIndex; | |||||
| int numToShift = numUsed - endIndex; | int numToShift = numUsed - endIndex; | ||||
| numUsed -= rangeSize; | numUsed -= rangeSize; | ||||
| @@ -815,7 +813,7 @@ public: | |||||
| ++e; | ++e; | ||||
| } | } | ||||
| if ((numUsed << 1) < this->numAllocated) | |||||
| if ((numUsed << 1) < data.numAllocated) | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| } | } | ||||
| @@ -832,7 +830,7 @@ public: | |||||
| lock.enter(); | lock.enter(); | ||||
| numUsed = jmax (0, numUsed - howManyToRemove); | numUsed = jmax (0, numUsed - howManyToRemove); | ||||
| if ((numUsed << 1) < this->numAllocated) | |||||
| if ((numUsed << 1) < data.numAllocated) | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -858,7 +856,7 @@ public: | |||||
| if (otherArray.size() > 0) | if (otherArray.size() > 0) | ||||
| { | { | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (otherArray.contains (this->elements [i])) | |||||
| if (otherArray.contains (data.elements [i])) | |||||
| remove (i); | remove (i); | ||||
| } | } | ||||
| } | } | ||||
| @@ -889,7 +887,7 @@ public: | |||||
| else | else | ||||
| { | { | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (! otherArray.contains (this->elements [i])) | |||||
| if (! otherArray.contains (data.elements [i])) | |||||
| remove (i); | remove (i); | ||||
| } | } | ||||
| } | } | ||||
| @@ -914,8 +912,8 @@ public: | |||||
| if (((unsigned int) index1) < (unsigned int) numUsed | if (((unsigned int) index1) < (unsigned int) numUsed | ||||
| && ((unsigned int) index2) < (unsigned int) numUsed) | && ((unsigned int) index2) < (unsigned int) numUsed) | ||||
| { | { | ||||
| swapVariables (this->elements [index1], | |||||
| this->elements [index2]); | |||||
| swapVariables (data.elements [index1], | |||||
| data.elements [index2]); | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -947,22 +945,22 @@ public: | |||||
| if (((unsigned int) newIndex) >= (unsigned int) numUsed) | if (((unsigned int) newIndex) >= (unsigned int) numUsed) | ||||
| newIndex = numUsed - 1; | newIndex = numUsed - 1; | ||||
| const ElementType value = this->elements [currentIndex]; | |||||
| const ElementType value = data.elements [currentIndex]; | |||||
| if (newIndex > currentIndex) | if (newIndex > currentIndex) | ||||
| { | { | ||||
| memmove (this->elements + currentIndex, | |||||
| this->elements + currentIndex + 1, | |||||
| memmove (data.elements + currentIndex, | |||||
| data.elements + currentIndex + 1, | |||||
| (newIndex - currentIndex) * sizeof (ElementType)); | (newIndex - currentIndex) * sizeof (ElementType)); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| memmove (this->elements + newIndex + 1, | |||||
| this->elements + newIndex, | |||||
| memmove (data.elements + newIndex + 1, | |||||
| data.elements + newIndex, | |||||
| (currentIndex - newIndex) * sizeof (ElementType)); | (currentIndex - newIndex) * sizeof (ElementType)); | ||||
| } | } | ||||
| this->elements [newIndex] = value; | |||||
| data.elements [newIndex] = value; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -982,14 +980,14 @@ public: | |||||
| if (numUsed == 0) | if (numUsed == 0) | ||||
| { | { | ||||
| this->setAllocatedSize (0); | |||||
| data.setAllocatedSize (0); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| const int newAllocation = this->granularity * (numUsed / this->granularity + 1); | |||||
| const int newAllocation = data.granularity * (numUsed / data.granularity + 1); | |||||
| if (newAllocation < this->numAllocated) | |||||
| this->setAllocatedSize (newAllocation); | |||||
| if (newAllocation < data.numAllocated) | |||||
| data.setAllocatedSize (newAllocation); | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -1003,7 +1001,7 @@ public: | |||||
| */ | */ | ||||
| void ensureStorageAllocated (const int minNumElements) throw() | void ensureStorageAllocated (const int minNumElements) throw() | ||||
| { | { | ||||
| this->ensureAllocatedSize (minNumElements); | |||||
| data.ensureAllocatedSize (minNumElements); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -1040,7 +1038,7 @@ public: | |||||
| (void) comparator; // if you pass in an object with a static compareElements() method, this | (void) comparator; // if you pass in an object with a static compareElements() method, this | ||||
| // avoids getting warning messages about the parameter being unused | // avoids getting warning messages about the parameter being unused | ||||
| lock.enter(); | lock.enter(); | ||||
| sortArray (comparator, this->elements, 0, size() - 1, retainOrderOfEquivalentItems); | |||||
| sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -1074,6 +1072,7 @@ public: | |||||
| juce_UseDebuggingNewOperator | juce_UseDebuggingNewOperator | ||||
| private: | private: | ||||
| ArrayAllocationBase <ElementType> data; | |||||
| int numUsed; | int numUsed; | ||||
| TypeOfCriticalSectionToUse lock; | TypeOfCriticalSectionToUse lock; | ||||
| }; | }; | ||||
| @@ -47,7 +47,7 @@ const int juceDefaultArrayGranularity = 8; | |||||
| template <class ElementType> | template <class ElementType> | ||||
| class ArrayAllocationBase | class ArrayAllocationBase | ||||
| { | { | ||||
| protected: | |||||
| public: | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Creates an empty array. | /** Creates an empty array. | ||||
| @@ -53,7 +53,7 @@ | |||||
| template <class ObjectClass, | template <class ObjectClass, | ||||
| class TypeOfCriticalSectionToUse = DummyCriticalSection> | class TypeOfCriticalSectionToUse = DummyCriticalSection> | ||||
| class OwnedArray : private ArrayAllocationBase <ObjectClass*> | |||||
| class OwnedArray | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -62,11 +62,9 @@ public: | |||||
| @param granularity this is the size of increment by which the internal storage | @param granularity this is the size of increment by which the internal storage | ||||
| used by the array will grow. Only change it from the default if you know the | used by the array will grow. Only change it from the default if you know the | ||||
| array is going to be very big and needs to be able to grow efficiently. | array is going to be very big and needs to be able to grow efficiently. | ||||
| @see ArrayAllocationBase | |||||
| */ | */ | ||||
| OwnedArray (const int granularity_ = juceDefaultArrayGranularity) throw() | OwnedArray (const int granularity_ = juceDefaultArrayGranularity) throw() | ||||
| : ArrayAllocationBase <ObjectClass*> (granularity_), | |||||
| : data (granularity_), | |||||
| numUsed (0) | numUsed (0) | ||||
| { | { | ||||
| } | } | ||||
| @@ -90,10 +88,10 @@ public: | |||||
| if (deleteObjects) | if (deleteObjects) | ||||
| { | { | ||||
| while (numUsed > 0) | while (numUsed > 0) | ||||
| delete this->elements [--numUsed]; | |||||
| delete data.elements [--numUsed]; | |||||
| } | } | ||||
| this->setAllocatedSize (0); | |||||
| data.setAllocatedSize (0); | |||||
| numUsed = 0; | numUsed = 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -119,7 +117,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| ObjectClass* const result = (((unsigned int) index) < (unsigned int) numUsed) | ObjectClass* const result = (((unsigned int) index) < (unsigned int) numUsed) | ||||
| ? this->elements [index] | |||||
| ? data.elements [index] | |||||
| : (ObjectClass*) 0; | : (ObjectClass*) 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -135,7 +133,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| jassert (((unsigned int) index) < (unsigned int) numUsed); | jassert (((unsigned int) index) < (unsigned int) numUsed); | ||||
| ObjectClass* const result = this->elements [index]; | |||||
| ObjectClass* const result = data.elements [index]; | |||||
| lock.exit(); | lock.exit(); | ||||
| return result; | return result; | ||||
| @@ -149,7 +147,7 @@ public: | |||||
| inline ObjectClass* getFirst() const throw() | inline ObjectClass* getFirst() const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| ObjectClass* const result = (numUsed > 0) ? this->elements [0] | |||||
| ObjectClass* const result = (numUsed > 0) ? data.elements [0] | |||||
| : (ObjectClass*) 0; | : (ObjectClass*) 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| return result; | return result; | ||||
| @@ -163,7 +161,7 @@ public: | |||||
| inline ObjectClass* getLast() const throw() | inline ObjectClass* getLast() const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| ObjectClass* const result = (numUsed > 0) ? this->elements [numUsed - 1] | |||||
| ObjectClass* const result = (numUsed > 0) ? data.elements [numUsed - 1] | |||||
| : (ObjectClass*) 0; | : (ObjectClass*) 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -181,13 +179,13 @@ public: | |||||
| int result = -1; | int result = -1; | ||||
| lock.enter(); | lock.enter(); | ||||
| ObjectClass* const* e = this->elements; | |||||
| ObjectClass* const* e = data.elements; | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (objectToLookFor == *e) | if (objectToLookFor == *e) | ||||
| { | { | ||||
| result = (int) (e - this->elements); | |||||
| result = (int) (e - data.elements); | |||||
| break; | break; | ||||
| } | } | ||||
| @@ -207,7 +205,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| ObjectClass* const* e = this->elements; | |||||
| ObjectClass* const* e = data.elements; | |||||
| int i = numUsed; | int i = numUsed; | ||||
| while (i >= 4) | while (i >= 4) | ||||
| @@ -256,8 +254,8 @@ public: | |||||
| void add (const ObjectClass* const newObject) throw() | void add (const ObjectClass* const newObject) throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| this->elements [numUsed++] = const_cast <ObjectClass*> (newObject); | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| data.elements [numUsed++] = const_cast <ObjectClass*> (newObject); | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -288,9 +286,9 @@ public: | |||||
| if (indexToInsertAt > numUsed) | if (indexToInsertAt > numUsed) | ||||
| indexToInsertAt = numUsed; | indexToInsertAt = numUsed; | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| ObjectClass** const e = this->elements + indexToInsertAt; | |||||
| ObjectClass** const e = data.elements + indexToInsertAt; | |||||
| const int numToMove = numUsed - indexToInsertAt; | const int numToMove = numUsed - indexToInsertAt; | ||||
| if (numToMove > 0) | if (numToMove > 0) | ||||
| @@ -350,18 +348,18 @@ public: | |||||
| { | { | ||||
| if (deleteOldElement) | if (deleteOldElement) | ||||
| { | { | ||||
| toDelete = this->elements [indexToChange]; | |||||
| toDelete = data.elements [indexToChange]; | |||||
| if (toDelete == newObject) | if (toDelete == newObject) | ||||
| toDelete = 0; | toDelete = 0; | ||||
| } | } | ||||
| this->elements [indexToChange] = const_cast <ObjectClass*> (newObject); | |||||
| data.elements [indexToChange] = const_cast <ObjectClass*> (newObject); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| this->elements [numUsed++] = const_cast <ObjectClass*> (newObject); | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| data.elements [numUsed++] = const_cast <ObjectClass*> (newObject); | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -388,7 +386,7 @@ public: | |||||
| (void) comparator; // if you pass in an object with a static compareElements() method, this | (void) comparator; // if you pass in an object with a static compareElements() method, this | ||||
| // avoids getting warning messages about the parameter being unused | // avoids getting warning messages about the parameter being unused | ||||
| lock.enter(); | lock.enter(); | ||||
| insert (findInsertIndexInSortedArray (comparator, this->elements, newObject, 0, numUsed), newObject); | |||||
| insert (findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed), newObject); | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -422,7 +420,7 @@ public: | |||||
| lock.exit(); | lock.exit(); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| else if (comparator.compareElements (objectToLookFor, this->elements [start]) == 0) | |||||
| else if (comparator.compareElements (objectToLookFor, data.elements [start]) == 0) | |||||
| { | { | ||||
| lock.exit(); | lock.exit(); | ||||
| return start; | return start; | ||||
| @@ -436,7 +434,7 @@ public: | |||||
| lock.exit(); | lock.exit(); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| else if (comparator.compareElements (objectToLookFor, this->elements [halfway]) >= 0) | |||||
| else if (comparator.compareElements (objectToLookFor, data.elements [halfway]) >= 0) | |||||
| start = halfway; | start = halfway; | ||||
| else | else | ||||
| end = halfway; | end = halfway; | ||||
| @@ -463,7 +461,7 @@ public: | |||||
| if (((unsigned int) indexToRemove) < (unsigned int) numUsed) | if (((unsigned int) indexToRemove) < (unsigned int) numUsed) | ||||
| { | { | ||||
| ObjectClass** const e = this->elements + indexToRemove; | |||||
| ObjectClass** const e = data.elements + indexToRemove; | |||||
| if (deleteObject) | if (deleteObject) | ||||
| toDelete = *e; | toDelete = *e; | ||||
| @@ -474,7 +472,7 @@ public: | |||||
| if (numToShift > 0) | if (numToShift > 0) | ||||
| memmove (e, e + 1, numToShift * sizeof (ObjectClass*)); | memmove (e, e + 1, numToShift * sizeof (ObjectClass*)); | ||||
| if ((numUsed << 1) < this->numAllocated) | |||||
| if ((numUsed << 1) < data.numAllocated) | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| } | } | ||||
| @@ -495,13 +493,13 @@ public: | |||||
| const bool deleteObject = true) | const bool deleteObject = true) | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| ObjectClass** e = this->elements; | |||||
| ObjectClass** e = data.elements; | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (objectToRemove == *e) | if (objectToRemove == *e) | ||||
| { | { | ||||
| remove ((int) (e - this->elements), deleteObject); | |||||
| remove ((int) (e - data.elements), deleteObject); | |||||
| break; | break; | ||||
| } | } | ||||
| @@ -538,13 +536,13 @@ public: | |||||
| { | { | ||||
| for (int i = startIndex; i < endIndex; ++i) | for (int i = startIndex; i < endIndex; ++i) | ||||
| { | { | ||||
| delete this->elements [i]; | |||||
| this->elements [i] = 0; // (in case one of the destructors accesses this array and hits a dangling pointer) | |||||
| delete data.elements [i]; | |||||
| data.elements [i] = 0; // (in case one of the destructors accesses this array and hits a dangling pointer) | |||||
| } | } | ||||
| } | } | ||||
| const int rangeSize = endIndex - startIndex; | const int rangeSize = endIndex - startIndex; | ||||
| ObjectClass** e = this->elements + startIndex; | |||||
| ObjectClass** e = data.elements + startIndex; | |||||
| int numToShift = numUsed - endIndex; | int numToShift = numUsed - endIndex; | ||||
| numUsed -= rangeSize; | numUsed -= rangeSize; | ||||
| @@ -554,7 +552,7 @@ public: | |||||
| ++e; | ++e; | ||||
| } | } | ||||
| if ((numUsed << 1) < this->numAllocated) | |||||
| if ((numUsed << 1) < data.numAllocated) | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| } | } | ||||
| @@ -598,8 +596,8 @@ public: | |||||
| if (((unsigned int) index1) < (unsigned int) numUsed | if (((unsigned int) index1) < (unsigned int) numUsed | ||||
| && ((unsigned int) index2) < (unsigned int) numUsed) | && ((unsigned int) index2) < (unsigned int) numUsed) | ||||
| { | { | ||||
| swapVariables (this->elements [index1], | |||||
| this->elements [index2]); | |||||
| swapVariables (data.elements [index1], | |||||
| data.elements [index2]); | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -630,22 +628,22 @@ public: | |||||
| if (((unsigned int) newIndex) >= (unsigned int) numUsed) | if (((unsigned int) newIndex) >= (unsigned int) numUsed) | ||||
| newIndex = numUsed - 1; | newIndex = numUsed - 1; | ||||
| ObjectClass* const value = this->elements [currentIndex]; | |||||
| ObjectClass* const value = data.elements [currentIndex]; | |||||
| if (newIndex > currentIndex) | if (newIndex > currentIndex) | ||||
| { | { | ||||
| memmove (this->elements + currentIndex, | |||||
| this->elements + currentIndex + 1, | |||||
| memmove (data.elements + currentIndex, | |||||
| data.elements + currentIndex + 1, | |||||
| (newIndex - currentIndex) * sizeof (ObjectClass*)); | (newIndex - currentIndex) * sizeof (ObjectClass*)); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| memmove (this->elements + newIndex + 1, | |||||
| this->elements + newIndex, | |||||
| memmove (data.elements + newIndex + 1, | |||||
| data.elements + newIndex, | |||||
| (currentIndex - newIndex) * sizeof (ObjectClass*)); | (currentIndex - newIndex) * sizeof (ObjectClass*)); | ||||
| } | } | ||||
| this->elements [newIndex] = value; | |||||
| data.elements [newIndex] = value; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -662,9 +660,9 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| otherArray.lock.enter(); | otherArray.lock.enter(); | ||||
| swapVariables <int> (this->numUsed, otherArray.numUsed); | |||||
| swapVariables <ObjectClass**> (this->elements, otherArray.elements); | |||||
| swapVariables <int> (this->numAllocated, otherArray.numAllocated); | |||||
| swapVariables <int> (numUsed, otherArray.numUsed); | |||||
| swapVariables <ObjectClass**> (data.elements, otherArray.data.elements); | |||||
| swapVariables <int> (data.numAllocated, otherArray.data.numAllocated); | |||||
| otherArray.lock.exit(); | otherArray.lock.exit(); | ||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -682,14 +680,14 @@ public: | |||||
| if (numUsed == 0) | if (numUsed == 0) | ||||
| { | { | ||||
| this->setAllocatedSize (0); | |||||
| data.setAllocatedSize (0); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| const int newAllocation = this->granularity * (numUsed / this->granularity + 1); | |||||
| const int newAllocation = data.granularity * (numUsed / data.granularity + 1); | |||||
| if (newAllocation < this->numAllocated) | |||||
| this->setAllocatedSize (newAllocation); | |||||
| if (newAllocation < data.numAllocated) | |||||
| data.setAllocatedSize (newAllocation); | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -703,7 +701,7 @@ public: | |||||
| */ | */ | ||||
| void ensureStorageAllocated (const int minNumElements) throw() | void ensureStorageAllocated (const int minNumElements) throw() | ||||
| { | { | ||||
| this->ensureAllocatedSize (minNumElements); | |||||
| data.ensureAllocatedSize (minNumElements); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -740,7 +738,7 @@ public: | |||||
| // avoids getting warning messages about the parameter being unused | // avoids getting warning messages about the parameter being unused | ||||
| lock.enter(); | lock.enter(); | ||||
| sortArray (comparator, this->elements, 0, size() - 1, retainOrderOfEquivalentItems); | |||||
| sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -774,6 +772,7 @@ public: | |||||
| juce_UseDebuggingNewOperator | juce_UseDebuggingNewOperator | ||||
| private: | private: | ||||
| ArrayAllocationBase <ObjectClass*> data; | |||||
| int numUsed; | int numUsed; | ||||
| TypeOfCriticalSectionToUse lock; | TypeOfCriticalSectionToUse lock; | ||||
| @@ -46,7 +46,7 @@ | |||||
| @see Array, OwnedArray, StringArray | @see Array, OwnedArray, StringArray | ||||
| */ | */ | ||||
| template <class ObjectClass, class TypeOfCriticalSectionToUse = DummyCriticalSection> | template <class ObjectClass, class TypeOfCriticalSectionToUse = DummyCriticalSection> | ||||
| class ReferenceCountedArray : private ArrayAllocationBase <ObjectClass*> | |||||
| class ReferenceCountedArray | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -56,26 +56,26 @@ public: | |||||
| used by the array will grow. Only change it from the default if you know the | used by the array will grow. Only change it from the default if you know the | ||||
| array is going to be very big and needs to be able to grow efficiently. | array is going to be very big and needs to be able to grow efficiently. | ||||
| @see ReferenceCountedObject, ArrayAllocationBase, Array, OwnedArray | |||||
| @see ReferenceCountedObject, Array, OwnedArray | |||||
| */ | */ | ||||
| ReferenceCountedArray (const int granularity_ = juceDefaultArrayGranularity) throw() | ReferenceCountedArray (const int granularity_ = juceDefaultArrayGranularity) throw() | ||||
| : ArrayAllocationBase <ObjectClass*> (granularity_), | |||||
| : data (granularity_), | |||||
| numUsed (0) | numUsed (0) | ||||
| { | { | ||||
| } | } | ||||
| /** Creates a copy of another array */ | /** Creates a copy of another array */ | ||||
| ReferenceCountedArray (const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& other) throw() | ReferenceCountedArray (const ReferenceCountedArray<ObjectClass, TypeOfCriticalSectionToUse>& other) throw() | ||||
| : ArrayAllocationBase <ObjectClass*> (other.granularity) | |||||
| : data (other.data.granularity) | |||||
| { | { | ||||
| other.lockArray(); | other.lockArray(); | ||||
| numUsed = other.numUsed; | numUsed = other.numUsed; | ||||
| this->setAllocatedSize (numUsed); | |||||
| memcpy (this->elements, other.elements, numUsed * sizeof (ObjectClass*)); | |||||
| data.setAllocatedSize (numUsed); | |||||
| memcpy (data.elements, other.data.elements, numUsed * sizeof (ObjectClass*)); | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (this->elements[i] != 0) | |||||
| this->elements[i]->incReferenceCount(); | |||||
| if (data.elements[i] != 0) | |||||
| data.elements[i]->incReferenceCount(); | |||||
| other.unlockArray(); | other.unlockArray(); | ||||
| } | } | ||||
| @@ -93,15 +93,15 @@ public: | |||||
| clear(); | clear(); | ||||
| this->granularity = other.granularity; | |||||
| this->ensureAllocatedSize (other.numUsed); | |||||
| data.granularity = other.granularity; | |||||
| data.ensureAllocatedSize (other.numUsed); | |||||
| numUsed = other.numUsed; | numUsed = other.numUsed; | ||||
| memcpy (this->elements, other.elements, numUsed * sizeof (ObjectClass*)); | |||||
| memcpy (data.elements, other.data.elements, numUsed * sizeof (ObjectClass*)); | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (this->elements[i] != 0) | |||||
| this->elements[i]->incReferenceCount(); | |||||
| if (data.elements[i] != 0) | |||||
| data.elements[i]->incReferenceCount(); | |||||
| lock.exit(); | lock.exit(); | ||||
| other.unlockArray(); | other.unlockArray(); | ||||
| @@ -129,11 +129,11 @@ public: | |||||
| lock.enter(); | lock.enter(); | ||||
| while (numUsed > 0) | while (numUsed > 0) | ||||
| if (this->elements [--numUsed] != 0) | |||||
| this->elements [numUsed]->decReferenceCount(); | |||||
| if (data.elements [--numUsed] != 0) | |||||
| data.elements [numUsed]->decReferenceCount(); | |||||
| jassert (numUsed == 0); | jassert (numUsed == 0); | ||||
| this->setAllocatedSize (0); | |||||
| data.setAllocatedSize (0); | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -156,7 +156,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ReferenceCountedObjectPtr<ObjectClass> result ((((unsigned int) index) < (unsigned int) numUsed) | const ReferenceCountedObjectPtr<ObjectClass> result ((((unsigned int) index) < (unsigned int) numUsed) | ||||
| ? this->elements [index] | |||||
| ? data.elements [index] | |||||
| : (ObjectClass*) 0); | : (ObjectClass*) 0); | ||||
| lock.exit(); | lock.exit(); | ||||
| return result; | return result; | ||||
| @@ -171,7 +171,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| jassert (((unsigned int) index) < (unsigned int) numUsed); | jassert (((unsigned int) index) < (unsigned int) numUsed); | ||||
| const ReferenceCountedObjectPtr<ObjectClass> result (this->elements [index]); | |||||
| const ReferenceCountedObjectPtr<ObjectClass> result (data.elements [index]); | |||||
| lock.exit(); | lock.exit(); | ||||
| return result; | return result; | ||||
| } | } | ||||
| @@ -184,7 +184,7 @@ public: | |||||
| inline const ReferenceCountedObjectPtr<ObjectClass> getFirst() const throw() | inline const ReferenceCountedObjectPtr<ObjectClass> getFirst() const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ReferenceCountedObjectPtr<ObjectClass> result ((numUsed > 0) ? this->elements [0] | |||||
| const ReferenceCountedObjectPtr<ObjectClass> result ((numUsed > 0) ? data.elements [0] | |||||
| : (ObjectClass*) 0); | : (ObjectClass*) 0); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -199,7 +199,7 @@ public: | |||||
| inline const ReferenceCountedObjectPtr<ObjectClass> getLast() const throw() | inline const ReferenceCountedObjectPtr<ObjectClass> getLast() const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ReferenceCountedObjectPtr<ObjectClass> result ((numUsed > 0) ? this->elements [numUsed - 1] | |||||
| const ReferenceCountedObjectPtr<ObjectClass> result ((numUsed > 0) ? data.elements [numUsed - 1] | |||||
| : (ObjectClass*) 0); | : (ObjectClass*) 0); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -217,13 +217,13 @@ public: | |||||
| int result = -1; | int result = -1; | ||||
| lock.enter(); | lock.enter(); | ||||
| ObjectClass** e = this->elements; | |||||
| ObjectClass** e = data.elements; | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (objectToLookFor == *e) | if (objectToLookFor == *e) | ||||
| { | { | ||||
| result = (int) (e - this->elements); | |||||
| result = (int) (e - data.elements); | |||||
| break; | break; | ||||
| } | } | ||||
| @@ -242,7 +242,7 @@ public: | |||||
| bool contains (const ObjectClass* const objectToLookFor) const throw() | bool contains (const ObjectClass* const objectToLookFor) const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| ObjectClass** e = this->elements; | |||||
| ObjectClass** e = data.elements; | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| @@ -269,8 +269,8 @@ public: | |||||
| void add (ObjectClass* const newObject) throw() | void add (ObjectClass* const newObject) throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| this->elements [numUsed++] = newObject; | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| data.elements [numUsed++] = newObject; | |||||
| if (newObject != 0) | if (newObject != 0) | ||||
| newObject->incReferenceCount(); | newObject->incReferenceCount(); | ||||
| @@ -301,9 +301,9 @@ public: | |||||
| if (indexToInsertAt > numUsed) | if (indexToInsertAt > numUsed) | ||||
| indexToInsertAt = numUsed; | indexToInsertAt = numUsed; | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| ObjectClass** const e = this->elements + indexToInsertAt; | |||||
| ObjectClass** const e = data.elements + indexToInsertAt; | |||||
| const int numToMove = numUsed - indexToInsertAt; | const int numToMove = numUsed - indexToInsertAt; | ||||
| if (numToMove > 0) | if (numToMove > 0) | ||||
| @@ -364,15 +364,15 @@ public: | |||||
| if (indexToChange < numUsed) | if (indexToChange < numUsed) | ||||
| { | { | ||||
| if (this->elements [indexToChange] != 0) | |||||
| this->elements [indexToChange]->decReferenceCount(); | |||||
| if (data.elements [indexToChange] != 0) | |||||
| data.elements [indexToChange]->decReferenceCount(); | |||||
| this->elements [indexToChange] = newObject; | |||||
| data.elements [indexToChange] = newObject; | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| this->elements [numUsed++] = newObject; | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| data.elements [numUsed++] = newObject; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -406,7 +406,7 @@ public: | |||||
| if (numElementsToAdd > 0) | if (numElementsToAdd > 0) | ||||
| { | { | ||||
| this->ensureAllocatedSize (numUsed + numElementsToAdd); | |||||
| data.ensureAllocatedSize (numUsed + numElementsToAdd); | |||||
| while (--numElementsToAdd >= 0) | while (--numElementsToAdd >= 0) | ||||
| add (arrayToAddFrom.getUnchecked (startIndex++)); | add (arrayToAddFrom.getUnchecked (startIndex++)); | ||||
| @@ -432,7 +432,7 @@ public: | |||||
| ObjectClass* newObject) throw() | ObjectClass* newObject) throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| insert (findInsertIndexInSortedArray (comparator, this->elements, newObject, 0, numUsed), newObject); | |||||
| insert (findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed), newObject); | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -446,9 +446,9 @@ public: | |||||
| ObjectClass* newObject) throw() | ObjectClass* newObject) throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const int index = findInsertIndexInSortedArray (comparator, this->elements, newObject, 0, numUsed); | |||||
| const int index = findInsertIndexInSortedArray (comparator, data.elements, newObject, 0, numUsed); | |||||
| if (index > 0 && comparator.compareElements (newObject, this->elements [index - 1]) == 0) | |||||
| if (index > 0 && comparator.compareElements (newObject, data.elements [index - 1]) == 0) | |||||
| set (index - 1, newObject); // replace an existing object that matches | set (index - 1, newObject); // replace an existing object that matches | ||||
| else | else | ||||
| insert (index, newObject); // no match, so insert the new one | insert (index, newObject); // no match, so insert the new one | ||||
| @@ -476,7 +476,7 @@ public: | |||||
| if (((unsigned int) indexToRemove) < (unsigned int) numUsed) | if (((unsigned int) indexToRemove) < (unsigned int) numUsed) | ||||
| { | { | ||||
| ObjectClass** const e = this->elements + indexToRemove; | |||||
| ObjectClass** const e = data.elements + indexToRemove; | |||||
| if (*e != 0) | if (*e != 0) | ||||
| (*e)->decReferenceCount(); | (*e)->decReferenceCount(); | ||||
| @@ -487,7 +487,7 @@ public: | |||||
| if (numberToShift > 0) | if (numberToShift > 0) | ||||
| memmove (e, e + 1, numberToShift * sizeof (ObjectClass*)); | memmove (e, e + 1, numberToShift * sizeof (ObjectClass*)); | ||||
| if ((numUsed << 1) < this->numAllocated) | |||||
| if ((numUsed << 1) < data.numAllocated) | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| } | } | ||||
| @@ -537,15 +537,15 @@ public: | |||||
| int i; | int i; | ||||
| for (i = start; i < end; ++i) | for (i = start; i < end; ++i) | ||||
| { | { | ||||
| if (this->elements[i] != 0) | |||||
| if (data.elements[i] != 0) | |||||
| { | { | ||||
| this->elements[i]->decReferenceCount(); | |||||
| this->elements[i] = 0; // (in case one of the destructors accesses this array and hits a dangling pointer) | |||||
| data.elements[i]->decReferenceCount(); | |||||
| data.elements[i] = 0; // (in case one of the destructors accesses this array and hits a dangling pointer) | |||||
| } | } | ||||
| } | } | ||||
| const int rangeSize = end - start; | const int rangeSize = end - start; | ||||
| ObjectClass** e = this->elements + start; | |||||
| ObjectClass** e = data.elements + start; | |||||
| i = numUsed - end; | i = numUsed - end; | ||||
| numUsed -= rangeSize; | numUsed -= rangeSize; | ||||
| @@ -555,7 +555,7 @@ public: | |||||
| ++e; | ++e; | ||||
| } | } | ||||
| if ((numUsed << 1) < this->numAllocated) | |||||
| if ((numUsed << 1) < data.numAllocated) | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| } | } | ||||
| @@ -596,8 +596,8 @@ public: | |||||
| if (((unsigned int) index1) < (unsigned int) numUsed | if (((unsigned int) index1) < (unsigned int) numUsed | ||||
| && ((unsigned int) index2) < (unsigned int) numUsed) | && ((unsigned int) index2) < (unsigned int) numUsed) | ||||
| { | { | ||||
| swapVariables (this->elements [index1], | |||||
| this->elements [index2]); | |||||
| swapVariables (data.elements [index1], | |||||
| data.elements [index2]); | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -628,22 +628,22 @@ public: | |||||
| if (((unsigned int) newIndex) >= (unsigned int) numUsed) | if (((unsigned int) newIndex) >= (unsigned int) numUsed) | ||||
| newIndex = numUsed - 1; | newIndex = numUsed - 1; | ||||
| ObjectClass* const value = this->elements [currentIndex]; | |||||
| ObjectClass* const value = data.elements [currentIndex]; | |||||
| if (newIndex > currentIndex) | if (newIndex > currentIndex) | ||||
| { | { | ||||
| memmove (this->elements + currentIndex, | |||||
| this->elements + currentIndex + 1, | |||||
| memmove (data.elements + currentIndex, | |||||
| data.elements + currentIndex + 1, | |||||
| (newIndex - currentIndex) * sizeof (ObjectClass*)); | (newIndex - currentIndex) * sizeof (ObjectClass*)); | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| memmove (this->elements + newIndex + 1, | |||||
| this->elements + newIndex, | |||||
| memmove (data.elements + newIndex + 1, | |||||
| data.elements + newIndex, | |||||
| (currentIndex - newIndex) * sizeof (ObjectClass*)); | (currentIndex - newIndex) * sizeof (ObjectClass*)); | ||||
| } | } | ||||
| this->elements [newIndex] = value; | |||||
| data.elements [newIndex] = value; | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -666,7 +666,7 @@ public: | |||||
| { | { | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (this->elements [i] != other.elements [i]) | |||||
| if (data.elements [i] != other.data.elements [i]) | |||||
| { | { | ||||
| result = false; | result = false; | ||||
| break; | break; | ||||
| @@ -724,7 +724,7 @@ public: | |||||
| // avoids getting warning messages about the parameter being unused | // avoids getting warning messages about the parameter being unused | ||||
| lock.enter(); | lock.enter(); | ||||
| sortArray (comparator, this->elements, 0, size() - 1, retainOrderOfEquivalentItems); | |||||
| sortArray (comparator, data.elements, 0, size() - 1, retainOrderOfEquivalentItems); | |||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -741,14 +741,14 @@ public: | |||||
| if (numUsed == 0) | if (numUsed == 0) | ||||
| { | { | ||||
| this->setAllocatedSize (0); | |||||
| data.setAllocatedSize (0); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| const int newAllocation = this->granularity * (numUsed / this->granularity + 1); | |||||
| const int newAllocation = data.granularity * (numUsed / data.granularity + 1); | |||||
| if (newAllocation < this->numAllocated) | |||||
| this->setAllocatedSize (newAllocation); | |||||
| if (newAllocation < data.numAllocated) | |||||
| data.setAllocatedSize (newAllocation); | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -784,6 +784,7 @@ public: | |||||
| juce_UseDebuggingNewOperator | juce_UseDebuggingNewOperator | ||||
| private: | private: | ||||
| ArrayAllocationBase <ObjectClass*> data; | |||||
| int numUsed; | int numUsed; | ||||
| TypeOfCriticalSectionToUse lock; | TypeOfCriticalSectionToUse lock; | ||||
| }; | }; | ||||
| @@ -58,7 +58,7 @@ | |||||
| @see Array, OwnedArray, ReferenceCountedArray, StringArray, CriticalSection | @see Array, OwnedArray, ReferenceCountedArray, StringArray, CriticalSection | ||||
| */ | */ | ||||
| template <class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection> | template <class ElementType, class TypeOfCriticalSectionToUse = DummyCriticalSection> | ||||
| class SortedSet : private ArrayAllocationBase <ElementType> | |||||
| class SortedSet | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -67,11 +67,9 @@ public: | |||||
| @param granularity this is the size of increment by which the internal storage | @param granularity this is the size of increment by which the internal storage | ||||
| used by the array will grow. Only change it from the default if you know the | used by the array will grow. Only change it from the default if you know the | ||||
| array is going to be very big and needs to be able to grow efficiently. | array is going to be very big and needs to be able to grow efficiently. | ||||
| @see ArrayAllocationBase | |||||
| */ | */ | ||||
| SortedSet (const int granularity_ = juceDefaultArrayGranularity) throw() | SortedSet (const int granularity_ = juceDefaultArrayGranularity) throw() | ||||
| : ArrayAllocationBase <ElementType> (granularity_), | |||||
| : data (granularity_), | |||||
| numUsed (0) | numUsed (0) | ||||
| { | { | ||||
| } | } | ||||
| @@ -80,12 +78,12 @@ public: | |||||
| @param other the set to copy | @param other the set to copy | ||||
| */ | */ | ||||
| SortedSet (const SortedSet<ElementType, TypeOfCriticalSectionToUse>& other) throw() | SortedSet (const SortedSet<ElementType, TypeOfCriticalSectionToUse>& other) throw() | ||||
| : ArrayAllocationBase <ElementType> (other.granularity) | |||||
| : data (other.data.granularity) | |||||
| { | { | ||||
| other.lockSet(); | other.lockSet(); | ||||
| numUsed = other.numUsed; | numUsed = other.numUsed; | ||||
| setAllocatedSize (other.numUsed); | |||||
| memcpy (this->elements, other.elements, numUsed * sizeof (ElementType)); | |||||
| data.setAllocatedSize (other.numUsed); | |||||
| memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); | |||||
| other.unlockSet(); | other.unlockSet(); | ||||
| } | } | ||||
| @@ -104,10 +102,10 @@ public: | |||||
| other.lockSet(); | other.lockSet(); | ||||
| lock.enter(); | lock.enter(); | ||||
| this->granularity = other.granularity; | |||||
| ensureAllocatedSize (other.size()); | |||||
| data.granularity = other.data.granularity; | |||||
| data.ensureAllocatedSize (other.size()); | |||||
| numUsed = other.numUsed; | numUsed = other.numUsed; | ||||
| memcpy (this->elements, other.elements, numUsed * sizeof (ElementType)); | |||||
| memcpy (data.elements, other.data.elements, numUsed * sizeof (ElementType)); | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -137,7 +135,7 @@ public: | |||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| { | { | ||||
| if (this->elements [i] != other.elements [i]) | |||||
| if (data.elements [i] != other.data.elements [i]) | |||||
| { | { | ||||
| lock.exit(); | lock.exit(); | ||||
| return false; | return false; | ||||
| @@ -172,7 +170,7 @@ public: | |||||
| void clear() throw() | void clear() throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| this->setAllocatedSize (0); | |||||
| data.setAllocatedSize (0); | |||||
| numUsed = 0; | numUsed = 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| } | } | ||||
| @@ -211,7 +209,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ElementType result = (((unsigned int) index) < (unsigned int) numUsed) | const ElementType result = (((unsigned int) index) < (unsigned int) numUsed) | ||||
| ? this->elements [index] | |||||
| ? data.elements [index] | |||||
| : (ElementType) 0; | : (ElementType) 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -230,7 +228,7 @@ public: | |||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| jassert (((unsigned int) index) < (unsigned int) numUsed); | jassert (((unsigned int) index) < (unsigned int) numUsed); | ||||
| const ElementType result = this->elements [index]; | |||||
| const ElementType result = data.elements [index]; | |||||
| lock.exit(); | lock.exit(); | ||||
| return result; | return result; | ||||
| @@ -243,7 +241,7 @@ public: | |||||
| inline ElementType getFirst() const throw() | inline ElementType getFirst() const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ElementType result = (numUsed > 0) ? this->elements [0] | |||||
| const ElementType result = (numUsed > 0) ? data.elements [0] | |||||
| : (ElementType) 0; | : (ElementType) 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -257,7 +255,7 @@ public: | |||||
| inline ElementType getLast() const throw() | inline ElementType getLast() const throw() | ||||
| { | { | ||||
| lock.enter(); | lock.enter(); | ||||
| const ElementType result = (numUsed > 0) ? this->elements [numUsed - 1] | |||||
| const ElementType result = (numUsed > 0) ? data.elements [numUsed - 1] | |||||
| : (ElementType) 0; | : (ElementType) 0; | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -287,7 +285,7 @@ public: | |||||
| lock.exit(); | lock.exit(); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| else if (elementToLookFor == this->elements [start]) | |||||
| else if (elementToLookFor == data.elements [start]) | |||||
| { | { | ||||
| lock.exit(); | lock.exit(); | ||||
| return start; | return start; | ||||
| @@ -301,7 +299,7 @@ public: | |||||
| lock.exit(); | lock.exit(); | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| else if (elementToLookFor >= this->elements [halfway]) | |||||
| else if (elementToLookFor >= data.elements [halfway]) | |||||
| start = halfway; | start = halfway; | ||||
| else | else | ||||
| end = halfway; | end = halfway; | ||||
| @@ -328,7 +326,7 @@ public: | |||||
| lock.exit(); | lock.exit(); | ||||
| return false; | return false; | ||||
| } | } | ||||
| else if (elementToLookFor == this->elements [start]) | |||||
| else if (elementToLookFor == data.elements [start]) | |||||
| { | { | ||||
| lock.exit(); | lock.exit(); | ||||
| return true; | return true; | ||||
| @@ -342,7 +340,7 @@ public: | |||||
| lock.exit(); | lock.exit(); | ||||
| return false; | return false; | ||||
| } | } | ||||
| else if (elementToLookFor >= this->elements [halfway]) | |||||
| else if (elementToLookFor >= data.elements [halfway]) | |||||
| start = halfway; | start = halfway; | ||||
| else | else | ||||
| end = halfway; | end = halfway; | ||||
| @@ -371,7 +369,7 @@ public: | |||||
| insertInternal (start, newElement); | insertInternal (start, newElement); | ||||
| break; | break; | ||||
| } | } | ||||
| else if (newElement == this->elements [start]) | |||||
| else if (newElement == data.elements [start]) | |||||
| { | { | ||||
| break; | break; | ||||
| } | } | ||||
| @@ -381,14 +379,14 @@ public: | |||||
| if (halfway == start) | if (halfway == start) | ||||
| { | { | ||||
| if (newElement >= this->elements [halfway]) | |||||
| if (newElement >= data.elements [halfway]) | |||||
| insertInternal (start + 1, newElement); | insertInternal (start + 1, newElement); | ||||
| else | else | ||||
| insertInternal (start, newElement); | insertInternal (start, newElement); | ||||
| break; | break; | ||||
| } | } | ||||
| else if (newElement >= this->elements [halfway]) | |||||
| else if (newElement >= data.elements [halfway]) | |||||
| start = halfway; | start = halfway; | ||||
| else | else | ||||
| end = halfway; | end = halfway; | ||||
| @@ -470,14 +468,14 @@ public: | |||||
| { | { | ||||
| --numUsed; | --numUsed; | ||||
| ElementType* const e = this->elements + indexToRemove; | |||||
| ElementType* const e = data.elements + indexToRemove; | |||||
| ElementType const removed = *e; | ElementType const removed = *e; | ||||
| const int numberToShift = numUsed - indexToRemove; | const int numberToShift = numUsed - indexToRemove; | ||||
| if (numberToShift > 0) | if (numberToShift > 0) | ||||
| memmove (e, e + 1, numberToShift * sizeof (ElementType)); | memmove (e, e + 1, numberToShift * sizeof (ElementType)); | ||||
| if ((numUsed << 1) < this->numAllocated) | |||||
| if ((numUsed << 1) < data.numAllocated) | |||||
| minimiseStorageOverheads(); | minimiseStorageOverheads(); | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -524,7 +522,7 @@ public: | |||||
| if (otherSet.size() > 0) | if (otherSet.size() > 0) | ||||
| { | { | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (otherSet.contains (this->elements [i])) | |||||
| if (otherSet.contains (data.elements [i])) | |||||
| remove (i); | remove (i); | ||||
| } | } | ||||
| } | } | ||||
| @@ -555,7 +553,7 @@ public: | |||||
| else | else | ||||
| { | { | ||||
| for (int i = numUsed; --i >= 0;) | for (int i = numUsed; --i >= 0;) | ||||
| if (! otherSet.contains (this->elements [i])) | |||||
| if (! otherSet.contains (data.elements [i])) | |||||
| remove (i); | remove (i); | ||||
| } | } | ||||
| } | } | ||||
| @@ -577,14 +575,14 @@ public: | |||||
| if (numUsed == 0) | if (numUsed == 0) | ||||
| { | { | ||||
| this->setAllocatedSize (0); | |||||
| data.setAllocatedSize (0); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| const int newAllocation = this->granularity * (numUsed / this->granularity + 1); | |||||
| const int newAllocation = data.granularity * (numUsed / data.granularity + 1); | |||||
| if (newAllocation < this->numAllocated) | |||||
| this->setAllocatedSize (newAllocation); | |||||
| if (newAllocation < data.numAllocated) | |||||
| data.setAllocatedSize (newAllocation); | |||||
| } | } | ||||
| lock.exit(); | lock.exit(); | ||||
| @@ -620,14 +618,15 @@ public: | |||||
| juce_UseDebuggingNewOperator | juce_UseDebuggingNewOperator | ||||
| private: | private: | ||||
| ArrayAllocationBase <ElementType> data; | |||||
| int numUsed; | int numUsed; | ||||
| TypeOfCriticalSectionToUse lock; | TypeOfCriticalSectionToUse lock; | ||||
| void insertInternal (const int indexToInsertAt, const ElementType newElement) throw() | void insertInternal (const int indexToInsertAt, const ElementType newElement) throw() | ||||
| { | { | ||||
| this->ensureAllocatedSize (numUsed + 1); | |||||
| data.ensureAllocatedSize (numUsed + 1); | |||||
| ElementType* const insertPos = this->elements + indexToInsertAt; | |||||
| ElementType* const insertPos = data.elements + indexToInsertAt; | |||||
| const int numberToMove = numUsed - indexToInsertAt; | const int numberToMove = numUsed - indexToInsertAt; | ||||
| if (numberToMove > 0) | if (numberToMove > 0) | ||||
| @@ -90,8 +90,9 @@ class ValueTreeChildChangeAction : public UndoableAction | |||||
| public: | public: | ||||
| ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_, | ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_, | ||||
| const ValueTree::SharedObjectPtr& newChild_) throw() | const ValueTree::SharedObjectPtr& newChild_) throw() | ||||
| : target (target_), childIndex (childIndex_), | |||||
| : target (target_), | |||||
| child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]), | child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]), | ||||
| childIndex (childIndex_), | |||||
| isDeleting (newChild_ == 0) | isDeleting (newChild_ == 0) | ||||
| { | { | ||||
| jassert (child != 0); | jassert (child != 0); | ||||
| @@ -71,7 +71,8 @@ public: | |||||
| buttonOnColourId = 0x1000101, /**< The colour used to fill the button shape (when the button is toggled | buttonOnColourId = 0x1000101, /**< The colour used to fill the button shape (when the button is toggled | ||||
| 'on'). The look-and-feel class might re-interpret this to add | 'on'). The look-and-feel class might re-interpret this to add | ||||
| effects, etc. */ | effects, etc. */ | ||||
| textColourId = 0x1000102 /**< The colour to use for the button's text. */ | |||||
| textColourOffId = 0x1000102, /**< The colour to use for the button's text when the button's toggle state is "off". */ | |||||
| textColourOnId = 0x1000103 /**< The colour to use for the button's text.when the button's toggle state is "on". */ | |||||
| }; | }; | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -212,16 +212,16 @@ bool CodeDocument::Iterator::isEOF() const throw() | |||||
| //============================================================================== | //============================================================================== | ||||
| CodeDocument::Position::Position() throw() | CodeDocument::Position::Position() throw() | ||||
| : owner (0), line (0), indexInLine (0), | |||||
| characterPos (0), positionMaintained (false) | |||||
| : owner (0), characterPos (0), line (0), | |||||
| indexInLine (0), positionMaintained (false) | |||||
| { | { | ||||
| } | } | ||||
| CodeDocument::Position::Position (const CodeDocument* const ownerDocument, | CodeDocument::Position::Position (const CodeDocument* const ownerDocument, | ||||
| const int line_, const int indexInLine_) throw() | const int line_, const int indexInLine_) throw() | ||||
| : owner (const_cast <CodeDocument*> (ownerDocument)), | : owner (const_cast <CodeDocument*> (ownerDocument)), | ||||
| line (line_), indexInLine (indexInLine_), | |||||
| characterPos (0), positionMaintained (false) | |||||
| characterPos (0), line (line_), | |||||
| indexInLine (indexInLine_), positionMaintained (false) | |||||
| { | { | ||||
| setLineAndIndex (line_, indexInLine_); | setLineAndIndex (line_, indexInLine_); | ||||
| } | } | ||||
| @@ -235,9 +235,8 @@ CodeDocument::Position::Position (const CodeDocument* const ownerDocument, | |||||
| } | } | ||||
| CodeDocument::Position::Position (const Position& other) throw() | CodeDocument::Position::Position (const Position& other) throw() | ||||
| : owner (other.owner), line (other.line), | |||||
| indexInLine (other.indexInLine), characterPos (other.characterPos), | |||||
| positionMaintained (false) | |||||
| : owner (other.owner), characterPos (other.characterPos), line (other.line), | |||||
| indexInLine (other.indexInLine), positionMaintained (false) | |||||
| { | { | ||||
| jassert (*this == other); | jassert (*this == other); | ||||
| } | } | ||||
| @@ -277,16 +277,16 @@ private: | |||||
| CodeEditorComponent::CodeEditorComponent (CodeDocument& document_, | CodeEditorComponent::CodeEditorComponent (CodeDocument& document_, | ||||
| CodeTokeniser* const codeTokeniser_) | CodeTokeniser* const codeTokeniser_) | ||||
| : document (document_), | : document (document_), | ||||
| codeTokeniser (codeTokeniser_), | |||||
| firstLineOnScreen (0), | |||||
| gutter (5), | gutter (5), | ||||
| spacesPerTab (4), | spacesPerTab (4), | ||||
| lineHeight (0), | lineHeight (0), | ||||
| firstLineOnScreen (0), | |||||
| linesOnScreen (0), | linesOnScreen (0), | ||||
| columnsOnScreen (0), | columnsOnScreen (0), | ||||
| scrollbarThickness (16), | scrollbarThickness (16), | ||||
| useSpacesForTabs (false), | |||||
| xOffset (0), | xOffset (0), | ||||
| useSpacesForTabs (false) | |||||
| codeTokeniser (codeTokeniser_) | |||||
| { | { | ||||
| caretPos = CodeDocument::Position (&document_, 0, 0); | caretPos = CodeDocument::Position (&document_, 0, 0); | ||||
| caretPos.setPositionMaintained (true); | caretPos.setPositionMaintained (true); | ||||
| @@ -565,6 +565,14 @@ TreeViewItem* TreeView::getItemAt (int y) const throw() | |||||
| return tc->findItemAt (y, pos); | return tc->findItemAt (y, pos); | ||||
| } | } | ||||
| TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const | |||||
| { | |||||
| if (rootItem == 0) | |||||
| return 0; | |||||
| return rootItem->findItemFromIdentifierString (identifierString); | |||||
| } | |||||
| //============================================================================== | //============================================================================== | ||||
| XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const | XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const | ||||
| { | { | ||||
| @@ -1679,6 +1687,44 @@ TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw( | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| const String TreeViewItem::getItemIdentifierString() const | |||||
| { | |||||
| String s; | |||||
| if (parentItem != 0) | |||||
| s = parentItem->getItemIdentifierString(); | |||||
| return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\')); | |||||
| } | |||||
| TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString) | |||||
| { | |||||
| const String uid (getUniqueName()); | |||||
| if (uid == identifierString) | |||||
| return this; | |||||
| if (identifierString.startsWith (uid + T("/"))) | |||||
| { | |||||
| const String remainingPath (identifierString.substring (uid.length() + 1)); | |||||
| bool wasOpen = isOpen(); | |||||
| setOpen (true); | |||||
| for (int i = subItems.size(); --i >= 0;) | |||||
| { | |||||
| TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath); | |||||
| if (item != 0) | |||||
| return item; | |||||
| } | |||||
| setOpen (wasOpen); | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| void TreeViewItem::restoreOpennessState (const XmlElement& e) throw() | void TreeViewItem::restoreOpennessState (const XmlElement& e) throw() | ||||
| { | { | ||||
| if (e.hasTagName (T("CLOSED"))) | if (e.hasTagName (T("CLOSED"))) | ||||
| @@ -450,6 +450,15 @@ public: | |||||
| /** Returns true if this item is the last of its parent's sub-itens. */ | /** Returns true if this item is the last of its parent's sub-itens. */ | ||||
| bool isLastOfSiblings() const throw(); | bool isLastOfSiblings() const throw(); | ||||
| /** Creates a string that can be used to uniquely retrieve this item in the tree. | |||||
| The string that is returned can be passed to TreeView::findItemFromIdentifierString(). | |||||
| The string takes the form of a path, constructed from the getUniqueName() of this | |||||
| item and all its parents, so these must all be correctly implemented for it to work. | |||||
| @see TreeView::findItemFromIdentifierString, getUniqueName | |||||
| */ | |||||
| const String getItemIdentifierString() const; | |||||
| //============================================================================== | //============================================================================== | ||||
| juce_UseDebuggingNewOperator | juce_UseDebuggingNewOperator | ||||
| @@ -481,6 +490,7 @@ private: | |||||
| int countSelectedItemsRecursively() const throw(); | int countSelectedItemsRecursively() const throw(); | ||||
| TreeViewItem* getSelectedItemWithIndex (int index) throw(); | TreeViewItem* getSelectedItemWithIndex (int index) throw(); | ||||
| TreeViewItem* getNextVisibleItem (const bool recurse) const throw(); | TreeViewItem* getNextVisibleItem (const bool recurse) const throw(); | ||||
| TreeViewItem* findItemFromIdentifierString (const String& identifierString); | |||||
| TreeViewItem (const TreeViewItem&); | TreeViewItem (const TreeViewItem&); | ||||
| const TreeViewItem& operator= (const TreeViewItem&); | const TreeViewItem& operator= (const TreeViewItem&); | ||||
| @@ -654,6 +664,13 @@ public: | |||||
| */ | */ | ||||
| void setIndentSize (const int newIndentSize); | void setIndentSize (const int newIndentSize); | ||||
| /** Searches the tree for an item with the specified identifier. | |||||
| The identifer string must have been created by calling TreeViewItem::getItemIdentifierString(). | |||||
| If no such item exists, this will return false. If the item is found, all of its items | |||||
| will be automatically opened. | |||||
| */ | |||||
| TreeViewItem* findItemFromIdentifierString (const String& identifierString) const; | |||||
| //============================================================================== | //============================================================================== | ||||
| /** Saves the current state of open/closed nodes so it can be restored later. | /** Saves the current state of open/closed nodes so it can be restored later. | ||||
| @@ -114,7 +114,8 @@ LookAndFeel::LookAndFeel() | |||||
| { | { | ||||
| TextButton::buttonColourId, textButtonColour, | TextButton::buttonColourId, textButtonColour, | ||||
| TextButton::buttonOnColourId, 0xff4444ff, | TextButton::buttonOnColourId, 0xff4444ff, | ||||
| TextButton::textColourId, 0xff000000, | |||||
| TextButton::textColourOnId, 0xff000000, | |||||
| TextButton::textColourOffId, 0xff000000, | |||||
| ComboBox::buttonColourId, 0xffbbbbff, | ComboBox::buttonColourId, 0xffbbbbff, | ||||
| ComboBox::outlineColourId, standardOutlineColour, | ComboBox::outlineColourId, standardOutlineColour, | ||||
| @@ -386,7 +387,8 @@ void LookAndFeel::drawButtonText (Graphics& g, TextButton& button, | |||||
| { | { | ||||
| Font font (getFontForTextButton (button)); | Font font (getFontForTextButton (button)); | ||||
| g.setFont (font); | g.setFont (font); | ||||
| g.setColour (button.findColour (TextButton::textColourId) | |||||
| g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId | |||||
| : TextButton::textColourOffId) | |||||
| .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f)); | .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f)); | ||||
| const int yIndent = jmin (4, button.proportionOfHeight (0.3f)); | const int yIndent = jmin (4, button.proportionOfHeight (0.3f)); | ||||
| @@ -48,7 +48,7 @@ static const int defaultGranularity = 32; | |||||
| //============================================================================== | //============================================================================== | ||||
| Path::Path() throw() | Path::Path() throw() | ||||
| : ArrayAllocationBase <float> (defaultGranularity), | |||||
| : data (defaultGranularity), | |||||
| numElements (0), | numElements (0), | ||||
| pathXMin (0), | pathXMin (0), | ||||
| pathXMax (0), | pathXMax (0), | ||||
| @@ -63,7 +63,7 @@ Path::~Path() throw() | |||||
| } | } | ||||
| Path::Path (const Path& other) throw() | Path::Path (const Path& other) throw() | ||||
| : ArrayAllocationBase <float> (defaultGranularity), | |||||
| : data (defaultGranularity), | |||||
| numElements (other.numElements), | numElements (other.numElements), | ||||
| pathXMin (other.pathXMin), | pathXMin (other.pathXMin), | ||||
| pathXMax (other.pathXMax), | pathXMax (other.pathXMax), | ||||
| @@ -73,8 +73,8 @@ Path::Path (const Path& other) throw() | |||||
| { | { | ||||
| if (numElements > 0) | if (numElements > 0) | ||||
| { | { | ||||
| setAllocatedSize (numElements); | |||||
| memcpy (elements, other.elements, numElements * sizeof (float)); | |||||
| data.setAllocatedSize (numElements); | |||||
| memcpy (data.elements, other.data.elements, numElements * sizeof (float)); | |||||
| } | } | ||||
| } | } | ||||
| @@ -82,7 +82,7 @@ const Path& Path::operator= (const Path& other) throw() | |||||
| { | { | ||||
| if (this != &other) | if (this != &other) | ||||
| { | { | ||||
| ensureAllocatedSize (other.numElements); | |||||
| data.ensureAllocatedSize (other.numElements); | |||||
| numElements = other.numElements; | numElements = other.numElements; | ||||
| pathXMin = other.pathXMin; | pathXMin = other.pathXMin; | ||||
| @@ -92,7 +92,7 @@ const Path& Path::operator= (const Path& other) throw() | |||||
| useNonZeroWinding = other.useNonZeroWinding; | useNonZeroWinding = other.useNonZeroWinding; | ||||
| if (numElements > 0) | if (numElements > 0) | ||||
| memcpy (elements, other.elements, numElements * sizeof (float)); | |||||
| memcpy (data.elements, other.data.elements, numElements * sizeof (float)); | |||||
| } | } | ||||
| return *this; | return *this; | ||||
| @@ -109,14 +109,14 @@ void Path::clear() throw() | |||||
| void Path::swapWithPath (Path& other) | void Path::swapWithPath (Path& other) | ||||
| { | { | ||||
| swapVariables <int> (this->numAllocated, other.numAllocated); | |||||
| swapVariables <float*> (this->elements, other.elements); | |||||
| swapVariables <int> (this->numElements, other.numElements); | |||||
| swapVariables <float> (this->pathXMin, other.pathXMin); | |||||
| swapVariables <float> (this->pathXMax, other.pathXMax); | |||||
| swapVariables <float> (this->pathYMin, other.pathYMin); | |||||
| swapVariables <float> (this->pathYMax, other.pathYMax); | |||||
| swapVariables <bool> (this->useNonZeroWinding, other.useNonZeroWinding); | |||||
| swapVariables <int> (data.numAllocated, other.data.numAllocated); | |||||
| swapVariables <float*> (data.elements, other.data.elements); | |||||
| swapVariables <int> (numElements, other.numElements); | |||||
| swapVariables <float> (pathXMin, other.pathXMin); | |||||
| swapVariables <float> (pathXMax, other.pathXMax); | |||||
| swapVariables <float> (pathYMin, other.pathYMin); | |||||
| swapVariables <float> (pathYMax, other.pathYMax); | |||||
| swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding); | |||||
| } | } | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -138,7 +138,7 @@ bool Path::isEmpty() const throw() | |||||
| while (i < numElements) | while (i < numElements) | ||||
| { | { | ||||
| const float type = elements [i++]; | |||||
| const float type = data.elements [i++]; | |||||
| if (type == moveMarker) | if (type == moveMarker) | ||||
| { | { | ||||
| @@ -210,11 +210,11 @@ void Path::startNewSubPath (const float x, | |||||
| pathYMax = jmax (pathYMax, y); | pathYMax = jmax (pathYMax, y); | ||||
| } | } | ||||
| ensureAllocatedSize (numElements + 3); | |||||
| data.ensureAllocatedSize (numElements + 3); | |||||
| elements [numElements++] = moveMarker; | |||||
| elements [numElements++] = x; | |||||
| elements [numElements++] = y; | |||||
| data.elements [numElements++] = moveMarker; | |||||
| data.elements [numElements++] = x; | |||||
| data.elements [numElements++] = y; | |||||
| } | } | ||||
| void Path::lineTo (const float x, const float y) throw() | void Path::lineTo (const float x, const float y) throw() | ||||
| @@ -224,11 +224,11 @@ void Path::lineTo (const float x, const float y) throw() | |||||
| if (numElements == 0) | if (numElements == 0) | ||||
| startNewSubPath (0, 0); | startNewSubPath (0, 0); | ||||
| ensureAllocatedSize (numElements + 3); | |||||
| data.ensureAllocatedSize (numElements + 3); | |||||
| elements [numElements++] = lineMarker; | |||||
| elements [numElements++] = x; | |||||
| elements [numElements++] = y; | |||||
| data.elements [numElements++] = lineMarker; | |||||
| data.elements [numElements++] = x; | |||||
| data.elements [numElements++] = y; | |||||
| pathXMin = jmin (pathXMin, x); | pathXMin = jmin (pathXMin, x); | ||||
| pathXMax = jmax (pathXMax, x); | pathXMax = jmax (pathXMax, x); | ||||
| @@ -245,13 +245,13 @@ void Path::quadraticTo (const float x1, const float y1, | |||||
| if (numElements == 0) | if (numElements == 0) | ||||
| startNewSubPath (0, 0); | startNewSubPath (0, 0); | ||||
| ensureAllocatedSize (numElements + 5); | |||||
| data.ensureAllocatedSize (numElements + 5); | |||||
| elements [numElements++] = quadMarker; | |||||
| elements [numElements++] = x1; | |||||
| elements [numElements++] = y1; | |||||
| elements [numElements++] = x2; | |||||
| elements [numElements++] = y2; | |||||
| data.elements [numElements++] = quadMarker; | |||||
| data.elements [numElements++] = x1; | |||||
| data.elements [numElements++] = y1; | |||||
| data.elements [numElements++] = x2; | |||||
| data.elements [numElements++] = y2; | |||||
| pathXMin = jmin (pathXMin, x1, x2); | pathXMin = jmin (pathXMin, x1, x2); | ||||
| pathXMax = jmax (pathXMax, x1, x2); | pathXMax = jmax (pathXMax, x1, x2); | ||||
| @@ -270,15 +270,15 @@ void Path::cubicTo (const float x1, const float y1, | |||||
| if (numElements == 0) | if (numElements == 0) | ||||
| startNewSubPath (0, 0); | startNewSubPath (0, 0); | ||||
| ensureAllocatedSize (numElements + 7); | |||||
| data.ensureAllocatedSize (numElements + 7); | |||||
| elements [numElements++] = cubicMarker; | |||||
| elements [numElements++] = x1; | |||||
| elements [numElements++] = y1; | |||||
| elements [numElements++] = x2; | |||||
| elements [numElements++] = y2; | |||||
| elements [numElements++] = x3; | |||||
| elements [numElements++] = y3; | |||||
| data.elements [numElements++] = cubicMarker; | |||||
| data.elements [numElements++] = x1; | |||||
| data.elements [numElements++] = y1; | |||||
| data.elements [numElements++] = x2; | |||||
| data.elements [numElements++] = y2; | |||||
| data.elements [numElements++] = x3; | |||||
| data.elements [numElements++] = y3; | |||||
| pathXMin = jmin (pathXMin, x1, x2, x3); | pathXMin = jmin (pathXMin, x1, x2, x3); | ||||
| pathXMax = jmax (pathXMax, x1, x2, x3); | pathXMax = jmax (pathXMax, x1, x2, x3); | ||||
| @@ -289,10 +289,10 @@ void Path::cubicTo (const float x1, const float y1, | |||||
| void Path::closeSubPath() throw() | void Path::closeSubPath() throw() | ||||
| { | { | ||||
| if (numElements > 0 | if (numElements > 0 | ||||
| && elements [numElements - 1] != closeSubPathMarker) | |||||
| && data.elements [numElements - 1] != closeSubPathMarker) | |||||
| { | { | ||||
| ensureAllocatedSize (numElements + 1); | |||||
| elements [numElements++] = closeSubPathMarker; | |||||
| data.ensureAllocatedSize (numElements + 1); | |||||
| data.elements [numElements++] = closeSubPathMarker; | |||||
| } | } | ||||
| } | } | ||||
| @@ -300,11 +300,11 @@ const Point Path::getCurrentPosition() const | |||||
| { | { | ||||
| int i = numElements - 1; | int i = numElements - 1; | ||||
| if (i > 0 && elements[i] == closeSubPathMarker) | |||||
| if (i > 0 && data.elements[i] == closeSubPathMarker) | |||||
| { | { | ||||
| while (i >= 0) | while (i >= 0) | ||||
| { | { | ||||
| if (elements[i] == moveMarker) | |||||
| if (data.elements[i] == moveMarker) | |||||
| { | { | ||||
| i += 2; | i += 2; | ||||
| break; | break; | ||||
| @@ -315,7 +315,7 @@ const Point Path::getCurrentPosition() const | |||||
| } | } | ||||
| if (i > 0) | if (i > 0) | ||||
| return Point (elements [i - 1], elements [i]); | |||||
| return Point (data.elements [i - 1], data.elements [i]); | |||||
| return Point (0.0f, 0.0f); | return Point (0.0f, 0.0f); | ||||
| } | } | ||||
| @@ -331,7 +331,7 @@ void Path::addRectangle (const float x, const float y, | |||||
| if (h < 0) | if (h < 0) | ||||
| swapVariables (y1, y2); | swapVariables (y1, y2); | ||||
| ensureAllocatedSize (numElements + 13); | |||||
| data.ensureAllocatedSize (numElements + 13); | |||||
| if (numElements == 0) | if (numElements == 0) | ||||
| { | { | ||||
| @@ -348,19 +348,19 @@ void Path::addRectangle (const float x, const float y, | |||||
| pathYMax = jmax (pathYMax, y2); | pathYMax = jmax (pathYMax, y2); | ||||
| } | } | ||||
| elements [numElements++] = moveMarker; | |||||
| elements [numElements++] = x1; | |||||
| elements [numElements++] = y2; | |||||
| elements [numElements++] = lineMarker; | |||||
| elements [numElements++] = x1; | |||||
| elements [numElements++] = y1; | |||||
| elements [numElements++] = lineMarker; | |||||
| elements [numElements++] = x2; | |||||
| elements [numElements++] = y1; | |||||
| elements [numElements++] = lineMarker; | |||||
| elements [numElements++] = x2; | |||||
| elements [numElements++] = y2; | |||||
| elements [numElements++] = closeSubPathMarker; | |||||
| data.elements [numElements++] = moveMarker; | |||||
| data.elements [numElements++] = x1; | |||||
| data.elements [numElements++] = y2; | |||||
| data.elements [numElements++] = lineMarker; | |||||
| data.elements [numElements++] = x1; | |||||
| data.elements [numElements++] = y1; | |||||
| data.elements [numElements++] = lineMarker; | |||||
| data.elements [numElements++] = x2; | |||||
| data.elements [numElements++] = y1; | |||||
| data.elements [numElements++] = lineMarker; | |||||
| data.elements [numElements++] = x2; | |||||
| data.elements [numElements++] = y2; | |||||
| data.elements [numElements++] = closeSubPathMarker; | |||||
| } | } | ||||
| void Path::addRectangle (const Rectangle& rectangle) throw() | void Path::addRectangle (const Rectangle& rectangle) throw() | ||||
| @@ -791,38 +791,38 @@ void Path::addPath (const Path& other) throw() | |||||
| while (i < other.numElements) | while (i < other.numElements) | ||||
| { | { | ||||
| const float type = other.elements [i++]; | |||||
| const float type = other.data.elements [i++]; | |||||
| if (type == moveMarker) | if (type == moveMarker) | ||||
| { | { | ||||
| startNewSubPath (other.elements [i], | |||||
| other.elements [i + 1]); | |||||
| startNewSubPath (other.data.elements [i], | |||||
| other.data.elements [i + 1]); | |||||
| i += 2; | i += 2; | ||||
| } | } | ||||
| else if (type == lineMarker) | else if (type == lineMarker) | ||||
| { | { | ||||
| lineTo (other.elements [i], | |||||
| other.elements [i + 1]); | |||||
| lineTo (other.data.elements [i], | |||||
| other.data.elements [i + 1]); | |||||
| i += 2; | i += 2; | ||||
| } | } | ||||
| else if (type == quadMarker) | else if (type == quadMarker) | ||||
| { | { | ||||
| quadraticTo (other.elements [i], | |||||
| other.elements [i + 1], | |||||
| other.elements [i + 2], | |||||
| other.elements [i + 3]); | |||||
| quadraticTo (other.data.elements [i], | |||||
| other.data.elements [i + 1], | |||||
| other.data.elements [i + 2], | |||||
| other.data.elements [i + 3]); | |||||
| i += 4; | i += 4; | ||||
| } | } | ||||
| else if (type == cubicMarker) | else if (type == cubicMarker) | ||||
| { | { | ||||
| cubicTo (other.elements [i], | |||||
| other.elements [i + 1], | |||||
| other.elements [i + 2], | |||||
| other.elements [i + 3], | |||||
| other.elements [i + 4], | |||||
| other.elements [i + 5]); | |||||
| cubicTo (other.data.elements [i], | |||||
| other.data.elements [i + 1], | |||||
| other.data.elements [i + 2], | |||||
| other.data.elements [i + 3], | |||||
| other.data.elements [i + 4], | |||||
| other.data.elements [i + 5]); | |||||
| i += 6; | i += 6; | ||||
| } | } | ||||
| @@ -845,7 +845,7 @@ void Path::addPath (const Path& other, | |||||
| while (i < other.numElements) | while (i < other.numElements) | ||||
| { | { | ||||
| const float type = other.elements [i++]; | |||||
| const float type = other.data.elements [i++]; | |||||
| if (type == closeSubPathMarker) | if (type == closeSubPathMarker) | ||||
| { | { | ||||
| @@ -853,8 +853,8 @@ void Path::addPath (const Path& other, | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| float x = other.elements [i++]; | |||||
| float y = other.elements [i++]; | |||||
| float x = other.data.elements [i++]; | |||||
| float y = other.data.elements [i++]; | |||||
| transformToApply.transformPoint (x, y); | transformToApply.transformPoint (x, y); | ||||
| if (type == moveMarker) | if (type == moveMarker) | ||||
| @@ -867,18 +867,18 @@ void Path::addPath (const Path& other, | |||||
| } | } | ||||
| else if (type == quadMarker) | else if (type == quadMarker) | ||||
| { | { | ||||
| float x2 = other.elements [i++]; | |||||
| float y2 = other.elements [i++]; | |||||
| float x2 = other.data.elements [i++]; | |||||
| float y2 = other.data.elements [i++]; | |||||
| transformToApply.transformPoint (x2, y2); | transformToApply.transformPoint (x2, y2); | ||||
| quadraticTo (x, y, x2, y2); | quadraticTo (x, y, x2, y2); | ||||
| } | } | ||||
| else if (type == cubicMarker) | else if (type == cubicMarker) | ||||
| { | { | ||||
| float x2 = other.elements [i++]; | |||||
| float y2 = other.elements [i++]; | |||||
| float x3 = other.elements [i++]; | |||||
| float y3 = other.elements [i++]; | |||||
| float x2 = other.data.elements [i++]; | |||||
| float y2 = other.data.elements [i++]; | |||||
| float x3 = other.data.elements [i++]; | |||||
| float y3 = other.data.elements [i++]; | |||||
| transformToApply.transformPoint (x2, y2); | transformToApply.transformPoint (x2, y2); | ||||
| transformToApply.transformPoint (x3, y3); | transformToApply.transformPoint (x3, y3); | ||||
| @@ -903,24 +903,24 @@ void Path::applyTransform (const AffineTransform& transform) throw() | |||||
| while (i < numElements) | while (i < numElements) | ||||
| { | { | ||||
| const float type = elements [i++]; | |||||
| const float type = data.elements [i++]; | |||||
| if (type == moveMarker) | if (type == moveMarker) | ||||
| { | { | ||||
| transform.transformPoint (elements [i], | |||||
| elements [i + 1]); | |||||
| transform.transformPoint (data.elements [i], | |||||
| data.elements [i + 1]); | |||||
| if (setMaxMin) | if (setMaxMin) | ||||
| { | { | ||||
| pathXMin = jmin (pathXMin, elements [i]); | |||||
| pathXMax = jmax (pathXMax, elements [i]); | |||||
| pathYMin = jmin (pathYMin, elements [i + 1]); | |||||
| pathYMax = jmax (pathYMax, elements [i + 1]); | |||||
| pathXMin = jmin (pathXMin, data.elements [i]); | |||||
| pathXMax = jmax (pathXMax, data.elements [i]); | |||||
| pathYMin = jmin (pathYMin, data.elements [i + 1]); | |||||
| pathYMax = jmax (pathYMax, data.elements [i + 1]); | |||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| pathXMin = pathXMax = elements [i]; | |||||
| pathYMin = pathYMax = elements [i + 1]; | |||||
| pathXMin = pathXMax = data.elements [i]; | |||||
| pathYMin = pathYMax = data.elements [i + 1]; | |||||
| setMaxMin = true; | setMaxMin = true; | ||||
| } | } | ||||
| @@ -928,46 +928,46 @@ void Path::applyTransform (const AffineTransform& transform) throw() | |||||
| } | } | ||||
| else if (type == lineMarker) | else if (type == lineMarker) | ||||
| { | { | ||||
| transform.transformPoint (elements [i], | |||||
| elements [i + 1]); | |||||
| transform.transformPoint (data.elements [i], | |||||
| data.elements [i + 1]); | |||||
| pathXMin = jmin (pathXMin, elements [i]); | |||||
| pathXMax = jmax (pathXMax, elements [i]); | |||||
| pathYMin = jmin (pathYMin, elements [i + 1]); | |||||
| pathYMax = jmax (pathYMax, elements [i + 1]); | |||||
| pathXMin = jmin (pathXMin, data.elements [i]); | |||||
| pathXMax = jmax (pathXMax, data.elements [i]); | |||||
| pathYMin = jmin (pathYMin, data.elements [i + 1]); | |||||
| pathYMax = jmax (pathYMax, data.elements [i + 1]); | |||||
| i += 2; | i += 2; | ||||
| } | } | ||||
| else if (type == quadMarker) | else if (type == quadMarker) | ||||
| { | { | ||||
| transform.transformPoint (elements [i], | |||||
| elements [i + 1]); | |||||
| transform.transformPoint (data.elements [i], | |||||
| data.elements [i + 1]); | |||||
| transform.transformPoint (elements [i + 2], | |||||
| elements [i + 3]); | |||||
| transform.transformPoint (data.elements [i + 2], | |||||
| data.elements [i + 3]); | |||||
| pathXMin = jmin (pathXMin, elements [i], elements [i + 2]); | |||||
| pathXMax = jmax (pathXMax, elements [i], elements [i + 2]); | |||||
| pathYMin = jmin (pathYMin, elements [i + 1], elements [i + 3]); | |||||
| pathYMax = jmax (pathYMax, elements [i + 1], elements [i + 3]); | |||||
| pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]); | |||||
| pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]); | |||||
| pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]); | |||||
| pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]); | |||||
| i += 4; | i += 4; | ||||
| } | } | ||||
| else if (type == cubicMarker) | else if (type == cubicMarker) | ||||
| { | { | ||||
| transform.transformPoint (elements [i], | |||||
| elements [i + 1]); | |||||
| transform.transformPoint (data.elements [i], | |||||
| data.elements [i + 1]); | |||||
| transform.transformPoint (elements [i + 2], | |||||
| elements [i + 3]); | |||||
| transform.transformPoint (data.elements [i + 2], | |||||
| data.elements [i + 3]); | |||||
| transform.transformPoint (elements [i + 4], | |||||
| elements [i + 5]); | |||||
| transform.transformPoint (data.elements [i + 4], | |||||
| data.elements [i + 5]); | |||||
| pathXMin = jmin (pathXMin, elements [i], elements [i + 2], elements [i + 4]); | |||||
| pathXMax = jmax (pathXMax, elements [i], elements [i + 2], elements [i + 4]); | |||||
| pathYMin = jmin (pathYMin, elements [i + 1], elements [i + 3], elements [i + 5]); | |||||
| pathYMax = jmax (pathYMax, elements [i + 1], elements [i + 3], elements [i + 5]); | |||||
| pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]); | |||||
| pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]); | |||||
| pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]); | |||||
| pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]); | |||||
| i += 6; | i += 6; | ||||
| } | } | ||||
| @@ -1098,17 +1098,17 @@ const Path Path::createPathWithRoundedCorners (const float cornerRadius) const t | |||||
| while (n < numElements) | while (n < numElements) | ||||
| { | { | ||||
| const float type = elements [n++]; | |||||
| const float type = data.elements [n++]; | |||||
| if (type == moveMarker) | if (type == moveMarker) | ||||
| { | { | ||||
| indexOfPathStart = p.numElements; | indexOfPathStart = p.numElements; | ||||
| indexOfPathStartThis = n - 1; | indexOfPathStartThis = n - 1; | ||||
| const float x = elements [n++]; | |||||
| const float y = elements [n++]; | |||||
| const float x = data.elements [n++]; | |||||
| const float y = data.elements [n++]; | |||||
| p.startNewSubPath (x, y); | p.startNewSubPath (x, y); | ||||
| lastWasLine = false; | lastWasLine = false; | ||||
| firstWasLine = (elements [n] == lineMarker); | |||||
| firstWasLine = (data.elements [n] == lineMarker); | |||||
| } | } | ||||
| else if (type == lineMarker || type == closeSubPathMarker) | else if (type == lineMarker || type == closeSubPathMarker) | ||||
| { | { | ||||
| @@ -1116,28 +1116,28 @@ const Path Path::createPathWithRoundedCorners (const float cornerRadius) const t | |||||
| if (type == lineMarker) | if (type == lineMarker) | ||||
| { | { | ||||
| endX = elements [n++]; | |||||
| endY = elements [n++]; | |||||
| endX = data.elements [n++]; | |||||
| endY = data.elements [n++]; | |||||
| if (n > 8) | if (n > 8) | ||||
| { | { | ||||
| startX = elements [n - 8]; | |||||
| startY = elements [n - 7]; | |||||
| joinX = elements [n - 5]; | |||||
| joinY = elements [n - 4]; | |||||
| startX = data.elements [n - 8]; | |||||
| startY = data.elements [n - 7]; | |||||
| joinX = data.elements [n - 5]; | |||||
| joinY = data.elements [n - 4]; | |||||
| } | } | ||||
| } | } | ||||
| else | else | ||||
| { | { | ||||
| endX = elements [indexOfPathStartThis + 1]; | |||||
| endY = elements [indexOfPathStartThis + 2]; | |||||
| endX = data.elements [indexOfPathStartThis + 1]; | |||||
| endY = data.elements [indexOfPathStartThis + 2]; | |||||
| if (n > 6) | if (n > 6) | ||||
| { | { | ||||
| startX = elements [n - 6]; | |||||
| startY = elements [n - 5]; | |||||
| joinX = elements [n - 3]; | |||||
| joinY = elements [n - 2]; | |||||
| startX = data.elements [n - 6]; | |||||
| startY = data.elements [n - 5]; | |||||
| joinX = data.elements [n - 3]; | |||||
| joinY = data.elements [n - 2]; | |||||
| } | } | ||||
| } | } | ||||
| @@ -1150,8 +1150,8 @@ const Path Path::createPathWithRoundedCorners (const float cornerRadius) const t | |||||
| { | { | ||||
| const double propNeeded = jmin (0.5, cornerRadius / len1); | const double propNeeded = jmin (0.5, cornerRadius / len1); | ||||
| p.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded); | |||||
| p.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded); | |||||
| p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded); | |||||
| p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded); | |||||
| } | } | ||||
| const double len2 = juce_hypot (endX - joinX, | const double len2 = juce_hypot (endX - joinX, | ||||
| @@ -1178,12 +1178,12 @@ const Path Path::createPathWithRoundedCorners (const float cornerRadius) const t | |||||
| { | { | ||||
| if (firstWasLine) | if (firstWasLine) | ||||
| { | { | ||||
| startX = elements [n - 3]; | |||||
| startY = elements [n - 2]; | |||||
| startX = data.elements [n - 3]; | |||||
| startY = data.elements [n - 2]; | |||||
| joinX = endX; | joinX = endX; | ||||
| joinY = endY; | joinY = endY; | ||||
| endX = elements [indexOfPathStartThis + 4]; | |||||
| endY = elements [indexOfPathStartThis + 5]; | |||||
| endX = data.elements [indexOfPathStartThis + 4]; | |||||
| endY = data.elements [indexOfPathStartThis + 5]; | |||||
| const double len1 = juce_hypot (startX - joinX, | const double len1 = juce_hypot (startX - joinX, | ||||
| startY - joinY); | startY - joinY); | ||||
| @@ -1192,8 +1192,8 @@ const Path Path::createPathWithRoundedCorners (const float cornerRadius) const t | |||||
| { | { | ||||
| const double propNeeded = jmin (0.5, cornerRadius / len1); | const double propNeeded = jmin (0.5, cornerRadius / len1); | ||||
| p.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded); | |||||
| p.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded); | |||||
| p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded); | |||||
| p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded); | |||||
| } | } | ||||
| const double len2 = juce_hypot (endX - joinX, | const double len2 = juce_hypot (endX - joinX, | ||||
| @@ -1208,8 +1208,8 @@ const Path Path::createPathWithRoundedCorners (const float cornerRadius) const t | |||||
| p.quadraticTo (joinX, joinY, endX, endY); | p.quadraticTo (joinX, joinY, endX, endY); | ||||
| p.elements [indexOfPathStart + 1] = endX; | |||||
| p.elements [indexOfPathStart + 2] = endY; | |||||
| p.data.elements [indexOfPathStart + 1] = endX; | |||||
| p.data.elements [indexOfPathStart + 2] = endY; | |||||
| } | } | ||||
| } | } | ||||
| @@ -1219,21 +1219,21 @@ const Path Path::createPathWithRoundedCorners (const float cornerRadius) const t | |||||
| else if (type == quadMarker) | else if (type == quadMarker) | ||||
| { | { | ||||
| lastWasLine = false; | lastWasLine = false; | ||||
| const float x1 = elements [n++]; | |||||
| const float y1 = elements [n++]; | |||||
| const float x2 = elements [n++]; | |||||
| const float y2 = elements [n++]; | |||||
| const float x1 = data.elements [n++]; | |||||
| const float y1 = data.elements [n++]; | |||||
| const float x2 = data.elements [n++]; | |||||
| const float y2 = data.elements [n++]; | |||||
| p.quadraticTo (x1, y1, x2, y2); | p.quadraticTo (x1, y1, x2, y2); | ||||
| } | } | ||||
| else if (type == cubicMarker) | else if (type == cubicMarker) | ||||
| { | { | ||||
| lastWasLine = false; | lastWasLine = false; | ||||
| const float x1 = elements [n++]; | |||||
| const float y1 = elements [n++]; | |||||
| const float x2 = elements [n++]; | |||||
| const float y2 = elements [n++]; | |||||
| const float x3 = elements [n++]; | |||||
| const float y3 = elements [n++]; | |||||
| const float x1 = data.elements [n++]; | |||||
| const float y1 = data.elements [n++]; | |||||
| const float x2 = data.elements [n++]; | |||||
| const float y2 = data.elements [n++]; | |||||
| const float x3 = data.elements [n++]; | |||||
| const float y3 = data.elements [n++]; | |||||
| p.cubicTo (x1, y1, x2, y2, x3, y3); | p.cubicTo (x1, y1, x2, y2, x3, y3); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1322,37 +1322,37 @@ void Path::writePathToStream (OutputStream& dest) const | |||||
| int i = 0; | int i = 0; | ||||
| while (i < numElements) | while (i < numElements) | ||||
| { | { | ||||
| const float type = elements [i++]; | |||||
| const float type = data.elements [i++]; | |||||
| if (type == moveMarker) | if (type == moveMarker) | ||||
| { | { | ||||
| dest.writeByte ('m'); | dest.writeByte ('m'); | ||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| } | } | ||||
| else if (type == lineMarker) | else if (type == lineMarker) | ||||
| { | { | ||||
| dest.writeByte ('l'); | dest.writeByte ('l'); | ||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| } | } | ||||
| else if (type == quadMarker) | else if (type == quadMarker) | ||||
| { | { | ||||
| dest.writeByte ('q'); | dest.writeByte ('q'); | ||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| } | } | ||||
| else if (type == cubicMarker) | else if (type == cubicMarker) | ||||
| { | { | ||||
| dest.writeByte ('b'); | dest.writeByte ('b'); | ||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| dest.writeFloat (data.elements [i++]); | |||||
| } | } | ||||
| else if (type == closeSubPathMarker) | else if (type == closeSubPathMarker) | ||||
| { | { | ||||
| @@ -1375,7 +1375,7 @@ const String Path::toString() const | |||||
| while (i < numElements) | while (i < numElements) | ||||
| { | { | ||||
| const float marker = elements [i++]; | |||||
| const float marker = data.elements [i++]; | |||||
| tchar markerChar = 0; | tchar markerChar = 0; | ||||
| int numCoords = 0; | int numCoords = 0; | ||||
| @@ -1413,7 +1413,7 @@ const String Path::toString() const | |||||
| while (--numCoords >= 0 && i < numElements) | while (--numCoords >= 0 && i < numElements) | ||||
| { | { | ||||
| String n (elements [i++], 3); | |||||
| String n (data.elements [i++], 3); | |||||
| while (n.endsWithChar (T('0'))) | while (n.endsWithChar (T('0'))) | ||||
| n = n.dropLastCharacters (1); | n = n.dropLastCharacters (1); | ||||
| @@ -1541,7 +1541,7 @@ Path::Iterator::~Iterator() | |||||
| bool Path::Iterator::next() | bool Path::Iterator::next() | ||||
| { | { | ||||
| const float* const elements = path.elements; | |||||
| const float* const elements = path.data.elements; | |||||
| if (index < path.numElements) | if (index < path.numElements) | ||||
| { | { | ||||
| @@ -69,7 +69,7 @@ class Image; | |||||
| @see PathFlatteningIterator, PathStrokeType, Graphics | @see PathFlatteningIterator, PathStrokeType, Graphics | ||||
| */ | */ | ||||
| class JUCE_API Path : private ArrayAllocationBase <float> | |||||
| class JUCE_API Path | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| @@ -632,6 +632,7 @@ public: | |||||
| private: | private: | ||||
| friend class PathFlatteningIterator; | friend class PathFlatteningIterator; | ||||
| friend class Path::Iterator; | friend class Path::Iterator; | ||||
| ArrayAllocationBase <float> data; | |||||
| int numElements; | int numElements; | ||||
| float pathXMin, pathXMax, pathYMin, pathYMax; | float pathXMin, pathXMax, pathYMin, pathYMax; | ||||
| bool useNonZeroWinding; | bool useNonZeroWinding; | ||||
| @@ -44,7 +44,7 @@ PathFlatteningIterator::PathFlatteningIterator (const Path& path_, | |||||
| subPathIndex (-1), | subPathIndex (-1), | ||||
| path (path_), | path (path_), | ||||
| transform (transform_), | transform (transform_), | ||||
| points (path_.elements), | |||||
| points (path_.data.elements), | |||||
| tolerence (tolerence_ * tolerence_), | tolerence (tolerence_ * tolerence_), | ||||
| subPathCloseX (0), | subPathCloseX (0), | ||||
| subPathCloseY (0), | subPathCloseY (0), | ||||
| @@ -464,10 +464,20 @@ public: | |||||
| return true; | return true; | ||||
| DWORD playCursor, writeCursor; | DWORD playCursor, writeCursor; | ||||
| HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor); | |||||
| if (hr != S_OK) | |||||
| for (;;) | |||||
| { | { | ||||
| HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor); | |||||
| if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST | |||||
| { | |||||
| pOutputBuffer->Restore(); | |||||
| continue; | |||||
| } | |||||
| if (hr == S_OK) | |||||
| break; | |||||
| logError (hr); | logError (hr); | ||||
| jassertfalse | jassertfalse | ||||
| return true; | return true; | ||||