GIDForums  

Go Back   GIDForums > Computer Programming Forums > MS Visual C++ / MFC Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 10-May-2004, 07:24
Nelly Nelly is offline
New Member
 
Join Date: Apr 2004
Posts: 15
Nelly is on a distinguished road

Undo Drawing


Hi Hi,

I have a draw function which is drawing 25 rectangle on mouse click on my Scroll view, which is the main viewclass.

I have another Form view which contains some 25 Radiobuttons and Edit controls. When I click on the radio button, then click on the main, it draws the rectangle and displays the cordinate in the edit controls in the formview.



CPP / C++ / C Code:
void CMFFAView::OnDrawFeat(CDC* pDC)
{
	CMFFADoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	UINT pointIndex = pDoc-> m_pointIndex;

	for ( int i = 0; i < pointIndex; ++i)
	{
	CBrush brush( RGB( 0, 255, 0 ) );
	CBrush* pOldBrush = pDC->SelectObject( &brush );
	pDC-> Rectangle( pDoc->m_point[i].x-3, pDoc->m_point[i].y-3,   pDoc->m_point[i].x + 3, pDoc->m_point[i].y + 3);

	pDC->SetPixel(pDoc->m_point[i].x,pDoc->m_point[i].y,RGB(0,0,0));
	
	pDC->SelectObject( pOldBrush );

	}
}


void CMFFAView::OnLButtonDown(UINT nFlags, CPoint point) 
{
          CMFFADoc *pDoc = GetDocument();
          pDoc->m_pnt = point;
          if ( pDoc->m_pointIndex == 25 )
            {
	return;
              }
          pDoc->m_point[pDoc->m_pointIndex] = pDoc->m_pnt;
           pDoc->m_pointIndex++;

            UpdateData(FALSE);	
 
 	/**marks the document as modified or "dirty"
	Any code you write that change any document variables 
	should call SetModifiedFlag().**/
	pDoc->SetModifiedFlag(); 
	
	/**Call the OnDraw() function, where the window's display
	is redrawn with the new data.  
	Invalidate();

		
	CMainFrame* pFrame =  (CMainFrame*)::AfxGetMainWnd();
    CFeature* pView = (CFeature*) pFrame->m_WndSplitterDB.GetPane(0, 0);	
	pView->OnUpdate(this, NULL, NULL);


	CScrollView::OnLButtonDown(nFlags, point);
}

void CFeature::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
{
	
  // 1 - Get the current data from our document
 CMFFADoc* pDoc = GetDocument();
 
  if (m_myRadio == 0 )
{
    m_RMouthX = pDoc->m_pnt.x - 30;
    m_RMouthY = pDoc->m_pnt.y - 30; 
    FaceFeat.Mth.XRCorner = m_RMouthX;
    FaceFeat.Mth.YRCorner = m_RMouthY;
    Undo (UndoVector);
}
    else
  if (m_myRadio == 1 )
{
    m_LMouthX = pDoc->m_pnt.x - 30;
    m_LMouthY = pDoc->m_pnt.y - 30;
    FaceFeat.Mth.XLCorner = m_LMouthX;
    FaceFeat.Mth.YLCorner = m_LMouthY;
................................
....................................			
}
// 2 - Show the current data in our controls
	UpdateData( FALSE );
}
	


I need to be able to undo the drawing, lets say I've click it in the wrong place, then re-click in the right position.
In other words, how can I undo the drawing of the rectangle.

Please can anyone help.....
Last edited by dsmith : 10-May-2004 at 07:29. Reason: Use [c] & [/c] for C-syntax highlighting
  #2  
Old 10-May-2004, 14:12
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
Hmmm... I would have a couple of global variables that store identifiers to describe what the user just did, and what the user did before that. Or you could even make a linked list of the user's actions. Then, to undo, all you have to do is clear the screen and draw what happened last time the user did something.
__________________
-Aaron
  #3  
Old 10-May-2004, 19:39
Max Payne's Avatar
Max Payne Max Payne is offline
Regular Member
 
Join Date: Apr 2004
Location: 3° 08 North 101° 42 East
Posts: 332
Max Payne is a jewel in the roughMax Payne is a jewel in the roughMax Payne is a jewel in the rough
The simplest way to do this is by using stack. you push user action and just simply pop when you want undo. Are you using MFC here?? THe you should look at this article, it may help:

UndoRedo1

There more if you search the site.

Using linked list is also a fine idea, but what is important is what and how you store the user action. Redrawing it is not that hard but it could be slow..
__________________
When you say "I wrote a program that crashed Windows," people just stare at you blankly and say "Hey, I got those with the system, for free." Linus Torvalds
  #4  
Old 10-May-2004, 21:14
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
I haven't learned about stacks yet, so that was my only idea, and yeah... I realized it might take up a few more cycles than are really necessary :-P
__________________
-Aaron
 
 

Recent GIDBlogPython ebook by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
drawing dot and rect Nelly MS Visual C++ / MFC Forum 2 22-Apr-2004 13:09
Back to the drawing board... spudtheimpaler C Programming Language 9 15-Mar-2004 10:12

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:00.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.