void SvgalibScreen::blit32To8(const QImage &image, const QPoint &topLeft, const QRegion ®ion) { const int imageStride = image.bytesPerLine() / 4; const QVector<QRect> rects = region.rects(); for (int i = 0; i < rects.size(); ++i) { const QRect r = rects.at(i).translated(-topLeft); int y = r.y(); const quint32 *s = reinterpret_cast<const quint32*>(image.scanLine(y)); while (y <= r.bottom()) { int x1 = r.x(); while (x1 <= r.right()) { const quint32 c = s[x1]; int x2 = x1; // find span length while ((x2+1 < r.right()) && (s[x2+1] == c)) ++x2; gl_hline(x1 + topLeft.x(), y + topLeft.y(), x2 + topLeft.x(), qt_colorConvert<quint8, quint32>(c, 0)); x1 = x2 + 1; } s += imageStride; ++y; } } }
/* before call this function, must lock the console */ void refresh_input_method_area (void) { char str[25]; int tTopY; int tLeftX; int ii, jj; tTopY = 458; tLeftX = 540; NEWRootEmpty (); //NEWDispRootArea(); input_clear_line (2, INPUT_BGCOLOR); gInputCount = 0; ClrSelArea (); gSelectingMode_flag = 0; input_clear_area (INPUT_BGCOLOR); if (use_fb) { fb_setfgcolor (15); fb_drawline (0, INPUT_AREAY - 7, 639, INPUT_AREAY - 7); fb_drawline (0, INPUT_AREAY - 4, 639, INPUT_AREAY - 4); for (ii = 0; ii < 100; ii++) fb_setfgcolor (12); } else { #ifdef VGALIB gl_hline(0, INPUT_AREAY - 7, WIDTH-1, GRAY); gl_hline(0, INPUT_AREAY - 4, WIDTH-1, GRAY); #endif #ifdef VGA__ vga_setcolor (15); vga_drawline (0, INPUT_AREAY - 7, 639, INPUT_AREAY - 7); vga_drawline (0, INPUT_AREAY - 4, 639, INPUT_AREAY - 4); for (ii = 0; ii < 100; ii++) vga_setcolor (12); #endif } if (!IsHanziInput) { if (gEncode == BIG5) { input_print_string (POS_OF_VERSIONSTRING, 0, VERSION_STRING, INPUT_FGCOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_INPUTNAME, 0, "【英數】", INPUT_FGCOLOR, INPUT_BGCOLOR); } if (gEncode == GB) { input_print_string (POS_OF_VERSIONSTRING, 0, string_BIG5toGB (VERSION_STRING), INPUT_FGCOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_INPUTNAME, 0, string_BIG5toGB ("【英數】"), INPUT_FGCOLOR, INPUT_BGCOLOR); } } else { if ((gsCurrent_input_table->IsExtInpMethod) == 1) { if (gEncode == BIG5) { input_print_string (POS_OF_INPUTNAME, 0, gsInput_table_array[gsCurrent_method]->cname, INPUT_FGCOLOR, INPUT_BGCOLOR); } if (gEncode == GB) { input_print_string (POS_OF_INPUTNAME, 0, gsInput_table_array[gsCurrent_method]->cname, INPUT_FGCOLOR, INPUT_BGCOLOR); } } else { fprintf (stderr, "%c", 0x7); if (gEncode == BIG5) { #ifdef NEW_CHEWING if (gsCurrent_method == 7) input_print_string (POS_OF_INPUTNAME, 0, "酷音", INPUT_FGCOLOR, INPUT_BGCOLOR); #else input_print_string (POS_OF_INPUTNAME, 0, "!無輸入法!", INPUT_FGCOLOR, INPUT_BGCOLOR); #endif } if (gEncode == GB) { input_print_string (POS_OF_INPUTNAME, 0, string_BIG5toGB ("!無輸入法!"), INPUT_FGCOLOR, INPUT_BGCOLOR); } } } if (gsCurrent_input_table) { if (gsCurrent_input_table->CaseTransPolicy == 0) { input_print_string (POS_OF_CASEHINT, 0, "A", HINT_CASEHICOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_CASEHINT + 1, 0, " ", INPUT_FGCOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_CASEHINT + 2, 0, "a", HINT_CASECOLOR, INPUT_BGCOLOR); } if (gsCurrent_input_table->CaseTransPolicy == 1) { input_print_string (POS_OF_CASEHINT, 0, "a", HINT_CASECOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_CASEHINT + 1, 0, "=", HINT_CASECOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_CASEHINT + 2, 0, "A", HINT_CASECOLOR, INPUT_BGCOLOR); } if (gsCurrent_input_table->CaseTransPolicy == 2) { input_print_string (POS_OF_CASEHINT, 0, "A", HINT_CASECOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_CASEHINT + 1, 0, "=", HINT_CASECOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_CASEHINT + 2, 0, "a", HINT_CASECOLOR, INPUT_BGCOLOR); } } if (gEncode == BIG5) { input_print_string (POS_OF_FULLHALF, 0, half_full_strBIG5[IsFullChar], INPUT_FGCOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_HISTORYMODE, 0, history_normal_strBIG5[console_mode], INPUT_FGCOLOR, INPUT_BGCOLOR); sprintf (str, "【視窗%1d】", hztty_list->index); } if (gEncode == GB) { input_print_string (POS_OF_FULLHALF, 0, half_full_strGB[IsFullChar], INPUT_FGCOLOR, INPUT_BGCOLOR); input_print_string (POS_OF_HISTORYMODE, 0, history_normal_strGB[console_mode], INPUT_FGCOLOR, INPUT_BGCOLOR); sprintf (str, "▽敦諳%1d▼", hztty_list->index); } input_print_string (POS_OF_WINDOWNO, 0, str, INPUT_FGCOLOR, INPUT_BGCOLOR); if (IsHanziInput > 0 && gsCurrent_method == 7) #ifdef CHEWING ChewReDrawText (); /* Chewing */ #else ; #endif input_print_string (76, 1, encode_name, RED, INPUT_BGCOLOR); }
void main(void) { struct timeval timeout; fd_set inputs; char bitmap[16 * 16 * 4]; /* big enough for 10x10 bitmap in any mode */ int vgamode, color, pipefd[2], x, y, button, event, cursorsize = 5; char loop = 1, drawcursor = 1; #ifdef USE_RAWKEYBOARD char space_pressed = 0; #endif puts("This is a demo showing the abilities of the new vga_waitevent() function\n" "If something goes wrong it might hang your machine. Thus hit <ctrl>-C now\n" "to bailout if in doubt.\n" "Use mouse to move cursor. 1-9,0 to set the cursor size. Space to change the\n" "cursor color. Left button to draw. Right button or 'Q' to bailout.\n" "The cursor goes on/off every half second by usage of a timeout passed to\n" "vga_waitevent. Every 5 secs a string from a child process (the time) arrives\n" "asynchronously and is displayed by the frontend."); #ifdef USE_RAWKEYBOARD puts("\nBEWARE! This has been compiled to use the raw keyboard. A crash might\n" "render the console unusable. (but shouldn't)."); #endif fputs("\nHit <Enter> if brave enough, else ^C to bailout: ", stdout); fflush(stdout); getchar(); fflush(stdin); /* clear I/O buffer */ pipe(pipefd); if (fork() == 0) { /* fork off b4 touching graphix to avoid side effects */ close(pipefd[0]); /* Important: close reading side, else it remains */ /* opened by child when parent exits and we don't get */ /* a SIGPIPE! */ child(pipefd[1]); } vga_init(); vgamode = vga_getdefaultmode(); if (vgamode == -1) vgamode = G320x200x256; if (!vga_hasmode(vgamode)) { printf("Mode not available.\n"); exit(-1); } /* Enable automatic mouse setup at mode set. */ vga_setmousesupport(1); vga_setmode(vgamode); /* Disable wrapping (default). */ /* mouse_setwrap(MOUSE_NOWRAP); */ gl_setcontextvga(vgamode); gl_enableclipping(); /* There might be some scrap data in the serial buffer from the mouse. It will make vga_waitevent block because it thinks the mouse wants to send data but then no mouse packet arrives. */ color = newcolor(); x = 0; y = 0; gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED); gl_setfont(8, 8, gl_font8x8); gl_setfontcolors(0, newcolor()); #ifdef USE_RAWKEYBOARD if (keyboard_init()) { printf("Could not initialize keyboard.\n"); exit(1); } #endif while (loop) { gl_getbox(x, y, 10, 10, bitmap); if (drawcursor) { gl_hline(x, y, x + cursorsize, color); gl_hline(x, y + cursorsize, x + cursorsize, color); gl_line(x, y, x, y + cursorsize, color); gl_line(x + cursorsize, y, x + cursorsize, y + cursorsize, color); } FD_ZERO(&inputs); FD_SET(pipefd[0], &inputs); timeout.tv_sec = 0; timeout.tv_usec = 500000; /* 0.5 second time out */ event = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT, &inputs, NULL, NULL, &timeout); gl_putbox(x, y, 10, 10, bitmap); if (timeout.tv_sec || timeout.tv_usec) { /* No timeout. An actual event occured. Reset to visible cursor. Note: This is actually a bug as the cursor will get visible on time updates. However, it's better this way for demo/test purposes. */ drawcursor = 1; } else { drawcursor ^= 1; } if (FD_ISSET(pipefd[0], &inputs)) process_input(pipefd[0]); if (event & VGA_MOUSEEVENT) { x = mouse_getx(); y = mouse_gety(); button = mouse_getbutton(); if (button & MOUSE_LEFTBUTTON) gl_fillbox(x, y, cursorsize + 1, cursorsize + 1, color); if (button & MOUSE_RIGHTBUTTON) loop = 0; } if (event & VGA_KEYEVENT) { #ifdef USE_RAWKEYBOARD if (keyboard_keypressed(SCANCODE_1)) cursorsize = 0; if (keyboard_keypressed(SCANCODE_2)) cursorsize = 1; if (keyboard_keypressed(SCANCODE_3)) cursorsize = 2; if (keyboard_keypressed(SCANCODE_4)) cursorsize = 3; if (keyboard_keypressed(SCANCODE_5)) cursorsize = 4; if (keyboard_keypressed(SCANCODE_6)) cursorsize = 5; if (keyboard_keypressed(SCANCODE_7)) cursorsize = 6; if (keyboard_keypressed(SCANCODE_8)) cursorsize = 7; if (keyboard_keypressed(SCANCODE_9)) cursorsize = 8; if (keyboard_keypressed(SCANCODE_0)) cursorsize = 9; if (keyboard_keypressed(SCANCODE_Q)) loop = 0; if (keyboard_keypressed(SCANCODE_SPACE)) { if (!space_pressed) { color = newcolor(); space_pressed = 1; } } else { space_pressed = 0; } #else switch (vga_getch()) { case '1': cursorsize = 0; break; case '2': cursorsize = 1; break; case '3': cursorsize = 2; break; case '4': cursorsize = 3; break; case '5': cursorsize = 4; break; case '6': cursorsize = 5; break; case '7': cursorsize = 6; break; case '8': cursorsize = 7; break; case '9': cursorsize = 8; break; case '0': cursorsize = 9; break; case ' ': color = newcolor(); break; case 'q': case 'Q': loop = 0; break; default: ping(); break; } #endif } } #ifdef USE_RAWKEYBOARD keyboard_close(); /* Don't forget this! */ #endif vga_setmode(TEXT); exit(0); }