Changeset 351


Ignore:
Timestamp:
Jan 14, 2004, 11:34:20 AM (18 years ago)
Author:
Sam Hocevar
Message:
  • src/event.c: + Make sure the mouse coordinates stay within the screen boundaries even

if the window was resized.

  • src/bitmap.c: + Fixed a buffer underflow in the rendering routine that caused the bottom

and rightmost pixels to be missed in certain conditions.

+ Minor speed optimisation.

Location:
libcaca/trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/src/bitmap.c

    r326 r351  
    457457        "????";
    458458
    459     int x, y, w, h, pitch;
     459    int x, y, w, h, pitch, deltax, deltay;
    460460
    461461    if(!bitmap || !pixels)
     
    475475        int tmp = y2; y2 = y1; y1 = tmp;
    476476    }
     477
     478    deltax = x2 - x1 + 1;
     479    deltay = y2 - y1 + 1;
    477480
    478481    switch(_caca_dithering)
     
    530533        if(_caca_antialiasing == CACA_ANTIALIASING_PREFILTER)
    531534        {
    532             fromx = ((x - x1) * (w - 1)) / (x2 - x1 + 1);
    533             fromy = ((y - y1) * (h - 1)) / (y2 - y1 + 1);
    534             tox = ((x - x1 + 1) * (w - 1)) / (x2 - x1 + 1);
    535             toy = ((y - y1 + 1) * (h - 1)) / (y2 - y1 + 1);
     535            fromx = (x - x1) * w / deltax;
     536            fromy = (y - y1) * h / deltay;
     537            tox = (x - x1 + 1) * w / deltax;
     538            toy = (y - y1 + 1) * h / deltay;
     539
     540            /* We want at least one pixel */
     541            if(tox == fromx) tox++;
     542            if(toy == fromy) toy++;
     543
    536544            dots = 0;
    537545
    538             for(myx = fromx; myx <= tox; myx++)
    539                 for(myy = fromy; myy <= toy; myy++)
     546            for(myx = fromx; myx < tox; myx++)
     547                for(myy = fromy; myy < toy; myy++)
    540548            {
    541549                dots++;
     
    551559        else
    552560        {
    553             fromx = ((x - x1) * (w - 1)) / (x2 - x1 + 1);
    554             fromy = ((y - y1) * (h - 1)) / (y2 - y1 + 1);
    555             tox = ((x - x1 + 1) * (w - 1)) / (x2 - x1 + 1);
    556             toy = ((y - y1 + 1) * (h - 1)) / (y2 - y1 + 1);
    557 
     561            fromx = (x - x1) * w / deltax;
     562            fromy = (y - y1) * h / deltay;
     563            tox = (x - x1 + 1) * w / deltax;
     564            toy = (y - y1 + 1) * h / deltay;
     565
     566            /* tox and toy can overflow the screen, but they cannot overflow
     567             * when averaged with fromx and fromy because these are guaranteed
     568             * to be within the pixel boundaries. */
    558569            myx = (fromx + tox) / 2;
    559570            myy = (fromy + toy) / 2;
  • libcaca/trunk/src/event.c

    r349 r351  
    144144unsigned int caca_get_mouse_x(void)
    145145{
     146    if(mouse_x >= _caca_width)
     147        mouse_x = _caca_width - 1;
     148
    146149    return mouse_x;
    147150}
     
    158161unsigned int caca_get_mouse_y(void)
    159162{
     163    if(mouse_y >= _caca_height)
     164        mouse_y = _caca_height - 1;
     165
    160166    return mouse_y;
    161167}
Note: See TracChangeset for help on using the changeset viewer.