Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Redrawing..

Redrawing..

Scheduled Pinned Locked Moved C / C++ / MFC
comgraphicshostingquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    staticv
    wrote on last edited by
    #1

    // Verify the left button is down
    if ((nFlags & MK_LBUTTON) && (this == GetCapture()))
    {
    m_SecondPoint = point; // Save the current cursor position

    	if (m\_pTempElement)
    	{
    		// Redraw the old element so it disappears from the view
    		m\_pTempElement->Draw(&aDC);
    		delete m\_pTempElement;				// Delete the old element
    		m\_pTempElement = 0;				// Reset the pointer to 0
    	}
    
    	// Create a temporary element of the type and color that
    	// is recorded in the document object and draw it
    	m\_pTempElement = CreateElement();			// Create a new element
    	m\_pTempElement->Draw(&aDC);					// Draw the element
    }
    

    This is a code of a message handler in a drawing application which now supports drawing lines, rectangles and circles. We save the first cursor position in the Mouse button down handler The CreateElement() creates an element (rectangle, circle, line, curve) on the heap and returns a pointer to it. I don't understand why do we need to redraw the old element. Like I created an element and then a mouse move occurs then why do we draw it two times? First, in the inner if block and second, after the if block. It is drawing over the previously drawn element in the inner if block right?

    Top Web Hosting Providers[^] Whatever the mind can conceive and believe, the mind can achieve - Dr. Napoleon Hill

    C L 2 Replies Last reply
    0
    • S staticv

      // Verify the left button is down
      if ((nFlags & MK_LBUTTON) && (this == GetCapture()))
      {
      m_SecondPoint = point; // Save the current cursor position

      	if (m\_pTempElement)
      	{
      		// Redraw the old element so it disappears from the view
      		m\_pTempElement->Draw(&aDC);
      		delete m\_pTempElement;				// Delete the old element
      		m\_pTempElement = 0;				// Reset the pointer to 0
      	}
      
      	// Create a temporary element of the type and color that
      	// is recorded in the document object and draw it
      	m\_pTempElement = CreateElement();			// Create a new element
      	m\_pTempElement->Draw(&aDC);					// Draw the element
      }
      

      This is a code of a message handler in a drawing application which now supports drawing lines, rectangles and circles. We save the first cursor position in the Mouse button down handler The CreateElement() creates an element (rectangle, circle, line, curve) on the heap and returns a pointer to it. I don't understand why do we need to redraw the old element. Like I created an element and then a mouse move occurs then why do we draw it two times? First, in the inner if block and second, after the if block. It is drawing over the previously drawn element in the inner if block right?

      Top Web Hosting Providers[^] Whatever the mind can conceive and believe, the mind can achieve - Dr. Napoleon Hill

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      Please elaborate. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      1 Reply Last reply
      0
      • S staticv

        // Verify the left button is down
        if ((nFlags & MK_LBUTTON) && (this == GetCapture()))
        {
        m_SecondPoint = point; // Save the current cursor position

        	if (m\_pTempElement)
        	{
        		// Redraw the old element so it disappears from the view
        		m\_pTempElement->Draw(&aDC);
        		delete m\_pTempElement;				// Delete the old element
        		m\_pTempElement = 0;				// Reset the pointer to 0
        	}
        
        	// Create a temporary element of the type and color that
        	// is recorded in the document object and draw it
        	m\_pTempElement = CreateElement();			// Create a new element
        	m\_pTempElement->Draw(&aDC);					// Draw the element
        }
        

        This is a code of a message handler in a drawing application which now supports drawing lines, rectangles and circles. We save the first cursor position in the Mouse button down handler The CreateElement() creates an element (rectangle, circle, line, curve) on the heap and returns a pointer to it. I don't understand why do we need to redraw the old element. Like I created an element and then a mouse move occurs then why do we draw it two times? First, in the inner if block and second, after the if block. It is drawing over the previously drawn element in the inner if block right?

        Top Web Hosting Providers[^] Whatever the mind can conceive and believe, the mind can achieve - Dr. Napoleon Hill

        L Offline
        L Offline
        L Madhavan
        wrote on last edited by
        #3

        Looks like the Draw method is using an XOR pen, which is a common method for drawing shapes. An XOR operation is similar to inverting the colours, so by drawing it the second time, you effectively erase the old shape before drawing the shape at the new position.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups