I'm using XInput for a project and I'm having a problem using the xbox controller. When I use the B button to return to a previous state, its registering the button press so fast that it continues to push back multiple states that use the B button to exit.
if( ( player1.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) || ( player2.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) ) {
return ESC_BUTTON;
}
I've tried resetting the buffer by adding an & 1 but than the input never registers. Is there an easy way to fix this problem?
UPDATE:
current = (DWORD)( ( start - GetTickCount() ) / 1000.f );
if( current > 0.005f )
{
if( ( player1.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) || ( player2.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) )
{
start = GetTickCount();
return ESC_BUTTON;
}
}
Still having issues with resetting. Sometimes it works, sometimes it doesn't...thoughts?
Related
I've started learning Maxscripts and i've now hit a wall,
im trying to get the name of my selection, if it's a single object and
then if its more than 1, have the label display the number of objects as a string.
but i keep getting an error... any idea?
group "Current Selection:"
(
label lbl_01 "Nothing Selected"
)
---------------------------------------------------------------------------------------------------------------// Current Selection Function
fn letmeknow obj=
(
local contador = (selection.count as string)
if selection.count != 0 then
(
lbl_01.text = ("Name: " + obj.name)
)
else
(
lbl_01.text = "Nothing Selected"
)
if selection.count >= 2 do (lbl_01.text = ("Objects: " + contador))
)
Looks like the issue is outside the code you've supplied and without seeing the rest of the code, it's hard to tell. Anyway, here's a working example using case expression instead of multiple ifs:
rollout test "Test"
(
group "Current Selection:"
(
label lbl_01 "Nothing Selected"
)
button btnTest "Test"
fn getSelectionString =
(
case selection.count of
(
0 : "Nothing Selected"
1 : "Name: " + selection[1].name
default : "Objects: " + selection.count as string
)
)
on btnTest pressed do
lbl_01.text = getSelectionString()
)
createDialog test
I am working on a Project that requires me to place a BUYSTOP and a SELLSTOP pair of orders and then on the next bar if those orders are not triggered, then delete them and place fresh ones.
Here is my code:
if(logic == true && OrdersTotal() == 0)
{bool res = OrderSend(....);}
if(OrdersTotal() != 0)
{
if(ordertype == OP_BUY || ordertype == OP_SELL)
{
bool del = OrderDelete(....);
}
}
This code is properly placing orders and deleting them as well when I am testing.
But when the EA is active on the live server, it does not open orders because the platform already has orders of other instruments open.
I'm sure there would be quite an easy way to get around this but since I am a novice, I'm not able to figure that out.
it is not clear whether you use magic number and symbol check.
you should check sth like
int _ordersTotal = OrdersTotal()-1;
for (int i = _ordersTotal; i >= 0; i--){
if (OrderSymbol() != Symbol() || OrderMagicNumber() != magic) continue;
....
}
in different realization, i.e. you can create a function(String Symbol) that checks if you have some working orders placed of the indicated Symbol.
Old proverb says:Measure twice before cut onceThere are actually four values ( three for pendings ) to check before OrderDelete()
As your definition states to handle { OP_{BUY|SELL}STOP } orders, there are following three items to check:
Symbol() match ( not causing unwanted side-effects by deleting other EA's or manual orders )
OrderType() match ( not ignoring the actual state { PENDING | AT_MARKET } and direction { BUY | SELL } of the order )
OrderMagicNumber() match ( not ignoring the UUID selector utility available to be set for each individual OrderSend() )
So, let's sketch the detection process:
int myEaContextAwareMagicNUMBER = ...;
for ( int ii = OrdersTotal();
ii >= 0;
ii--
)
if OrderSelect( ii, SELECT_BY_POS, MODE_TRADES )
{
if ( OrderSymbol() != _Symbol
&& OrderMagicNumber() != myEaContextAwareMagicNUMBER
&& OrderOpenTime() >= Time[1] // Prev. Bar
&& !( OrderType() == OP_BUYSTOP
|| OrderType() == OP_SELLSTOP
)
) continue; // __^ __^ __^ __^ __^ __^ loop for next test
// -------------------------------------------+
// FINALLY PROCESS THE MATCHING OrderDelete() |
// -------------------------------------------+
...
..
.
// -------------------------------------------+
}
else Print( "WARN: OrderSelect() failed at db.POOL.SELECT(), RECORD_NUMBER == ", ii );
So how to delete un-triggered pendings is done.
Next comes the remark about
"... when the ea is active on the live server, it does not open orders because the platform already has orders of other instruments open."
There could hardly be any advice provided without delivering the exact { GetLastError() | _LastError } values.
Some Brokers for some account types do indeed restrict OrderSend() acceptance policies, and thus besides the GetLastError() value the respective Broker Terms and Conditions apply.
Do not hesitate to ask more & may enjoy other Questions/Answers in MQL4 domain.
I use QGraphicsView and QGraphicsScene to display a map - a lot of object (lines, images, polygons, etc). I implemented zooming the view this way:
...
void MapView::wheelEvent( QWheelEvent *pEvent )
{
if ( pEvent->modifiers() & Qt::ControlModifier )
{
if ( pEvent->delta() > 0 )
zoomIn();
else
zoomOut();
pEvent->accept();
}
else
{
QGraphicsView::wheelEvent( pEvent );
}
}
...
void MapView::zoomIn( int nValue )
{
m_dZoom = ( nValue == -1 ) ? qMin( ( m_dZoom + m_dZoomStep ), m_dZoomMax ) : qMin( ( m_dZoom + qreal( nValue ) ), m_dZoomMax );
setupTransform();
}
void MapView::zoomOut( int nValue )
{
m_dZoom = ( nValue == -1 ) ? qMax( ( m_dZoom - m_dZoomStep ), m_dZoomMin ) : qMax( ( m_dZoom - qreal( nValue ) ), m_dZoomMin );
setupTransform();
}
...
void MapView::setupTransform()
{
QTransform t = transform();
t.reset();
qreal dScale = qPow( qreal( 2 ), ( m_dZoom - ( m_dZoomMax / 4 ) ) / qreal( 50 ) );
t.scale( dScale, dScale );
setTransform( t );
emit onZoomChanged( m_dZoom );
}
...
When I run application on Linux (CentOS 6.3, Qt 4.8) - zooming the view runs very good (smoothly). But when I run it on Windows (Windows 7 32bit, Qt 5.4) zoomig the view freezes - I constanly rotate the mouse wheel with no effect (no zooming, the view is not responding), and after a second or two later the view starts responding again. When this happens current zoom position turned out to be correctly set - it seems like the view were zooming but not updating the picture. The problem occurs with different zoom values and scroll positions, but always when the view is going to crop map objects (paths).
Do you have any ideas how to fix that problem, or am I doing something wrong?
Thank you very much in advance.
I think it a big limitation that you can't use "newTextField" in corona simulator, I actually need to build the app and install it on my device to see if it's working.
The following code for some reason not working for me, and I don't know how to debug it.
I simply want to save "players name"
local function textListener( event )
if ( event.phase == "began" ) then
-- user begins editing text field
print( event.text )
myGameSettings.playerName = event.text
saveSettings()
elseif ( event.phase == "ended" ) then
-- text field loses focus
myGameSettings.playerName = event.text
saveSettings()
elseif ( event.phase == "ended" or event.phase == "submitted" ) then
myGameSettings.playerName = event.text
saveSettings()
-- do something with defaultField's text
elseif ( event.phase == "editing" ) then
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
end
end
local playerName = native.newTextField( centerX, display.contentCenterY-100, display.contentWidth, 50 )
display.newText("Choose a name", 20, playerName.y-70, native.systemFont)
playerName:addEventListener( "userInput", textListener )
It appears to be supported only in the Enterprise version.
Is your problem that it isn't working in the Simulator? Because they don't work on the Windows PC simulator but they work in the Mac simulator. I develop on Mac and PC and can use them perfectly on Mac but not on PC. I'm also no on the Enterprise edition but am on the free edition.
When I'm working on my PC how I debug is to hook my device up to the computer and print out the debug log as it will print any errors (I obviously can only use Android devices hooked up to my PC).
First of all the native.newTextField does not display on window machine simulator. you need to build it on device for testing. But you can debug it on simulator though.
Use below code for debug on simulator.
Note: the textField area is not visible but when you click on it(Assuming text field position), will show you the textfield with blue rectangle border.
-- Hide the status bar
display.setStatusBar( display.HiddenStatusBar )
-- Set the background to white
display.setDefault( "background", 255, 255, 255 )
-- Require the widget & storyboard libraries
local widget = require( "widget" )
local function textListener( event )
if ( event.phase == "began" ) then
print( event.text )
elseif ( event.phase == "ended" or event.phase == "submitted" ) then
-- do something with defaultField's text
elseif ( event.phase == "editing" ) then
print("in move")
print( event.newCharacters )
print( event.oldText )
print( event.startPosition )
print( event.text )
end
end
local playerName = native.newTextField( 300, 300, 400, 50 )
local a = display.newText("Choose a name", 20, playerName.y-70, native.systemFont)
a.x=100
a.y = playerName.y-70
a:setTextColor(0,0,0)
playerName:addEventListener( "userInput", textListener )
A window should stay on top of all other windows. Is this somehow possible with plain x11/xlib? Googling for "Always on top" and "x11" / "xlib" didn't return anything useful.
I'd avoid toolkits like GTK+, if somehow possible.
I'm using Ubuntu with gnome desktop. In the window menu, there's an option "Always On Top". Is this provided by the X server or the window manager? If the second is the case, is there a general function that can be called for nearly any wm? Or how to do this in an "X11-generic" way?
Edit: I implemented fizzer's answer, now having following code:
XSelectInput(this->display, this->window,
ButtonPressMask |
StructureNotifyMask |
ExposureMask |
KeyPressMask |
PropertyChangeMask |
VisibilityChangeMask );
// ...
// In a loop:
if (XPending(this->display) >= 0)
{
XNextEvent(this->display, &ev);
switch(ev.type) {
// ...
case VisibilityNotify:
XRaiseWindow(this->display, this->window);
XFlush(this->display);
break;
// ...
}
}
But the eventhandling and raising nearly never gets executed even my mask is correct?!
#define _NET_WM_STATE_REMOVE 0 // remove/unset property
#define _NET_WM_STATE_ADD 1 // add/set property
#define _NET_WM_STATE_TOGGLE 2 // toggle property
Bool MakeAlwaysOnTop(Display* display, Window root, Window mywin)
{
Atom wmStateAbove = XInternAtom( display, "_NET_WM_STATE_ABOVE", 1 );
if( wmStateAbove != None ) {
printf( "_NET_WM_STATE_ABOVE has atom of %ld\n", (long)wmStateAbove );
} else {
printf( "ERROR: cannot find atom for _NET_WM_STATE_ABOVE !\n" );
return False;
}
Atom wmNetWmState = XInternAtom( display, "_NET_WM_STATE", 1 );
if( wmNetWmState != None ) {
printf( "_NET_WM_STATE has atom of %ld\n", (long)wmNetWmState );
} else {
printf( "ERROR: cannot find atom for _NET_WM_STATE !\n" );
return False;
}
// set window always on top hint
if( wmStateAbove != None )
{
XClientMessageEvent xclient;
memset( &xclient, 0, sizeof (xclient) );
//
//window = the respective client window
//message_type = _NET_WM_STATE
//format = 32
//data.l[0] = the action, as listed below
//data.l[1] = first property to alter
//data.l[2] = second property to alter
//data.l[3] = source indication (0-unk,1-normal app,2-pager)
//other data.l[] elements = 0
//
xclient.type = ClientMessage;
xclient.window = mywin; // GDK_WINDOW_XID(window);
xclient.message_type = wmNetWmState; //gdk_x11_get_xatom_by_name_for_display( display, "_NET_WM_STATE" );
xclient.format = 32;
xclient.data.l[0] = _NET_WM_STATE_ADD; // add ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE;
xclient.data.l[1] = wmStateAbove; //gdk_x11_atom_to_xatom_for_display (display, state1);
xclient.data.l[2] = 0; //gdk_x11_atom_to_xatom_for_display (display, state2);
xclient.data.l[3] = 0;
xclient.data.l[4] = 0;
//gdk_wmspec_change_state( FALSE, window,
// gdk_atom_intern_static_string ("_NET_WM_STATE_BELOW"),
// GDK_NONE );
XSendEvent( display,
//mywin - wrong, not app window, send to root window!
root, // <-- DefaultRootWindow( display )
False,
SubstructureRedirectMask | SubstructureNotifyMask,
(XEvent *)&xclient );
XFlush(display);
return True;
}
return False;
}
You don't want to use XRaiseWindow() to try to stay on top. Some window managers will ignore it entirely. For those that don't, consider what happens if more than one app tries to do this. Boom! That's why the window manager is in charge of stacking windows, not the app.
The way you do this is to use the protocols defined in the Extended Window Manager Hints (EWMH), see: http://www.freedesktop.org/wiki/Specifications/wm-spec
Specifically here you want _NET_WM_STATE_ABOVE which is how the "Always on Top" menu item works.
If you aren't using a toolkit you'll want to get used to scavenging in toolkit source code to figure out how to do things. In this case you could look at the function gdk_window_set_keep_above() in GTK+'s X11 backend. That will show how to use the _NET_WM_STATE_ABOVE hint.
I wrote something like this in Xlib many years ago. It's a few lines of code. When your window is partially obscured you get a VisibilityNotify event, then call XRaiseWindow. Watch out for the case where two of your 'always on top' windows overlap.
Use Actual Title Buttons (http://www.actualtools.com/titlebuttons/) for example. It allows to stay any windows always on top , roll up, make transparency and etc..