Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/hid/console/gcons.c

    r2ae1e6e r7e752b2  
    3838#include <stdio.h>
    3939#include <sys/mman.h>
    40 #include <string.h>
     40#include <str.h>
    4141#include <align.h>
    4242#include <bool.h>
     
    5454#define STATUS_HEIGHT  48
    5555
    56 #define MAIN_COLOR  0xffffff
     56#define COLOR_MAIN        0xffffff
     57#define COLOR_FOREGROUND  0x202020
     58#define COLOR_BACKGROUND  0xffffff
     59
     60extern char _binary_gfx_helenos_ppm_start[0];
     61extern int _binary_gfx_helenos_ppm_size;
     62extern char _binary_gfx_nameic_ppm_start[0];
     63extern int _binary_gfx_nameic_ppm_size;
     64
     65extern char _binary_gfx_anim_1_ppm_start[0];
     66extern int _binary_gfx_anim_1_ppm_size;
     67extern char _binary_gfx_anim_2_ppm_start[0];
     68extern int _binary_gfx_anim_2_ppm_size;
     69extern char _binary_gfx_anim_3_ppm_start[0];
     70extern int _binary_gfx_anim_3_ppm_size;
     71extern char _binary_gfx_anim_4_ppm_start[0];
     72extern int _binary_gfx_anim_4_ppm_size;
     73
     74extern char _binary_gfx_cons_selected_ppm_start[0];
     75extern int _binary_gfx_cons_selected_ppm_size;
     76extern char _binary_gfx_cons_idle_ppm_start[0];
     77extern int _binary_gfx_cons_idle_ppm_size;
     78extern char _binary_gfx_cons_has_data_ppm_start[0];
     79extern int _binary_gfx_cons_has_data_ppm_size;
     80extern char _binary_gfx_cons_kernel_ppm_start[0];
     81extern int _binary_gfx_cons_kernel_ppm_size;
    5782
    5883static bool use_gcons = false;
     
    82107static size_t active_console = 0;
    83108
    84 size_t mouse_x;
    85 size_t mouse_y;
    86 
    87 bool btn_pressed;
    88 size_t btn_x;
    89 size_t btn_y;
     109static ipcarg_t mouse_x = 0;
     110static ipcarg_t mouse_y= 0;
     111
     112static bool btn_pressed = false;
     113static ipcarg_t btn_x = 0;
     114static ipcarg_t btn_y = 0;
    90115
    91116static void vp_switch(int vp)
     
    95120
    96121/** Create view port */
    97 static int vp_create(size_t x, size_t y, size_t width, size_t height)
     122static int vp_create(ipcarg_t x, ipcarg_t y, ipcarg_t width, ipcarg_t height)
    98123{
    99124        return async_req_2_0(fbphone, FB_VIEWPORT_CREATE, (x << 16) | y,
     
    112137
    113138/** Transparent putchar */
    114 static void tran_putch(wchar_t ch, size_t col, size_t row)
     139static void tran_putch(wchar_t ch, ipcarg_t col, ipcarg_t row)
    115140{
    116141        async_msg_3(fbphone, FB_PUTCHAR, ch, col, row);
     
    132157               
    133158                char data[5];
    134                 snprintf(data, 5, "%u", index + 1);
     159                snprintf(data, 5, "%zu", index + 1);
    135160               
    136161                size_t i;
     
    259284void gcons_mouse_move(ssize_t dx, ssize_t dy)
    260285{
    261         mouse_x = limit(mouse_x + dx, 0, xres);
    262         mouse_y = limit(mouse_y + dy, 0, yres);
    263 
     286        ssize_t nx = (ssize_t) mouse_x + dx;
     287        ssize_t ny = (ssize_t) mouse_y + dy;
     288
     289        if (!use_gcons)
     290                return;
     291       
     292        mouse_x = (size_t) limit(nx, 0, xres);
     293        mouse_y = (size_t) limit(ny, 0, yres);
     294       
    264295        if (active_console != KERNEL_CONSOLE)
    265296                async_msg_2(fbphone, FB_POINTER_MOVE, mouse_x, mouse_y);
    266297}
    267298
    268 static int gcons_find_conbut(int x, int y)
    269 {
    270         int status_start = STATUS_START + (xres - 800) / 2;
     299static int gcons_find_conbut(ipcarg_t x, ipcarg_t y)
     300{
     301        ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
    271302       
    272303        if ((y < STATUS_TOP) || (y >= STATUS_TOP + STATUS_HEIGHT))
     
    278309        if (x >= status_start + (STATUS_WIDTH + STATUS_SPACE) * CONSOLE_COUNT)
    279310                return -1;
     311       
    280312        if (((x - status_start) % (STATUS_WIDTH + STATUS_SPACE)) < STATUS_SPACE)
    281313                return -1;
    282314       
    283         return (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
     315        ipcarg_t btn = (x - status_start) / (STATUS_WIDTH + STATUS_SPACE);
     316       
     317        if (btn < CONSOLE_COUNT)
     318                return btn;
     319       
     320        return -1;
    284321}
    285322
     
    287324 *
    288325 * @param state New state (true - pressed, false - depressed)
     326 *
    289327 */
    290328int gcons_mouse_btn(bool state)
    291329{
    292         int conbut;
     330        /* Ignore mouse clicks if no buttons
     331           are drawn at all */
     332        if (xres < 800)
     333                return -1;
    293334       
    294335        if (state) {
    295                 conbut = gcons_find_conbut(mouse_x, mouse_y);
     336                int conbut = gcons_find_conbut(mouse_x, mouse_y);
    296337                if (conbut != -1) {
    297338                        btn_pressed = true;
     
    307348        btn_pressed = false;
    308349       
    309         conbut = gcons_find_conbut(mouse_x, mouse_y);
     350        int conbut = gcons_find_conbut(mouse_x, mouse_y);
    310351        if (conbut == gcons_find_conbut(btn_x, btn_y))
    311352                return conbut;
     
    313354        return -1;
    314355}
    315 
    316356
    317357/** Draw a PPM pixmap to framebuffer
     
    321361 * @param x Coordinate of upper left corner
    322362 * @param y Coordinate of upper left corner
    323  */
    324 static void draw_pixmap(char *logo, size_t size, int x, int y)
    325 {
    326         char *shm;
    327         int rc;
    328        
     363 *
     364 */
     365static void draw_pixmap(char *logo, size_t size, ipcarg_t x, ipcarg_t y)
     366{
    329367        /* Create area */
    330         shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     368        char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    331369            MAP_ANONYMOUS, 0, 0);
    332370        if (shm == MAP_FAILED)
     
    336374       
    337375        /* Send area */
    338         rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
     376        int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
    339377        if (rc)
    340378                goto exit;
     
    356394}
    357395
    358 extern char _binary_gfx_helenos_ppm_start[0];
    359 extern int _binary_gfx_helenos_ppm_size;
    360 extern char _binary_gfx_nameic_ppm_start[0];
    361 extern int _binary_gfx_nameic_ppm_size;
    362 
    363396/** Redraws console graphics */
    364397void gcons_redraw_console(void)
    365398{
    366         int i;
    367        
    368399        if (!use_gcons)
    369400                return;
    370401       
    371402        vp_switch(0);
    372         set_rgb_color(MAIN_COLOR, MAIN_COLOR);
     403        set_rgb_color(COLOR_MAIN, COLOR_MAIN);
    373404        clear();
    374405        draw_pixmap(_binary_gfx_helenos_ppm_start,
     
    377408            (size_t) &_binary_gfx_nameic_ppm_size, 5, 17);
    378409       
     410        unsigned int i;
    379411        for (i = 0; i < CONSOLE_COUNT; i++)
    380412                redraw_state(i);
     
    393425static int make_pixmap(char *data, size_t size)
    394426{
    395         char *shm;
    396         int rc;
    397         int pxid = -1;
    398        
    399427        /* Create area */
    400         shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
     428        char *shm = mmap(NULL, size, PROTO_READ | PROTO_WRITE, MAP_SHARED |
    401429            MAP_ANONYMOUS, 0, 0);
    402430        if (shm == MAP_FAILED)
     
    405433        memcpy(shm, data, size);
    406434       
     435        int pxid = -1;
     436       
    407437        /* Send area */
    408         rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
     438        int rc = async_req_1_0(fbphone, FB_PREPARE_SHM, (ipcarg_t) shm);
    409439        if (rc)
    410440                goto exit;
     
    432462}
    433463
    434 extern char _binary_gfx_anim_1_ppm_start[0];
    435 extern int _binary_gfx_anim_1_ppm_size;
    436 extern char _binary_gfx_anim_2_ppm_start[0];
    437 extern int _binary_gfx_anim_2_ppm_size;
    438 extern char _binary_gfx_anim_3_ppm_start[0];
    439 extern int _binary_gfx_anim_3_ppm_size;
    440 extern char _binary_gfx_anim_4_ppm_start[0];
    441 extern int _binary_gfx_anim_4_ppm_size;
    442 
    443464static void make_anim(void)
    444465{
    445         int an = async_req_1_0(fbphone, FB_ANIM_CREATE, cstatus_vp[KERNEL_CONSOLE]);
     466        int an = async_req_1_0(fbphone, FB_ANIM_CREATE,
     467            cstatus_vp[KERNEL_CONSOLE]);
    446468        if (an < 0)
    447469                return;
    448470       
    449471        int pm = make_pixmap(_binary_gfx_anim_1_ppm_start,
    450             (int) &_binary_gfx_anim_1_ppm_size);
     472            (size_t) &_binary_gfx_anim_1_ppm_size);
    451473        async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
    452474       
    453475        pm = make_pixmap(_binary_gfx_anim_2_ppm_start,
    454             (int) &_binary_gfx_anim_2_ppm_size);
     476            (size_t) &_binary_gfx_anim_2_ppm_size);
    455477        async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
    456478       
    457479        pm = make_pixmap(_binary_gfx_anim_3_ppm_start,
    458             (int) &_binary_gfx_anim_3_ppm_size);
     480            (size_t) &_binary_gfx_anim_3_ppm_size);
    459481        async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
    460482       
    461483        pm = make_pixmap(_binary_gfx_anim_4_ppm_start,
    462             (int) &_binary_gfx_anim_4_ppm_size);
     484            (size_t) &_binary_gfx_anim_4_ppm_size);
    463485        async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
    464486       
     
    467489        animation = an;
    468490}
    469 
    470 extern char _binary_gfx_cons_selected_ppm_start[0];
    471 extern int _binary_gfx_cons_selected_ppm_size;
    472 extern char _binary_gfx_cons_idle_ppm_start[0];
    473 extern int _binary_gfx_cons_idle_ppm_size;
    474 extern char _binary_gfx_cons_has_data_ppm_start[0];
    475 extern int _binary_gfx_cons_has_data_ppm_size;
    476 extern char _binary_gfx_cons_kernel_ppm_start[0];
    477 extern int _binary_gfx_cons_kernel_ppm_size;
    478491
    479492/** Initialize nice graphical console environment */
     
    500513       
    501514        /* Create status buttons */
    502         size_t status_start = STATUS_START + (xres - 800) / 2;
     515        ipcarg_t status_start = STATUS_START + (xres - 800) / 2;
    503516        size_t i;
    504517        for (i = 0; i < CONSOLE_COUNT; i++) {
     
    511524               
    512525                vp_switch(cstatus_vp[i]);
    513                 set_rgb_color(0x202020, 0xffffff);
     526                set_rgb_color(COLOR_FOREGROUND, COLOR_BACKGROUND);
    514527        }
    515528       
Note: See TracChangeset for help on using the changeset viewer.