[ create a new paste ] login | about

Link: http://codepad.org/VL1dz5PT    [ raw code | fork ]

almostautomated - C++, pasted on Feb 22:
//  Returns -1 if there isn't enough space for markCount, else returns the first markerID
//  available with enough contiguous space to allow for markerCount.
int getFirstAvailableMarker(int markerCount)
{
	//  Since all markers are not available let NB_MAX_PLUGINMARKERS be at least < 24.
	if ( markerCount > NB_MAX_PLUGINMARKERS ) return ( false );

	//  Make the protected ViewStyle public to allow access to the marker array.
	class MarkerAccessor : public Editor {
	public:
		using Editor::vs;
	};

	MarkerAccessor* p_mView = reinterpret_cast<MarkerAccessor *>(::GetWindowLongPtr( npp_plugin::hMainView(), 0));
	MarkerAccessor* p_sView = reinterpret_cast<MarkerAccessor *>(::GetWindowLongPtr( npp_plugin::hSecondView(), 0));

	int firstAvail = -1;
	int contiguous = 0;
	LineMarker em;		//  Empty mark to test against.
	LineMarker* mvm;	//  Main view mark to test.
	LineMarker* svm;	//  Second view mark to test.

	for ( int i = 0; i < NB_MAX_PLUGINMARKERS; i++ ) {
		mvm = &p_mView->vs.markers[i];
		svm = &p_sView->vs.markers[i];

		if ( ( em.markType == mvm->markType ) && ( em.markType == svm->markType ) &&
				( em.alpha == mvm->alpha ) && ( em.alpha == svm->alpha ) &&
				( em.fore.allocated.AsLong() == mvm->fore.allocated.AsLong() ) &&
				( em.fore.allocated.AsLong() == svm->fore.allocated.AsLong() ) &&
				( em.back.allocated.AsLong() == mvm->back.allocated.AsLong() ) &&
				( em.back.allocated.AsLong() == svm->back.allocated.AsLong() ) ) {

			if ( contiguous == 0 ) firstAvail = i;
			contiguous++;
		}
		else {
			contiguous = 0;
		}

		if ( contiguous == markerCount ) break;
	}

	if ( contiguous != markerCount ) firstAvail = -1;

	return ( firstAvail );
}


Create a new paste based on this one


Comments: