Draw a line...??

This is a discussion on Draw a line...?? within the C Programming forums, part of the General Programming Boards category; How can I save the first coordinate oldx & oldy, while I'm still moving around with the mouse. I need ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    64

    Draw a line...??

    How can I save the first coordinate oldx & oldy, while I'm still
    moving around with the mouse.

    I need to hold down the left button and then drag the mousecursor to another point, and when I release the left button I should draw a line from the first point I was at, to the last point.
    Where the cursor is now...

    Gugge

    -----------------------------------code:

    case ST_DRAW_LINE:
    while(1)
    {
    while(popMouseEvent(p, &event, &button, &x, &y, &xcount, &ycount))
    {
    int oldx = x; int oldy = y;
    if((button & 0x01) == 0x01)
    {
    setcolor(YELLOW);
    line(oldx,oldy,x,y);
    }
    if(event == 4)
    {
    outtextxy (50,35, "LINE: Left button up");
    line(oldx,oldy,x,y);
    goto out2;
    }
    }
    }
    out2:
    menustate = ST_INACTIVE;
    break;
    !G!

  2. #2
    Registered User
    Join Date
    Mar 2002
    Posts
    64
    I figured it out...



    case ST_DRAW_LINE:
    while(1)
    {
    while(popMouseEvent(p, &event, &button, &x, &y, &xcount, &ycount))
    {
    if(event == 2)
    {
    int oldx = x; int oldy = y;
    }
    if((button & 0x01) == 0x01)
    {
    setcolor(YELLOW);
    line(oldx,oldy,x,y);
    }
    if(event == 4)
    {
    outtextxy (50,35, "LINE: Left button up");
    line(oldx,oldy,x,y);
    goto out2;
    }
    }
    }
    out2:
    menustate = ST_INACTIVE;
    break;
    !G!

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    You should make use of XOR for this.


    curcolor=GetPixel(x,y)
    Line (x,y,x2,y2,curcolor ^ 0xFF); //draws a see through line

    Line (x,y,x2,y2,curcolor ^ 0xFF); //erases the line

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    64

    Cursor....

    Tx for your answer.
    That I will sure be needing.

    But can you tell me how to make a cursor, which only will follow the x & y coordinates.

    I have tried with:
    /*-------Mouse Cursor -------------------------------------------*/
    if(button == 0)
    {
    setcolor(CYAN);
    savescreen(x-1,y-1,x+1,y+1,cursor);
    outtextxy(x,y,"*");
    restorescreen(x,y,cursor);
    }

    But theres something wrong.
    I doesn't disappear, but just makes a line of *..

    Gugge
    !G!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ASM beginner gets 24 compiler errors on hello world...
    By Desolation in forum Tech Board
    Replies: 12
    Last Post: 06-16-2007, 10:21 PM
  2. Replies: 19
    Last Post: 05-30-2007, 05:47 PM
  3. Which is the better way to draw?
    By g4j31a5 in forum Game Programming
    Replies: 16
    Last Post: 01-22-2007, 10:56 PM
  4. Move the Caret to a line
    By TheDan in forum Windows Programming
    Replies: 3
    Last Post: 08-07-2005, 12:59 PM
  5. Debugging link error
    By bubux in forum C Programming
    Replies: 5
    Last Post: 07-06-2002, 02:19 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21