SFML community forums
Help => Graphics => Topic started by: Ankou on July 24, 2008, 01:07:32 am
-
Hi,
I have a sfml RenderWindow which is also a wxControl and I don't want any stretching or shrinking or something else when I resize the wxControl.
So I tried to use the method sf::RenderWindow::Create to set up a new VideoMode, but it's opened in a new Window, and not where it should be.
What can I do?
-
SFML separates the concepts of container (the window) and content (the graphics displayed inside). Basically if you want to change what's shown in your window you don't have to change anything on the window itself, just change what's displayed inside.
In this case the simplest solution is to resize the default view (see RenderWindow::GetDefaultView) to the window's dimensions. By default the view always keeps the same size, that's why graphics are stretched.
-
mhm, it doesn't work, at least not as I expected it to do.
I will explain what's the problem:
The window is a RenderWindow embedded in a wxControl.
First I just tried to draw on it, but it looked like this:
(http://imagesload.net/daten_no/1216907158_Before.png)
I expected that it looks like this, because the RenderWindow is created(with the Tutorialcode for wxGTK) before wxWidgets adjusts the size of the window(It's in a wxSizer).
So I thought I would have to resize the VideoMode(which was probably wrong) so I asked and tried the following Code:
87 void MappingTool::resizeSFWindow(bool force)
88 {
89 static int width(0), height(0);
90 if(width != GetSize().GetWidth() || height != GetSize().GetHeight() || force)
91 GetDefaultView().SetHalfSize(GetSize().GetWidth()/2.0, GetSize().GetHeight()/2.0);
92 width = GetSize().GetWidth();
93 height = GetSize().GetHeight();
94 }
But now it's looking like this:
(http://imagesload.net/daten_no/1216907485_After.png)
(a few pixelrows are cut, but that doesn't matter, but it IS smaller than the first Image)
The first Image shows the upper left corner of the desired image, the second one is extremly shrinked.
So what could it be? How can I show the Image how it should be?
I don't think that you need it, but
here's the DrawingCode:
52 wxPaintDC dc(this);
53
54 sf::Sprite tileset;
55 if(map)
56 {
57
58 if(currentTileset == MainTileset)
59 tileset = ImageList::GetInstance()->GetSpriteByImage(map->GetMainTileset().GetImage());
60 else if(currentTileset >= 0)
61 tileset = ImageList::GetInstance()->GetSpriteByImage(map->GetSideTileset(currentTileset).GetImage());
62 }
63 sf::Shape rectangle(sf::Shape::Rectangle(0, 0, tileset.GetSize().x, tileset.GetSize().y, sf::Color(255, 255, 255, 255)));
64 Draw(rectangle);
65
66 if(map)
67 Draw(tileset);
68
69 Display();
And this is there Code where the Sprite comes from:
201 const sf::Sprite& ImageList::GetSpriteByImage(SFImageID id)
202 {
203 if(spriteIDs[id] == -1)
204 {
205 sf::Sprite sprite(sfImages[id]);
206 sfSprites[id] = sprite;
207 spriteIDs[id] = sfSprites.size() - 1;
208 }
209
210 return sfSprites[id];
211 }
and sfImages[id] is set up here:
65 SpriteID ImageList::addSFImage(bf::path imagePath, std::string subDir)
66 {
67 bf::path ImageDir(copyImageToDirectory(imagePath, subDir));
68
69 std::string filePath((ImageDir/imagePath.leaf()).native_file_string());
70 sf::Image image;
71 image.LoadFromFile(filePath);
72
73 sfImages.push_back(image);
74 spriteIDs[sfImages.size() - 1] = -1;
75
76 return sfImages.size() - 1;
77 }
-
Your code looks good. Did you check the values passed to the view, did you try some debugging ? There are plenty of values which could be wrong, I think you should first do some debugging, and reduce the code to something very simple.
-
Ok,
RenderWindow::GetWidth() and RenderWindow::GetHeight() are both 20 while wxControl::GetSize()::GetWidth() and Height both have the expected values, after calling resizeSFWindow(true);(code in the post before).
The breakpoint at line 91 is reached.
-
Then you should create the RenderWindow only after the wxWidgets control has the proper size.
-
That's not possible, because the User can resize it and I don't want any shrinking, stretching, or odd appearances(like the current).
So it wouldn't solve the problem.
-
You can recreate the window when the wxWidgets control is resized.
-
x.x I already tried that and it didn't work.
Now I tried it again and it works fine.
Well, Thanks
-
Yah, I did some voodoo magic just before you tried again ;)
-
Aie! Donc touch this doll! It's me!