📄 svgawin.c
字号:
// left button
if (mouseb & 4)
if (!(ob & 4))
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_DOWN | MOUSE_FLAG_BUTTON1,
mousex + mcursor.x, mousey + mcursor.y);
if (ob & 4)
if (!(mouseb & 4))
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_BUTTON1,
mousex + mcursor.x, mousey + mcursor.y);
}
if (mousex != ox || mousey != oy) // movement
{
rdp_send_input(0, RDP_INPUT_MOUSE, MOUSE_FLAG_MOVE,
mousex + mcursor.x, mousey + mcursor.y);
draw_cursor_under(ox, oy);
draw_cursor();
}
}
/*****************************************************************************/
void process_keyboard(void)
{
if (!UpAndRunning)
return;
}
/*****************************************************************************/
BOOL ui_main_loop(void)
{
int sel;
fd_set rfds;
if (!rdp_connect(g_servername, RDP_LOGON_NORMAL, "", "", "", ""))
return False;
UpAndRunning = 1;
FD_ZERO(&rfds);
FD_SET(g_sock, &rfds);
sel = vga_waitevent(3, &rfds, NULL, NULL, NULL);
while (sel >= 0)
{
if (sel & 1) /* mouse */
{
process_mouse();
}
else if (sel & 2) /* keyboard */
{
process_keyboard();
}
else
{
if (!rdp_loop(&deactivated, &ext_disc_reason))
return True; /* ok */
}
FD_ZERO(&rfds);
FD_SET(g_sock, &rfds);
sel = vga_waitevent(3, &rfds, NULL, NULL, NULL);
}
return True;
}
/*****************************************************************************/
void ui_bell(void)
{
}
/*****************************************************************************/
int ui_select(int in)
{
g_sock = in;
return 1;
}
/*****************************************************************************/
void* ui_create_glyph(int width, int height, uint8* data)
{
int i, j;
uint8* glyph_data;
bitmap* the_glyph;
glyph_data = (uint8*)xmalloc(width * height);
the_glyph = (bitmap*)xmalloc(sizeof(bitmap));
the_glyph->width = width;
the_glyph->height = height;
the_glyph->data = glyph_data;
memset(glyph_data, 0, width * height);
for (i = 0; i < height; i++)
for (j = 0; j < width; j++)
if (is_pixel_on(data, j, i, width, 1))
set_pixel_on(glyph_data, j, i, width, 8, 255);
return the_glyph;
}
/*****************************************************************************/
void ui_destroy_glyph(void* glyph)
{
bitmap* the_glyph;
the_glyph = (bitmap*)glyph;
if (the_glyph != NULL)
{
if (the_glyph->data != NULL)
xfree(the_glyph->data);
xfree(the_glyph);
}
}
/*****************************************************************************/
void ui_destroy_bitmap(void* bmp)
{
bitmap* b;
b = (bitmap*)bmp;
xfree(b->data);
xfree(b);
}
/*****************************************************************************/
void ui_reset_clip(void)
{
clip_startx = 0;
clip_starty = 0;
clip_endx = g_width;
clip_endy = g_height;
}
/*****************************************************************************/
void ui_set_clip(int x, int y, int cx, int cy)
{
clip_startx = x;
clip_starty = y;
clip_endx = x + cx;
clip_endy = y + cy;
}
/*****************************************************************************/
void* ui_create_colourmap(COLOURMAP * colours)
{
int i = 0;
int n = colours->ncolours;
COLOURENTRY* c = colours->colours;
int* cmap = (int*)xmalloc(3 * 256 * sizeof (int));
if (n > 256)
n = 256;
bzero(cmap, 256 * 3 * sizeof (int));
for (i = 0; i < (3 * n); c++)
{
cmap[i++] = (c->red) >> 2;
cmap[i++] = (c->green) >> 2;
cmap[i++] = (c->blue) >> 2;
}
return cmap;
}
/*****************************************************************************/
void ui_destroy_colourmap(HCOLOURMAP map)
{
if (colmap == map)
colmap = 0;
xfree(map);
}
/*****************************************************************************/
void ui_set_colourmap(void* map)
{
if (colmap != 0)
xfree(colmap);
vga_setpalvec(0, 256, (int*)map);
colmap = map;
}
/*****************************************************************************/
HBITMAP ui_create_bitmap(int width, int height, uint8* data)
{
bitmap* b;
b = (bitmap*)xmalloc(sizeof(bitmap));
b->data = (uint8*)xmalloc(width * height * g_server_Bpp);
b->width = width;
b->height = height;
b->Bpp = g_server_Bpp;
copy_mem(b->data, data, width * height * g_server_Bpp);
return (void*)b;
}
//*****************************************************************************
void draw_glyph (int x, int y, HGLYPH glyph, int fgcolour)
{
bitmap* the_glyph;
int i, j;
the_glyph = (bitmap*)glyph;
if (the_glyph == NULL)
return;
for (i = 0; i < the_glyph->height; i++)
for (j = 0; j < the_glyph->width; j++)
if (is_pixel_on(the_glyph->data, j, i, the_glyph->width, 8))
set_pixel(x + j, y + i, fgcolour, 0xc);
}
#define DO_GLYPH(ttext,idx) \
{\
glyph = cache_get_font (font, ttext[idx]);\
if (!(flags & TEXT2_IMPLICIT_X))\
{\
xyoffset = ttext[++idx];\
if ((xyoffset & 0x80))\
{\
if (flags & TEXT2_VERTICAL) \
y += ttext[idx+1] | (ttext[idx+2] << 8);\
else\
x += ttext[idx+1] | (ttext[idx+2] << 8);\
idx += 2;\
}\
else\
{\
if (flags & TEXT2_VERTICAL) \
y += xyoffset;\
else\
x += xyoffset;\
}\
}\
if (glyph != NULL)\
{\
draw_glyph (x + glyph->offset, y + glyph->baseline, glyph->pixmap, fgcolour);\
if (flags & TEXT2_IMPLICIT_X)\
x += glyph->width;\
}\
}
/*****************************************************************************/
void ui_draw_text(uint8 font, uint8 flags, uint8 opcode, int mixmode,
int x, int y,
int clipx, int clipy, int clipcx, int clipcy,
int boxx, int boxy, int boxcx, int boxcy, BRUSH * brush,
int bgcolour, int fgcolour, uint8* text, uint8 length)
{
int i;
int j;
int xyoffset;
DATABLOB* entry;
FONTGLYPH* glyph;
if (boxcx > 1)
{
if (contains_mouse(boxx, boxy, boxcx, boxcy))
draw_cursor_under(mousex, mousey);
fill_rect(boxx, boxy, boxcx, boxcy, bgcolour, 0xc);
}
else
{
if (contains_mouse(clipx, clipy, clipcx, clipcy))
draw_cursor_under(mousex, mousey);
if (mixmode == MIX_OPAQUE)
fill_rect(clipx, clipy, clipcx, clipcy, bgcolour, 0xc);
}
/* Paint text, character by character */
for (i = 0; i < length;)
{
switch (text[i])
{
case 0xff:
if (i + 2 < length)
cache_put_text(text[i + 1], text, text[i + 2]);
else
{
error("this shouldn't be happening\n");
exit(1);
}
/* this will move pointer from start to first character after FF command */
length -= i + 3;
text = &(text[i + 3]);
i = 0;
break;
case 0xfe:
entry = cache_get_text(text[i + 1]);
if (entry != NULL)
{
if ((((uint8 *) (entry->data))[1] == 0) && (!(flags & TEXT2_IMPLICIT_X)))
{
if (flags & TEXT2_VERTICAL)
y += text[i + 2];
else
x += text[i + 2];
}
for (j = 0; j < entry->size; j++)
DO_GLYPH(((uint8 *) (entry->data)), j);
}
if (i + 2 < length)
i += 3;
else
i += 2;
length -= i;
/* this will move pointer from start to first character after FE command */
text = &(text[i]);
i = 0;
break;
default:
DO_GLYPH(text, i);
i++;
break;
}
}
if (boxcx > 1)
cache_rect(boxx, boxy, boxcx, boxcy, True);
else
cache_rect(clipx, clipy, clipcx, clipcy, True);
}
//*****************************************************************************
// Bresenham's line drawing algorithm
void ui_line(uint8 opcode, int startx, int starty, int endx,
int endy, PEN* pen)
{
int dx;
int dy;
int incx;
int incy;
int dpr;
int dpru;
int p;
int left;
int top;
int right;
int bottom;
if (startx > endx)
{
dx = startx - endx;
incx = -1;
left = endx;
right = startx;
}
else
{
dx = endx - startx;
incx = 1;
left = startx;
right = endx;
}
if (starty > endy)
{
dy = starty - endy;
incy = -1;
top = endy;
bottom = starty;
}
else
{
dy = endy - starty;
incy = 1;
top = starty;
bottom = endy;
}
if (contains_mouse(left, top, (right - left) + 1, (bottom - top) + 1))
draw_cursor_under(mousex, mousey);
if (dx >= dy)
{
dpr = dy << 1;
dpru = dpr - (dx << 1);
p = dpr - dx;
for (; dx >= 0; dx--)
{
set_pixel(startx, starty, pen->colour, opcode);
if (p > 0)
{
startx += incx;
starty += incy;
p += dpru;
}
else
{
startx += incx;
p += dpr;
}
}
}
else
{
dpr = dx << 1;
dpru = dpr - (dy << 1);
p = dpr - dy;
for (; dy >= 0; dy--)
{
set_pixel(startx, starty, pen->colour, opcode);
if (p > 0)
{
startx += incx;
starty += incy;
p += dpru;
}
else
{
starty += incy;
p += dpr;
}
}
}
cache_rect(left, top, (right - left) + 1, (bottom - top) + 1, True);
}
/*****************************************************************************/
void ui_triblt(uint8 opcode, int x, int y, int cx, int cy,
HBITMAP src, int srcx, int srcy,
BRUSH* brush, int bgcolour, int fgcolour)
{
// non used
}
/*****************************************************************************/
void ui_memblt(uint8 opcode, int x, int y, int cx, int cy,
HBITMAP src, int srcx, int srcy)
{
bitmap* b;
int i;
int j;
int pixel;
if (warp_coords(&x, &y, &cx, &cy, &srcx, &srcy))
{
if (contains_mouse(x, y, cx, cy))
draw_cursor_under(mousex, mousey);
b = (bitmap*)src;
if (opcode == 0xc)
accel_draw_box(x, y, cx, cy, get_ptr(srcx, srcy, b->data, b->width, g_server_bpp),
b->width * g_server_Bpp);
else
{
for (i = 0; i < cy; i++)
{
for (j = 0; j < cx; j++)
{
pixel = get_pixel2(srcx + j, srcy + i, b->data, b->width, g_server_bpp);
set_pixel(x + j, y + i, pixel, opcode);
}
}
}
cache_rect(x, y, cx, cy, False);
}
}
/*****************************************************************************/
void ui_desktop_restore(uint32 offset, int x, int y, int cx, int cy)
{
uint8* p;
if (offset > 0x38400)
offset = 0;
if (offset + cx * cy > 0x38400)
return;
p = desk_save + offset * g_server_Bpp;
ui_paint_bitmap(x, y, cx, cy, cx, cy, p);
}
/*****************************************************************************/
void ui_desktop_save(uint32 offset, int x, int y, int cx, int cy)
{
uint8* p;
if (offset > 0x38400)
offset = 0;
if (offset + cx * cy > 0x38400)
return;
if (contains_mouse(x, y, cx, cy))
draw_cursor_under(mousex, mousey);
p = desk_save + offset * g_server_Bpp;
get_rect(x, y, cx, cy, p);
}
/*****************************************************************************/
void ui_rect(int x, int y, int cx, int cy, int colour)
{
if (warp_coords(&x, &y, &cx, &cy, NULL, NULL))
{
if (contains_mouse(x, y, cx, cy))
draw_cursor_under(mousex, mousey);
accel_fill_rect(x, y, cx, cy, colour);
cache_rect(x, y, cx, cy, False);
}
}
/*****************************************************************************/
void ui_screenblt(uint8 opcode, int x, int y, int cx, int cy,
int srcx, int srcy)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -