예제 #1
0
bool CUIVertScrollBar::SendChildMessage(int message,int p1,int p2,SDL_Surface *si)
{
	switch (message)
	{
	case UIEV_LBUTTONDOWN:
		{
			int mx,my;
			GETMOUSEPOS(p1,&mx,&my);
			if (my<y+arrowlng+slidepos)
			{
				baseval=MAX(min,baseval-nve);
				SendChildMessage(INTERNEV_REDRAW,0,0,si);
			}
			else if (my>y+arrowlng+slidepos+lslidebar)
			{
				baseval=MIN(baseval+nve,max-nve+1);
				SendChildMessage(INTERNEV_REDRAW,0,0,si);
			}
			else
			{
				barclickpos=my-slidepos-arrowlng-y;
				SendChildMessage(INTERNEV_REDRAW,0,0,si);
			}
			return true;
		}
	case UIEV_LBUTTONUP:
		{
			if (barclickpos>=0)
			{
				barclickpos=-1;
				return true;
			}
			return false;
		}
	case UIEV_MOUSEMOVE:
		{
			if (barclickpos>=0)
			{
				int mx,my;
				GETMOUSEPOS(p1,&mx,&my);
				if (my<=y+arrowlng)
				{
					my=y+arrowlng+1;
				}
				if (my>=y+h-arrowlng)
				{
					my=y+h-arrowlng-1;
				}				
				int newstartpos=my-barclickpos-y-arrowlng; // new starting position
				int nbaseval=min+(newstartpos*(valdomain-nve+1))/(lslidezone-lslidebar);
				SetBaseVal(nbaseval);
				SendChildMessage(INTERNEV_REDRAW,0,0,si);
				return true;
			}
			return false;
		}
	case UIEV_DRAW:
		{
			lslidezone=h-(2*arrowlng);
			valdomain=max-min;
			slideregion.SaveRegion(si,x,y+arrowlng,w,lslidezone);
			if (valdomain>nve)
			{
				lslidebar=(lslidezone*nve)/(valdomain+1);	
			}
			else
			{
				lslidebar=-1;
			}
			SendChildMessage(INTERNEV_REDRAW,0,0,si);
			return true;
		}
	case INTERNEV_REDRAW:
		{
			if (lslidebar>-1)
			{
				// redraw background
				slideregion.RestaurRegion(si);
				// compute slidepos
				slidepos=((baseval-min)*(lslidezone-lslidebar))/(valdomain-nve+1);
				// draw slide
				SGU_FillRectAlpha(si,x,y+arrowlng+slidepos,w,lslidebar,theme->WgtBack);				
				if (ismouseover)
				{
					SGU_RectShade(si,x,y+arrowlng+slidepos,w,lslidebar,theme->FHiCol,theme->FMidCol,theme->FLowCol);
				}
				else
				{
					SGU_RectShade(si,x,y+arrowlng+slidepos,w,lslidebar,theme->BHiCol,theme->BMidCol,theme->BLowCol);
				}
				return true;
			}
			return false;
		}
	case UIEV_GETMOUSEOVER:
		{
			ismouseover=true;
			SendChildMessage(INTERNEV_REDRAW,0,0,si);
			return true;
		}
	case UIEV_LOSEMOUSEOVER:
		{
			ismouseover=false;
			SendChildMessage(INTERNEV_REDRAW,0,0,si);
			return true;
		}
	case UIEV_LOSEFOCUS:
		{
			barclickpos=-1;
			return true;
		}
	default:
		{
			return false;
		}
	}
}
예제 #2
0
bool CUIHorzValueBar::SendChildMessage(int message,int p1,int p2,SDL_Surface *si)
{
	switch (message)
	{
	case UIEV_LBUTTONDOWN:
		{
			int mx,my;
			GETMOUSEPOS(p1,&mx,&my);
			if (abs(mx-(barlng+x+arrowlng))<CLICKTHRESHOLD)
			{
				dragged=true;
			}
			return true;
		}
	case UIEV_LBUTTONUP:
		{
			dragged=false;
			return false;
		}
	case UIEV_MOUSEMOVE:
		{
			if (dragged)
			{
				int mx,my;
				GETMOUSEPOS(p1,&mx,&my);
				if (mx<=x+arrowlng)
				{
					mx=x+arrowlng+1;
				}
				if (mx>=x+w-arrowlng)
				{
					mx=x+h-arrowlng-1;
				}				
				int newstartpos=mx-x-arrowlng; // new starting position
				int nbaseval=min+(newstartpos*(max-min))/(lbarzone);
				SetVal(nbaseval);
				SendChildMessage(INTERNEV_REDRAW,0,0,si);
				return true;
			}
			return false;
		}
	case UIEV_DRAW:
		{
			lbarzone=w-(2*arrowlng);
			barregion.SaveRegion(si,x+arrowlng,y,lbarzone,h);
			SendChildMessage(INTERNEV_REDRAW,0,0,si);
			return true;
		}
	case INTERNEV_REDRAW:
		{
			// redraw background
			barregion.RestaurRegion(si);
			// compute slidepos
			barlng=((val-min)*(lbarzone))/(max-min);
			// draw slide
			SGU_FillRectAlpha(si,x+arrowlng,y,barlng,h,theme->WgtBack);				
			if (ismouseover)
			{
				SGU_RectShade(si,x+arrowlng,y,barlng,h,theme->FHiCol,theme->FMidCol,theme->FLowCol);
			}
			else
			{
				SGU_RectShade(si,x+arrowlng,y,barlng,h,theme->BHiCol,theme->BMidCol,theme->BLowCol);
			}
			return true;
		}
	case UIEV_GETMOUSEOVER:
		{
			ismouseover=true;
			SendChildMessage(INTERNEV_REDRAW,0,0,si);
			return true;
		}
	case UIEV_LOSEMOUSEOVER:
		{
			ismouseover=false;
			SendChildMessage(INTERNEV_REDRAW,0,0,si);
			return true;
		}
	case UIEV_LOSEFOCUS:
		{
			dragged=false;
			return true;
		}
	default:
		{
			return false;
		}
	}
}