dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Thread: [RESOLVED] Code Blocks + Graphics.h : why the style fill uses the entire window?

  1. #1
    Join Date
    Apr 2009
    Posts
    1,268

    [RESOLVED] Code Blocks + Graphics.h : why the style fill uses the entire window?

    i'm using C\C++ on Code Blocks with graphics.h.
    i'm drawing 2 filled circles.
    if i draw just 1 circle the style is done on 1 circle, if i do with 2 circles it will do it for all window... why these behavior? what i'm doing wrong?
    heres the code:
    Code:
    #include <graphics.h>
    #include <conio.h>
    #include <stdio.h>
    
    
    int main()
    {
    
    
        int page=1;
        int gd=DETECT, gm, i, x=0, y=0;
        initgraph(&gd, &gm, "");
    
    
        circle(100, 100, 20);
        setfillstyle(LINE_FILL,RED);
        circle(200, 200, 20);
        floodfill(200,200, RED);
        getch(); //for don't close before we press a key
        closegraph();
        return 0;
    }

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,618

    Re: Code Blocks + Graphics.h : why the style fill uses the entire window?

    Quote Originally Posted by Cambalinho View Post
    i'm drawing 2 filled circles.
    if i draw just 1 circle the style is done on 1 circle, if i do with 2 circles it will do it for all window... why these behavior? what i'm doing wrong?
    And what behavior do you expect?
    Victor Nijegorodov

  3. #3
    Join Date
    Apr 2009
    Posts
    1,268

    Re: Code Blocks + Graphics.h : why the style fill uses the entire window?

    Quote Originally Posted by VictorN View Post
    And what behavior do you expect?
    only on circles and not the entire window

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,618

    Re: Code Blocks + Graphics.h : why the style fill uses the entire window?

    Have a look at this video. Perhaps it will help you to understand how these <graphics.h> functions work.
    Victor Nijegorodov

  5. #5
    Join Date
    Apr 2009
    Posts
    1,268

    Re: Code Blocks + Graphics.h : why the style fill uses the entire window?

    i'm trying understand the floodfill(), but i'm confused... even with video.
    the video show us that problem, but i still confused about inside and outside the circle.
    see on minute 2.
    i'm confused because i can't see the difference between outside and inside the circle
    what i now is: the floodfill() accepts 3 arguments:
    1 - position X;
    2 - position Y;
    3 - the color.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,618

    Re: Code Blocks + Graphics.h : why the style fill uses the entire window?

    Just try to play with different colors and positions.
    BTW, why do you call two different circle functions?
    Victor Nijegorodov

  7. #7
    Join Date
    Apr 2009
    Posts
    1,268

    Re: Code Blocks + Graphics.h : why the style fill uses the entire window?

    what i mean is just that i'm learning... and when i used 2 circles or call the floodfill() 2 times, the entire window is filled with style. but thanks to that video i'm understanding it better.
    thank you so much for all
    i'm so sorry, but i can't rate your answer.. sorry.. something about forum rules

  8. #8
    Join Date
    Apr 2009
    Posts
    1,268

    Re: Code Blocks + Graphics.h : why the style fill uses the entire window?

    maybe now, with some time, i will understand better the double buffer(yes the graphics.h have some functions for it) and get the image size

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,618

    Re: Code Blocks + Graphics.h : why the style fill uses the entire window?

    Quote Originally Posted by Cambalinho View Post
    thank you so much for all
    i'm so sorry, but i can't rate your answer.. sorry.. something about forum rules
    You are welcome!
    And don't worry about the rating!
    Victor Nijegorodov

  10. #10
    Join Date
    Apr 2009
    Posts
    1,268

    Re: [RESOLVED] Code Blocks + Graphics.h : why the style fill uses the entire window?

    now i can move a double circle(like a glasses) and the style remains correct.. thank you so much for all

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,247

    Re: [RESOLVED] Code Blocks + Graphics.h : why the style fill uses the entire window?

    Quote Originally Posted by Cambalinho View Post
    now i can move a double circle(like a glasses) and the style remains correct.. thank you so much for all
    Please post the updated code.

  12. #12
    Join Date
    Apr 2009
    Posts
    1,268

    Re: [RESOLVED] Code Blocks + Graphics.h : why the style fill uses the entire window?

    sure...
    heres the updated code with Double Buffer working:
    Code:
    #include <graphics.h>
    #include <conio.h>
    #include <stdio.h>
    #include <windows.h>
    
    
    int main()
    {
        //initializate graphics:
        int gd=DETECT, gm;
        initgraph(&gd, &gm, "");
    
    
    
    
        //Circles Positions and the Page(the Page is for control the Double Buffer:
        int PosX=0, PosY=0, Page=0;
    
    
        //the loop for draw the circles and get the keyboard keys for the movement:
        do
        {
            //change the view(the Double Buffer):
            setactivepage(Page);
            setvisualpage(1-Page);
    
    
            //clear the view before draw:
            cleardevice();
    
    
            //draw the filled circles with style
            setfillstyle(SOLID_FILL,WHITE);
            circle(PosX, PosY, 75);
    
    
            //if we use more on PosX\PosY it will fill the entire window... test these for see the results
            floodfill(PosX,PosY, WHITE);
    
    
            setfillstyle(LINE_FILL,RED);
            //the '150' is for draw the circles side by side
            circle(PosX+150, PosY, 75);
            floodfill(PosX+150,PosY, WHITE);
    
    
            //get the arrow keys:
            //the '& 0x8000' is for get the pressed state
            //or if the GetKeyState() returns '<0' then is pressed:
            if( GetKeyState(VK_ESCAPE) & 0x8000 )
            {
                break; //exit
            }
            else if( GetKeyState(VK_UP) & 0x8000 )
            {
                PosY-=1;
            }
            else if( GetKeyState(VK_DOWN) & 0x8000 )
            {
                PosY+=1;
            }
            else if( GetKeyState(VK_LEFT) & 0x8000 )
            {
                PosX-=1;
            }
            else if( GetKeyState(VK_RIGHT) & 0x8000 )
            {
                PosX+=1;
            }
    
    
            //we must change the view position
            Page=1-Page;
    
    
            //the delay is for we get a better movement:
            delay(5);
        }while(true);
    
    
        getch(); //for don't close before we press a key
        closegraph();
        return 0;
    }
    Last edited by Cambalinho; March 20th, 2020 at 10:44 AM.

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,618

    Re: [RESOLVED] Code Blocks + Graphics.h : why the style fill uses the entire window?

    Thank you for the code sample!
    Victor Nijegorodov

  14. #14
    Join Date
    Apr 2009
    Posts
    1,268

    Re: [RESOLVED] Code Blocks + Graphics.h : why the style fill uses the entire window?

    maybe it's so many comments, but it's better for the others readers

  15. #15
    Join Date
    Apr 2009
    Posts
    1,268

    Re: [RESOLVED] Code Blocks + Graphics.h : why the style fill uses the entire window?

    when you move, up and down, de circles, the line filled circle seems strange. because the lines seems go to different way instead stay like on begin drawed.
    test yourself

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)