AntTweakBar doesn't register SFML mouse events - c++

I'm trying to add GUI for easier level editing in our game engine. We're using SFML for all the basic stuff (window management, input events etc). I've chosen AntTweakBar because it is a well known library with a few examples around. I was following the tutorial at AntTweakBar's website
I was able to draw a simple bar with those example codes. However, mouse events received by SFML are not registered by AntTweakBar's TwEventSDL()function. Here is an example code for Input:
sf::Event event;
while (_pWindow->pollEvent(event))
{
// Check if the event should be handled by AntTweakBar
int handled = TwEventSFML(&event, 2, 3); // for SFML version 2.3
if (!handled){
switch (event.type)
{
case sf::Event::MouseButtonPressed: // To check whether SFML received mouse button events properly
if (event.mouseButton.button == sf::Mouse::Button::Left){
std::cout << "Left button pressed" << std::endl;
std::cout << "x: " << event.mouseButton.x << std::endl;
std::cout << "y: " << event.mouseButton.y << std::endl;
}
}
}
else{ //To check whether TwEventSFML received events
std::cout << "FINALLY!" << std::endl;
}
When I press buttons, I can see "FINALLY!" showing up. I can also see that my mouse clicks are received by SFML. However, when I click on an AntTweakBar element (be it a button or help section) it doesn't register it. (Also, I can't see "FINALLY!" when I use the mouse).
Any help or ideas will be appreciated.

Anttweakbar hasnt been updated in 3 years, last SFML integration was for SFML 1.6
What version of SFML are you using ?
If not 1.6 then you have to create your own input handler for it.

Related

How to get mouse input and keyboard input into a C++ application in ubuntu environment?

class MouseEventHandler {
void leftClick() {
cout << "leftClickDetected" <<endl;
}
void rightClick() {
cout << "rightClickDetected" <<endl;
}
pair<int, int> getCursorPosition() {
}
};
Hi all,
I am trying to write a mouse event handler library that would respond to leftclicks and rightclicks, get current curson positions etc, when the the application is launched. I am not sure how to write the callee for the event handler class. What C API can I use to get my functions in the EventHandler class called in response to mouse events? Please advise on how to go about this.
Thanks

Identify stylus barrel button (win32)

I am creating an application that uses the tablet API for windows and so far I was able to capture the input of the stylus succesfully. I am able to handle the movement, stylus down and up events and pressure. What I am still missing is the ability to identify the barrel button pressed. While I am capturing the StylusButtonDown event, this is fired also when the stylus is down on the tablet.
For reference here is my (ideal) implementation:
STDMETHOD(StylusButtonDown)(IRealTimeStylus* rts, STYLUS_ID id, const GUID* guid, POINT* pt)
{
if (BARREL_BUTTON_ID == *guid) {
s_buttonDown = true;
// DEBUG
std::cout << "[StylusButtonDown]" << std::endl;
// DEBUG
}
return S_OK;
}
The problem I have is to fill in the BARREL_BUTTON_ID constant. Any expert with an idea?
Thanks a lot!

Get the GTK Window from which a Clipboard signal_owner_change originated (Gtkmm)

My application needs to listen to clipboard changes to record them. I can currently achieve that with a signal_owner_change callback which then requests the contents of the clipboard. However, I need to figure out which window the event originated from, so that I can ignore when a user copies text from the application itself (using Ctrl+C, not programmatically).
The signal_owner_change callback takes a GdkEventOwnerChange* as a parameter, which contains the fields owner and window of type GdkWindow*.
The field owner changes for each different application / window I copy from, but never corresponds to the window pointer of my application.
The field window is always the same, but also does not match my application window.
Unfortunately, the GTK+ documentation is very unclear about what the "owner" and the "window" of a GdkEventOwnerChange is, or how to exploit the data.
My application window is a class inheriting from Gtk::ApplicationWindow. I get the GdkWindow* as such:
GdkWindow* win = gtk_widget_get_window(GTK_WIDGET(gobj()));
Here is an extract of the clipboard owner change even handler: (in another class, which gets the window pointer above as parentWindow)
MyNamespace::MyClass::MyClass(GdkWindow* parentWindow)
: parentWindow(parentWindow) {
// setup UI, etc...
clipboard = Gtk::Clipboard::get();
clipboard->signal_owner_change().connect(
sigc::mem_fun(*this, &MyClass::on_clipboard_owner_change));
}
void MyNamespace::MyClass::on_clipboard_owner_change(GdkEventOwnerChange* event) {
std::cout << "Owner: " << event->owner
<< ", window: " << event->window
<< ", parent: " << parentWindow
<< std::endl;
// This does not work
if (event->owner == parentWindow)
return;
switch (get_clipboard_content_type()) {
case ClipboardDataType::Text: {
clipboard->request_text(
sigc::mem_fun(*this, &MyClass::on_clipboard_text_received));
break;
}
case ClipboardDataType::Image: {
std::cout << "Image is available, unimplemented handler" << std::endl;
break;
}
case ClipboardDataType::URIs: {
std::cout << "URIs is available, unimplemented handler" << std::endl;
break;
}
default: {
std::cout << "Unknown or unsupported clipboard data type" << std::endl;
}
}
}
Here is the console output:
# Copy from another application
Owner: 0x5571ec44dc80, window: 0x5571ec08f330, parent: 0x5571ec08f4c0
# Copy from the application itself
Owner: 0x5571ec44de10, window: 0x5571ec08f330, parent: 0x5571ec08f4c0
I have tried comparing with the Gtk::Application toplevel window, or with the window of the Gtk::Label (label->get_window()->gobj()) that gets copied but none of the pointers match.

Creating a standalone gtkmm dialog

In a particular situation I need my command line based C++ application to launch a quick dialog using gtkmm 2.4. I could really use some direction here.
I tried launching the dialog as a standalone without initializing the top level window:
Gtk::Main kit( NULL,NULL );
Gtk::Window toplevel;
MyApp::myDialog d(toplevel);
int result = d.run();
This created my dialog but it doesn't close when the ok or cancel button is hit and none of quit/delete/hide api calls I could find could get rid of it. It only goes away when the program exits (even if it is created in a method which exits earlier). I'm guessing this is in part because it needs an active main window to handle some of its lifetime/visibility management. If I could make it respond normally to the ok/cancel buttons I would be all set!
Next I tried creating and launching the main window properly and launching the dialog from within the constructor of the main window. (It takes the Gtk::Main as an argument so I could try killing that directly.)
class cprompt : public Gtk::Window
{
public:
cprompt(Gtk::Main* prompt){
MyApp::myDialog* d = new MyApp::myDialog (*this);
std::cout << "ABOUT TO RUN DIALOG" << std::endl;
int result = d->run();
std::cout << "RAN DIALOG" << std::endl;
d->hide();
delete d;
std::cout << "CALLING QUIT" << std::endl;
this->hide();
Gtk::Main::quit();
prompt->quit();
//None of the above calls do anything. The empty 'top level' window hangs around and blocks until manually closed.
std::cout << "CALLED QUIT" << std::endl;
};
virtual ~cprompt(){};
};
Now the dialog works as expected, but the main window pops up after the dialog is closed (an empty gray square with an exit button) and I can't find a way to hide or exit it outside of clicking the exit button. All the calls I make to close it or quit the gtk loop automatically are inside the constructor so I'm guessing they aren't valid at that point. If I could make the whole operation shut down after the dialog returns in the window constructor, again I would be all set.
My next approach is going to be to use the top level window itself as the dialog, but I was hoping to avoid this because the dialog I need is already provided by another library and I'll have to re-implement the ui from scratch if I can't launch the dialog straight up.
Had the same problem with Gtk. To fix it, I neeeded to manually close the window and then do the gtk loop iterations. My code looks like this (for a filechooser_dialog) :
gint result = gtk_dialog_run(GTK_DIALOG(m_fileDialog));
if(result == GTK_RESPONSE_ACCEPT)
{
char* filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_fileDialog));
m_selectedFileName = std::string(filename);
g_free(filename);
}
gtk_window_close(GTK_WINDOW(m_fileDialog)); //Close the dialog manually
while (gtk_events_pending()) //until there are no more events :
gtk_main_iteration_do(false); //process the main iteration

Qt Embedded Touchscreen QMouseEvents Not Received Until MouseButtonRelease Received

I am using Qt 4.8.3 on a small ARM embedded Linux device with a touchscreen. I have my touchscreen configured with tslib and calibrated it so there is a pointercal file in /etc/. The locations of my touch events work just fine but no matter what I get a QEvent for Mouse Move before Mouse Press or Mouse Release Events. Furthermore, I don't get any Mouse Related Events until I physically lift my finger from the touchscreen. I need normal behavior where I press on the touchscreen and receive a mouse down event immediately and then my move events ( if there are any ) and then a mouse release event when I lift my finger.
So what I'm seeing from the point of view of events received when I pressed down and then release looks like:
50 SockAct <-- Received right at press down
<-- NO Other events received until press released
<-- Now release by lifting finger from screen
50 SockAct <-- Immediately received a 50 ( SockAct ) and the rest of the events below:
2 <-- 2 == mouse down
2 <-- 2 == mouse down
3 <-- 3 == mouse release / up
3 <-- 3 == mouse release / up
77 <-- 77 == redraw
I also attempted to look at the QWS Server events by implementing the following qwsEventFilter to watch QWS events that come in to my QApplication:
/// For investigation mouse events
#include <QWSServer>
#include <QWSMouseHandler>
#include <QWSEvent>
bool GUIApp::qwsEventFilter(QWSEvent *e)
{
qDebug() << e->type;
if(e->type == QWSEvent::Mouse) {
QWSMouseHandler *curMouse = QWSServer::mouseHandler();
qDebug() << "mouse position is: " << curMouse->pos();
}
return false;
/*
QWSEvent::NoEvent 0 No event has occurred.
QWSEvent::Connected 1 An application has connected to the server.
QWSEvent::Mouse 2 A mouse button is pressed or released, or the mouse cursor is moved. See also Qt for Embedded Linux Pointer Handling.
*/
}
Now, when I launch my App I am seeing the same behavior after touching the screen -- that is the following is printed:
2 <-- Nothing is printed until I release my finger from the screen!
mouse position is: QPoint(89,312)
2
mouse position is: QPoint(89,312)
As you can see as soon as I release my finger I get 2 events, presumably press down and release.
I've run 'evtest' on my /dev/input/touchscreen device in Linux and certainly see a touch down event immediately when pressing down on the screen. And I do not get a mouse release event until I lift my finger, so the driver behaves as expected. There are also no 'repeat' touch down events when I press - it is just one event for one press down , but behaves correctly.
I'm not sure why I'm seeing the behavior I do. There must be a translation issue between Qt and the input device.
Furthermore, If I add a small 3ms delay in processing my MouseButtonRelease received event, then I get desired behavior in terms of how the app works but I still do not receive my Mouse events until I release the press. I should not have to add a delay at all, I would expect my mouse down to happen, then any moves, and finally a mouse up event in turn
Does anybody know how to fix this or what may be causing this?? Thank you very much!
--
I don't see the following printed out until I actually lift my finger:
...
MOVE TYPE: 5
"Mouse move (382,129)"
MOUSE BUTTON PRESS TYPE: 2
"Mouse Button Press (1)"
MOUSE BUTTON RELEASE TYPE: 3
"Mouse Button Release (1)"
....
Here is my eventFilter where I examine my received events in my App:
////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Just for kicks print out the mouse position
if (event->type() == QEvent::MouseButtonPress)
{
qDebug() << "MOUSE BUTTON PRESS TYPE: " << event->type();
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
qDebug() << QString("Mouse Button Press (%1)").arg(mouseEvent->button());
}
if (event->type() == QEvent::MouseMove)
{
qDebug() << "MOVE TYPE: " << event->type();
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
qDebug() << QString("Mouse move (%1,%2)").arg(mouseEvent->globalX()).arg(mouseEvent->globalY());
}
if (event->type() == QEvent::MouseButtonRelease)
{
qDebug() << "MOUSE BUTTON RELEASE TYPE: " << event->type();
QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
delay();
qDebug() << QString("Mouse Button Release (%1)").arg(mouseEvent->button());
//return true; // Gobble the event
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
Here is my delay function:
void Monitor::delay()
{
QTime dieTime = QTime::currentTime().addMSecs(3);
while( QTime::currentTime() < dieTime )
QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}
Solved- I found this thread: https://github.com/kergoth/tslib/issues/10 which outlines the same problem. It seems to be an issue in Tslib with the Atmel MXT Maxtouch driver. Commenting out the Variance module in the ts.conf file solved my problem - I now get mouse down events immediately after touching the screen.