MCPcopy Create free account
hub / github.com/TASEmulators/fceux / gui_drawline_internal

Function gui_drawline_internal

src/lua-engine.cpp:3570–3642  ·  view source on GitHub ↗

draw a line on gui_data (checks boundaries)

Source from the content-addressed store, hash-verified

3568
3569// draw a line on gui_data (checks boundaries)
3570static void gui_drawline_internal(int x1, int y1, int x2, int y2, bool lastPixel, uint32 colour) {
3571
3572 //gui_prepare();
3573
3574 // Note: New version of Bresenham's Line Algorithm
3575 // http://groups.google.co.jp/group/rec.games.roguelike.development/browse_thread/thread/345f4c42c3b25858/29e07a3af3a450e6?show_docid=29e07a3af3a450e6
3576
3577 int swappedx = 0;
3578 int swappedy = 0;
3579
3580 int xtemp = x1-x2;
3581 int ytemp = y1-y2;
3582 if (xtemp == 0 && ytemp == 0) {
3583 gui_drawpixel_internal(x1, y1, colour);
3584 return;
3585 }
3586 if (xtemp < 0) {
3587 xtemp = -xtemp;
3588 swappedx = 1;
3589 }
3590 if (ytemp < 0) {
3591 ytemp = -ytemp;
3592 swappedy = 1;
3593 }
3594
3595 int delta_x = xtemp << 1;
3596 int delta_y = ytemp << 1;
3597
3598 signed char ix = x1 > x2?1:-1;
3599 signed char iy = y1 > y2?1:-1;
3600
3601 if (lastPixel)
3602 gui_drawpixel_internal(x2, y2, colour);
3603
3604 if (delta_x >= delta_y) {
3605 int error = delta_y - (delta_x >> 1);
3606
3607 while (x2 != x1) {
3608 if (error == 0 && !swappedx)
3609 gui_drawpixel_internal(x2+ix, y2, colour);
3610 if (error >= 0) {
3611 if (error || (ix > 0)) {
3612 y2 += iy;
3613 error -= delta_x;
3614 }
3615 }
3616 x2 += ix;
3617 gui_drawpixel_internal(x2, y2, colour);
3618 if (error == 0 && swappedx)
3619 gui_drawpixel_internal(x2, y2+iy, colour);
3620 error += delta_y;
3621 }
3622 }
3623 else {
3624 int error = delta_x - (delta_y >> 1);
3625
3626 while (y2 != y1) {
3627 if (error == 0 && !swappedy)

Callers 2

gui_drawbox_internalFunction · 0.85
gui_lineFunction · 0.85

Calls 1

gui_drawpixel_internalFunction · 0.85

Tested by

no test coverage detected