Files
nethack/win/Qt/qt_key.cpp
PatR 2e90c1ebd4 implement "--More--" for Qt
Support MSGTYPE=stop by having qt_display_nhwindow(WIN_MESSAGE,TRUE)
issue a tty-style --More-- prompt.  For popup_dialog Off, the prompt
gets appended to the most recent message; for popup_dialog On, it is
issued via a popup and not displayed in the message window.

It accepts <space>, ^J, ^M, and ^[ (ESC) to dismiss.  There's no way
to dismiss it with the mouse (for !popup_dialog) which might need
some fix....

Several adventures along the way.  The '^C-in-parent-terminal triggers
infinite loop repeatedly complaining about "event loop already running"'
is now a one-shot complaint.  It isn't fixed but the severity of
having it happen is greatly reduced.
2020-10-01 03:16:14 -07:00

94 lines
1.7 KiB
C++

// Copyright (c) Warwick Allison, 1999.
// Qt4 conversion copyright (c) Ray Chason, 2012-2014.
// NetHack may be freely redistributed. See license for details.
// qt_key.cpp -- a key buffer
extern "C" {
#include "hack.h"
}
#include "qt_pre.h"
#include <QtGui/QtGui>
#include "qt_post.h"
#include "qt_key.h"
namespace nethack_qt_ {
NetHackQtKeyBuffer::NetHackQtKeyBuffer() :
in(0), out(0)
{
}
bool NetHackQtKeyBuffer::Empty() const { return in==out; }
bool NetHackQtKeyBuffer::Full() const { return (in+1)%maxkey==out; }
void NetHackQtKeyBuffer::Put(int k, int a, uint kbstate)
{
//raw_printf("k:%3d a:'%s' s:0x%08x", k, visctrl((char) a), kbstate);
if ( Full() ) return; // Safety
key[in] = k;
ascii[in] = a;
state[in] = (Qt::KeyboardModifiers) kbstate;
in = (in + 1) % maxkey;
}
void NetHackQtKeyBuffer::Put(char a)
{
Put(0, a, 0U);
}
void NetHackQtKeyBuffer::Put(const char* str)
{
while (*str) Put(*str++);
}
int NetHackQtKeyBuffer::GetKey()
{
if ( Empty() ) return 0;
int r=TopKey();
out=(out+1)%maxkey;
return r;
}
int NetHackQtKeyBuffer::GetAscii()
{
if ( Empty() ) return 0; // Safety
int r=TopAscii();
out=(out+1)%maxkey;
return r;
}
Qt::KeyboardModifiers NetHackQtKeyBuffer::GetState()
{
if ( Empty() ) return 0;
Qt::KeyboardModifiers r=TopState();
out=(out+1)%maxkey;
return r;
}
int NetHackQtKeyBuffer::TopKey() const
{
if ( Empty() ) return 0;
return key[out];
}
int NetHackQtKeyBuffer::TopAscii() const
{
if ( Empty() ) return 0;
return ascii[out];
}
Qt::KeyboardModifiers NetHackQtKeyBuffer::TopState() const
{
if ( Empty() ) return 0;
return state[out];
}
void NetHackQtKeyBuffer::Drain()
{
in = out = 0;
}
} // namespace nethack_qt_