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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - cob59

Pages: [1]
1
Window / Splash screen
« on: July 22, 2020, 02:46:07 pm »
Hi,
I'm having a few issues with windows using sf::Style::None to implement something like a splash screen.

#include <SFML/Graphics.hpp>

int main()
{
   sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!", sf::Style::None);

   // center the window
   sf::Vector2i splashOrig = {
      int(sf::VideoMode::getDesktopMode().width)  / 2 - int(window.getSize().x) / 2,
      int(sf::VideoMode::getDesktopMode().height) / 2 - int(window.getSize().y) / 2
   };

   window.setPosition(splashOrig);

   sf::CircleShape shape(100.f);
   shape.setFillColor(sf::Color::Green);

   bool dragging { false };
   sf::Vector2i dragAnchor;

   while (window.isOpen())
   {
      sf::Event event;
      while (window.pollEvent(event))
      {
         if (event.type == sf::Event::Closed)
            window.close();

         if (event.type ==  sf::Event::MouseButtonPressed)
         {
            if (event.mouseButton.button == sf::Mouse::Left)
            {
               dragging = true;
               dragAnchor = sf::Mouse::getPosition();
            }
         }

         if (event.type == sf::Event::MouseButtonReleased)
         {
            if (event.mouseButton.button == sf::Mouse::Left)
            {
               dragging = false;
               dragAnchor = {};
            }
         }

         if (dragging)
         {
            auto currentPos = sf::Mouse::getPosition();
            auto deltaPos = dragAnchor - currentPos;

            window.setPosition(window.getPosition() - deltaPos);

            dragAnchor = sf::Mouse::getPosition();
         }
      }

      window.clear();
      window.draw(shape);
      window.display();
   }

   return 0;
}

 

1. I want my window to be positioned at the center of my main monitor on startup, but since I have 2 monitors the getDesktopMode() gives an area which is the sum of those 2 and the window ends up astride both. It kind of makes sense, but how can I set up "splashOrig" so that my window appears at the center of my main, or current, or any screen?

2. I'm trying to make the window movable by drag-n-dropping as you can see. It kind of works, but the anchor point I set when left-clicking isn't stuck to the cursor... the faster I move, the more it "drags behind".
I've already implemented an Image viewer before in SFML and I know you need mapPixelToCoords/mapCoordsToPixel transformations in some cases... so what am I missing?

PS: I'm aware using sf::Style::None and tweaking it so it behaves like an sf::Style::Default is a bit odd... I'm just testing the limits of the thing. If it's more convenient I'll go with sf::Style::Titlebar in order to move my splash screen around.

2
Feature requests / std::size_t instead of unsigned int
« on: November 10, 2014, 10:57:38 pm »
Hi :)
Just a quick suggestion about the types used for indexing.

I'm compiling a VC++ projects in 64bits right now and I've noticed some sf::VertexArray methods use the 32bits unsigned int (i.e. unsigned long) index types, even though their underneath std::vector<Vertex> uses the 64bits unsigned long long types.

This leads to unnecessary casts and warnings.

So I think you should use std::size_t for unsigned indexes and std::ptrdiff_t for the signed ones.

NB: I didn't check, but sf::VertexArray probably isn't the only concerned class.

Pages: [1]
anything