Example #1
0
bool scroll_mmove(SCROLLABLE *s, int UNUSED(px), int UNUSED(py), int width, int height, int x, int y, int UNUSED(dx),
                  int dy) {
    bool draw = false;

    bool hit = inrect(x, y, s->left ? 0 : (width - SCROLL_WIDTH), 0, SCROLL_WIDTH, height);
    if (s->mouseover != hit) {
        s->mouseover = hit;
        draw         = true;
    }

    s->mouseover2 = inrect(x, y, 0, 0, width, height);

    if (s->mousedown) {
        uint32_t c = s->content_height;
        uint32_t h = height;

        if (c > h) {
            uint32_t m = (h * h) / c;
            double   d = (h - m);

            s->d = ((s->d * d) + (double)dy) / d;

            if (s->d < 0.0) {
                s->d = 0.0;
            } else if (s->d >= 1.0) {
                s->d = 1.0;
            }

            draw = true;
        }
    }

    return draw;
}
Example #2
0
static GLboolean
check_results(int dstx, int dsty, int w, int h)
{
	GLfloat *results;
	GLboolean pass = GL_TRUE;
	int x, y;

	results = malloc(w * h * 4 * sizeof(GLfloat));

	/* Check the results */
	glReadPixels(dstx, dsty, w, h, GL_RGBA, GL_FLOAT, results);
	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			GLfloat expected[3];

			if (inrect(x, y, 5, h/2, w - 5, h - 5)) {
				expected[0] = 0.0;
				expected[1] = 0.0;
				expected[2] = 1.0;
			} else if (inrect(x, y, 5, 5, w - 5, h/2)) {
				expected[0] = 0.0;
				expected[1] = 1.0;
				expected[2] = 0.0;
			} else {
				expected[0] = 1.0;
				expected[1] = 0.0;
				expected[2] = 0.0;
			}

			if (results[(y * w + x) * 4 + 0] != expected[0] ||
			    results[(y * w + x) * 4 + 1] != expected[1] ||
			    results[(y * w + x) * 4 + 2] != expected[2]) {
				printf("Expected at (%d,%d): %f,%f,%f\n",
				       x, y,
				       expected[0], expected[1], expected[2]);
				printf("Probed at   (%d,%d): %f,%f,%f\n",
				       x, y,
				       results[(y * w + x) * 4 + 0],
				       results[(y * w + x) * 4 + 1],
				       results[(y * w + x) * 4 + 2]);
				pass = GL_FALSE;
			}
		}
	}

	free(results);
	return pass;
}
Example #3
0
_Bool dropdown_mmove(DROPDOWN *d, int UNUSED(x), int y, int w, int h, int mx, int my, int UNUSED(dx), int UNUSED(dy)) {
    if (d->open) {
        int over = my / h + d->selected;

        if(y + h * d->dropcount > settings.window_height) {
            // over = my > 0 ? 0 : ((-my) / h + 1);
        }

        if (my < 0) over--;

        if (over < d->dropcount) {
            // over = index(d, over);
            if (over != d->over) {
                d->over = over;
                return 1;
            }
        }
    } else {
        _Bool mouseover = inrect(mx, my, 0, 0, w, h);
        if (mouseover != d->mouseover) {
            d->mouseover = mouseover;
            return 1;
        }
    }

    return 0;
}
Example #4
0
_Bool button_mmove(BUTTON *b, int UNUSED(x), int UNUSED(y), int width, int height, int mx, int my, int UNUSED(dx), int UNUSED(dy))
{
    // Ensure that font is set before calculating position and width.
    setfont(FONT_SELF_NAME);

    int real_x = 0, real_w = width;
    calculate_pos_and_width(b, &real_x, &real_w);

    _Bool mouseover = inrect(mx, my, real_x, 0, real_w, height);
    if(mouseover) {
        if(!b->disabled) {
            cursor = CURSOR_HAND;
        }

        if(maybe_i18nal_string_is_valid(&b->tooltip_text)) {
            tooltip_new(&b->tooltip_text);
        }

    }
    if(mouseover != b->mouseover) {
        b->mouseover = mouseover;
        return 1;
    }

    return 0;
}
Example #5
0
_Bool edit_mmove(EDIT *edit, int px, int py, int width, int height, int x, int y, int dx, int dy)
{
    if(utox_window_baseline && py > utox_window_baseline - font_small_lineheight - 4 * SCALE) {
        y += py - (utox_window_baseline - font_small_lineheight - 4 * SCALE);
        py = utox_window_baseline - font_small_lineheight - 4 * SCALE;
    }

    _Bool need_redraw = 0;

    _Bool mouseover = inrect(x, y, 0, 0, width - (edit->multiline ? SCROLL_WIDTH : 0), height);
    if(mouseover) {
        cursor = CURSOR_TEXT;
    }
    if(mouseover != edit->mouseover) {
        edit->mouseover = mouseover;
        if(edit != active_edit) {
            need_redraw = 1;
        }
    }

    if(edit->multiline) {
        need_redraw |= scroll_mmove(edit->scroll, px, py, width, height, x, y, dx, dy);
        y += scroll_gety(edit->scroll, height);
    }

    if(edit == active_edit && edit_select) {
        if (edit->select_completely) {
            edit_setfocus(edit);
            need_redraw = 1;
            return need_redraw;
        }
 
        setfont(FONT_TEXT);
        edit_sel.p2 = hittextmultiline(x - 2 * SCALE, width - 4 * SCALE - (edit->multiline ? SCROLL_WIDTH : 0), y - 2 * SCALE, INT_MAX, font_small_lineheight, edit->data, edit->length, edit->multiline);

        STRING_IDX start, length;
        if(edit_sel.p2 > edit_sel.p1) {
            start = edit_sel.p1;
            length = edit_sel.p2 - edit_sel.p1;
        } else {
            start = edit_sel.p2;
            length = edit_sel.p1 - edit_sel.p2;
        }

        if(start != edit_sel.start || length != edit_sel.length) {
            edit_sel.start = start;
            edit_sel.length = length;
            need_redraw = 1;
        }
    } else if(mouseover) {
        setfont(FONT_TEXT);
        edit->mouseover_char = hittextmultiline(x - 2 * SCALE, width - 4 * SCALE - (edit->multiline ? SCROLL_WIDTH : 0), y - 2 * SCALE, INT_MAX, font_small_lineheight, edit->data, edit->length, edit->multiline);
    }

    return need_redraw;
}
Example #6
0
_Bool button_mmove(BUTTON *b, int x, int y, int dy, int width, int height)
{
    _Bool mouseover = inrect(x, y, 0, 0, width, height);
    if(mouseover != b->mouseover) {
        b->mouseover = mouseover;
        return 1;
    }

    return 0;
}
Example #7
0
_Bool button_mmove(BUTTON *b, int UNUSED(x), int UNUSED(y), int width, int height, int mx, int my, int UNUSED(dx), int UNUSED(dy))
{
    // Ensure that font is set before calculating position and width.
    setfont(FONT_SELF_NAME);

    int real_x = 0, real_w = width;
    calculate_pos_and_width(b, &real_x, &real_w);

    _Bool mouseover = inrect(mx, my, real_x, 0, real_w, height);
    if(mouseover) {
        cursor = CURSOR_HAND;
    }
    if(mouseover != b->mouseover) {
        b->mouseover = mouseover;
        return 1;
    }

    return 0;
}
Example #8
0
_Bool contextmenu_mmove(int mx, int my, int UNUSED(dx), int UNUSED(dy))
{
    CONTEXTMENU *b = &context_menu;

    if(!b->open) {
        return 0;
    }

    cursor = CURSOR_NONE;

    // Ensure that font is set before calculating position and width.
    setfont(FONT_TEXT);
    setcolor(COLOR_BACKGROUND_MAIN);

    int x, w;
    calculate_pos_and_width(b, &x, &w);

    _Bool mouseover = inrect(mx, my, x, b->y, w, b->height);
    if(!mouseover) {
        if(b->over != 0xFF) {
            b->over = 0xFF;
            return 1;
        }
        return 0;
    }

    uint8_t over = (my - b->y) / CONTEXT_HEIGHT;
    if(over >= b->count) {
        over = 0xFF;
    }

    if(over != b->over) {
        b->over = over;
        return 1;
    }

    return 0;
}
Example #9
0
_Bool dropdown_mmove(DROPDOWN *b, int UNUSED(x), int y, int w, int h, int mx, int my, int UNUSED(dx), int UNUSED(dy))
{
    if(b->open) {
        int over = my / h;
        if(y + h * b->dropcount > utox_window_height) {
            over = my > 0 ? 0 : ((-my) / h + 1);
        }
        if(over < b->dropcount) {
            over = index(b, over);
            if(over != b->over) {
                b->over = over;
                return 1;
            }
        }
    } else {
        _Bool mouseover = inrect(mx, my, 0, 0, w, h);
        if(mouseover != b->mouseover) {
            b->mouseover = mouseover;
            return 1;
        }
    }

    return 0;
}
Example #10
0
bool PARTICLE::overlap (VERTEX * rect1, VERTEX * rect2)
{
	return (inrect(rect1, rect2[0]) || inrect(rect1, rect2[1]) 
			|| inrect(rect1, rect2[2]) || inrect(rect1, rect2[3]));
}