📄 qtewin.cpp
字号:
rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x2a, 0); // shift
rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x1d, 0); // control
rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE, 0x38, 0); // alt
}
else if (MenuID == 4) // double click
{
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
rd(c2sx(mx)), rd(c2sy(my)));
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
rd(c2sx(mx)), rd(c2sy(my)));
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
rd(c2sx(mx)), rd(c2sy(my)));
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
rd(c2sx(mx)), rd(c2sy(my)));
}
}
/******************************************************************************/
void QMyMainWindow::mouseMoveEvent(QMouseEvent* e)
{
int x, y;
x = e->x();
y = e->y();
if (timer_id)
{
x = x - mx;
y = y - my;
if (x < -10 || x > 10 || y < -10 || y > 10)
{
killTimer(timer_id);
timer_id = 0;
}
}
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE, c2sx(e->x()),
c2sy(e->y()));
}
/******************************************************************************/
void QMyMainWindow::mousePressEvent(QMouseEvent* e)
{
timer_id = startTimer(1000);
mx = e->x();
my = e->y();
if (e->button() == LeftButton)
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
c2sx(e->x()), c2sy(e->y()));
else if (e->button() == RightButton)
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
c2sx(e->x()), c2sy(e->y()));
else if (e->button() == MidButton)
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3,
c2sx(e->x()), c2sy(e->y()));
}
/******************************************************************************/
void QMyMainWindow::mouseReleaseEvent(QMouseEvent* e)
{
killTimer(timer_id);
timer_id = 0;
if (e->button() == LeftButton)
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1, c2sx(e->x()),
c2sy(e->y()));
else if (e->button() == RightButton)
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2, c2sx(e->x()),
c2sy(e->y()));
else if (e->button() == MidButton)
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3, c2sx(e->x()),
c2sy(e->y()));
}
/******************************************************************************/
void QMyMainWindow::wheelEvent(QWheelEvent* e)
{
if (e->delta() > 0)
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON4, c2sx(e->x()),
c2sy(e->y()));
else if (e->delta() < 0)
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON5, c2sx(e->x()),
c2sy(e->y()));
}
#define NOT(x) (~x)
/******************************************************************************/
int rop(int rop, int src, int dst)
{
switch (rop)
{
case 0x0: return 0;
case 0x1: return NOT (src | dst);
case 0x2: return NOT (src) & dst;
case 0x3: return NOT (src);
case 0x4: return src & NOT (dst);
case 0x5: return NOT (dst);
case 0x6: return src ^ dst;
case 0x7: return NOT (src & dst);
case 0x8: return src & dst;
case 0x9: return NOT (src) ^ dst;
case 0xa: return dst;
case 0xb: return NOT (src) | dst;
case 0xc: return src;
case 0xd: return src | NOT (dst);
case 0xe: return src | dst;
case 0xf: return NOT (0);
}
return dst;
}
/*****************************************************************************/
int get_pixel(int x, int y)
{
if (x >= 0 && x < g_width && y >= 0 && y < g_height)
{
if (g_server_bpp == 8)
return GETPIXEL8(g_BS, x, y, g_width);
else if (g_server_bpp == 16)
return GETPIXEL16(g_BS, x, y, g_width);
else if (g_server_bpp == 24)
return GETPIXEL32(g_BS, x, y, g_width);
else
return 0;
}
else
return 0;
}
/******************************************************************************/
void set_pixel(int x, int y, int pixel, int op = 0xc)
{
int p;
if (x >= g_clipx && x < (g_clipx + g_clipcx) &&
y >= g_clipy && y < (g_clipy + g_clipcy))
{
if (x >= 0 && x < g_width && y >= 0 && y < g_height)
{
if (op == 0xc)
{
if (g_server_bpp == 8)
{
SETPIXEL8(g_BS, x, y, g_width, pixel);
}
else if (g_server_bpp == 16)
{
SETPIXEL16(g_BS, x, y, g_width, pixel);
}
else if (g_server_bpp == 24)
{
SETPIXEL32(g_BS, x, y, g_width, pixel);
}
}
else
{
if (g_server_bpp == 8)
{
p = GETPIXEL8(g_BS, x, y, g_width);
p = rop(op, pixel, p);
SETPIXEL8(g_BS, x, y, g_width, p);
}
else if (g_server_bpp == 16)
{
p = GETPIXEL16(g_BS, x, y, g_width);
p = rop(op, pixel, p);
SETPIXEL16(g_BS, x, y, g_width, p);
}
else if (g_server_bpp == 24)
{
p = GETPIXEL32(g_BS, x, y, g_width);
p = rop(op, pixel, p);
SETPIXEL32(g_BS, x, y, g_width, p);
}
}
}
}
}
/******************************************************************************/
// adjust coordinates for cliping rect
bool WarpCoords(int * x, int * y, int * cx, int * cy, int * srcx, int * srcy)
{
int dx, dy;
QRect InRect(*x, *y, *cx, *cy);
QRect OutRect;
QRect CRect(g_clipx, g_clipy, g_clipcx, g_clipcy);
OutRect = InRect.intersect(CRect);
if (OutRect.isEmpty())
return false;
dx = OutRect.x() - InRect.x();
dy = OutRect.y() - InRect.y();
*x = OutRect.x();
*y = OutRect.y();
*cx = OutRect.width();
*cy = OutRect.height();
if (srcx != NULL)
*srcx = *srcx + dx;
if (srcy != NULL)
*srcy = *srcy + dy;
return true;
}
/******************************************************************************/
void QMyMainWindow::paintEvent(QPaintEvent * pe)
{
QImage * Image;
QPainter * Painter;
QRect Rect;
int i, j, w, h, l, t, pixel, r, g, b;
uint8 * data;
double sx, sy;
Image = 0;
data = 0;
if (!testWFlags(WRepaintNoErase))
setWFlags(WRepaintNoErase);
if (g_CM != NULL || g_server_bpp > 8)
{
sx = (double)g_client_width / (double)g_width;
sy = (double)g_client_height / (double)g_height;
Rect = pe->rect();
l = rd(Rect.left() / sx);
t = rd(Rect.top() / sy);
w = rd(Rect.width() / sx);
h = rd(Rect.height() / sy);
if (w > 0 && h > 0)
{
if (g_server_bpp == 8 && g_CM->NumColors > 0)
{
w = (w + 3) & ~3;
data = (uint8*)xmalloc(w * h);
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
data[i * w + j] = GETPIXEL8(g_BS, l + j, t + i, g_width);
Image = new QImage(data, w, h, 8,(QRgb*)g_CM->RGBColors,
g_CM->NumColors, QImage::IgnoreEndian);
}
else if (g_server_bpp == 16)
{
w = (w + 3) & ~3;
data = (uint8*)xmalloc(w * h * 4);
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
{
pixel = GETPIXEL16(g_BS, l + j, t + i, g_width);
r = ((pixel >> 8) & 0xf8) | ((pixel >> 13) & 0x7);
g = ((pixel >> 3) & 0xfc) | ((pixel >> 9) & 0x3);
b = ((pixel << 3) & 0xf8) | ((pixel >> 2) & 0x7);
pixel = ((r << 16) | (g << 8) | b);
SETPIXEL32(data, j, i, w, pixel);
}
Image = new QImage(data, w, h, 32, NULL,
0, QImage::IgnoreEndian);
}
else if (g_server_bpp == 24)
{
w = (w + 3) & ~3;
data = (uint8*)xmalloc(w * h * 4);
for (i = 0; i < h; i++)
for (j = 0; j < w; j++)
{
pixel = GETPIXEL32(g_BS, l + j, t + i, g_width);
r = (pixel >> 0) & 0xff;
g = (pixel >> 8) & 0xff;
b = (pixel >> 16) & 0xff;
pixel = ((r << 16) | (g << 8) | b);
SETPIXEL32(data, j, i, w, pixel);
}
Image = new QImage(data, w, h, 32, NULL,
0, QImage::IgnoreEndian);
}
if (Image != 0)
{
Painter = new QPainter(this);
Painter->scale(sx, sy);
Painter->drawImage(l, t, *Image, 0, 0, w, h);
delete Painter;
delete Image;
}
xfree(data);
}
}
}
/******************************************************************************/
void QMyMainWindow::closeEvent(QCloseEvent * e)
{
e->accept();
}
/******************************************************************************/
void QMyMainWindow::dataReceived()
{
if (!rdp_loop(&g_deactivated, &g_ext_disc_reason))
g_SV->close();
#ifdef WITH_RDPSND
if (g_dsp_busy)
{
if (g_SoundNotifier == 0)
{
g_SoundNotifier = new QSocketNotifier(g_dsp_fd, QSocketNotifier::Write,
g_MW);
g_MW->connect(g_SoundNotifier, SIGNAL(activated(int)), g_MW,
SLOT(soundSend()));
}
else
{
if (!g_SoundNotifier->isEnabled())
g_SoundNotifier->setEnabled(true);
}
}
#endif
}
/******************************************************************************/
void QMyMainWindow::soundSend()
{
#ifdef WITH_RDPSND
g_SoundNotifier->setEnabled(false);
wave_out_play();
if (g_dsp_busy)
{
g_SoundNotifier->setEnabled(true);
}
#endif
}
/******************************************************************************/
void redraw(int x, int y, int cx, int cy)
{
double sx, sy;
if (WarpCoords(&x, &y, &cx, &cy, NULL, NULL))
{
sx = (double)g_client_width / (double)g_width;
sy = (double)g_client_height / (double)g_height;
x = rd(x * sx);
y = rd(y * sy);
cx = rd(cx * sx);
cy = rd(cy * sy);
g_MW->update(x, y, cx, cy);
}
}
/******************************************************************************/
/* Returns 0 after user quit, 1 otherwise */
int ui_select(int rdp_socket)
{
if (g_global_sock == 0)
g_global_sock = rdp_socket;
return 1;
}
/******************************************************************************/
void ui_move_pointer(int /*x*/, int /*y*/)
{
}
/******************************************************************************/
void ui_set_null_cursor(void)
{
}
/******************************************************************************/
HBITMAP ui_create_bitmap(int width, int height, uint8 * data)
{
struct bitmap * the_bitmap;
uint8 * bitmap_data;
int i, j;
int r, g, b, pixel;
bitmap_data = (uint8*)xmalloc(width * height * 4);
the_bitmap = (struct bitmap*)xmalloc(sizeof(struct bitmap));
the_bitmap->w = width;
the_bitmap->h = height;
the_bitmap->data = bitmap_data;
if (g_server_bpp == 8)
{
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
bitmap_data[i * width + j] = data[i * width + j];
}
else if (g_server_bpp == 16)
{
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
*(((uint16*)bitmap_data) + (i * width + j)) =
*(((uint16*)data) + (i * width + j));
}
else if (g_server_bpp == 24)
{
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
{
r = data[(i * width + j) * 3 + 0];
g = data[(i * width + j) * 3 + 1];
b = data[(i * width + j) * 3 + 2];
pixel = (r << 16) | (g << 8) | b;
SETPIXEL32(bitmap_data, j, i, width, pixel);
}
}
return the_bitmap;
}
/******************************************************************************/
void ui_paint_bitmap(int x, int y, int cx, int cy, int width,
int height, uint8 * data)
{
int i, j;
int r, g, b, pixel;
if (g_server_bpp == 8)
{
for (i = 0; i < cy; i++)
for (j = 0; j < cx; j++)
if (i < height)
if (j < width)
set_pixel(x + j, y + i, data[i * width + j]);
}
else if (g_server_bpp == 16)
{
for (i = 0; i < cy; i++)
for (j = 0; j < cx; j++)
if (i < height)
if (j < width)
set_pixel(x + j, y + i, *(((uint16*)data) + (i * width + j)));
}
else if (g_server_bpp == 24)
{
for (i = 0; i < cy; i++)
for (j = 0; j < cx; j++)
if (i < height)
if (j < width)
{
r = data[(i * width + j) * 3 + 0];
g = data[(i * width + j) * 3 + 1];
b = data[(i * width + j) * 3 + 2];
pixel = (r << 16) | (g << 8) | b;
set_pixel(x + j, y + i, pixel);
}
}
redraw(x, y, cx, cy);
}
/******************************************************************************/
void ui_destroy_bitmap(HBITMAP bmp)
{
struct bitmap* the_bitmap;
the_bitmap = (struct bitmap*)bmp;
if (the_bitmap != NULL)
{
if (the_bitmap->data != NULL)
xfree(the_bitmap->data);
xfree(the_bitmap);
}
}
/******************************************************************************/
bool is_pixel_on(uint8 * data, int x, int y, int width, int bpp)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -