Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [solved]Rectangle inside Rectangle  (Read 4050 times)

0 Members and 1 Guest are viewing this topic.

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[solved]Rectangle inside Rectangle
« on: July 28, 2009, 10:48:26 pm »
This is the code that makes two rectangles. One inside the other. But I can't see the small rectangle. I tried lowering the Alpha of the big rectangle color and I saw the small rectangle, but not in white color of course. Is there anyway to choose which rectangle is drawn last or something. (I tried changing the changing places of draw statements on the code but didnt work.)

Code: [Select]

sf::Shape Rect1;
...//some code here
{
Rect1 = sf::Shape::Rectangle(10, 100, 90, 190, sf::Color(255, 255, 255));
Window->Draw(Rect1);
sf::Shape Rect2 = sf::Shape::Rectangle(0, 0, 100, 600, sf::Color(100, 100, 100));
Window->Draw(Rect2);
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Rectangle inside Rectangle
« Reply #1 on: July 28, 2009, 11:00:12 pm »
The objects appear in the same order that you draw them. So you have to draw the big one first.
Laurent Gomila - SFML developer

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[solved]Rectangle inside Rectangle
« Reply #2 on: July 29, 2009, 08:15:28 am »
You mean like this :
Code: [Select]

sf::Shape Rect1;
//...
sf::Shape Rect2 = sf::Shape::Rectangle(0, 0, 100, 600, sf::Color(100, 100, 100));
Window->Draw(Rect2);
Rect1 = sf::Shape::Rectangle(10, 100, 90, 190, sf::Color(255, 255, 255));
Window->Draw(Rect1);


I tried and it didnt work.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Rectangle inside Rectangle
« Reply #3 on: July 29, 2009, 08:32:30 am »
What does "it didn't work" means? Can you show a screenshot?
Laurent Gomila - SFML developer

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[solved]Rectangle inside Rectangle
« Reply #4 on: July 29, 2009, 12:21:05 pm »
I dont know how to put an image here but I'll try to explain.
I have two Rectangles
Code: [Select]

    Rect 1                                               Rect2
__________                                       _________________
|         |                                      |                |
|         |                                      |                |
|         |                                      |                |
|_________|                                      |                |
                                                 |                |
                                                 |                |
                                                 |                |
                                                 |                |
                                                 |________________|


And I put Rect1 inside Rect2 but I see only Rect2. Rect1 isnt visible.
This is how it should look:

____________________
|             Rect2 |
|                   |
|                   |
|     _________     |
|    |   Rect1 |    |
|    |         |    |
|    |         |    |
|    |_________|    |
|                   |
|                   |
|___________________|


And this is how it looks
____________________
|             Rect2 |
|                   |
|                   |
|                   |
|                   |
|                   |
|                   |
|                   |
|                   |
|                   |
|___________________|

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Rectangle inside Rectangle
« Reply #5 on: July 29, 2009, 12:24:36 pm »
Quote
I dont know how to put an image here

There are plenty of websites that allow you to upload and store images, like imageshack.us.

Can you post a minimal and complete example that reproduces your problem?
Laurent Gomila - SFML developer

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[solved]Rectangle inside Rectangle
« Reply #6 on: July 29, 2009, 12:52:59 pm »
I couldnt upload at imageshack so I did it here.

This is how it is:
[img=http://www.freeimagehosting.net/uploads/4bc1a8c0d2.jpg]

And this is how it should be:
[img=http://www.freeimagehosting.net/uploads/a38284f572.jpg]

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Rectangle inside Rectangle
« Reply #7 on: July 29, 2009, 01:07:24 pm »
Your links are broken. Anyway, I've understood your problem ;)

What about your code?
Laurent Gomila - SFML developer

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[solved]Rectangle inside Rectangle
« Reply #8 on: July 30, 2009, 06:02:20 pm »
Here is my code. I'm trying to make a simple Paint program.

Code: [Select]

sf::RenderWindow Paint(sf::VideoMode(800, 600), "Paint");

sf::String GetString()
{
sf::Input mouseInput;
std::stringstream out;
out << "x: " << Paint.GetInput().GetMouseX() << "\ny: " << Paint.GetInput().GetMouseY();
std::string myString;
myString = out.str();
sf::Unicode::Text myText(myString);
sf::String thisString(myText, sf::Font::GetDefaultFont(), 15);
return thisString;
}


class DrawingSpace
{
public:
sf::Shape Rect1;
DrawingSpace(sf::RenderWindow* Paint)
{
        // the color panel
sf::Shape Panel = sf::Shape::Rectangle(0, 0, 100, 600, sf::Color(100, 100, 100));
Paint->Draw(Panel);
// the white color
Rect1 = sf::Shape::Rectangle(10, 100, 90, 190, sf::Color(0, 0, 0));
Paint->Draw(Rect1);
// the drawing space
sf::Shape space = sf::Shape::Rectangle(100, 0, 800, 600, sf::Color(0, 0, 0));
Paint->Draw(space);
}
};

int main()
{
DrawingSpace* Space = new DrawingSpace(&Paint);
while (Paint.IsOpened())
{
sf::Event myEvent;
while (Paint.GetEvent(myEvent))
{
if (myEvent.Type == sf::Event::MouseMoved)
{
Paint.Clear();
delete Space;
Space = new DrawingSpace(&Paint);
Paint.Draw(GetString());
}

if (myEvent.Type == sf::Event::Closed)
Paint.Close();
}
Paint.Display();
}
return  0;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
[solved]Rectangle inside Rectangle
« Reply #9 on: July 30, 2009, 06:55:34 pm »
It works for me.
Laurent Gomila - SFML developer

Devil0150

  • Newbie
  • *
  • Posts: 25
    • View Profile
    • Email
[solved]Rectangle inside Rectangle
« Reply #10 on: July 30, 2009, 07:02:37 pm »
I fixed it accidentally while posting here. thx.

 

anything