SDL Forum Index
SDL
Simple DirectMedia Layer Forums
Reply to topic
actsl


Joined: 09 Feb 2016
Posts: 83
Reply with quote
MrTAToad wrote:
Oh yes, keys repeat - unfortunately every key press repeats...

Every time there is SDL_TEXTINPUT event, it receives event->text.text, which is the string of chars for one character. That is, it is always a string with length 1, if one uses only ascii characters, more if there is a unicode character.

If you receive a character twice, this means that there had to be two SDL_TEXTINPUT events for the same key press. I don't know how this can happen. I have never seen that in any platforms. Then it should be something about the SDL or the operating system. There is nothing about setting it in the code of kiss_sdl, than SDL_StartTextInput(), once in kiss_init(). Fixing it in the rest of the code may not be possible, unless when one knows that every key press always causes two events.

Find out with some test code, whether your key presses always cause two SDL_TEXTINPUT events, and when this is the case, then this is a general problem, and should be talked somewhere separately, of how to fix it.

I don't know of course what else may be wrong. It looks like adding an event function of an entry widget twice to the event loop or something. Anyway, by that what you say, i cannot reproduce it.

_________________
kiss_sdl - Simple generic GUI widget toolkit for SDL2 https://github.com/actsl/kiss_sdl
View user's profileSend private message
actsl


Joined: 09 Feb 2016
Posts: 83
Reply with quote
But you are of course right that it should not go ahead when an image or a font cannot be loaded, this is my bad attention. It is fixed now, it prints a message to stderr when a resource cannot be loaded, frees the resources, and kiss_init() returns NULL.

So one more release :p

kiss_init() now returns NULL at error, in the new version 1.0.12 https://github.com/actsl/kiss_sdl .

_________________
kiss_sdl - Simple generic GUI widget toolkit for SDL2 https://github.com/actsl/kiss_sdl
View user's profileSend private message
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Reply with quote
It is also possible to position widgets on/outside the decoration area. I think a valid area needs to be calculated for display of widgets (x+borderSize+1,y+borderSize+1,w-borderSize-1,h-borderSize-1) - or preferably when the window displayed first - and this is then used to offset widget positions and detection.

Could also instead use it for a clipping area, although I dont prefer that as it could have a speed problem
View user's profileSend private message
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Reply with quote
Actually that wont work due to combo boxes Smile
View user's profileSend private message
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Reply with quote
I'm actually seeing if it will - I need it really to be able to centre text
View user's profileSend private message
actsl


Joined: 09 Feb 2016
Posts: 83
Reply with quote
What problem is centering text? You add to the origin x of an area, half the width of that area, minus half the width of your text. Or i didn't understand the problem you have.

_________________
kiss_sdl - Simple generic GUI widget toolkit for SDL2 https://github.com/actsl/kiss_sdl
View user's profileSend private message
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Reply with quote
The problem is that currently widgets are based on the screen position rather than the position of the window.

At the moment (although I have only tested one widget at the moment), it seems to be working - a widget's X & Y position also takes into account a windows X & Y position plus the windows decoration size, so that all widgets are inside a window and just cant appear everywhere.

It should work with lists fine as the text will e positioned inside a new window with up/down arrows based on the position of the initial wndow.
View user's profileSend private message
actsl


Joined: 09 Feb 2016
Posts: 83
Reply with quote
Yes these are simple calculations, all is much simpler when all coordinates are screen coordinates, that is SDL window coordinates. There are calculations, but these calculations are easy to understand, self-evident and need almost no explanation. Different from like, widget packing in GTK.

_________________
kiss_sdl - Simple generic GUI widget toolkit for SDL2 https://github.com/actsl/kiss_sdl
View user's profileSend private message
actsl


Joined: 09 Feb 2016
Posts: 83
Reply with quote
With widget toolkits there is always that question, did i used the right one, or did i had to use another one. With kiss_sdl there might not be such question, as kiss_sdl is a generic, rudimentary way of creating graphical user interfaces in SDL. So it is almost like making it only in SDL, or if you made it only in SDL, and in a simple enough way, then it likely may not much differ. This is just to say again why kiss_sdl is not yet another widget toolkit. Or it is, but only what concerns the basic way of doing things, which is the same in almost all widget toolkits, but is mostly hidden.

_________________
kiss_sdl - Simple generic GUI widget toolkit for SDL2 https://github.com/actsl/kiss_sdl
View user's profileSend private message
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Reply with quote
One thing that is a problem (but more to do with SDL2 events), is that holding down the mouse button for up/down/left/right slider buttons will only generate one event, so you have to keep tapping the buttons...
View user's profileSend private message
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Reply with quote
What is needed (later) is to record button status in the polling event and then KISS uses that.
View user's profileSend private message
actsl


Joined: 09 Feb 2016
Posts: 83
Reply with quote
MrTAToad wrote:
One thing that is a problem (but more to do with SDL2 events), is that holding down the mouse button for up/down/left/right slider buttons will only generate one event, so you have to keep tapping the buttons...

The event function of a scrollbar, progress bar and combo box has to be in the event loop and also in the main loop after the event loop with the event argument NULL. This generates pseudo "time events". Because mouse clicking is not repeated by the operating system like a key press, so some "time events" are necessary for repeated clicking.

When doing it so, adding the scrollbar event function in two places, isn't the clicking on the arrows repeated then? I have never seen that happening, so when you did not forget to add the scrollbar event function second time with the event argument NULL, and the clicking is still not repeated, then you should write a bug report, writing the platform where you use it, and everything else that makes it possible to reproduce the bug.

It is the function kiss_getticks() in kiss_draw.c which provides the number of milliseconds since the initialization, that is used to generate the repeated "click events". This function by default just calls the function SDL_GetTicks(). So when it really doesn't work, then likely SDL_GetTicks() doesn't work for some reason.

Why is it done in that way? First it is simple, and difficult to fail, as it only relies on getting the milliseconds, by default with SDL_GetTicks(). But second, calling an event function with the event argument NULL, is the general way of doing things. Like, one can generate some continuous animation of ones widgets, and activate it by calling the event function of that widget also with the event argument NULL. Thus generating effects which one cannot even easily dream about when using widget toolkits like GTK or Qt.

_________________
kiss_sdl - Simple generic GUI widget toolkit for SDL2 https://github.com/actsl/kiss_sdl
View user's profileSend private message
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Reply with quote
Yes, I didn't have the routine in the two places.

The text part was somewhat similar - I suspect it was effectively polling twice.
View user's profileSend private message
MrTAToad


Joined: 13 Feb 2014
Posts: 205
Location: Chichester, England
Reply with quote
I've modified the system a fair bit now (https://drive.google.com/file/d/0Bzff3iRdz9Jqd0F3RmJ0Vy1DSUE/view?usp=sharing) to get rid of the global variables and to add various extra things I will be needing for my game (which I should now be able to continue with).

The only slight problem at the moment is text selected from a dropdown option can overwrite the text entry box (and not clip) - that can be sorted later.
View user's profileSend private message
actsl


Joined: 09 Feb 2016
Posts: 83
Reply with quote
It is ok to modify, it is made for that.

There is by itself nothing wrong in global variables, it is important how they are used. Getting rid of global variables is the easiest way to avoid all the problems they may cause, but it is just a no-brainer to solve the problems. In kiss_sdl, global variables are supposed to be used as constants only, and changed only during the initiation. When one really does not like them, then it is ok to get rid of them, but i didn't do it because i didn't want to make the code more complex. One more argument to the functions, or one more member to the structures, all matters. Or if you have some other reason why you want to get rid of them, have several sets of settings or whatever, that's perfectly ok.

_________________
kiss_sdl - Simple generic GUI widget toolkit for SDL2 https://github.com/actsl/kiss_sdl
View user's profileSend private message
kiss_sdl - Simple universal GUI widget toolkit for SDL
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 4 of 6  

  
  
 Reply to topic