[Solved] CEGUI Spinner check for focus

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Gykonik
Just popping in
Just popping in
Posts: 15
Joined: Thu Mar 31, 2016 18:33

[Solved] CEGUI Spinner check for focus

Postby Gykonik » Thu Mar 31, 2016 18:41

I'm trying to find out, how I can check a CEGUI::Spinner, if the field is in focus. I mean, if you clicked on the field, so you can enter numbers, etc...

Is there a way, how I can check, if a Spinner is in focus?
E.g. the EventMouseClicked event is not enough, because I don't want the Event powered one time, if we click on it. I want it to power the whole time, the spinner is in focus...

Thank you in advance :wink:

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: CEGUI Spinner check for focus

Postby YaronCT » Thu Mar 31, 2016 19:47

Add the following method to class CEGUI::Spinner (or to a class u inherit from it)

Code: Select all

bool Spinner::isEditboxActive() const
{
    return getEditbox()->isActive();
}


I'll submit this to cegui later on.

Gykonik
Just popping in
Just popping in
Posts: 15
Joined: Thu Mar 31, 2016 18:33

Re: CEGUI Spinner check for focus

Postby Gykonik » Thu Mar 31, 2016 23:17

Add the following method to class CEGUI::Spinner (or to a class u inherit from it)


What class do you mean? :(

lucebac
Just can't stay away
Just can't stay away
Posts: 193
Joined: Sat May 24, 2014 21:55

Re: CEGUI Spinner check for focus

Postby lucebac » Fri Apr 01, 2016 00:12

Yaron is right, you need to get the isActive() status from the spinners editbox. You can query the editbox by calling getEditbox() on the spinner and then call isActive() on it. This function return true as long as it has focus (= the caret is active in the editbox).

IIRC this function can go straight into v0-8 since you just add a function to the API and don't change or remove any API function that existed before.

Gykonik
Just popping in
Just popping in
Posts: 15
Joined: Thu Mar 31, 2016 18:33

Re: CEGUI Spinner check for focus

Postby Gykonik » Fri Apr 01, 2016 01:09

I don't get it...

Let me say, I have a Spinner called "widthSpinner"

I generate it like this:

Code: Select all

m_widthSpinner = static_cast<CEGUI::Spinner*>(m_gui.createWidget("TaharezLook/Spinner", glm::vec4(X_POS + PADDING, Y_POS, 0.0f, 0.0f), glm::vec4(0.0f, 0.0f, DIMS_PIXELS * X_FACTOR, DIMS_PIXELS * Y_FACTOR), "WidthSpinner"));
m_widthSpinner->setMinimumValue(0.2);
m_widthSpinner->setMaximumValue(10000.0);
m_widthSpinner->setCurrentValue(m_boxDims.x);
m_widthSpinner->setStepSize(0.1);
m_widthSpinner->setTextInputMode(CEGUI::Spinner::FloatingPoint);
m_widthSpinner->subscribeEvent(CEGUI::Spinner::EventValueChanged, CEGUI::Event::Subscriber(&EditorScreen::onWidthValueChange, this))


And in the Header I set m_widthSpinner.

Right.


Now I want to check, if the Spinner is active, so I think i have to do it this way:

Code: Select all

m_widthSpinner->getEditbox().isActive()


And in the fact, that I want to check this like a bool i put it into a if-statement:

Code: Select all

if (m_widthSpinner->getEditbox().isActive()) {
   //Active
}


But then I get an error and it says, that I don't have access to the function, declared in line 319 in Spinner.h...
What is wrong with that and how can I fix this?


Thanks in advance :wink:

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: CEGUI Spinner check for focus

Postby YaronCT » Fri Apr 01, 2016 06:28

Gykonik:

Indeed, u can't access the method "Spinner::getEditbox" coz it's "protected". Read here. Therefore you'll have to add a method to class CEGUI::Spinner (thus changing cegui's code), or create a class that inherits (say MySpinner) from it and add this method to that class. Then, use the class MySpinner rather than Spinner.

Gykonik
Just popping in
Just popping in
Posts: 15
Joined: Thu Mar 31, 2016 18:33

Re: CEGUI Spinner check for focus

Postby Gykonik » Fri Apr 01, 2016 10:26

Ahh, now I got it....


Now I added to the Spinner-class in Spinner.h this:

Code: Select all

bool isEditboxActive() const;


And down, outside of the class, I did this:

Code: Select all

bool Spinner::isEditboxActive() const {
   return getEditbox()->isActive();
}


Now it says me, that getEditbox isn't definded...
But it is, as a protected class :(

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: CEGUI Spinner check for focus

Postby YaronCT » Fri Apr 01, 2016 12:36

Gykonik: That's coz the class Editbox is defined in another header file. To use it, you'll have to add:

Code: Select all

#include "./Editbox.h"


to the top of the file "Spinner.h". But don't do that! Coz u have a deeper problem. In general, methods should be declared in the header file (i.e. a ".h" file) (inside the class definition, of course), but be defined in a source file (i.e., a ".cpp" file). Otherwise, if the header file is included by several source files, from the compiler's perspective the method would be defined multiple times, which is an error.

So that means u should leave the declaration:

Code: Select all

bool isEditboxActive() const;


inside the definition of the class Spinner (in the file "Spinner.h"), but move the definition (i.e. the method's body):

Code: Select all

bool Spinner::isEditboxActive() const {
   return getEditbox()->isActive();
}


to the source file (i.e. "Spinner.cpp"). Then everything should work fine. You don't have to add:

Code: Select all

#include "./Editbox.h"


to the file "Spinner.cpp" coz it already includes that file.

Gykonik
Just popping in
Just popping in
Posts: 15
Joined: Thu Mar 31, 2016 18:33

Re: CEGUI Spinner check for focus

Postby Gykonik » Fri Apr 01, 2016 12:51

But I don't have a Spinner.cpp file... (Maybe it's in the library?)

I only have a Spinner.h file

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: CEGUI Spinner check for focus

Postby YaronCT » Fri Apr 01, 2016 12:53

Yes, it's in the library.. you must make the changes in "Spinner.h" and "Spinner.cpp" in the cegui source, then build cegui again and then install cegui again.

Gykonik
Just popping in
Just popping in
Posts: 15
Joined: Thu Mar 31, 2016 18:33

Re: CEGUI Spinner check for focus

Postby Gykonik » Fri Apr 01, 2016 14:29

srsly? :(

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: CEGUI Spinner check for focus

Postby YaronCT » Fri Apr 01, 2016 14:39

Gykonik: my assumption was that as u use cegui, you've already managed to build it, haven't u? And if so, what's the problem building it again?

Cheer up, buddy, I'm already all in tears from all your sad faces.

Gykonik
Just popping in
Just popping in
Posts: 15
Joined: Thu Mar 31, 2016 18:33

Re: CEGUI Spinner check for focus

Postby Gykonik » Fri Apr 01, 2016 15:22

It takes time... :D

YaronCT
CEGUI Team
Posts: 448
Joined: Fri Jun 19, 2015 12:18
Location: Kiryat-Bialik, Israel

Re: CEGUI Spinner check for focus

Postby YaronCT » Fri Apr 01, 2016 15:25

On my linux machine rebuilding cegui takes less than a minute. If your'e on Windows, s***w u :lol:

Gykonik
Just popping in
Just popping in
Posts: 15
Joined: Thu Mar 31, 2016 18:33

Re: CEGUI Spinner check for focus

Postby Gykonik » Fri Apr 01, 2016 16:32

I'm on windows....

You can rebuild it for me, if you want to xDD


Return to “Help”

Who is online

Users browsing this forum: No registered users and 25 guests