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.


Messages - ingar

Pages: [1] 2
1
General Discussion / Re: TGUI and Unicode
« on: 04 June 2019, 21:05:01 »
Worked! :)

But I wonder what Mikkesoft is doing. Because their font files are about 1Mb in size, and I have never
had problems to display Unicode Asian characters.

Ingar

2
General Discussion / Re: TGUI and Unicode
« on: 04 June 2019, 19:48:26 »
Thanks a lot. I will try that.

3
General Discussion / Re: TGUI and Unicode
« on: 04 June 2019, 16:38:35 »
HI again,

Arial is one of the most commonly used fonts used by Windows, and does indeed support Japanese and other Asian languages.
I also tried Tahoma. This font also displays just about everything.

One thing I haven't tried is to use the font in an SFML only app I have (i.e. without any tgui components).

Ingar


I don't see anything wrong with your steps.

Maybe storing the buffer in an std::string can be skipped if fromUtf8 supports a begin and end pointer (I'm not sure if it does), but it will work equally well when first stored in an std::string.

The type is Uint32 because it stores the string as UTF32. Two bytes wouldn't be enough to store ALL possible unicode characters.

If squares are displayed then it would mean that the chosen font (arial.ttf in this case) does not contain these japanese characters.

4
General Discussion / Re: TGUI and Unicode
« on: 04 June 2019, 16:13:42 »
Hi again,

I am still having problems with tgui/sfml and Unicode. I have a server returning UTF8 data in a character buffer.
The data may contain Asian characters.

I have previously received some very useful help here, so I am thinking I am doing things the correct way:

First I am creating a "tgui::Font" object from a Windows font file (arial.ttf or other).

Then I am doing "m_labShipname->getRenderer()->setFont(Font)", where "m_labShipname" is
a pointer to a Label field. This works, I can see that the text displays in the correct font.

From the server I am receiving this in a character buffer, named "buffer":

0x41, 0x42, 0xe6, 0x9d, 0xb1, 0xe4, 0xba, 0xac,0

In case you do not see what this is, :), it is AB東京 in UTF8 Japanese (A and B in front of "TOKYO").

I am then doing:

std::string s = buffer;
sf::String str;

str=sf::String::fromUtf8(s.begin(),s.end());
m_labShipname->setText(str);


I finally check the content of my "sf::String str". This I do using the sf::String::Iterator.
The iterator is of type Uint32 (this is a bit strange, why not Uint16?).
And the content of my Unicode string is:

0x0041 , 0x0042, 0x6771, 0x4eac

This is correct. Unfortunately, it is displayed as AB[][].

When I receive another string with Norwegian UTF8 characters containing ÆØÅ,
they display correctly.

What could be wrong? Perhaps tgui/sfml does  not support the Windows True Type fonts?
Or did I miss something?

My OS is Raspian Stretch. I see the same on VmWare X86 as well as on a native Raspberry Pi.

Ingar


Hi all,

A general question:

Are there any ways of supporting Unicode in TGUI? I am hoping to be able to replace a Windows CE application with a TGUI app. But the Windows CE app is connecting to a server that returns UTF8 data.
And I cannot see how to TGUI can display those Japanese names...

Ingar

5
General Discussion / Updating existing Picture widget
« on: 15 May 2019, 22:08:19 »
Hi again,

I have this scenario:

I receive a .jpg file image on TCP/IP from an external server.
So I have a byte buffer (with a given length) containing the jpg file.

So how do I update an existing Picture widget from this buffer?

I know how to create a NEW Picture widget from a buffer, using an sf::Texture in the constructor,
but isn't it a bit overkill to create a new one every time? I saw that a function tgui::Picture::setTexture was available
in version 0.78, but this function has been removed in the latest version (0.85).

Ingar

6
General Discussion / TGUI and Unicode
« on: 07 May 2019, 21:53:12 »
Hi all,

A general question:

Are there any ways of supporting Unicode in TGUI? I am hoping to be able to replace a Windows CE application with a TGUI app. But the Windows CE app is connecting to a server that returns UTF8 data.
And I cannot see how to TGUI can display those Japanese names...

Ingar


7
Hi again,

OK. I can do a mutex. And probably call a function to handle the external event from the main event loop.

Thanks,
Ingar


You can't access the same SFML or TGUI objects from multiple threads at the same time, it is up to you to do the synchronization. One way would be to use mutexes around the TGUI objects you access, but that will likely decrease performance as you would have to lock practically everywhere in the main thread (locks around both event handling and drawing and anywhere else where you access TGUI widgets). So the best way is probably to only let the main thread access TGUI and get your data to the main thread somehow. How to do this is of course not related to TGUI.

I don't have much experience with syncing between threads myself, other than on a windows-only project that uses the Windows functions like PostMessage, SetEvent and WaitForSingleObject.
A pure c++ alternative to SetEvent/WaitForSingleObject would probably be to have a mutex around a shared variable. Every frame (or every X milliseconds) you lock the mutex, check the variable and unlock the mutex again. In the other thread, when data is read from the card, it locks the mutex, writes the data in the variable and unlock the mutex again.

8
General Discussion / Triggering action from another thread
« on: 05 May 2019, 09:25:23 »
Hi,

In my app I have a thread that checks if an RFID card is placed over an RFID reader. If a card is detected the app reads some data from the card. This data I would like to pass to an event handler in my main thread. Q: What's the best method for doing this in tgui?

I Windows programming, the thread typically issues a PostMessage to the main window thread, and the message handler in the main thread does the handling.

Regards,
Ingar

9
General Discussion / Re: Re-using RenderWindow
« on: 03 May 2019, 11:34:42 »
Hi again!

VERY GOOD NEWS. I tried the tgui:Group and it worked beautifully.

So now I only create ONE RenderWindow. In my screen class  I declare tgui::Group::Ptr and load all my
widgets into the group from a stringstream (gui-builder was used to create the screen). And then I did gui.add(...).

When I enter the second screen, I did what you said: Doing setVisible(false), and when the second screen closes I do
setVisible(true). I do not have to do a setVisible(false) on the second group, because (I guess) the Group is destroyed
when my second screen class is destroyed, or perhaps when the second Gui is destroyed. What is correct? I am worried to create memory/resource leaks.

I am bit confused by the tgui::Ptr's. They cannot be C++ class pointers, since I cannot do new/delete on them. But still,
I have to use -> operator, not dot(.).

Ingar

10
General Discussion / Re: Re-using RenderWindow
« on: 03 May 2019, 10:04:10 »
Hi again,

Thanks for the hints. :)
For now I just keep the multiple RenderWindows. I will try out Group widgets later. On my Raspberry by creating RenderWindow is not that slow, it's when I am running via an X-Windows (Xming) window on another computer I can see a 2 second delay.
But, it would be interesting to know why the RenderWindows stops returning events AFTER the second Gui has been terminated.

My first app only contains two screens, but I am planning another bigger app that uses may sub-windows. In this case, I need to figure out what happens. Perhaps, by patching SFML, I can figure out why pollEvent always fails.

Another thing: I have now made an App that creates a new app with two windows. If I send it to you, you can decide if you want to publish it as a sample source.

Ingar

Is there anything that prevents you from just keeping the window and gui and just calling gui.removeAllWidgets() and adding the widgets for the next screen?
Multiple screens could be prepared upfront by creating a Group widget per screen (and adding the widgets to the group instead of to the gui). Then showing another screen is as simple as calling group1->setVisible(false); group2->setVisible(true);

Or maybe use a tgui::ChildWindow instead of an actual window?

11
General Discussion / Re: Re-using RenderWindow
« on: 02 May 2019, 17:35:29 »
Hi again,

I tried it. The second window just set a flag, and the event loop was finished for the second Gui.

But, unfortunately, the RenderWindow stopped responding to events. After the Gui was closed, three more
events came out of RenderWindow (I will figure out what events), and after that, pollEvent always returned false.
I guess, the Gui somehow is doing something so that RenderWindow does not return events.

Ingar



Hi again,

Thanks. I will try to re-use the RenderWindow.

My application has a main window, and a button for starting a "Setup" window. So what is then the best procedure?

A: Creating a new RenderWindow and a new Gui, as I am doing now
B: Re-using the RenderWindow with a new Gui.
    The change in my code will then be to let the "Back" (or "OK") button just set a "Finish" flag,
    instead of, as now, closing the RenderWindow.
C: Other method?

Ingar




tgui::Gui just keeps a pointer to the RenderWindow, it will not destroy the window when the Gui gets destroyed. You only have to make sure not to call functions on the Gui object after the window it uses has been destroyed.

Why do you need a second sf::RenderWindow? Can't you just continue to use the existing window? If you really need a second window then you also need a second Gui that renders to that window.

12
General Discussion / Re: Re-using RenderWindow
« on: 02 May 2019, 14:53:31 »
Hi again,

Thanks. I will try to re-use the RenderWindow.

My application has a main window, and a button for starting a "Setup" window. So what is then the best procedure?

A: Creating a new RenderWindow and a new Gui, as I am doing now
B: Re-using the RenderWindow with a new Gui.
    The change in my code will then be to let the "Back" (or "OK") button just set a "Finish" flag,
    instead of, as now, closing the RenderWindow.
C: Other method?

Ingar




tgui::Gui just keeps a pointer to the RenderWindow, it will not destroy the window when the Gui gets destroyed. You only have to make sure not to call functions on the Gui object after the window it uses has been destroyed.

Why do you need a second sf::RenderWindow? Can't you just continue to use the existing window? If you really need a second window then you also need a second Gui that renders to that window.

13
General Discussion / Re-using RenderWindow
« on: 30 April 2019, 15:50:39 »
Hi,

I have a TGUI app where a screen (dialog) starts another screen (dialog) with a button.
The second screen creates an sf::RenderWindow and attaches this window to a tgui::Gui.
This works, but to construct a new sf::RenderWindow everytime takes time.

Q: Is there a way a new tgui:Gui can reuse a window used by another tgui:Gui?
     The problem, as I can see, is that the render windows also gets destroyed when the Gui is destroyed,
     so that the old Gui crashes when it continues trying to use the destroyed window.
     Perhaps sf::RenderWindow has a copy constructor that doesn't take that long time to execute,
     or there is a way of detaching a window from the Gui?

Ingar


14
Installation help / Re: Cannot install TGUI as STATIC library
« on: 30 April 2019, 14:28:52 »
Hi again,

Not so important, but it did not work. I did:

export SFML_ROOT=/usr/local/sfml_251
cmake . -DTGUI_SHARED_LIBS=FALSE
make -j2
sudo make install

Everything worked fine, except static TGUI still uses SHARED sfml libraries.

Linux system is: Native Raspberry Pi board (Raspian Linux (=Debian Stretch)).

Regards,
Ingar

That option has to be set to FALSE, but it should be done in cmake (either by unchecking it in the gui or by specifying -DTGUI_SHARED_LIBS=FALSE at the command line). If that option is TRUE then you are building dynamic tgui libraries (which will obviously link to dynamic sfml libraries).

15
Help requests / MessageBox how to use
« on: 26 April 2019, 18:43:47 »
Hi all,

I am sure this question has been posted many times before, but anyway:

How do I display a message box in TGUI?

I have tried tgui::MessageBox::Create("Heading","Message",{"OK", "Cancel"});
Then I add it to the gui, and it displays in the upper left corner.

But how do I get the events from my buttons (OK or Cancel)?

Can someone give me a complete example. Then I can make a function that just displays the message and returns with a value.

Ingar

Pages: [1] 2