Beispiel #1
0
static LRESULT CALLBACK _funcToolProcedure(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
{
//	static BOOL bCapture=false;
//	static POINT Dif;
	RECT Rect; 
//	POINT Point;
    INT Child=0;
	
	LPDRAWITEMSTRUCT DIs;
    // S_WINSCENA WScena;
	CHAR *lpIcone;
//	INT OldCol;
    INT wID;	
	INT a,x,y;
	PAINTSTRUCT ps;
	LPRECT lprc;
	INT ColBg;
	S_WTOOLBAR * psTb;
	HDC hDC;
    TOOLINFO ti;
    INT SizePlus=GetSystemMetrics(SM_CXFRAME)*2;
	INT ilx,ily,slx,sly;
	CHAR Buf[10];
	INT idx;
	LPCREATESTRUCT psCs;
	WINDOWPLACEMENT  sWp;
	
	psTb=(S_WTOOLBAR *) GetWindowLong(hWnd,GWL_USERDATA);

	switch (message)
	{
		case WM_CREATE: 

            //if (_s.iToolNow==-1) ehExit("ToolBar Full");

			psCs=(LPCREATESTRUCT) lParam;
			psTb=psCs->lpCreateParams;
			SetWindowLong(hWnd,GWL_USERDATA,(LONG) psTb);

			psTb->hWnd=hWnd;
			psTb->hWndTT= CreateWindowEx(0, TOOLTIPS_CLASS, (LPSTR) NULL, 
							           TTS_ALWAYSTIP, 
							           CW_USEDEFAULT, CW_USEDEFAULT, 
							           CW_USEDEFAULT, CW_USEDEFAULT, 
							           psTb->hWnd, (HMENU) NULL, 
							           sys.EhWinInstance, NULL); 

			// Creo la ToolTip
			//InitCommonControls();  
			for (a=0;a<psTb->iElement;a++)
			{
				psTb->arhButton[a]=CreateWindow("Button","",
					WS_CHILD|BS_OWNERDRAW|WS_VISIBLE|
					//BS_FLAT|
					BS_PUSHLIKE|BS_NOTIFY|
					BS_VCENTER,						        
					0,0,10,10,
					hWnd,
					//GetForegroundWindow(),
					(HMENU) a,
					sys.EhWinInstance,
					NULL);

				// Inserisco i Nuovi ToolTip
				ti.cbSize = sizeof(TOOLINFO);             
				ti.uFlags = TTF_IDISHWND|TTF_SUBCLASS; 
				ti.hwnd   = hWnd;             
				ti.hinst  = 0;//sys.EhWinInstance; 
				ti.uId    = (UINT) psTb->arhButton[a];             
				ti.lpszText    = psTb->arsObj[a].lpHmz; 
				SendMessage(psTb->hWndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);

				if (!psTb->arsObj[a].bEnable) EnableWindow(psTb->arhButton[a],FALSE); 
			}
			break;

		case WM_DESTROY: 
//			if ((Tb=GiveMeTb(hWnd))==NULL) break;
			
			if (!psTb) break;
			for (a=0;a<psTb->iElement;a++) DestroyWindow(psTb->arhButton[a]);
            DestroyWindow(psTb->hWndTT);
			break;

		case WM_MOVE: break;
		
		case WM_SIZE: 
			// if ((Tb=GiveMeTb(hWnd))==NULL) break;
			GetWindowRect(psTb->hWnd,&Rect);  
            psTb->WinLx=Rect.right-Rect.left;
            psTb->WinLy=Rect.bottom-Rect.top;

			GetClientRect(psTb->hWnd,&Rect);  
            psTb->ClientLx=Rect.right-Rect.left;
            psTb->ClientLy=Rect.bottom-Rect.top;

			_keysMove(psTb); //return 0;
			break;
        
		case WM_EXITSIZEMOVE: 
//			if ((Tb=GiveMeTb(hWnd))==NULL) break;
			SetFocus(psTb->hWndOwner); 
			break;

		case WM_SIZING:
			//fwSide = wParam;       
            lprc = (LPRECT) lParam;
//			if ((Tb=GiveMeTb(hWnd))==NULL) break;
			//dispx(" ->> %d      ",GetSystemMetrics(SM_CYEDGE));
			switch (wParam)
			{
				 case WMSZ_TOP: 
				 case WMSZ_BOTTOM: 
				 case WMSZ_BOTTOMLEFT: 
				 case WMSZ_BOTTOMRIGHT: 
								   a=lprc->bottom-lprc->top-psTb->KeySy-SizePlus; 
								   y=(a/psTb->KeyLy); if (y<1) y=1;
								   x=(psTb->iElement/y); if (x<1) x=1;
								   for (;;)
								   {
									   if ((x*y)<psTb->iElement) x++; else break;
								   }
	                               
								   if ((x*y)>(psTb->iElement-x))  {y=((psTb->iElement+x-1)/x);}

								   break;
				 case WMSZ_LEFT: 
				 case WMSZ_RIGHT: 
				 default:
								   a=lprc->right-lprc->left-(psTb->KeySx<<1)-SizePlus; 
								   x=(a/psTb->KeyLx); if (x<1) x=1;
								   y=(psTb->iElement/x); if (y<1) y=1;
								   for (;;)
								   {
									   if ((x*y)<psTb->iElement) y++; else break;
								   }
							   break;
			}


			if ((y*x)>psTb->iElement)
			{
			  if (x==1) y=psTb->iElement; 
              if (y==1) x=psTb->iElement;
			}

            GiveToolRect(psTb,x,y,lprc);
            return TRUE;

		case WM_MEASUREITEM:
            //MIs=(LPMEASUREITEMSTRUCT) lParam;
			//MIs->itemWidth=24;
			//MIs->itemHeight=24;
			return TRUE;

		case WM_DRAWITEM: 

			// DRAWITEMSTRUCT
			{
				RECT rc;
				RECTD rcd;
				HDC dc;
				DIs=(LPDRAWITEMSTRUCT) lParam;
				dc=DIs->hDC;

	//			dispx("%d- %d",DIs->CtlID,DIs->itemState&ODS_CHECKED);

				// WinDirectDC(DIs->hDC,&WScena,NULL);
				
//				OldCol=ModeColor(TRUE);
				idx=DIs->CtlID%psTb->iElement;
				lpIcone=psTb->arsObj[idx].lpIcone;
			
				switch(psTb->arsObj[idx].iType)
				{
					case O_TBCOLORRADIO:
						
						rectCopy(rc,DIs->rcItem); rc.right--; rc.bottom--;
						dcBoxp(dc,&rc,sys.ColorBackGround);
					//boxp(DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.right-1,DIs->rcItem.bottom-1,sys.ColorBackGround,SET);
						if (strlen(lpIcone)==6)
						{
							Buf[2]=0;
							memcpy(Buf,lpIcone,2);   ColBg=xtoi(Buf);
							memcpy(Buf,lpIcone+2,2); ColBg+=(xtoi(Buf)<<8);
							memcpy(Buf,lpIcone+4,2); ColBg+=(xtoi(Buf)<<16);
						}

						rc.left+=2; rc.top+=2; rc.right--; rc.bottom--;
						dcBoxp(dc,&rc,ColBg);

						//boxp(DIs->rcItem.left+2,DIs->rcItem.top+2,DIs->rcItem.right-3,DIs->rcItem.bottom-3,ColBg,SET); 

					if (*lpIcone=='*')
					{
						dcBoxp(dc,rectFill(&rc,DIs->rcItem.left+2,DIs->rcItem.top+2,DIs->rcItem.right-3,DIs->rcItem.bottom-3),sys.arsColor[15]);
					  //boxp(DIs->rcItem.left+2,DIs->rcItem.top+2,DIs->rcItem.right-3,DIs->rcItem.bottom-3,sys.arsColor[15],SET); 
						dcLine(dc,DIs->rcItem.left+2,DIs->rcItem.top+2,DIs->rcItem.right-3,DIs->rcItem.bottom-3,0);
						dcLine(dc,DIs->rcItem.right-3,DIs->rcItem.top+2,DIs->rcItem.left+2,DIs->rcItem.bottom-3,0);
					}

					if ((DIs->itemState&ODS_SELECTED)||psTb->arsObj[DIs->CtlID].fChecked)
					{
						//box(DIs->rcItem.left+2,DIs->rcItem.top+2,DIs->rcItem.right-3,DIs->rcItem.bottom-3,15,XOR);
						dcBoxp(dc,rectFill(&rc,DIs->rcItem.left+2,DIs->rcItem.top+2,DIs->rcItem.right-3,DIs->rcItem.bottom-3),sys.arsColor[15]);
						//box3d(DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.right-1,DIs->rcItem.bottom-1,1);
						//box3d(DIs->rcItem.left+1,DIs->rcItem.top+1,DIs->rcItem.right-2,DIs->rcItem.bottom-2,4);
					}
					else
					{
					 //box3d(DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.right-1,DIs->rcItem.bottom-1,0);
					}
					break;
				
				 default:
                

					if (DIs->itemState&ODS_SELECTED) ColBg=ColorLum(sys.ColorBackGround,-4); else ColBg=sys.ColorBackGround;
					if (psTb->arsObj[DIs->CtlID].fChecked)  
					{   INT a,b;
						INT Len=DIs->rcItem.right-DIs->rcItem.left+1;
						for (a=0,b=0;a<Len;a++,b+=4)
						{
						// X:100:A:(len-1)  

						 //boxp(DIs->rcItem.left+a,DIs->rcItem.top,DIs->rcItem.left+a,DIs->rcItem.bottom,ColorFusion(RGB(0,80,200),RGB(0,200,255),a*100/(Len-1)),SET);	
							dcBoxp(dc,rectFill(&rc,DIs->rcItem.left+a,DIs->rcItem.top,DIs->rcItem.left+a,DIs->rcItem.bottom),ColorFusion(RGB(0,80,200),RGB(0,200,255),a*100/(Len-1)));
						}
						/*
						ColBg=ColorLum(sys.ColorBackGround,-20);
						boxp(DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.left,DIs->rcItem.bottom,ColBg,SET);	
						for (a=0,b=0;a<7;a++,b+=16)
						{
						 box(DIs->rcItem.left+a,DIs->rcItem.top+a,DIs->rcItem.right-a,DIs->rcItem.bottom-a,
							  ColorFusion(ColorLum(sys.ColorBackGround,70),ColBg,b),SET);	
						}
						*/

					} 
					else
					//boxp(DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.right-1,DIs->rcItem.bottom-1,ColBg,SET);
						dcBoxp(dc,rectFill(&rc,DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.right-1,DIs->rcItem.bottom-1),ColBg);
	            
					if (ico_info(&ilx,&ily,lpIcone)<0) break; //{ilx=1;ily=1;}
					slx=(psTb->KeyLx-ilx)>>1; sly=(psTb->KeyLy-ily)>>1;
					
					if ((DIs->itemState&ODS_SELECTED)||psTb->arsObj[idx].fChecked)
					{
						//ico_disp(DIs->rcItem.left+1+slx,DIs->rcItem.top+1+sly,lpIcone);
						dcIcone(dc,DIs->rcItem.left+1+slx,DIs->rcItem.top+1+sly,lpIcone);
					//	box3d(DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.right-1,DIs->rcItem.bottom-1,1);
					//	box3d(DIs->rcItem.left+1,DIs->rcItem.top+1,DIs->rcItem.right-2,DIs->rcItem.bottom-2,4);
					}
					else
					{
						S_ICONE_EFFECT sEfx;
						sEfx.enType=IEFX_GRAYSCALE;

						if (DIs->itemState&ODS_DISABLED) //ico_disp3D(DIs->rcItem.left+slx,DIs->rcItem.top+sly,sys.ColorBackGround,lpIcone);
														 //dcIconeEx(dc,DIs->rcItem.left+slx,DIs->rcItem.top+sly,lpIcone,&sEfx);
														 dcIconeGray(dc,DIs->rcItem.left+slx,DIs->rcItem.top+sly,lpIcone,sys.Color3DShadow,0);
														 else
														 //ico_disp(DIs->rcItem.left+slx,DIs->rcItem.top+sly,lpIcone);
														 dcIcone(dc,DIs->rcItem.left+slx,DIs->rcItem.top+sly,lpIcone);
						dcBox(dc,rectFillD(&rcd,DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.right-1,DIs->rcItem.bottom-1),rgba(0,0,0,255),1.0);
						//box3d(DIs->rcItem.left,DIs->rcItem.top,DIs->rcItem.right-1,DIs->rcItem.bottom-1,0);
					}
					
					break;
				}
	//AVANTISSIMO:
//				ModeColor(OldCol);
			//WinDirectDC(NULL,&WScena,NULL);
			}
			break;

		case WM_LBUTTONDOWN:

			psTb->bCapture=true;
			sWp.length=sizeof(sWp);
			GetWindowPlacement(hWnd,&sWp);
			//GetWindowRect(hWnd,&psTb->rcShot); // Posizione attuale
			rectCopy(psTb->rcShot,sWp.rcNormalPosition);
			GetCursorPos(&psTb->ptStart);
			SetCapture(hWnd);
//			Dif.x=Point.x-Rect.left;
//			Dif.y=Point.y-Rect.top;
			//return TRUE;
			break;
		
		case WM_LBUTTONUP:
			if (psTb->bCapture) ReleaseCapture();
			psTb->bCapture=false;
			break;
			//return TRUE;
			//break;
	
		case WM_RBUTTONDOWN:
		case WM_RBUTTONUP:
		case WM_LBUTTONDBLCLK:
		case WM_ACTIVATEAPP:
			break;

		case WM_MOUSEMOVE: 
			if (psTb->bCapture)
			{
				POINT ptNow;
				POINT ptDelta;
				GetCursorPos(&ptNow);
				ptDelta.x=ptNow.x-psTb->ptStart.x;
				ptDelta.y=ptNow.y-psTb->ptStart.y;
//				printf("%d,%d" CRLF,ptDelta.x,ptDelta.y);
				MoveWindow(hWnd,psTb->rcShot.left+ptDelta.x,psTb->rcShot.top+ptDelta.y,psTb->WinLx,psTb->WinLy,TRUE);
			}
			break;

        case WM_NCHITTEST: 
//			if ((Tb=GiveMeTb(hWnd))==NULL) break;
			break;

		// Messaggio di cambio cursore
		//case WM_SETCURSOR: break;
		// Intercettazione degli oggetti Windows
		//case WM_COMMAND: break;
		case WM_COMMAND: 
			wID = LOWORD(wParam);
			if (HIWORD(wParam)==BN_CLICKED)
			{
//				 if ((Tb=GiveMeTb(hWnd))==NULL) break;
				 LKeySelect(psTb,wID);
				 _objEvent(psTb,wID);
				 SetFocus(psTb->hWndOwner); 
			}
			
			break;

		case WM_PAINT: 

			hDC=BeginPaint(hWnd,&ps); 
/*
			if ((Tb=GiveMeTb(hWnd))==NULL) break;
			// WinDirectDC(hDC,&WScena,NULL);
			if (psTb->ClientLy>psTb->ClientLx)
			{
			 box3d(0,0,psTb->ClientLx,1,0);
			 box3d(0,2,psTb->ClientLx,3,0);
			 box3d(0,psTb->ClientLy-2,psTb->ClientLx,psTb->ClientLy-1,0);
			 box3d(0,psTb->ClientLy-4,psTb->ClientLx,psTb->ClientLy-3,0);
			}
			 else
			{
			 box3d(0,0,1,psTb->ClientLy,0);
			 box3d(2,0,3,psTb->ClientLy,0);
			 box3d(psTb->ClientLx-2,0,psTb->ClientLx-1,psTb->ClientLy-1,0);
			 box3d(psTb->ClientLx-4,0,psTb->ClientLx-3,psTb->ClientLy-1,0);
			 //box3d(2,0,3,psTb->ClientLy,0);
			}
			WinDirectDC(NULL,&WScena,NULL);
			*/
			EndPaint(hWnd,&ps);
			break;
		//case WM_SETFOCUS: IsFocus=TRUE; break;
		//case WM_KILLFOCUS: IsFocus=FALSE; break;


	}  // switch message

 return(DefWindowProc(hWnd, message, wParam, lParam));
} 
Beispiel #2
0
void CRulerBar::DrawFace(CDC& dc)
{
    int nPageWidth = XTwipsToRuler(PrintWidth());
    int nPageEdge = XTwipsToRuler(PrintWidth() + m_rectMargin.right);

    dc.SaveDC();

    dc.SelectObject(&penBtnShadow);
    dc.MoveTo(0,0);
    dc.LineTo(nPageEdge - 1, 0);
    dc.LineTo(nPageEdge - 1, HEIGHT - 2);
    dc.LineTo(nPageWidth - 1, HEIGHT - 2);
    dc.LineTo(nPageWidth - 1, 1);
    dc.LineTo(nPageWidth, 1);
    dc.LineTo(nPageWidth, HEIGHT -2);

    dc.SelectObject(&penBtnHighLight);
    dc.MoveTo(nPageWidth, HEIGHT - 1);
    dc.LineTo(nPageEdge, HEIGHT -1);
    dc.MoveTo(nPageWidth + 1, HEIGHT - 3);
    dc.LineTo(nPageWidth + 1, 1);
    dc.LineTo(nPageEdge - 1, 1);

    dc.SelectObject(&penWindow);
    dc.MoveTo(0, HEIGHT - 1);
    dc.LineTo(nPageWidth, HEIGHT -1);

    dc.SelectObject(&penBtnFace);
    dc.MoveTo(1, HEIGHT - 2);
    dc.LineTo(nPageWidth - 1, HEIGHT - 2);

    dc.SelectObject(&penWindowFrame);
    dc.MoveTo(0, HEIGHT - 2);
    dc.LineTo(0, 1);
    dc.LineTo(nPageWidth - 1, 1);

    dc.FillRect(CRect(1, 2, nPageWidth - 1, HEIGHT-2), &brushWindow);
    dc.FillRect(CRect(nPageWidth + 2, 2, nPageEdge - 1, HEIGHT-2), &brushBtnFace);

    CRect rcClient;
    GetClientRect(&rcClient);
    ClientToRuler(rcClient);
    rcClient.top = HEIGHT;
    rcClient.bottom = HEIGHT + 2;
    dc.FillRect(rcClient, &brushBtnFace);

    CRect rectFill(rcClient.left, HEIGHT+4, rcClient.right, HEIGHT+9);
    dc.FillRect(rectFill, &brushWindow);

    if (m_bDraw3DExt)  // draws the 3D extension into the view
    {
        dc.SelectObject(&penBtnShadow);
        dc.MoveTo(rcClient.left, HEIGHT+8);
        dc.LineTo(rcClient.left, HEIGHT+2);
        dc.LineTo(rcClient.right-1, HEIGHT+2);

        dc.SelectObject(&penWindowFrame);
        dc.MoveTo(rcClient.left+1, HEIGHT+8);
        dc.LineTo(rcClient.left+1, HEIGHT+3);
        dc.LineTo(rcClient.right-2, HEIGHT+3);

        dc.SelectObject(&penBtnHighLight);
        dc.MoveTo(rcClient.right-1, HEIGHT+2);
        dc.LineTo(rcClient.right-1, HEIGHT+8);

        dc.SelectObject(&penBtnFace);
        dc.MoveTo(rcClient.right-2, HEIGHT+3);
        dc.LineTo(rcClient.right-2, HEIGHT+8);
    }
    else
    {
        dc.SelectObject(&penBtnShadow);
        dc.MoveTo(rcClient.left, HEIGHT+2);
        dc.LineTo(rcClient.right, HEIGHT+2);

        dc.SelectObject(&penWindowFrame);
        dc.MoveTo(rcClient.left, HEIGHT+3);
        dc.LineTo(rcClient.right, HEIGHT+3);
    }

    dc.RestoreDC(-1);
}
Beispiel #3
0
void	showImg(uchar * img, ushort largeur, ushort hauteur)
{		Gft * fnt = &nfont ;
		uchar * rotate_data=img ;
		ulong	cptx, cpty, startx, starty ;
		int		cpt ;//draw_pal = 0, cpt ;
		int	decalagex, size_draw_x ;
		int	decalagey, size_draw_y ;
		//int start_drax_x,start_drax_y, color ;
		int		scrool_speed = 8 ;
		ulong	scrool_time=0, speed_time=0, zoom_time=0 ;
		int		zoom  = 1	;
		int		nzoom = 2	;
		char buffer[512] ;
		int draw_pal=0 ;

		startx = (320-largeur)>>1 ;
		starty = (240-hauteur)>>1 ;

		decalagex=0 ;
		decalagey=0 ;

		size_draw_x = largeur ;
		size_draw_y = hauteur ;

		if(hauteur>240) {  starty=0 ;  size_draw_y = 240 ; }
		if(largeur>320) {  startx=0 ;  size_draw_x = 320 ; }
		loading=0 ;
		if(rotate_data)
		do {
			refreshKey() ;

			if(startx||starty)	clrScr() ;

			if(!zoom) // zoom 1/2
			{			
				  for(cptx=decalagex*nzoom;cptx<decalagex*nzoom+size_draw_x;cptx+=nzoom)
					for(cpty=decalagey*nzoom;cpty<decalagey*nzoom+size_draw_y;cpty+=nzoom)
					{	//*(screen[nflip] + (startx+(cptx/nzoom)-decalagex)*240 + (239-(starty+(cpty/nzoom)-decalagey))) = get_color_buffer(cptx, cpty, hauteur, rotate_data) ;
					} ;
			}
			else
			{
				if(zoom==1)
				{	  for(cptx=decalagex;cptx<decalagex+size_draw_x;cptx++)
						for(cpty=decalagey;cpty<decalagey+size_draw_y;cpty++)
						{	*(screen[nflip] + (startx+cptx-decalagex)*240 + (239-(starty+cpty-decalagey))) = get_color_buffer(cptx, cpty, hauteur, rotate_data) ;
						} ;
				} else {
					  for(cptx=decalagex;cptx<decalagex+(size_draw_x/zoom);cptx++)
						for(cpty=decalagey;cpty<decalagey+(size_draw_y/zoom);cpty++)
						{	rectFill(startx+(cptx-decalagex)*zoom,starty+(cpty-decalagey)*zoom,zoom,zoom,get_color_buffer(cptx, cpty, hauteur, rotate_data)) ;
						} ;
					}
			}

			if(!keyPush(kSelect))
			{
				if(keyPush(kRight)) // right
				{
					if(zoom) {	for(cpt=0;cpt<scrool_speed;cpt++)	if(decalagex+(size_draw_x/zoom)<largeur)	decalagex++ ; }
					else	{	if(!startx) for(cpt=0;cpt<scrool_speed;cpt++)	if(decalagex < largeur/2-320)		decalagex++ ;
							//if((size_draw_x+decalagex)*nzoom>largeur*nzoom) decalagex -= ((decalagex+size_draw_x)*nzoom-(largeur*nzoom)) ;
						}					
					scrool_time = GpTickCountGet() ;
				}
	
				if(keyPush(kLeft)) // left
				{
					for(cpt=0;cpt<scrool_speed;cpt++)	if(decalagex)	decalagex-- ;
					
					scrool_time = GpTickCountGet() ;
				}
				
				if(keyPush(kDown)) // down
				{
					if(zoom) {	for(cpt=0;cpt<scrool_speed;cpt++)	if(decalagey+(size_draw_y/zoom)<hauteur)	decalagey++ ; }
					else	{	if(!starty) for(cpt=0;cpt<scrool_speed;cpt++)	if(decalagey < hauteur/2-240)		decalagey++ ;
							//if((startx+size_draw_y+decalagey)*nzoom>hauteur*nzoom) decalagey -= ((startx+decalagey+size_draw_y)*nzoom-(hauteur*nzoom)) ;
						}


					scrool_time = GpTickCountGet() ;
				}
				
				if(keyPush(kUp)) // up
				{
					for(cpt=0;cpt<scrool_speed;cpt++)	if(decalagey)	decalagey-- ;
					
					scrool_time = GpTickCountGet() ;
				}
			} else {
				if(keyUp(kDown)) // down, zoom -
				{
					if(zoom>1)
					{
						short old, _new, dif, cpt ;
						
						old = (size_draw_x/zoom) ;
						_new = (size_draw_x/(zoom-1)) ;
						dif = (_new-old)/2 ;
						
						for(cpt=0;cpt<dif;cpt++)
							if(decalagex)	decalagex-- ;
						
						old = (size_draw_y/zoom) ;
						_new = (size_draw_y/(zoom-1)) ;
						dif = (_new-old)/2 ;

						for(cpt=0;cpt<dif;cpt++)
							if(decalagey)	decalagey-- ;

						zoom-- ;
						
						startx = (320-largeur*zoom)>>1 ;
						starty = (240-hauteur*zoom)>>1 ;
				
						size_draw_y = hauteur*zoom ;
						size_draw_x = largeur*zoom ;
				
						if(hauteur*zoom>240) {  starty=0 ;  size_draw_y = 240 ; }
						if(largeur*zoom>320) {  startx=0 ;  size_draw_x = 320 ; }
						
						if(size_draw_x/zoom+decalagex>largeur) decalagex -= (decalagex+size_draw_x/zoom)-largeur ;
						if(decalagey+size_draw_y/zoom>hauteur) decalagey -= (decalagey+size_draw_y/zoom)-hauteur ;
					}		/*else if(zoom==1)
							{
								short cpt ;
		
								for(cpt=0;cpt<size_draw_x/2;cpt++)
									if(decalagex)	decalagex-- ;
		
								for(cpt=0;cpt<size_draw_y/2;cpt++)
									if(decalagey)	decalagey-- ;
		
								zoom=0 ;
		
								startx = (320-largeur/2)>>1 ;
								starty = (240-hauteur/2)>>1 ;
						
								size_draw_y = hauteur ;
								size_draw_x = largeur ;
						
								if(hauteur/2>240) {  starty=0 ;  size_draw_y = 240*2 ; }
								if(largeur/2>320) {  startx=0 ;  size_draw_x = 320*2 ; }

								if(size_draw_x*2+decalagex>largeur*2) decalagex -= (decalagex+size_draw_x*2)-largeur*2 ;
								if(decalagey+size_draw_y*2>hauteur*2) decalagey -= (decalagey+size_draw_y*2)-hauteur*2 ;
								
								if(decalagey > hauteur/2-240) decalagey = hauteur/2-240 ;
								if(decalagex > largeur/2-320) decalagex = largeur/2-320 ;	
							}*/

					zoom_time = GpTickCountGet() ;
				}
				
				if(keyUp(kUp)) // up, zoom +
				{					
					if(zoom < 20)
					{
						short old, _new, dif, cpt ;
						
						if(zoom)
						{
							old = (size_draw_x/zoom) ;
							_new = (size_draw_x/(zoom+1)) ;
							dif = (old-_new)/2 ;

							for(cpt=0;cpt<dif;cpt++)
								if(decalagex+(size_draw_x/zoom)<largeur)	decalagex++ ;

							old = (size_draw_y/zoom) ;
							_new = (size_draw_y/(zoom+1)) ;
							dif = (old-_new)/2 ;
	
							for(cpt=0;cpt<dif;cpt++)
								if(decalagey+(size_draw_y/zoom)<hauteur)	decalagey++ ;
						}
						else
						{
							size_draw_y/=2 ;
							size_draw_x/=2 ;
							
							old = (size_draw_x*2) ;
							_new = (size_draw_x/2) ;
							dif = (old-_new)/2 ;
							
							for(cpt=0;cpt<dif;cpt++)
								if(decalagex+(size_draw_x*2)<largeur)	decalagex++ ;
								
							old = (size_draw_y*2) ;
							_new = (size_draw_y/2) ;
							dif = (old-_new)/2 ;
	
							for(cpt=0;cpt<dif;cpt++)
								if(decalagey+(size_draw_y*2)<hauteur)	decalagey++ ;
						}

						zoom++ ;
						
						startx = (320-largeur*zoom)>>1 ;
						starty = (240-hauteur*zoom)>>1 ;
				
						size_draw_y = hauteur*zoom ;
						size_draw_x = largeur*zoom ;
				
						if(hauteur*zoom>240) {  starty=0 ;  size_draw_y = 240 ; }
						if(largeur*zoom>320) {  startx=0 ;  size_draw_x = 320 ; }
					}
					
					zoom_time = GpTickCountGet() ;
				}
			}
Beispiel #4
0
/* Callback function to handle ROS depth messages
 * 
 * PARAMETERS:
 *	    - msg: ROS message that contains the depth image its metadata
 * 
 * 
 * RETURN --
 */
void Depth_processing::depthCb(const sensor_msgs::ImageConstPtr& msg)
{
    Mat cur_depth;
    Mat temp_depth;
    int morph_elem = 0;
    int morph_size = 2;
    int morph_operator = 0;
    cv_bridge::CvImagePtr cv_ptr_depth;
    
    try
    {
	    cv_ptr_depth = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::TYPE_32FC1);
    }
    catch (cv_bridge::Exception& e)	
    {
	    ROS_ERROR("cv_bridge exception: %s", e.what());
	    return;
    }
    
    cur_depth = (cv_ptr_depth->image);
    //Converting depth values to 0-255
    depthToGray(cur_depth, cur_depth, min_depth, max_depth);
    
    if (dFrameCounter == -1)
    {
	    ref_depth = cur_depth.clone();
	    dFrameCounter++;
    }
    
    //Depth preprocessing
    Mat element = getStructuringElement( morph_elem, Size( 2*morph_size + 1, 2*morph_size+1 ), Point( morph_size, morph_size ) );
    
    Mat depth_dif;
    morphologyEx(cur_depth, cur_depth, 3, element);
    
    //Filling areas in the depth image that have no value because
    //of sensor noise or surface reflectivity
    rectFill(cur_depth, 0.3, 2);
    upVerticalFill(cur_depth, 0.3, true);
    

    /* Frame difference
     * 
     * 
    temp_depth = cur_depth.clone();

    medianBlur(temp_depth, temp_depth, 15);
    
    frameDif(temp_depth, ref_depth, dif_depth, 255*0.07);
    
    morphologyEx(dif_depth, dif_depth, 2, element);
    
    ref_depth = temp_depth.clone();
    */
    
    
    //Display
    if(display)
    {
	    
	    imshow("cur_depth", cur_depth);
	    moveWindow("cur_depth", 0, 0);
	    
	/*
	 * 
	    //blob detection
	detectBlobs(dif_depth, depth_rects, 15);
	
	//display
	Mat temp = dif_depth.clone();
	for(Rect rect: depth_rects)
		rectangle(temp, rect, 255, 1);
	depth_rects.clear();
	
	
	imshow("dif_depth", temp);
	moveWindow("dif_depth", 0, 550);
	*/
    }

    /* Depth backgound estimation 
    * 
    * 
    //~ int kernel_size = 3;
    //~ int scale = ;
    //~ int delta = 0;
    //~ int ddepth = CV_16S;
    //~ 
    //~ Laplacian( cur_depth, cur_depth, ddepth, kernel_size, scale, delta, BORDER_DEFAULT );
    //~ 
    //~ convertScaleAbs( cur_depth, cur_depth );
    Mat detected_edges;
    Mat  whatever;
    whatever.create( cur_depth.size(), cur_depth.type() );
    int lowThreshold = 500;
    int ratio = 3;
    int kernel_size = 5;
    
    
    blur( cur_depth, cur_depth, Size(3,3) );
    Canny( cur_depth, cur_depth, lowThreshold, lowThreshold*ratio, kernel_size );
    whatever = Scalar::all(0);

    //~ cur_depth.copyTo( whatever, detected_edges);
    
    imshow("whatever", cur_depth);
    moveWindow("whatever", 0, 550);

    
    Mat back_depth;
estimateBackground(cur_depth, back_depth, depth_storage, 100, 0.025);

Mat back_dif = cur_depth.clone();
estimateForeground(cur_depth, back_depth, back_dif);
    
//~ adaptiveThreshold(back_dif, back_dif, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 15, -5);
//~ medianBlur(back_dif, back_dif, 3);

vector< Rect_<int> > back_dif_rects;
detectBlobs(back_dif, back_dif_rects, 3);

    imshow("back_dif", back_dif);
    moveWindow("back_dif", 645, 550);
    */
    
    waitKey(1);
    
    //Converting chroma values to meters
    grayToDepth(cur_depth, cur_depth, max_depth);
    
    
    //Publish corrected depth image
    cv_ptr_depth->image = cur_depth;
    depth_pub.publish(cv_ptr_depth->toImageMsg());
	

}