Page 1 of 2

[Solved] CEGUI Spinner check for focus

Posted: Thu Mar 31, 2016 18:41
by Gykonik
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:

Re: CEGUI Spinner check for focus

Posted: Thu Mar 31, 2016 19:47
by YaronCT
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.

Re: CEGUI Spinner check for focus

Posted: Thu Mar 31, 2016 23:17
by Gykonik
Add the following method to class CEGUI::Spinner (or to a class u inherit from it)


What class do you mean? :(

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 00:12
by lucebac
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.

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 01:09
by Gykonik
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:

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 06:28
by YaronCT
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.

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 10:26
by Gykonik
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 :(

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 12:36
by YaronCT
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.

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 12:51
by Gykonik
But I don't have a Spinner.cpp file... (Maybe it's in the library?)

I only have a Spinner.h file

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 12:53
by YaronCT
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.

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 14:29
by Gykonik
srsly? :(

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 14:39
by YaronCT
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.

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 15:22
by Gykonik
It takes time... :D

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 15:25
by YaronCT
On my linux machine rebuilding cegui takes less than a minute. If your'e on Windows, s***w u :lol:

Re: CEGUI Spinner check for focus

Posted: Fri Apr 01, 2016 16:32
by Gykonik
I'm on windows....

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