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. Discuss: rubber banding - erase a line

Discuss: rubber banding - erase a line

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++comtoolsannouncement
6 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.
  • I Offline
    I Offline
    includeh10
    wrote on last edited by
    #1

    I try to draw a line with mouse moves, similar to line-tool of MS Paint-Brush - see my previous post any idea to draw this line for more. http://www.codeproject.com/script/comments/forums.asp?forumid=1647&fr=151[^] I have downloaded several samples, but all of them are incorrect in basic concept, because they all call update function InvalidateRect(0), RedrawWindow(0) etc - if so, there is no neccessary to use Rubber band tech, as my understanding, rubber banding should only update requied pixels (such as a line) and without touching others (right?). //--- my MFC code is bellow, //--- I only copy key code for idea. CPoint ptStart,ptEnd; BOOL bDraw=0; OnLButtonDown(UINT nFlags, CPoint pt) { bDraw=1; ptStart=ptEnd=pt; } void OnPaint() { CPaintDC dc(this); if(bDraw) { CPen penB(PS_SOLID,10,RGB(0,0,0)); CPen*pPenOld=dc.SelectObject(&penB); dc.MoveTo(ptStart); dc.LineTo(ptEnd); dc.SelectObject(pPenOld); } } void OnMouseMove(UINT nFlags, CPoint pt) { if(bDraw) { CPoint ptT=ptEnd; ptEnd=pt; //erase RenewLine(ptT); //display RenewLine(pt); } } RenewLine(CPoint pt) { CDC*pDC=GetDC(); CPen penNull(PS_NULL,10,RGB(0,0,0)); CPen*pPenOld=pDC->SelectObject(&penNull); UINT u=R2_NOT; // UINT u=R2_XORPEN; int iROP=pDC->SetROP2(u); pDC->MoveTo(ptStart); pDC->LineTo(pt); pDC->SetROP2(iROP); pDC->SelectObject(pPenOld); ReleaseDC(pDC); } //ignore mouse up and capure etc. Result is none of lines can be seen, what is wrong?

    C T 2 Replies Last reply
    0
    • I includeh10

      I try to draw a line with mouse moves, similar to line-tool of MS Paint-Brush - see my previous post any idea to draw this line for more. http://www.codeproject.com/script/comments/forums.asp?forumid=1647&fr=151[^] I have downloaded several samples, but all of them are incorrect in basic concept, because they all call update function InvalidateRect(0), RedrawWindow(0) etc - if so, there is no neccessary to use Rubber band tech, as my understanding, rubber banding should only update requied pixels (such as a line) and without touching others (right?). //--- my MFC code is bellow, //--- I only copy key code for idea. CPoint ptStart,ptEnd; BOOL bDraw=0; OnLButtonDown(UINT nFlags, CPoint pt) { bDraw=1; ptStart=ptEnd=pt; } void OnPaint() { CPaintDC dc(this); if(bDraw) { CPen penB(PS_SOLID,10,RGB(0,0,0)); CPen*pPenOld=dc.SelectObject(&penB); dc.MoveTo(ptStart); dc.LineTo(ptEnd); dc.SelectObject(pPenOld); } } void OnMouseMove(UINT nFlags, CPoint pt) { if(bDraw) { CPoint ptT=ptEnd; ptEnd=pt; //erase RenewLine(ptT); //display RenewLine(pt); } } RenewLine(CPoint pt) { CDC*pDC=GetDC(); CPen penNull(PS_NULL,10,RGB(0,0,0)); CPen*pPenOld=pDC->SelectObject(&penNull); UINT u=R2_NOT; // UINT u=R2_XORPEN; int iROP=pDC->SetROP2(u); pDC->MoveTo(ptStart); pDC->LineTo(pt); pDC->SetROP2(iROP); pDC->SelectObject(pPenOld); ReleaseDC(pDC); } //ignore mouse up and capure etc. Result is none of lines can be seen, what is wrong?

      C Offline
      C Offline
      Cliff Hatch
      wrote on last edited by
      #2

      Hi includeh10

      includeh10 wrote:

      have downloaded several samples, but all of them are incorrect in basic concept, because they all call update function InvalidateRect(0), RedrawWindow(0) etc - if so, there is no neccessary to use Rubber band tech, as my understanding, rubber banding should only update requied pixels (such as a line) and without touching others (right?).

      I wrote an application that displays multiple models (as boxes) and treats connections between them as rubber bands. I used InvalidateRect(), and although I acknowledge that the technique redraws more of the image than is necessary, I wouldn't go so far as to call it incorrect in concept. It does the job and is plenty fast enough to keep pace with mouse moves, even when there are many connections to redraw. It also seems to be the 'windows way'. I'm not sure how to get parts of the view updated without using invalidation. I had some problems with flickering background rectangles in early versions, but solved this by using a memory device context and blitting to the view's device context. Best Regards Cliff

      I 2 Replies Last reply
      0
      • C Cliff Hatch

        Hi includeh10

        includeh10 wrote:

        have downloaded several samples, but all of them are incorrect in basic concept, because they all call update function InvalidateRect(0), RedrawWindow(0) etc - if so, there is no neccessary to use Rubber band tech, as my understanding, rubber banding should only update requied pixels (such as a line) and without touching others (right?).

        I wrote an application that displays multiple models (as boxes) and treats connections between them as rubber bands. I used InvalidateRect(), and although I acknowledge that the technique redraws more of the image than is necessary, I wouldn't go so far as to call it incorrect in concept. It does the job and is plenty fast enough to keep pace with mouse moves, even when there are many connections to redraw. It also seems to be the 'windows way'. I'm not sure how to get parts of the view updated without using invalidation. I had some problems with flickering background rectangles in early versions, but solved this by using a memory device context and blitting to the view's device context. Best Regards Cliff

        I Offline
        I Offline
        includeh10
        wrote on last edited by
        #3

        if u have an image in size of 2000x2000 pixels at background, you will know what happends by calling InvaliadateRect(0) - even 0 is set as a small rect. incorrect! definitely.

        1 Reply Last reply
        0
        • C Cliff Hatch

          Hi includeh10

          includeh10 wrote:

          have downloaded several samples, but all of them are incorrect in basic concept, because they all call update function InvalidateRect(0), RedrawWindow(0) etc - if so, there is no neccessary to use Rubber band tech, as my understanding, rubber banding should only update requied pixels (such as a line) and without touching others (right?).

          I wrote an application that displays multiple models (as boxes) and treats connections between them as rubber bands. I used InvalidateRect(), and although I acknowledge that the technique redraws more of the image than is necessary, I wouldn't go so far as to call it incorrect in concept. It does the job and is plenty fast enough to keep pace with mouse moves, even when there are many connections to redraw. It also seems to be the 'windows way'. I'm not sure how to get parts of the view updated without using invalidation. I had some problems with flickering background rectangles in early versions, but solved this by using a memory device context and blitting to the view's device context. Best Regards Cliff

          I Offline
          I Offline
          includeh10
          wrote on last edited by
          #4

          I have got it work! you are 100% incorrect!

          C 1 Reply Last reply
          0
          • I includeh10

            I have got it work! you are 100% incorrect!

            C Offline
            C Offline
            Cliff Hatch
            wrote on last edited by
            #5

            Oh well, it's good to score 100% now and again - it's normally just an aspirational target. :doh: I'm sorry that my reply was unhelpful and glad you have solved the problem. What's the key to updating the view without invalidation? Best Regards Cliff

            1 Reply Last reply
            0
            • I includeh10

              I try to draw a line with mouse moves, similar to line-tool of MS Paint-Brush - see my previous post any idea to draw this line for more. http://www.codeproject.com/script/comments/forums.asp?forumid=1647&fr=151[^] I have downloaded several samples, but all of them are incorrect in basic concept, because they all call update function InvalidateRect(0), RedrawWindow(0) etc - if so, there is no neccessary to use Rubber band tech, as my understanding, rubber banding should only update requied pixels (such as a line) and without touching others (right?). //--- my MFC code is bellow, //--- I only copy key code for idea. CPoint ptStart,ptEnd; BOOL bDraw=0; OnLButtonDown(UINT nFlags, CPoint pt) { bDraw=1; ptStart=ptEnd=pt; } void OnPaint() { CPaintDC dc(this); if(bDraw) { CPen penB(PS_SOLID,10,RGB(0,0,0)); CPen*pPenOld=dc.SelectObject(&penB); dc.MoveTo(ptStart); dc.LineTo(ptEnd); dc.SelectObject(pPenOld); } } void OnMouseMove(UINT nFlags, CPoint pt) { if(bDraw) { CPoint ptT=ptEnd; ptEnd=pt; //erase RenewLine(ptT); //display RenewLine(pt); } } RenewLine(CPoint pt) { CDC*pDC=GetDC(); CPen penNull(PS_NULL,10,RGB(0,0,0)); CPen*pPenOld=pDC->SelectObject(&penNull); UINT u=R2_NOT; // UINT u=R2_XORPEN; int iROP=pDC->SetROP2(u); pDC->MoveTo(ptStart); pDC->LineTo(pt); pDC->SetROP2(iROP); pDC->SelectObject(pPenOld); ReleaseDC(pDC); } //ignore mouse up and capure etc. Result is none of lines can be seen, what is wrong?

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              didn't i ever already asked you to post your code sample within <pre></pre> tags when you ask or answer something ? :suss:


              Don't know where to start ?
              Refer the Forums Guidelines and ask a friend

              [VisualCalc 3.0][Flags Beginner's Guide]

              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