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 - Celtic Minstrel

Pages: [1]
Window / Detecting keypresses on Mac OSX Catalina
« on: January 12, 2023, 03:27:40 pm »
I'm having issues with detecting certain keypresses when building on Mac OSX Catalina. The system seems to think that the application wants to be able to monitor input while in the background, which isn't even true.

According to another post I found on this forum (quoted below), it's caused by using IsKeyPressed, and the solution is to use events. But that's not possible – I'm trying to do is handle modified mouse clicks (eg, Alt+Click) and scroll wheel (eg, Ctrl+Wheel). The MouseButtonEvent does not have a modifier key field, so the only option is to manually check for the modifier. The same applies to the scroll event.

I know for certain that other apps can handle modified mouse clicks and scroll wheel without needing to register for input monitoring in System Preferences, so why is it that there's no way to do this in SFML? If IsKeyPressed does not work, what other options are there? Perhaps the Mac implementation of IsKeyPressed is incorrect.

If you actually use events and not real-time input (sf::Keyboard::IsKeyPressed), then things should work fine.

For real-time input you will have to grant the app input monitoring privileges as far as I know, that's one of the major changes in Catalina for all applications.
There are ways to disable some stuff for developers, but as I am not a macOS user, I don't really know and would need to research myself.

EDIT: Based on the contents of the framework package, I appear to be using version 2.5.1.

Window / Working with multiple monitors
« on: September 03, 2017, 03:44:12 am »
Is there any way to distinguish between the main monitor and secondary monitors? I have a fullscreen mode which calls getDesktopMode() to determine the size of the screen and resizes the window to fit it; however, it always uses only the size of the main monitor. I'd like it to take the size of whichever monitor the window currently resides on (based on the window's origin). Can this be done in SFML?

Window / Splash screen not showing
« on: April 07, 2014, 09:26:24 am »
I'm trying to create a splash screen on startup, but it seems that calling window.display() isn't sufficient to make the contents of the window instantly visible, for some reason. My procedure can be summed up as follows:
  • Fill the window with black (using a RectangleShape)
  • Load the splash screen into a texture.
  • Create a Sprite and draw it centred in the window.
  • Call display() on the window.
  • Play the sound. (This is the only part that works perfectly.)
  • Institute some sort of delay.
  • Repeat all the above steps a second time.

I actually have two problems; the main problem is that nothing shows up until the main event loop, by which point the splash screen has been erased; also, I'm unsure how to create the sort of delay where pressing a key ends it prematurely.

I'm not sure what portion of the code would be best to post here. It uses several utility functions, so simply copy-pasting the splash code would probably not be very instructive. The window does get created prior to the splash code, incidentally.

Stepping through the code in the debugger hasn't helped much, although somehow I'm sometimes able to see the second splash screen when I set certain breakpoints and hop between them with F9 (continue). With breakpoints disabled, this never seems to happen.

Any ideas? Or requests for particular parts of the code?

Graphics / Tesselations (texture issue)
« on: April 06, 2014, 11:43:05 pm »
I'm trying to tile an image across an area, but instead of tiling, the image is stretching to fill the area.

The tiling function is as follows:
Code: [Select]
void tileImage(sf::RenderTarget& target, RECT area, sf::Texture& img, RECT srcRect, sf::BlendMode mode){
sf::Vector2u imgSz = img.getSize();
area.left -= area.left % imgSz.x;
area.top -= area.top % imgSz.y;

sf::RectangleShape tessel(sf::Vector2f(area.width(),area.height()));
tessel.setPosition(area.left, area.top);
sf::RenderStates renderMode(mode);
glScissor(area.left, area.top, area.width(), area.height());
target.draw(tessel, renderMode);
The texture that's passed in contains several images of which I only want to tile one, that contained in the rectangle "srcRect". The rectangle "area" is the area in which the image should be tiled. The setActiveRenderTarget call just calls target.setActive() if target is a RenderWindow, because for some reason RenderTexture doesn't have a setActive function (which makes me wonder if this'll work on a RenderTexture, but I'll get to that later).

I'm hoping I'm just missing something obvious here. I know roughly what needs to happen (the texture should be drawn with normalized texture coordinates > 1), but I'm not sure what I've missed in trying to get SFML to do this. Will I need to copy the portion I want to repeat into a new texture?

System / Incorrect key mapping? (OSX)
« on: November 16, 2013, 12:44:15 am »
I just noticed that when I press the (-/_) key (between 0 and +/=) on my Apple keyboard, it's reported by keypress events as Keyboard::Menu instead of Keyboard::Dash. I'm on MacOSX (10.7), and I compiled the libraries myself using CMake. Does this happen for anyone else?

EDIT: More detail! The key event says it's KEY_MENU and in addition that it has all four modifier keys pressed, when in fact none were pressed; also, no TextEntered event seems to be generated. Pressing it with a modifier key seems not to trigger any keypress event, though with shift or option a TextEntered event is generated.

EDIT 2: On closer inspection, it looks like there's no KeyPressed event at all and the event is simply a TextEntered event. So, the TextEntered is generated, but the KeyPressed is not. This is contrary to the behaviour of (for example) alphabetic keys, which generate both a KeyPress and a TextEntered.

EDIT 3: This prompted me to try all keys to see what they're reported as, and I discovered that pressing tilde generates Keyboard::Dash instead of Keyboard::Tilde! However, if a modifier key is held while pressing tilde, no keypress seems to be reported. There were other things as well that I noticed, but they're probably not as important.

EDIT 4: Not quite related, but I can't catch Command-Period. When I press it I just hear the system alert sound and my program doesn't get an event. This could be related to Command-Period being a common "interrupt" sequence? I'm not sure.

Graphics / Best way to measure text?
« on: June 24, 2012, 08:55:28 am »
Since there's no measureText function anywhere, I've been measuring the size of a string by constructing a Text object, getting the bounds, and then discarding it. Is that a reasonable way to measure text, or would you say I should be using just a Font and calculating the size one character at a time by accessing the glyphs?

To put this another way, does constructing a text object with a string do anything towards rendering, or does it just store the string and font attributes and calculate the size of the string, leaving any rendering to when draw() is called?

I'll note that the lack of a measureText function in Font surprised me at first, since this is kind of an important thing to have. I've actually been having small performance issues in rendering large quantities of text and have figured out that the measuring, wrapping algorithm, and rendering take the most time overall. I think my wrapping algorithm could also use some work, but I'd like to know if there's any point in changing the measuring algorithm as well.

Graphics / Odd text artifacts
« on: June 21, 2012, 05:32:47 am »
I'm not sure whether this is something I'm doing wrong or a bug in the library, but I'm getting boxes around some of the letters when I render text. Example:

I'm not entirely sure what code to post, since I have no idea why this is happening. I created a small program that just draws text to the screen and then waits to be closed, but wasn't able to reproduce this.

If it's relevant, I'm on a Mac using clang and libc++, for which I had to compile SFML myself. I haven't checked yet whether this occurs on Windows as well (that would require a reboot and rewriting a few functions, so it's unlikely I'll check soon).

Here's the function I'm using to draw text (the "Left" in the name refers to alignment), and its subroutines:
Code: [Select]
FloatRect drawTextLeft(short left, short top, string str, int size, Color clr, int style) {
Text text = makeText(str, size, clr, style);
FloatRect bounds = text.getLocalBounds();
drawText(left, top, text);
adjustForWhitespace(str, &bounds.left, &bounds.width, text.getFont(), size, style);
return bounds;

void adjustForWhitespace(string str, float* left, float* width, const Font& font, int size, int style) {
// Hack to force the text drawing functions to account for whitespace
// Only accounts for actual space, unfortunately; tabs not handled
int space = ({
Text withSpace("| |", font, size);
Text withoutSpace("||", font, size);
withSpace.getLocalBounds().width - withoutSpace.getLocalBounds().width;
size_t pre = str.find_first_not_of(' ');
if(pre == string::npos) pre = 0;
size_t post = str.size() - str.find_last_not_of(' ') - 1;
if(left) *left -= pre * space;
if(width) *width += (pre + post) * space;

Text makeText(string str, int size, Color clr, int style) {
Text text(str);
return text;

void drawText(int left, int top, Text& text) {
text.setPosition(left, top);

When I commented out the call to adjustForWhitespace, there were less artifacts, but there were still some — less boxes, and sometimes just fragments of boxes. Also, I notice that it tends to happen to certain letters. Maybe that's a hint towards the cause of this?

Not entirely sure if this is the right area of the forum to post this in...

So, I discovered the existence of this a day or two ago as a substitute for SDL, when I was looking into ways of improving rendering speed (I was rendering a lot of tiles per frame and the time for rendering was quite a bit longer than the time I had allotted for a frame; I did try optimizing my rendering within SDL first, and then tried OpenGL with SDL, but the first didn't help much and I had strange problems with OpenGL). Converting the project from SDL to SFML was quite an undertaking, and was not entirely straightforward, but it did at least improve the rendering speed even though my drawing is still pretty inefficient (I'm currently creating and immediately discarding around 500 or so Sprites per frame in the "blit" function I used to make the transition easier; I might look into using a VertexArray later for the tiles that don't change often).

However, I noticed a couple of missing features in the library (none of which are absolutely essential for me, fortunately), and I also had some problems linking with it. (I'm using the SFML 2.0 latest development snapshot from the downloads page.)

A new project with the Xcode templates worked fine, but my existing project could not locate a number of SFML symbols. I compared my project settings with the template settings, and eventually figured out that the key was in the standard C++ library; the templates linked against GCC's C++ library, whereas I was linking against LLVM's C++ library for the C++11 support. Once I had figured this out it wasn't too hard to rebuild SFML with the other library (by setting the CMAKE_CXX_FLAGS variable to -stdlib=libc++ when building), but I was wondering if this might become an option in the prebuilt libraries anytime soon?

Some of the keys I was handling with SDL are not supported in SFML. These are the enter key on the numeric keypad, and the clear key in the same area (which would be num lock on a Windows keyboard). I noticed the numpad equals and period keys are also missing, as well as caps lock and one or two others (older Apple keyboards have a Help key, for example). Also, while I don't really need this, you only support function keys up to 15; I have 19 function keys (I use an Apple flat extended keyboard, with an Fn key in place of Help/Insert). I only really care about Enter and Clear/NumLock, though. And, uh, this is just an aesthetic thing, but calling Backspace "Back" threw me off for a few moments.

While I don't especially need it at this point, it would be nice to add a Strikethrough style to the Text class. There's already an Underline, and strikethrough is almost the same as underline for rendering (just a line in a different place). And speaking of the Text class, it seems to strip leading and trailing whitespace from the input string, which led to a whole lot of issues with my formatted text rendering (with embedded images, even) until I wrote a workaround to account for it. I don't think it should strip whitespace like this.

One other thing... a lot of the classes have many attributes, but only one or two of them can be specified in the constructor, so it would be nice to make the setXYZ functions return (*this) so that you can chain calls. For example:
Code: [Select]
Text text = Text("my string").setSize(16).setColor(blue).setStyle(Text::Bold);

Pages: [1]