Ejemplo n.º 1
0
size_t
AMUnitList::GetLastLabelIndexClipped(SPos v_off, SDst height) const
{
	// XXX: Conversion to 'SPos' might be implementation-defined.
	return vwList.GetHeadIndex() + min(size_t((SPos(height + uTopOffset)
		- v_off - 1) / SPos(GetItemHeight()) + 1), vwList.GetValid(GetTotal()));
}
Ejemplo n.º 2
0
Point
AMUnitList::GetUnitLocation(size_t idx) const
{
	// XXX: Conversion to 'SPos' might be implementation-defined.
	return Point(0, -SPos(uTopOffset) + SPos(GetItemHeight()) * (SPos(idx)
		- SPos(vwList.GetHeadIndex())));
}
Ejemplo n.º 3
0
void CEQDisplay::OnDraw(const SRect &rUpdate)
{
	ASSERT(mpCallback != NULL);

	memset(mpfBufferCurveTotal, 0, GetSize().iCX * sizeof(tfloat32));
	tuint uiBand;
	for (uiBand = 0; uiBand < muiNrOfBands; uiBand++) {
		mpCallback->GetCurve(miCallbackUserDefined, uiBand, mpfBufferCurveBand, GetSize().iCX);

		tint iIndex;
		for (iIndex = 0; iIndex < GetSize().iCX; iIndex++) {
			mpfBufferCurveTotal[iIndex] += mpfBufferCurveBand[iIndex];
		}
	}

//	const tfloat32 fdBMax = 12.0f;
//	const tfloat32 fdBMin = -24.0f;

	tint iIndex;
	for (iIndex = 0; iIndex < GetSize().iCX; iIndex++) {
		tfloat32 fdB = mpfBufferCurveTotal[iIndex];
		//fdB = min(fdB, mfdBMax);
		//fdB = max(fdB, mfdBMin);
		if ((fdB>=mfdBMin)&&(fdB<=mfdBMax)) {
			tfloat32 fIndex = (fdB - mfdBMin) / (mfdBMax - mfdBMin);
			tint32 iYPos = Float2Int((GetSize().iCY - 1) * (1 - fIndex));

			SPos Pos(GetPos() + SPos(iIndex, iYPos));

			mpDrawPrimitives->DrawPoint(rUpdate, Pos, mColour);
		}
	}

	CPane::OnDraw(rUpdate);
}
Ejemplo n.º 4
0
void CEQDisplay::Init(tint iID, IWindow* pWindow, IResourceManager* pResMan, tint32 iDotResID, tint32 iControlIDDot1, tint32 iControlIDDotSpan, tint iDotOffsetX, tint iDotOffsetY, tuint uiNrOfBands, SRGB Colour)
{
	CControl::Init(iID);

	miControlIDDot1 = iControlIDDot1;
	miControlIDDotSpan = iControlIDDotSpan;

	miDotOffsetX = iDotOffsetX;
	miDotOffsetY = iDotOffsetY;

	muiNrOfBands = uiNrOfBands;
	if (muiNrOfBands) {
		tuint uiBand;
		for (uiBand = 0; uiBand < muiNrOfBands; uiBand++) {
			I2D* p2D = I2D::Create();
			// Lasse: *Exterminated*!
			//p2D->Init(guiDotID1 + uiBand, pResMan->GetBitmap(pWindow, iDotResID + uiBand, 1, 1));
			p2D->Init(iControlIDDot1 + uiBand*iControlIDDotSpan, pResMan->GetBitmap(pWindow, iDotResID + uiBand, 1, 1));
			// .. Lasse
			p2D->AddListener(dynamic_cast<IEventReceiver*>(this));

			AddControl(dynamic_cast<IControl*>(p2D), SPos(-miDotOffsetX, -miDotOffsetY));
		}
	}

	mpDrawPrimitives = IDrawPrimitives::Create();
	mpDrawPrimitives->Init(pWindow);

	mColour = Colour;
}
Ejemplo n.º 5
0
char *SCreateReplace(const char *src, char *substring, char *replacement) {
  // replace any occurance of substring in src and return string without these substrings
  SCheck(src,"undefined SRC");
  SCheck(substring,"undefined SUBSTRING");
  SDebug("'%s', '%s', '%s'",src,substring,replacement);
  int a,iter=0,len1,len3,lenr=0;
  if (replacement)
    lenr = strlen(replacement);
  char *p = SCreate(src);
  char *p1, *p3;
  while ((a=SPos(p,substring))>=0) {
    iter++;
    SCheck(iter<S_MAX_ITER,"maximal iterations count exceeded");
    SDebug("ITER=%d: a=%d p='%s'",iter,a,p);
    //printf("p=%s\n",p);
    // create new string
    p1 = NULL;
    len1 = 0;
    if (a > 0) {
      p1 = SCreateBetween(p,0,a-1);
      len1 = strlen(p1);
    }
    p3 = NULL;
    len3 = 0;
    if (a+strlen(substring) < strlen(p)) {
      p3 = SCreateBetween(p,a+strlen(substring),strlen(src));
      len3 = strlen(p3);
    }
    SDebug("p1='%s' replacement='%s' p3='%s'",p1,replacement,p3);
    // if replacement is longer than substring, allocate p again
    if (strlen(p) < len1+lenr+len3) {
      SFree(p);
      p = SCreateSize(len1+lenr+len3+1);
    }
    // actual replacement
    if (p1) {
      if (p3==NULL) {
        sprintf(p,"%s%s",p1,replacement);
      } else {
        //printf("--strlen(p)=%d\n",strlen(p));
        //printf("--p1=%d strlen=%d str='%s'\n",(size_t)p1,strlen(p1),p1);
        //printf("--re=%d strlen=%d str='%s'\n",(size_t)replacement,strlen(replacement),replacement);
        //printf("--p3=%d strlen=%d str='%s'\n",(size_t)p3,strlen(p3),p3);
        sprintf(p,"%s%s%s",p1,replacement,p3);     
      }
    } else {
      if (p3==NULL)
        sprintf(p,"%s",replacement);
      else
        sprintf(p,"%s%s",replacement,p3);     
    }
    SDebug("p=%s",p);
    // release temporary strings
    if (p1) SFree(p1);
    if (p3) SFree(p3);
  }
  return p;
}
Ejemplo n.º 6
0
void CBrowser::OnDraw(const SRect &rUpdate)
{
	if( !IsVisible() )
		return;

	mpPrimitives->DrawRect(rUpdate, GetRect(), SRGB(192, 192, 192));

	SPos Pos(GetPos() + SPos(miMarginLeft, miMarginTop));
	DrawItems(rUpdate, mItemRoot.SubItems, Pos);
}
Ejemplo n.º 7
0
int SPosFrom(char *haystack, char *needle, int from) {
  // find position of substring in string from given index: ("AbcdeAbcde","A",3) returns 5
  SCheck(haystack,"undefined HAYSTACK");
  SCheck(needle,"undefined NEEDLE");
  SCheck(from >= 0,"FROM must be positive index in HAYSTACK");
  SCheck(from < strlen(haystack),"FROM must be lower than HAYSTACK length");
  SCheck(from < strlen(haystack)+strlen(needle),"FROM must be lower than HAYSTACK+NEEDLE length");
  // FIXME: not finding something in string is not fatal error, perhaps it should only return with -1 result  
  if (from == 0)
    return SPos(haystack,needle);
  char *f = SCreateBetween(haystack,from,strlen(haystack));
  int r = SPos(f,needle);
  //printf("f=%s r=%d\n",f,r);
  SFree(f);
  if (r >= 0)
    return from + r;
  else
    return -1;
}
Ejemplo n.º 8
0
void CScrollBar::Init(tint32 iID, EType Type, IWindow* pWnd, IResourceManager* pResMan, tint32 piIDs[BitmapCount], IScrollPane* pScrollPane, const SScrollPos& ScrollPos)
{
	CControl::Init(iID);

	mpScrollPane = pScrollPane;
	mType = Type;
	mScrollPos = ScrollPos;

	// Lasse, this very important part got deleted!!!! - added again 2008-05-09
	// Prepare to catch update-signal from scroll-pane
	if (mpScrollPane)
		mpScrollPane->AddListener(this);
	// .. Lasse

	// Create resources for first 2 bitmaps, and get the sizes. Also create controls and add them
	tint iBitmap;
	for (iBitmap = 0; iBitmap < 2; iBitmap++) {
		mppBitmapRes[iBitmap] = pResMan->GetBitmap(pWnd, piIDs[iBitmap], 2, 1);
		mppBitmapRes[iBitmap]->GetRealSize(mpBitmapSizes[iBitmap]);

		IButton* pButton = IButton::Create();
		pButton->Init(-1, mppBitmapRes[iBitmap]);
		pButton->AddListener(dynamic_cast<IEventReceiver*>(this));

		AddControl(pButton, SPos(0, 0));
	}

	// Create resources for last 3 bitmaps, and get the sizes
	for (iBitmap = 2; iBitmap < BitmapCount; iBitmap++) {
		mppBitmapRes[iBitmap] = pResMan->GetBitmap(pWnd, piIDs[iBitmap], 1, 1);
		mppBitmapRes[iBitmap]->GetRealSize(mpBitmapSizes[iBitmap]);
	}

	SetSize((SSize)(mScrollPos.VisibleRect), false);

	switch(mType) {
		case TypeHorizontal:
			{
				// Left
				mSize.iCY = mpBitmapSizes[BitmapLeftTop].iCY;
			}
			break;
		case TypeVertical:
			{
				// Up
				mSize.iCX = mpBitmapSizes[BitmapLeftTop].iCX;
			}
			break;
	}

	PositionControls();

	dynamic_cast<CScrollPane*>(mpScrollPane)->SetScrollBar(dynamic_cast<CScrollBar*>(this));
}
Ejemplo n.º 9
0
void CScrollBar::PositionControls()
{
	switch(mType) {
		case TypeHorizontal:
			{
				// Left
				std::list<IControl*>::iterator it = mControls.begin();
				if (mControls.size() > 2) {
					it++;
				}
				IControl* pControl = *it++;
				pControl->SetPos(SPos(0, 0));

				// Right
				pControl = *it;
				SPos Pos;
				Pos.iY = 0;
				Pos.iX = GetSize().iCX - mpBitmapSizes[BitmapRightDown].iCX;
				pControl->SetPos(Pos);
			}
			break;
		case TypeVertical:
			{
				// Up
				std::list<IControl*>::iterator it = mControls.begin();
				if (mControls.size() > 2) {
					it++;
				}
				IControl* pControl = *it++;
				pControl->SetPos(SPos(0, 0));

				// Down
				pControl = *it;
				SPos Pos2;
				Pos2.iY = GetSize().iCY - mpBitmapSizes[BitmapRightDown].iCY;
				Pos2.iX = 0;
				pControl->SetPos(Pos2);
			}
			break;
	}
}
Ejemplo n.º 10
0
void
DropDownList::Refresh(PaintEventArgs&& e)
{
    const auto cs(GetCursorState());

    if(FetchContainerPtr(lbContent))
        csCurrent = CursorState::Pressed;
    Button::Refresh(std::move(e));
    csCurrent = cs;
    // XXX: Conversion to 'SPos' might be implementation-defined.
    DrawArrow(e.Target, e.ClipArea, Rect(e.Location.X + SPos(GetWidth()) - 16,
                                         e.Location.Y, Size(16, GetHeight())), 4, RDeg270, ForeColor);
}
Ejemplo n.º 11
0
CBrowser::SItem* CBrowser::GetItem(const SPos& Pos)
{
	SPos PosCur(Pos);

	PosCur -= GetPos();

	PosCur -= SPos(miMarginLeft, miMarginTop);
	if (PosCur.iX < 0 || PosCur.iY < 0) {
		return NULL;
	}

	return GetItemRecur(PosCur, mItemRoot.SubItems);
}
Ejemplo n.º 12
0
CBrowser::CBrowser()
	: mpFont(NULL), mpArrow(NULL), mpPrimitives(NULL), mpScrollPane(NULL), mpScrollBar(NULL), mSizeMin(0, 0),
	mpItemSelected(NULL)
{
	mItemRoot.bFolder = true;

	miMaxDepth = 3;
	miSpaceBetweenItems = 16;
	miMarginLeft = 10;
	miMarginTop = 4;
	miSpaceBetweenFolders = 16;
	mTextPosition = SPos(20, 0);
}
Ejemplo n.º 13
0
void CBitmap::OnDraw(const SRect &rUpdate)
{
	if( !IsVisible() )
		return;

	if (mSize == mSizeBitmap) {
		// Size of control equals size of bitmap
		DrawBitmapFrame(GetBitmapResource(), rUpdate, SRect(GetPos(), mSizeBitmap),
			miFrameCur, miFrames);
	}
	else {
		if (mSize.iCX < mSizeBitmap.iCX) {
			DrawBitmapFrame(GetBitmapResource(), rUpdate, SRect(GetPos(), mSize),
				miFrameCur, miFrames);
		}
		else if (mSize.iCY < mSizeBitmap.iCY) {
			DrawBitmapFrame(GetBitmapResource(), rUpdate, SRect(GetPos(), mSize),
				miFrameCur, miFrames);
		}
		else {
			SPos PosThis;
			GetPos(PosThis);
			// Size of control doesn't equal size of bitmap, so tiling is needed
			tint32 iYPos = rUpdate.iY - PosThis.iY - mSizeBitmap.iCY;
			if (iYPos < 0) {
				iYPos = 0;
			}
			while ((iYPos < mSize.iCY) &&
				(PosThis.iY + iYPos < rUpdate.iY + rUpdate.iCY)) {
				tint32 iXPos = rUpdate.iX - PosThis.iX - mSizeBitmap.iCX;
				if (iXPos < 0) {
					iXPos = 0;
				}
				while ((iXPos < mSize.iCX) &&
					(PosThis.iX + iXPos < rUpdate.iX + rUpdate.iCX)) {
					DrawBitmapFrame(GetBitmapResource(), rUpdate, SRect(PosThis + SPos(iXPos, iYPos), mSizeBitmap),
						miFrameCur, miFrames);

						iXPos += mSizeBitmap.iCX;
				}

				iYPos += mSizeBitmap.iCY;
			}
		}
	}
}
Ejemplo n.º 14
0
BorderResizer::Area
BorderResizer::CheckArea(const Point& pt)
{
	const auto comp([](SPos q, SPos left, SPos left2){
		if(q >= 0)
		{
			const SPos a[]{SPos(), left, left2};
			const auto n(SwitchInterval(q, a, 3));

			if(n < 3)
				return BorderArea(n);
		}
		return BorderArea::Center;
	});
	const Size& size(GetSizeOf(widget));

	return {comp(pt.X, Margin.Left, size.Width - GetHorizontalOf(Margin)),
		comp(pt.Y, Margin.Top, size.Height - GetVerticalOf(Margin))};
}
Ejemplo n.º 15
0
void CWindowOSXQT::PaintToBuffer(tuchar* puchBuffer, tuint32 uiInterleave, const SRect& rUpdate)
{
	int iBytesNeeded = (mSize.iCX + 1) * (mSize.iCY + 1) * 4;
	if (iBytesNeeded > miDrawBufferSize) {
		if (mpcDrawBuffer) {
			delete[] mpcDrawBuffer;
		}

		miDrawBufferSize = iBytesNeeded;
		mpcDrawBuffer = new tuchar[miDrawBufferSize];
	}

	if (mpInvalidater->IsRectInvalidated() == true) {
		// We need to update the buffer
		SRect RectUpdate;
		mpInvalidater->GetInvalidatedRect(RectUpdate);
		mpInvalidater->Reset();

		// Limit update rect to our actual size
		SRect RectThis(SPos(0, 0), mSize);
		RectUpdate.FitInside(RectThis);
		// Limit update rect to, well, the update rect...
		RectUpdate.FitInside(rUpdate);

		GetPane()->OnDraw(RectUpdate);
		if (mpControlOnTop) {
			mpControlOnTop->OnDraw(RectUpdate);
		}
	}

	// Copy to buffer delivered
	tuint uiY;
	for (uiY = rUpdate.iY; uiY < mSize.iCY && uiY < (rUpdate.iY + rUpdate.iCY); uiY++) {
		tuchar* puchDest = puchBuffer + (uiInterleave * uiY);
		tuchar* puchSource = mpcDrawBuffer + (4 * mSize.iCX * uiY);
		tuint uiX;
		for (uiX = rUpdate.iX; uiX < mSize.iCX && uiX < (rUpdate.iX + rUpdate.iCX); uiX++) {
			((tuint32*)puchDest)[uiX] = ((tuint32*)puchSource)[uiX];
		}
	}
}
Ejemplo n.º 16
0
void CLED::OnDraw(const SRect &rUpdate)
{
	if( !IsVisible() )
		return;


	tfloat fDrawSize = (miCurrent - miMin) / (float)(miMax - miMin);
	
	int iPixelsToDraw = (int)(GetSize().iCY * fDrawSize);

	// Possion to draw from
	SPos Pos(GetPos() + SPos(0, GetSize().iCY - iPixelsToDraw));

	// Size to draw
	SSize Size(GetSize().iCX, iPixelsToDraw);

	// Set rect to draw
	SRect Rect(Pos, Size);

	// Draw
	mpPrimitives->DrawRect(rUpdate, Rect, mColor);
}
Ejemplo n.º 17
0
void CWindowOSXQT::OnPaint()
{
	int iBytesNeeded = (mSize.iCX + 1) * (mSize.iCY + 1) * 4;
	if (iBytesNeeded > miDrawBufferSize) {
		if (mpcDrawBuffer) {
			delete[] mpcDrawBuffer;
		}

		miDrawBufferSize = iBytesNeeded;
		mpcDrawBuffer = new tuchar[miDrawBufferSize];
	}

	if (mpInvalidater->IsRectInvalidated() == false) {
		// No updating neccasary
		return;
	}
	SRect RectUpdate;
	mpInvalidater->GetInvalidatedRect(RectUpdate);
	mpInvalidater->Reset();

	// Limit update rect to our actual size
	SRect RectThis(SPos(0, 0), mSize);
	RectUpdate.FitInside(RectThis);

	GetPane()->OnDraw(RectUpdate);
	if (mpControlOnTop) {
		mpControlOnTop->OnDraw(RectUpdate);
	}

	PixMap 			srcbm;
	GrafPtr 		saved;
	Rect 			portBounds;
	GrafPtr 		grafPtrThis;
	BitMapPtr 		dstbitmap;
	PixMapHandle	dstpixmap;

	memset(&srcbm,0,sizeof(PixMap));
	// setup begin
	srcbm.baseAddr = nil;
	srcbm.rowBytes = 0x8000;

	srcbm.bounds.left = 0;
	srcbm.bounds.top = 0;
	srcbm.bounds.right = mSize.iCX - 1;
	srcbm.bounds.bottom = mSize.iCY - 1;
	
	// ???
	int bytesPerRow = mSize.iCX * 4;

	srcbm.pmVersion = 4;
	srcbm.packType = 0;
	srcbm.packSize = 0;
	srcbm.hRes = 0x00480000;
	srcbm.vRes = 0x00480000;
	srcbm.pixelType = 0;
	srcbm.pixelSize = 0;
	srcbm.cmpCount = 0;
	srcbm.cmpSize = 0;
	srcbm.pmTable = nil;
	srcbm.pixelType = RGBDirect;
	srcbm.pixelSize = 32;
	srcbm.cmpCount = 3;
	srcbm.cmpSize = 5;
	srcbm.rowBytes = 0x8000 | (unsigned short) bytesPerRow;
	srcbm.baseAddr = (Ptr)mpcDrawBuffer;
	
	unsigned long ulOffsetX, ulOffsetY;
	ulOffsetX = 0;
	ulOffsetY = 0;
	
	Rect SrcRect;	
	SrcRect.left    = RectUpdate.iX;
	SrcRect.right   = RectUpdate.iX + RectUpdate.iCX - 1;
	SrcRect.top     = RectUpdate.iY;
	SrcRect.bottom  = RectUpdate.iY + RectUpdate.iCY - 1;

	Rect DstRect;
	DstRect = SrcRect;
		
	GetPort(&saved);
	
	grafPtrThis = (GrafPtr)::GetWindowPort(GetWindowRef());

	if (saved != grafPtrThis) {
		SetPort(grafPtrThis);
	}

	GetPortBounds(grafPtrThis, &portBounds);

	int port_offsetX = portBounds.left;
	int port_offsetY = portBounds.top;

	SetOrigin( port_offsetX, port_offsetY );
/*	Rect rctClip;
	rctClip.left = 0;
	rctClip.right = rctClip.left + mSize.iCX;
	rctClip.top = 0;
	rctClip.bottom = rctClip.top + mSize.iCY;
	ClipRect(&rctClip);*/
	
	dstpixmap = ::GetPortPixMap(grafPtrThis);
	
	dstbitmap = (BitMapPtr)(*dstpixmap);
	
	ForeColor(blackColor);
	BackColor(whiteColor);
	
	::CopyBits((BitMapPtr)&srcbm,
		dstbitmap,
		&SrcRect,
		&DstRect,
		srcCopy,
		nil);
		
//	SetOrigin(0, 0);

	if (saved != grafPtrThis) {
		SetPort(saved);
	}
}
Ejemplo n.º 18
0
void STests(int level) {
  // unit self tests
  char *a, *b, *c;
  int i,j,k;
  int ol = S_DEBUG_LEVEL;
  S_DEBUG_LEVEL=level;
  
  // test
  a = SCreate("Hello World");
  STest(a,"Hello World","string creation");
  
  // test
  SFree(a);
  STestI((intptr_t)a,0,"string free and set to NULL");
        
  // test
  a = SCreate("0123456789");
  i = SPos(a,"0");    STestI(i,0,"position of char on the begining of string");
  i = SPos(a,"012");  STestI(i,0,"position of string on the begining of string");
  i = SPos(a,"9");    STestI(i,9,"position of char on the end of string");
  i = SPos(a,"789");  STestI(i,7,"position of string on the end of string");
  i = SPos(a,"4");    STestI(i,4,"position of char in the middle of string");
  i = SPos(a,"456");  STestI(i,4,"position of string in the middle of string");
  SFree(a);
  
  // test
  //S_DEBUG_LEVEL=1;
  a = SCreate("I walked into bar and talked to bar");
  b = SCreateReplace(a,"bar","BAR");
  STest(b,"I walked into BAR and talked to BAR",
        "replacing on the end of string");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("foo bar foo");
  b = SCreateReplace(a,"bar","BAR");
  STest(b,"foo BAR foo",
        "replacing in the middle of string once");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("foo bar and bar foo");
  b = SCreateReplace(a,"bar","BAR");
  STest(b,"foo BAR and BAR foo",
        "replacing in the middle of string twice");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("foo bar foo");
  b = SCreateReplace(a,"foo","FOO");
  STest(b,"FOO bar FOO",
        "replacing on the begining and end of string");
  SFree(a);
  SFree(b);
  
  // test
  a = SCreate("abc");
  b = SCreateReplace(a,"b","B");
  STest(b,"aBc",
        "replacing one char on 2nd position");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("abc");
  b = SCreateReplace(a,"a","A");
  STest(b,"Abc",
        "replacing one char on 1st position");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("abc");
  b = SCreateReplace(a,"c","C");
  STest(b,"abC",
        "replacing one char on last position");
  SFree(a);
  SFree(b);
  
  // test
  a = SCreate("abc");
  b = SCreateReplace(a,"b","BBB");
  STest(b,"aBBBc",
        "replacing one char with 3char string");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("abbbc");
  b = SCreateReplace(a,"bbb","B");
  STest(b,"aBc",
        "replacing string with one char");
  SFree(a);
  SFree(b);

  // test
  a = SCreate("abbba");
  b = SCreateReplace(a,"a","AA");
  STest(b,"AAbbbAA",
        "multiple replacement with different length");
  SFree(a);
  SFree(b);
  
  // test
  a = SCreate("97%");
  b = SCreateReplace(a,"%","");
  STest(b,"97",
        "replacing percent sing from 97%%");
  SFree(a);
  SFree(b);
  
  // test
  a = SCreate("  Mono: Playback 62 [97%] [-2.00dB] [on]");
  i = SPos(a,"[");
  j = SPos(a,"]");
  b = SCreateBetween(a,i+1,j-1);
  c = SCreateReplace(b,"%","");
  k = SInt(c);
  STestI(k,97,"extracting alsa volume");
  SFree(a);
  SFree(b);
  SFree(c);
  
  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  b = SCreateBetween(a,10,50);
  STest(b,"Abcde","create string between longer that source");
  SFree(a);
  SFree(b);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"A",0);
  STestI(i,0,"position from 0 at 0");
  SFree(a);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"A",1);
  STestI(i,5,"position from 1 at 5");
  SFree(a);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"A",8);
  STestI(i,10,"position from 8 at 10");
  SFree(a);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"A",11);
  STestI(i,-1,"position from 11 at -1");
  SFree(a);

  // test      012345678901234
  a = SCreate("AbcdeAbcdeAbcde");
  i = SPosFrom(a,"e",11);
  STestI(i,14,"position from 14 at -1");
  SFree(a);

  if (S_DEBUG_LEVEL >= 1)
    printf("STest: all %d tests passed\n",S_TEST_ID);
  S_DEBUG_LEVEL=ol;        
}
Ejemplo n.º 19
0
void
BorderResizer::Wrap()
{
	auto& controller(widget.get().GetController());

	yunseq(
	FetchEvent<TouchDown>(controller).Add([this](CursorEventArgs&& e){
		yunseq(orig_loc = FetchGUIState().CursorLocation,
			locked_bounds = GetBoundsOf(widget), focused = CheckArea(e));
	}, 0xE0),
	FetchEvent<TouchHeld>(controller).Add([this](CursorEventArgs&& e){
		if(e.Strategy == RoutedEventArgs::Direct
			&& focused != Area(BorderArea::Center, BorderArea::Center))
		{
			auto& st(FetchGUIState());

			if(st.CheckDraggingOffset())
			{
				const auto offset(st.CursorLocation - orig_loc);
				auto bounds(locked_bounds);

				// XXX: Conversion to 'SPos' might be implementation-defined.
				switch(focused.first)
				{
				case BorderArea::Left:
					bounds.Width = SDst(max<SPos>(SPos(MinSize.Width),
						SPos(locked_bounds.Width) - offset.X));
					bounds.X += SPos(locked_bounds.Width) - SPos(bounds.Width);
					break;
				case BorderArea::Right:
					bounds.Width = SDst(max<SPos>(SPos(MinSize.Width),
						SPos(locked_bounds.Width) + offset.X));
					break;
				default:
					;
				}
				switch(focused.second)
				{
				case BorderArea::Up:
					bounds.Height = SDst(max<SPos>(SPos(MinSize.Height),
						SPos(locked_bounds.Height) - offset.Y));
					bounds.Y += SPos(locked_bounds.Height)
						- SPos(bounds.Height);
					break;
				case BorderArea::Down:
					bounds.Height = SDst(max<SPos>(SPos(MinSize.Height),
						SPos(locked_bounds.Height) + offset.Y));
					break;
				default:
					;
				}
				YTraceDe(Notice, "BorderResizer: new bounds = %s.",
					to_string(bounds).c_str());
				InvalidateParent(widget);
				if(RootMode)
				{
					const auto&
						off(bounds.GetPoint() - locked_bounds.GetPoint());

					SetBoundsOf(widget, bounds);

					const auto& nloc(FetchGUIState().CursorLocation - off);

					if(bounds.Width != MinSize.Width)
						orig_loc.X = nloc.X;
					if(bounds.Height != MinSize.Height)
						orig_loc.Y = nloc.Y;
					locked_bounds = GetBoundsOf(widget);
					locked_bounds.GetPointRef() -= off;
				}
				else
					SetBoundsOf(widget, bounds);
			}
			e.Handled = true;
			// XXX: Paint context target invalidated.
		}
	}, 0xE0),
	FetchEvent<Click>(controller).Add([this](CursorEventArgs&& e){
		CallEvent<ClickAcross>(widget, e);
	}, 0xE0),
	FetchEvent<ClickAcross>(controller).Add([this]{
		yunseq(orig_loc = Point::Invalid, locked_bounds = Rect(),
			focused = {BorderArea::Center, BorderArea::Center});
	}, 0xE0)
	);
}
Ejemplo n.º 20
0
size_t
AMUnitList::CheckPoint(const Size& s, const Point& pt)
{
	return Rect(s).Contains(pt) ? size_t((pt.Y + SPos(uTopOffset))
		/ SPos(GetItemHeight())) + vwList.GetHeadIndex() : size_t(-1);
}
Ejemplo n.º 21
0
DropDownList::DropDownList(const Rect& r, const shared_ptr<ListType>& h)
    : Button(r),
      lbContent( {}, h)
{
    const auto detacher([this](UIEventArgs&& e) {
        if(!dynamic_cast<RoutedEventArgs*>(&e))
            DetachTopWidget();
    });

    yunseq(
        Margin.Left = 4,
        Margin.Right = 18,
        HorizontalAlignment = TextAlignment::Left,
        lbContent.GetView().DependencyPtr = this,
    FetchEvent<TouchDown>(*this) += [this](CursorEventArgs&& e) {
        if(!FetchContainerPtr(lbContent))
        {
            Point pt;

            if(const auto p
                    = dynamic_cast<Panel*>(&FetchTopLevel(e.GetSender(), pt)))
            {
                // NOTE: Get height of top widget, top and bottom spaces.
                const SDst h0(GetSizeOf(*p).Height);
                // XXX: Conversion to 'SPos' might be implementation-defined.
                const SDst h1(SDst(max<SPos>(0, pt.Y))), h2(SDst(max<SPos>(0,
                        SPos(h0) - pt.Y - SPos(GetHeight()))));

                if(IsInOpenInterval(h1, h0) || IsInOpenInterval(h2, h0))
                {
                    lbContent.ResizeForPreferred(Size(0, max(h1, h2)),
                                                 Size(GetWidth(), 0));

                    const SDst h3(lbContent.GetHeight());

                    // NOTE: Bottom space is preferred.
                    // XXX: Conversion to 'SPos' might be
                    //	implementation-defined.
                    pt.Y += SPos(h2 < h3 ? -h3 : GetHeight());
                    SetLocationOf(lbContent, pt);
                    lbContent.AdjustViewLength();
                    {
                        const auto& lst(lbContent.GetList());
                        const auto i(std::find(lst.cbegin(), lst.cend(), Text));

                        if(i != lst.cend())
                            lbContent.SetSelected(size_t(i - lst.cbegin()));
                        else
                            lbContent.ClearSelected();
                    }
                    p->Add(lbContent, 224U); // TODO: Use non-magic number.
                    RequestFocusCascade(lbContent);
                    e.Handled = true;
                }
            }
        }
    },
    FetchEvent<LostFocus>(*this) += detacher,
                                    FetchEvent<LostFocus>(lbContent) += detacher,
    lbContent.GetConfirmed() += [this](IndexEventArgs&& e) {
        YAssert(e.Value < lbContent.GetList().size(), "Invalid index found.");

        Text = lbContent.GetList()[e.Value];
        // XXX: This seems to be redundant if the detached top widget would be
        //	always invalidated, however there is no such guarantee.
        Invalidate(e.GetSender()),
                   Invalidate(*this);
        DetachTopWidget();
    }
    );
}