Subversion Repositories HelenOS-historic

Rev

Rev 1709 | Rev 1713 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1709 Rev 1711
Line 59... Line 59...
59
#include "fb.h"
59
#include "fb.h"
60
#include "main.h"
60
#include "main.h"
61
#include "../console/screenbuffer.h"
61
#include "../console/screenbuffer.h"
62
#include "ppm.h"
62
#include "ppm.h"
63
 
63
 
-
 
64
#include "pointer.xbm"
-
 
65
#include "pointer_mask.xbm"
-
 
66
 
64
#define DEFAULT_BGCOLOR                0xf0f0f0
67
#define DEFAULT_BGCOLOR                0xf0f0f0
65
#define DEFAULT_FGCOLOR                0x0
68
#define DEFAULT_FGCOLOR                0x0
66
 
69
 
67
/***************************************************************/
70
/***************************************************************/
68
/* Pixel specific fuctions */
71
/* Pixel specific fuctions */
Line 426... Line 429...
426
            break;
429
            break;
427
    }
430
    }
428
    if (i == MAX_VIEWPORTS)
431
    if (i == MAX_VIEWPORTS)
429
        return ELIMIT;
432
        return ELIMIT;
430
 
433
 
431
    if (width ==0 || height == 0 ||
-
 
432
        x+width > screen.xres || y+height > screen.yres)
-
 
433
        return EINVAL;
-
 
434
    if (width < FONT_SCANLINES || height < COL_WIDTH)
-
 
435
        return EINVAL;
-
 
436
 
-
 
437
    viewports[i].x = x;
434
    viewports[i].x = x;
438
    viewports[i].y = y;
435
    viewports[i].y = y;
439
    viewports[i].width = width;
436
    viewports[i].width = width;
440
    viewports[i].height = height;
437
    viewports[i].height = height;
441
   
438
   
Line 733... Line 730...
733
    if (handled)
730
    if (handled)
734
        ipc_answer_fast(callid, retval, 0, 0);
731
        ipc_answer_fast(callid, retval, 0, 0);
735
    return handled;
732
    return handled;
736
}
733
}
737
 
734
 
738
/** Save viewport to pixmap */
-
 
739
static int save_vp_to_pixmap(int vp)
735
static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
740
{
736
{
741
    int pm;
-
 
742
    pixmap_t *pmap;
-
 
743
    viewport_t *vport = &viewports[vp];
-
 
744
    int x,y;
737
    int x,y;
745
    int rowsize;
738
    int rowsize;
746
    int tmp;
739
    int tmp;
-
 
740
    int width = vport->width;
-
 
741
    int height = vport->height;
-
 
742
 
-
 
743
    if (width + vport->x > screen.xres)
-
 
744
        width = screen.xres - vport->x;
-
 
745
    if (height + vport->y  > screen.yres)
-
 
746
        height = screen.yres - vport->y;
-
 
747
 
-
 
748
    rowsize = width * screen.pixelbytes;
-
 
749
 
-
 
750
    for (y=0;y < height; y++) {
-
 
751
        tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
-
 
752
        memcpy(pmap->data + rowsize*y, screen.fbaddress + tmp, rowsize);
-
 
753
    }
-
 
754
}
-
 
755
 
-
 
756
/** Save viewport to pixmap */
-
 
757
static int save_vp_to_pixmap(viewport_t *vport)
-
 
758
{
-
 
759
    int pm;
-
 
760
    pixmap_t *pmap;
747
 
761
 
748
    pm = find_free_pixmap();
762
    pm = find_free_pixmap();
749
    if (pm == -1)
763
    if (pm == -1)
750
        return ELIMIT;
764
        return ELIMIT;
751
   
765
   
Line 754... Line 768...
754
    if (!pmap->data)
768
    if (!pmap->data)
755
        return ENOMEM;
769
        return ENOMEM;
756
 
770
 
757
    pmap->width = vport->width;
771
    pmap->width = vport->width;
758
    pmap->height = vport->height;
772
    pmap->height = vport->height;
-
 
773
 
-
 
774
    copy_vp_to_pixmap(vport, pmap);
759
   
775
   
760
    rowsize = vport->width * screen.pixelbytes;
-
 
761
    for (y=0;y < vport->height; y++) {
-
 
762
        tmp = (vport->y + y) * screen.scanline + vport->x * screen.pixelbytes;
-
 
763
        memcpy(pmap->data + rowsize*y, screen.fbaddress + tmp, rowsize);
-
 
764
    }
-
 
765
    return pm;
776
    return pm;
766
}
777
}
767
 
778
 
768
/** Draw pixmap on screen
779
/** Draw pixmap on screen
769
 *
780
 *
Line 775... Line 786...
775
    pixmap_t *pmap = &pixmaps[pm];
786
    pixmap_t *pmap = &pixmaps[pm];
776
    viewport_t *vport = &viewports[vp];
787
    viewport_t *vport = &viewports[vp];
777
    int x,y;
788
    int x,y;
778
    int tmp, srcrowsize;
789
    int tmp, srcrowsize;
779
    int realwidth, realheight, realrowsize;
790
    int realwidth, realheight, realrowsize;
-
 
791
    int width = vport->width;
-
 
792
    int height = vport->height;
-
 
793
 
-
 
794
    if (width + vport->x > screen.xres)
-
 
795
        width = screen.xres - vport->x;
-
 
796
    if (height + vport->y > screen.yres)
-
 
797
        height = screen.yres - vport->y;
780
 
798
 
781
    if (!pmap->data)
799
    if (!pmap->data)
782
        return EINVAL;
800
        return EINVAL;
783
 
801
 
784
    realwidth = pmap->width <= vport->width ? pmap->width : vport->width;
802
    realwidth = pmap->width <= width ? pmap->width : width;
785
    realheight = pmap->height <= vport->height ? pmap->height : vport->height;
803
    realheight = pmap->height <= height ? pmap->height : height;
786
 
804
 
787
    srcrowsize = vport->width * screen.pixelbytes;
805
    srcrowsize = vport->width * screen.pixelbytes;
788
    realrowsize = realwidth * screen.pixelbytes;
806
    realrowsize = realwidth * screen.pixelbytes;
789
 
807
 
790
    for (y=0; y < realheight; y++) {
808
    for (y=0; y < realheight; y++) {
Line 811... Line 829...
811
        draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]);
829
        draw_pixmap(animations[i].vp, animations[i].pixmaps[animations[i].pos]);
812
        animations[i].pos = (animations[i].pos+1) % animations[i].animlen;
830
        animations[i].pos = (animations[i].pos+1) % animations[i].animlen;
813
    }
831
    }
814
}
832
}
815
 
833
 
-
 
834
 
-
 
835
static int pointer_x, pointer_y;
-
 
836
static int pointer_shown;
-
 
837
static int pointer_vport = -1;
-
 
838
static int pointer_pixmap = -1;
-
 
839
 
-
 
840
static void mouse_show(void)
-
 
841
{
-
 
842
    int i,j;
-
 
843
    int visibility;
-
 
844
    int color;
-
 
845
    int bytepos;
-
 
846
 
-
 
847
    /* Save image under the cursor */
-
 
848
    if (pointer_vport == -1) {
-
 
849
        pointer_vport = viewport_create(pointer_x, pointer_y, pointer_width, pointer_height);
-
 
850
        if (pointer_vport < 0)
-
 
851
            return;
-
 
852
    } else {
-
 
853
        viewports[pointer_vport].x = pointer_x;
-
 
854
        viewports[pointer_vport].y = pointer_y;
-
 
855
    }
-
 
856
 
-
 
857
    if (pointer_pixmap == -1)
-
 
858
        pointer_pixmap = save_vp_to_pixmap(&viewports[pointer_vport]);
-
 
859
    else
-
 
860
        copy_vp_to_pixmap(&viewports[pointer_vport], &pixmaps[pointer_pixmap]);
-
 
861
 
-
 
862
    /* Draw cursor */
-
 
863
    for (i=0; i < pointer_height; i++)
-
 
864
        for (j=0;j < pointer_width; j++) {
-
 
865
            bytepos = i*((pointer_width-1)/8+1) + j/8;
-
 
866
            visibility = pointer_mask_bits[bytepos] & (1 << (j % 8));
-
 
867
            if (visibility) {
-
 
868
                color = pointer_bits[bytepos] & (1 << (j % 8)) ? 0 : 0xffffff;
-
 
869
                if (pointer_x+j < screen.xres && pointer_y+i < screen.yres)
-
 
870
                    putpixel(&viewports[0], pointer_x+j, pointer_y+i, color);
-
 
871
            }
-
 
872
        }
-
 
873
    pointer_shown = 1;
-
 
874
}
-
 
875
 
-
 
876
static void mouse_hide(void)
-
 
877
{
-
 
878
    /* Restore image under the cursor */
-
 
879
    if (pointer_shown) {
-
 
880
        draw_pixmap(pointer_vport, pointer_pixmap);
-
 
881
        pointer_shown = 0;
-
 
882
    }
-
 
883
}
-
 
884
 
-
 
885
static void mouse_move(unsigned int x, unsigned int y)
-
 
886
{
-
 
887
    mouse_hide();
-
 
888
    pointer_x = x;
-
 
889
    pointer_y = y;
-
 
890
    mouse_show();
-
 
891
}
-
 
892
 
816
static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
893
static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
817
{
894
{
818
    int handled = 1;
895
    int handled = 1;
819
    int retval = 0;
896
    int retval = 0;
820
    int i,nvp;
897
    int i,nvp;
Line 929... Line 1006...
929
        if (nvp == -1)
1006
        if (nvp == -1)
930
            nvp = vp;
1007
            nvp = vp;
931
        if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized)
1008
        if (nvp < 0 || nvp >= MAX_VIEWPORTS || !viewports[nvp].initialized)
932
            retval = EINVAL;
1009
            retval = EINVAL;
933
        else
1010
        else
934
            retval = save_vp_to_pixmap(nvp);
1011
            retval = save_vp_to_pixmap(&viewports[nvp]);
935
        break;
1012
        break;
936
    case FB_DROP_PIXMAP:
1013
    case FB_DROP_PIXMAP:
937
        i = IPC_GET_ARG1(*call);
1014
        i = IPC_GET_ARG1(*call);
938
        if (i >= MAX_PIXMAPS) {
1015
        if (i >= MAX_PIXMAPS) {
939
            retval = EINVAL;
1016
            retval = EINVAL;
Line 1123... Line 1200...
1123
            break;
1200
            break;
1124
        case FB_GET_RESOLUTION:
1201
        case FB_GET_RESOLUTION:
1125
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
1202
            ipc_answer_fast(callid, 0, screen.xres,screen.yres);
1126
            continue;
1203
            continue;
1127
        case FB_POINTER_MOVE:
1204
        case FB_POINTER_MOVE:
1128
            putpixel(&viewports[0], IPC_GET_ARG1(call), IPC_GET_ARG2(call),
1205
            mouse_move(IPC_GET_ARG1(call), IPC_GET_ARG2(call));
1129
                 0xd0a080);
-
 
1130
            break;
1206
            break;
1131
        default:
1207
        default:
1132
            retval = ENOENT;
1208
            retval = ENOENT;
1133
        }
1209
        }
1134
        ipc_answer_fast(callid,retval,0,0);
1210
        ipc_answer_fast(callid,retval,0,0);