How to handle touch events for cocos? - cocos2d-iphone

Is it possible to handle touch enter or touch leave in cocos creator 1.9?
I don't find any.
i tried to do it with touch move but it doesn't worked.

You need to register callback for touch event.
Read manual here first.
In the sample code:
onLoad: function () {
this.node.on('mousedown', function ( event ) {
console.log('Hello!');
});}
Use cc.Node.EventType.TOUCH_START for touch enter (TOUCH_MOVE / TOUCH_END / TOUCH_CANCEL for other purpose) instead of 'mousedown';

Related

Call button click function from grandchild

I'm creating my first C++ wxWidgets application. I'm trying to create some kind of split button where the options are displayed in a grid. I have a custom button class which, when right-clicked on, opens a custom wxPopupTransientWindow that contains other buttons.
When I click on the buttons in the popup, I want to simulate a left click on the main button. I'm trying to achieve this through events, but I'm kinda confused.
void expandButton::mouseReleased(wxMouseEvent& evt)
{
if (pressed) {
pressed = false;
paintNow();
wxWindow* mBtn = this->GetGrandParent();
mBtn->SetLabel(this->GetLabel());
mBtn->Refresh();
wxCommandEvent event(wxEVT_BUTTON);
event.SetId(GetId());
event.SetEventObject(mBtn);
mBtn-> //make it process the event somehow?
wxPopupTransientWindow* popup = wxDynamicCast(this->GetParent(), wxPopupTransientWindow);
popup->Dismiss();
}
}
What is the best way to do this?
You should do mBtn->ProcessWindowEvent() which is a shorter synonym for mBtn->GetEventHandler()->ProcessEvent() already mentioned in the comments.
Note that, generally speaking, you're not supposed to create wxEVT_BUTTON events from your own code. In this particular case and with current (and all past) version(s) of wxWidgets it will work, but a cleaner, and guaranteed to also work with the future versions, solution would be define your own custom event and generate it instead.

call wxHyperlinkEvent without clicking on link

I am using wxHyperLink. OnHyperlinkClicked(wxHyperlinkEvent&) is called when user clicks on the link. OnHyperlinkClicked() helps to switch between 2 screens. I want to call this function explicitly - without user interaction.
I am using the following code for that:
BEGIN_EVENT_TABLE(UserRegistrationFrame, wxFrame)
EVT_HYPERLINK(wxID_ANY, UserRegistrationFrame::OnAuthCodeOptionLinkClicked)
END_EVENT_TABLE()
void MyClass::MyFunction()
{
wxHyperlinkEvent event;
OnAuthCodeOptionLinkClicked(event);
}
void MyClass::OnAuthCodeOptionLinkClicked(wxHyperlinkEvent& event)
{
// code to switch
}
Is this the correct way to achieve my goal? Or do I have to use something different?
The code is not correct, because with EVENT_TABLE you are setting a handler that doesn't exist.
When the user clicks on the control the event is fired, and the static table will call UserRegistrationFrame::OnAuthCodeOptionLinkClicked, not MyClass::OnAuthCodeOptionLinkClicked
I'd better forget EVENT_TABLES and go with Dynamic Event Handling. Using Bind() gives you more features.
Now, you want to call the event-handler function directly, not coming from a user action. Then you need to create an event just to pass it to the handler. That's what you do in MyClass::MyFunction(), right?
Don't mix jobs. If both your direct-call and the event-handler use a common feature, put it in a different function and call it directly or from the event-handler.
But the question is Why do you use a wxHyperlinkCtrl for a task like screen switching? Do you want also the default browser to be launched?

Wt C++ make window unclickable after button click

Edit: solution below
Using Wt (version 3) C++ framework:
When clicking on a WPushButton which calls a function:
button->clicked(boost::bind(&Service::burn, this));
How can one freeze the screen(or all the buttons) in such a way, that nothing can be clicked while the function runs (runs quite a long time). Currently, when the function Service::burn() runs, I can click other buttons which get queued up and executed after the function Service::burn() has finished.
Note that all buttons/screen needs to be restored after freeze. Also there's a function:
Solution:
Wt::WPushButton* spec_button;
void testclass::test_only()
{
spec_button = new Wt::WPushButton("slow func");
auto some_long_func = [&](){
cout << "#######start \n";
std::this_thread::sleep_for(std::chrono::seconds(1));
cout << "#######end \n";
spec_button->setDisabled(false);
};
content()->addWidget(spec_button);
spec_button->clicked().connect(spec_button, &WPushButton::disable);
spec_button->clicked().connect(boost::bind<void>(some_long_func));
}
This should work:
button->clicked(button, &WPushButton::disable);
button->clicked(boost::bind(&Service::burn, this));
So, you disable the UI using the first handler and then launch your heavy long process using the second one.
If you put those two handlers into a single call, it won't work, because the UI changes won't be propagated to a browser until that call is finished.
Wt doesn't send widget tree modifications to the browser until the event handling is completed, which means that the effect pf button disable will not become visible until after some_long_func completes.
One way around this is to call wApp->processEvents() after disabling the button and before calling some_long_func. This will cause an intermediate update of the widget tree to be sent to the browser immediately. The button clicked() handler can thus look like this (as one function to ensure the order of execution of the signal handers):
{
spec_button->disable();
wApp->processEvents();
some_long_func();
}
The Wt application have a main container with my own class like :
WtMain::WtMain ( void )
:Wt::WContainerWidget ( ) {
setId ( "wkmain-apps" ) ;
}
this class is create on a pointer C_Main.
When i will freeze the all application run this :
C_Main->doJavaScript ( "$('#wkmain-apps').css({'opacity': 0.5,'z-index': 5,'pointer-events': 'none' });" ) ;
and when your function finish is work do :
C_Main->doJavaScript ( "$('#wkmain-apps').css({'opacity': 1,'z-index': 'auto','pointer-events': 'all' });" ) ;
to un-freeze the screen.

QSystemTrayIcon activated signal: DoubleClick without Trigger

I want to show context menu on left click and run app on double click.
For this i have next code:
...
connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotActivated(QSystemTrayIcon::ActivationReason)));
...
void MyTray::slotActivated(ActivationReason reason)
{
if(reason==QSystemTrayIcon::DoubleClick)
startApp();
else
if(reason==QSystemTrayIcon::Trigger
|| reason==QSystemTrayIcon::MiddleClick)
contextMenu()->popup(QCursor::pos());
}
It works, but for double click case i got two slot calls - one for Trigger and only then for DoubleClick. As result context menu shown and hidding in a moment.
Is there is a way to avoid this?
Rather than using slotActivated, you need to handle the mouse events.
Whilst these aren't directly available in QSystemTrayIcon, it does allow you to install an event filter and handle the mouse events from there.

CDockingManager GetPaneList() causes assertion failure in wincore.cpp?

So I thought this would be pretty simple, but I forgot it's MFC. Instead of registering a notification listener for data model changes that would possibly require a GUI update on each individual control I figure why not register it once and then send a message to all the open dock panes and allow them to update their controls as needed on their own terms for efficiency.
My callback function for handling the notification from the server looks something like this:
void CMainFrame::ChangeCallback(uint32_t nNewVersion, const std::vector<uint32_t>& anChangedObjectTypes)
{
CObList panes;
GetDockingManager()->GetPaneList(panes); // assert failure
if (!panes.IsEmpty())
{
POSITION pos = panes.GetHeadPosition();
while (pos)
{
CDockablePane* pPane = dynamic_cast<CDockablePane*>(panes.GetNext(pos));
if (pPane)
pPane->PostMessage(DM_REFRESH, nNewVersion);
}
}
}
The error I am getting is an assertion failure on line 926 of wincore.cpp
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL); // right here
There is a comment below this saying this can happen if you pass controls across threads however this is a single threaded MFC application and this is all being done from the main frame.
Does anyone know what else can cause this?
If there is another way to go about sending a message to all the open CDockablePane derived windows in MFC that works as well ...
Here's the obvious workaround that I didn't want to have to do but after hours of debugging and no response here I guess this is a viable answer:
I added std::vector<CDockPane*> m_dockList; to the members of CMainFrame
Now after each call to AddPane in various places that can create and open new dock panes I make a subsequent call to push_back and then I override CDockablePane::OnClose like so:
CMainFrame* pMainFrame = reinterpret_cast<CMainFrame*>(AfxGetMainWnd());
if (pMainFrame)
{
std::vector<CDockPane*>::const_iterator found(
std::find(pMainFrame->DockList()->begin(), pMainFrame->DockList()->end(), this));
if (found != pMainFrame->DockList()->end())
pMainFrame->DockList()->erase(found);
}
CDockablePane::OnClose();
Now this list will only contain pointers to open dock panes which allows me to handle the event notification in my callback and simply do a for loop and PostMessage to each.