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

Author Topic: Resize VideoMode?  (Read 5151 times)

0 Members and 1 Guest are viewing this topic.

Ankou

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Resize VideoMode?
« 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Resize VideoMode?
« Reply #1 on: July 24, 2008, 05:22:39 am »
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.
Laurent Gomila - SFML developer

Ankou

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Resize VideoMode?
« Reply #2 on: July 24, 2008, 03:57:23 pm »
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:

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:
Code: [Select]

 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:

(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:
Code: [Select]

 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:
Code: [Select]

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:
Code: [Select]

 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   }

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Resize VideoMode?
« Reply #3 on: July 24, 2008, 04:06:45 pm »
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.
Laurent Gomila - SFML developer

Ankou

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Resize VideoMode?
« Reply #4 on: July 24, 2008, 04:50:23 pm »
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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Resize VideoMode?
« Reply #5 on: July 24, 2008, 05:09:10 pm »
Then you should create the RenderWindow only after the wxWidgets control has the proper size.
Laurent Gomila - SFML developer

Ankou

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Resize VideoMode?
« Reply #6 on: July 24, 2008, 05:11:35 pm »
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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Resize VideoMode?
« Reply #7 on: July 24, 2008, 05:18:09 pm »
You can recreate the window when the wxWidgets control is resized.
Laurent Gomila - SFML developer

Ankou

  • Jr. Member
  • **
  • Posts: 52
    • View Profile
Resize VideoMode?
« Reply #8 on: July 24, 2008, 05:26:45 pm »
x.x I already tried that and it didn't work.
Now I tried it again and it works fine.
Well, Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Resize VideoMode?
« Reply #9 on: July 24, 2008, 05:28:28 pm »
Yah, I did some voodoo magic just before you tried again ;)
Laurent Gomila - SFML developer

Daazku

  • Hero Member
  • *****
  • Posts: 896
    • View Profile
Resize VideoMode?
« Reply #10 on: July 24, 2008, 06:39:43 pm »
Aie! Donc touch this doll! It's me!
Pensez à mettre le tag [Résolu] une fois la réponse à votre question trouvée.
Remember to add the tag [Solved] when you got an answer to your question.

 

anything