📄 svgawin.c
字号:
if (srcy < y)
{ // bottom to top
s = get_ptr(srcx, (srcy + cy) - 1, sdata, g_width, g_server_bpp);
d = get_ptr(x, (y + cy) - 1, sdata, g_width, g_server_bpp);
for (i = 0; i < cy; i++) // copy down
{
copy_mem(d, s, cx * g_server_Bpp);
s = s - g_width * g_server_Bpp;
d = d - g_width * g_server_Bpp;
}
}
else if (srcy > y || srcx > x) // copy up or left
{ // top to bottom
s = get_ptr(srcx, srcy, sdata, g_width, g_server_bpp);
d = get_ptr(x, y, sdata, g_width, g_server_bpp);
for (i = 0; i < cy; i++)
{
copy_mem(d, s, cx * g_server_Bpp);
s = s + g_width * g_server_Bpp;
d = d + g_width * g_server_Bpp;
}
}
else // copy straight right
{
s = get_ptr(srcx, srcy, sdata, g_width, g_server_bpp);
d = get_ptr(x, y, sdata, g_width, g_server_bpp);
for (i = 0; i < cy; i++)
{
copy_memb(d, s, cx * g_server_Bpp);
s = s + g_width * g_server_Bpp;
d = d + g_width * g_server_Bpp;
}
}
}
else if (has_screen_copy)
{
vga_accel(ACCEL_SCREENCOPY, srcx, srcy, x, y, cx, cy);
}
else
{
// slow
temp = (uint8*)xmalloc(cx * cy * g_server_Bpp);
for (i = 0; i < cy; i++)
vga_getscansegment(get_ptr(0, i, temp, cx, g_server_bpp), srcx, srcy + i, cx * g_server_Bpp);
for (i = 0; i < cy; i++)
vga_drawscansegment(get_ptr(0, i, temp, cx, g_server_bpp), x, y + i, cx * g_server_Bpp);
xfree(temp);
}
}
//*****************************************************************************
// return bool
int contains_mouse(int x, int y, int cx, int cy)
{
if (mousex + 32 >= x &&
mousey + 32 >= y &&
mousex <= x + cx &&
mousey <= y + cy)
return 1;
else
return 0;
}
//*****************************************************************************
void fill_rect(int x, int y, int cx, int cy, int colour, int opcode)
{
int i;
int j;
if (warp_coords(&x, &y, &cx, &cy, NULL, NULL))
{
if (opcode == 0xc)
accel_fill_rect(x, y, cx, cy, colour);
else if (opcode == 0xf)
accel_fill_rect(x, y, cx, cy, -1);
else if (opcode == 0x0)
accel_fill_rect(x, y, cx, cy, 0);
else
{
for (i = 0; i < cy; i++)
for (j = 0; j < cx; j++)
set_pixel(x + j, y + i, colour, opcode);
}
}
}
//*****************************************************************************
void get_rect(int x, int y, int cx, int cy, uint8* p)
{
int i;
if (x < 0)
{
cx = cx + x;
x = 0;
}
if (y < 0)
{
cy = cy + y;
y = 0;
}
if (sdata != 0)
{
for (i = 0; i < cy; i++)
{
copy_mem(p, get_ptr(x, y + i, sdata, g_width, g_server_bpp), cx * g_server_Bpp);
p = p + cx * g_server_Bpp;
}
}
else
{
for (i = 0; i < cy; i++)
{
vga_getscansegment(p, x, y + i, cx * g_server_Bpp);
p = p + cx * g_server_Bpp;
}
}
}
/*****************************************************************************/
// return true if r1 is contained by r2
int is_contained_by(myrect* r1, myrect* r2)
{
if (r1->x >= r2->x &&
r1->y >= r2->y &&
r1->x + r1->cx <= r2->x + r2->cx &&
r1->y + r1->cy <= r2->y + r2->cy)
return 1;
else
return 0;
}
/*****************************************************************************/
void draw_cursor_under(int ox, int oy)
{
int i;
int j;
int k;
uint8* ptr;
int len;
if (ox < 0)
k = -ox;
else
k = 0;
j = g_width - ox;
if (j > 32)
j = 32;
if (j > 0)
{
for (i = 0; i < 32; i++)
{
ptr = get_ptr(k, i, mouse_under, 32, g_server_bpp);
len = (j - k) * g_server_Bpp;
if (ox + k >= 0 && oy + i >= 0 && ox + k < g_width && oy + i < g_height)
vga_drawscansegment(ptr, ox + k, oy + i, len);
}
}
g_draw_mouse = 1;
}
/*****************************************************************************/
void draw_cursor(void)
{
int i;
int j;
int k;
int pixel;
uint8 mouse_a[32 * 32 * 4];
uint8* ptr;
int len;
if (!g_draw_mouse)
return;
memset(mouse_under, 0, sizeof(mouse_under));
for (i = 0; i < 32; i++)
{
for (j = 0; j < 32; j++)
{
pixel = get_pixel(mousex + j, mousey + i);
set_pixel2(j, i, pixel, mouse_under, 32, g_server_bpp);
if (mcursor.andmask[i * 32 + j] == 0)
k = 0;
else
k = ~0;
pixel = rop(0x8, k, pixel);
if (mcursor.xormask[i * 32 + j] == 0)
k = 0;
else
k = ~0;
pixel = rop(0x6, k, pixel);
set_pixel2(j, i, pixel, mouse_a, 32, g_server_bpp);
}
}
if (mousex < 0)
k = -mousex;
else
k = 0;
j = g_width - mousex;
if (j > 32)
j = 32;
if (j > 0)
{
for (i = mousey; i < mousey + 32; i++)
if (i < g_height && i >= 0)
{
ptr = get_ptr(k, i - mousey, mouse_a, 32, g_server_bpp);
len = (j - k) * g_server_Bpp;
vga_drawscansegment(ptr, mousex + k, i, len);
}
}
g_draw_mouse = 0;
}
/*****************************************************************************/
// add a rect to cache
void cache_rect(int x, int y, int cx, int cy, int do_warp)
{
myrect* rect;
myrect* walk_rect;
if (sdata == 0)
{
draw_cursor();
return;
}
if (do_warp)
if (!warp_coords(&x, &y, &cx, &cy, NULL, NULL))
return;
rect = (myrect*)xmalloc(sizeof(myrect));
rect->x = x;
rect->y = y;
rect->cx = cx;
rect->cy = cy;
rect->next = 0;
rect->prev = 0;
if (head_rect == 0)
head_rect = rect;
else
{
walk_rect = 0;
do
{
if (walk_rect == 0)
walk_rect = head_rect;
else
walk_rect = walk_rect->next;
if (is_contained_by(rect, walk_rect))
{
xfree(rect);
return;
}
}
while (walk_rect->next != 0);
walk_rect->next = rect;
rect->prev = walk_rect;
}
}
//*****************************************************************************
void draw_cache_rects(void)
{
int i;
myrect* rect;
myrect* rect1;
uint8* p;
// draw all the rects
rect = head_rect;
while (rect != 0)
{
p = get_ptr(rect->x, rect->y, sdata, g_width, g_server_bpp);
for (i = 0; i < rect->cy; i++)
{
vga_drawscansegment(p, rect->x, rect->y + i, rect->cx * g_server_Bpp);
p = p + g_width * g_server_Bpp;
}
rect1 = rect;
rect = rect->next;
xfree(rect1);
}
head_rect = 0;
}
/*****************************************************************************/
void key_event(int scancode, int pressed)
{
int rdpkey;
int ext;
if (!UpAndRunning)
return;
rdpkey = scancode;
ext = 0;
// Keyboard LEDS
if ((scancode == SCANCODE_CAPSLOCK) && pressed)
{
capslock = !capslock;
setled(LED_CAP, capslock);
}
if ((scancode == SCANCODE_SCROLLLOCK) && pressed)
{
scrolllock = !scrolllock;
setled(LED_SCR, scrolllock);
}
if ((scancode == SCANCODE_NUMLOCK) && pressed)
{
numlock = !numlock;
setled(LED_NUM, numlock);
}
switch (scancode)
{
case SCANCODE_CURSORBLOCKUP: rdpkey = 0xc8; ext = KBD_FLAG_EXT; break; // up arrow
case SCANCODE_CURSORBLOCKDOWN: rdpkey = 0xd0; ext = KBD_FLAG_EXT; break; // down arrow
case SCANCODE_CURSORBLOCKRIGHT: rdpkey = 0xcd; ext = KBD_FLAG_EXT; break; // right arrow
case SCANCODE_CURSORBLOCKLEFT: rdpkey = 0xcb; ext = KBD_FLAG_EXT; break; // left arrow
case SCANCODE_PAGEDOWN: rdpkey = 0xd1; ext = KBD_FLAG_EXT; break; // page down
case SCANCODE_PAGEUP: rdpkey = 0xc9; ext = KBD_FLAG_EXT; break; // page up
case SCANCODE_HOME: rdpkey = 0xc7; ext = KBD_FLAG_EXT; break; // home
case SCANCODE_END: rdpkey = 0xcf; ext = KBD_FLAG_EXT; break; // end
case SCANCODE_INSERT: rdpkey = 0xd2; ext = KBD_FLAG_EXT; break; // insert
case SCANCODE_REMOVE: rdpkey = 0xd3; ext = KBD_FLAG_EXT; break; // delete
case SCANCODE_KEYPADDIVIDE: rdpkey = 0x35; break; // /
case SCANCODE_KEYPADENTER: rdpkey = 0x1c; break; // enter
case SCANCODE_RIGHTCONTROL: rdpkey = 0x1d; break; // right ctrl
case SCANCODE_RIGHTALT: rdpkey = 0x38; break; // right alt
case SCANCODE_LEFTWIN: rdpkey = 0x5b; ext = KBD_FLAG_EXT; break; // left win
case SCANCODE_RIGHTWIN: rdpkey = 0x5c; ext = KBD_FLAG_EXT; break; // right win
case 127: rdpkey = 0x5d; ext = KBD_FLAG_EXT; break; // menu key
case SCANCODE_PRINTSCREEN: rdpkey = 0x37; ext = KBD_FLAG_EXT; break; // print screen
case SCANCODE_BREAK: //rdpkey = 0; break; // break
{
if (pressed)
{
ext = KBD_FLAG_EXT;
rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS | ext, 0x46, 0);
rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS | ext, 0xc6, 0);
}
rdpkey = 0;
}
case SCANCODE_SCROLLLOCK: rdpkey = 0x46; break; // scroll lock
case 112: // mouse down
{
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON4,
mouse_getx(), mouse_gety());
return;
}
case 113: // mouse up
{
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON5,
mouse_getx(), mouse_gety());
return;
}
}
// printf("%d %d\n", scancode, pressed);
if (pressed)
rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYPRESS | ext, rdpkey, 0);
else
rdp_send_input(0, RDP_INPUT_SCANCODE, RDP_KEYRELEASE | ext, rdpkey, 0);
}
/*****************************************************************************/
int ui_init(void)
{
vga_init();
memset(&mcursor, 0, sizeof(tcursor));
desk_save = (uint8*)xmalloc(0x38400 * g_server_Bpp);
return 1;
}
/*****************************************************************************/
void ui_deinit(void)
{
xfree(desk_save);
}
/*****************************************************************************/
int ui_create_window(void)
{
int vgamode;
int i;
vgamode = G800x600x256;
if (g_width == 640 && g_height == 480)
{
if (g_server_Bpp == 1)
vgamode = G640x480x256;
else if (g_server_Bpp == 2)
vgamode = G640x480x64K;
}
else if (g_width == 800 && g_height == 600)
{
if (g_server_Bpp == 1)
vgamode = G800x600x256;
else if (g_server_Bpp == 2)
vgamode = G800x600x64K;
}
else if (g_width == 1024 && g_height == 768)
{
if (g_server_Bpp == 1)
vgamode = G1024x768x256;
else if (g_server_Bpp == 2)
vgamode = G1024x768x64K;
}
else
{
error("Invalid width / height");
return 0;
}
ui_reset_clip();
if (!vga_hasmode(vgamode))
{
error("Graphics unavailable");
return 0;
}
vga_setmousesupport(1);
mouse_setposition(g_width / 2, g_height / 2);
vga_setmode(vgamode);
if (keyboard_init())
{
error("Keyboard unavailable");
return 0;
}
keyboard_seteventhandler(key_event);
if (use_accel)
{
i = vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_ACCEL);
if (i & ACCELFLAG_PUTIMAGE)
has_put_image = 1;
if (i & ACCELFLAG_SCREENCOPY)
has_screen_copy = 1;
if (i & ACCELFLAG_FILLBOX)
has_fill_box = 1;
printf("accel %d\n", i);
}
if (!has_screen_copy && !g_save_mem)
sdata = xmalloc(g_width * g_height * g_server_Bpp);
return 1;
}
/*****************************************************************************/
void ui_destroy_window(void)
{
keyboard_close(); /* Don't forget this! */
vga_setmode(TEXT);
if (sdata != 0)
xfree(sdata);
}
/*****************************************************************************/
void process_mouse(void)
{
int ox = mousex;
int oy = mousey;
int ob = mouseb;
if (!UpAndRunning)
return;
mousex = mouse_getx() - mcursor.x;
mousey = mouse_gety() - mcursor.y;
mouseb = mouse_getbutton();
if (mouseb != ob) // button
{
// right button
if (mouseb & 1)
if (!(ob & 1))
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON2,
mousex + mcursor.x, mousey + mcursor.y);
if (ob & 1)
if (!(mouseb & 1))
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON2,
mousex + mcursor.x, mousey + mcursor.y);
// middle button
if (mouseb & 2)
if (!(ob & 2))
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON3,
mousex + mcursor.x, mousey + mcursor.y);
if (ob & 2)
if (!(mouseb & 2))
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON3,
mousex + mcursor.x, mousey + mcursor.y);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -