static void dview_draw_outlined_box(DView *dv, int rtype, int x, int y, int w, int h, rgb_t bg) { rectangle r; dview_get_rect(dv, rtype, &r); ui_draw_outlined_box(dv->container, NX(dv, x + r.min_x), NY(dv, y + r.min_y), NX(dv, x + r.min_x + w), NY(dv, y + r.min_y + h), bg); }
static void dview_draw_size(DView *dv) { rectangle r; dview_get_rect(dv, RECT_DVIEW_SIZE, &r); dview_draw_outlined_box(dv, RECT_DVIEW_SIZE, 0, 0, rect_get_width(&r),rect_get_height(&r), MAKE_ARGB(0xff, 0xff, 0xff, 0x00)); }
static int dview_xy_in_rect(DView *dv, int type, int x, int y) { rectangle r; dview_get_rect(dv, type, &r); if (x >= r.min_x && x <= r.max_x && y >= r.min_y && y <= r.max_y) return TRUE; return FALSE; }
static void dview_draw_box(DView *dv, int rtype, int x, int y, int w, int h, rgb_t col) { rectangle r; dview_get_rect(dv, rtype, &r); dv->container->add_rect(NX(dv, x + r.min_x), NY(dv, y + r.min_y), NX(dv, x + r.min_x + w), NY(dv, y + r.min_y + h), col, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA)); }
static void dview_draw_size(DView *dv) { rectangle r; dview_get_rect(dv, RECT_DVIEW_SIZE, r); dview_draw_outlined_box(dv, RECT_DVIEW_SIZE, 0, 0, r.width(),r.height(), rgb_t(0xff, 0xff, 0xff, 0x00)); }
static int dview_xy_in_rect(DView *dv, int type, int x, int y) { rectangle r; dview_get_rect(dv, type, r); if (r.contains(x, y)) return TRUE; return FALSE; }
static void dview_draw_char(DView *dv, int rtype, int x, int y, int h, rgb_t col, UINT16 ch) { rectangle r; dview_get_rect(dv, rtype, &r); dv->container->add_char( NX(dv, x + r.min_x), NY(dv, y + r.min_y), NY(dv, h), debug_font_aspect, //(float) rect_get_height(&dv->bounds) / (float) rect_get_width(&dv->bounds), //render_get_ui_aspect(), col, *debug_font, ch); }
static void dview_draw_title(DView *dv) { int i; rgb_t col = MAKE_ARGB(0xff,0x00,0x00,0xff); rectangle r; dview_get_rect(dv, RECT_DVIEW_TITLE, &r); if (dv == focus_view) col = MAKE_ARGB(0xff,0x00,0x7f,0x00); dview_draw_outlined_box(dv, RECT_DVIEW_TITLE, 0, 0, rect_get_width(&dv->bounds), TITLE_HEIGHT, col); if (!dv->title) return; for (i=0; i<strlen(dv->title); i++) { dview_draw_char(dv, RECT_DVIEW_TITLE, i * debug_font_width + BORDER_XTHICKNESS, BORDER_YTHICKNESS, debug_font_height, //r.max_y - 2 * BORDER_YTHICKNESS, MAKE_ARGB(0xff,0xff,0xff,0xff), (UINT16) dv->title[i] ); } }
static void dview_draw_vsb(DView *dv) { int vt; int ts; //int sz = SLIDER_SIZE; int sz; rectangle r; adjustment *sb = &dv->vsb; dview_get_rect(dv, RECT_DVIEW_VSB, &r); dview_draw_outlined_box(dv, RECT_DVIEW_VSB, 0, rect_get_height(&r) - HSB_HEIGHT, VSB_WIDTH, HSB_HEIGHT, MAKE_ARGB(0xff, 0xff, 0x00, 0x00)); dview_draw_outlined_box(dv, RECT_DVIEW_VSB, 0, 0, VSB_WIDTH, HSB_HEIGHT, MAKE_ARGB(0xff, 0xff, 0x00, 0x00)); ts = (r.max_y - r.min_y + 1) - 2 * HSB_HEIGHT; sz = (ts * (sb->page_size)) / (sb->upper - sb->lower); ts = ts - sz; vt = (ts * (sb->value - sb->lower)) / (sb->upper - sb->lower - sb->page_size) + sz / 2 + HSB_HEIGHT; dview_draw_outlined_box(dv, RECT_DVIEW_VSB, 0, vt - sz / 2, VSB_WIDTH, sz, MAKE_ARGB(0xff, 0xff, 0x00, 0x00)); }
static void dview_draw_hsb(DView *dv) { int vt; int ts; //int sz = SLIDER_SIZE; int sz; rectangle r; adjustment *sb = &dv->hsb; dview_get_rect(dv, RECT_DVIEW_HSB, &r); dview_draw_outlined_box(dv, RECT_DVIEW_HSB, 0, 0, VSB_WIDTH,HSB_HEIGHT, MAKE_ARGB(0xff, 0xff, 0x00, 0x00)); dview_draw_outlined_box(dv, RECT_DVIEW_HSB, rect_get_width(&r) - VSB_WIDTH, 0, VSB_WIDTH, HSB_HEIGHT, MAKE_ARGB(0xff, 0xff, 0x00, 0x00)); ts = (r.max_x - r.min_x + 1) - 2 * VSB_WIDTH; sz = (ts * (sb->page_size)) / (sb->upper - sb->lower); ts = ts - sz; vt = (ts * (sb->value - sb->lower)) / (sb->upper - sb->lower - sb->page_size) + sz / 2 + r.min_x + VSB_WIDTH; dview_draw_outlined_box(dv, RECT_DVIEW_HSB, vt - sz / 2, 0, sz, HSB_HEIGHT, MAKE_ARGB(0xff, 0xff, 0x00, 0x00)); }
static int dview_on_mouse(DView *dv, int mx, int my, int button) { int clicked = (button && !dview_is_state(dv, VIEW_STATE_BUTTON)); int handled = TRUE; int x,y; if (button && dview_is_state_all(dv, VIEW_STATE_BUTTON | VIEW_STATE_MOVING)) { int dx = mx - dv->last_x; int dy = my - dv->last_y; dv->ofs_x += dx; dv->ofs_y += dy; dv->last_x = mx; dv->last_y = my; dview_set_state(dv, VIEW_STATE_NEEDS_UPDATE, TRUE); return TRUE; } else if (button && dview_is_state_all(dv, VIEW_STATE_BUTTON | VIEW_STATE_SIZING)) { int dx = mx - dv->last_x; int dy = my - dv->last_y; dv->bounds.max_x += dx; dv->bounds.max_y += dy; dv->last_x = mx; dv->last_y = my; dview_set_state(dv, VIEW_STATE_NEEDS_UPDATE, TRUE); return TRUE; } else dview_set_state(dv, VIEW_STATE_MOVING | VIEW_STATE_SIZING, FALSE); if (!map_point(dv, mx, my, &x, &y)) return FALSE; if (dview_xy_in_rect(dv, RECT_DVIEW_TITLE, x, y)) { /* on title, do nothing */ if (clicked) { dv->last_x = mx; dv->last_y = my; set_focus_view(dv); dview_set_state(dv, VIEW_STATE_MOVING, TRUE); } } else if (dview_xy_in_rect(dv, RECT_DVIEW_HSB, x, y)) { /* on horizontal scrollbar */ debug_view_xy pos; adjustment *sb = &dv->hsb; if (clicked) { rectangle r; int xt; dview_get_rect(dv, RECT_DVIEW_HSB, &r); x -= r.min_x; xt = (x - VSB_WIDTH) * (sb->upper - sb->lower) / (rect_get_width(&r) - 2 * dv->vsb.visible * VSB_WIDTH) + sb->lower; if (x < VSB_WIDTH) sb->value -= sb->step_increment; else if (x > rect_get_width(&r) - VSB_WIDTH) sb->value += sb->step_increment; else if (xt < sb->value) sb->value -= sb->page_increment; else if (xt > sb->value) sb->value += sb->page_increment; if (sb->value < sb->lower) sb->value = sb->lower; if (sb->value > sb->upper) sb->value = sb->upper; } pos = dv->view->visible_position(); if (sb->value != pos.x) { pos.x = sb->value; dv->view->set_visible_position(pos); dview_set_state(dv, VIEW_STATE_NEEDS_UPDATE, TRUE); } } else if (dview_xy_in_rect(dv, RECT_DVIEW_VSB, x, y) ) { /* on vertical scrollbar */ debug_view_xy pos; adjustment *sb = &dv->vsb; if (clicked) { rectangle r; int yt; dview_get_rect(dv, RECT_DVIEW_VSB, &r); y -= r.min_y; yt = (y - HSB_HEIGHT) * (sb->upper - sb->lower) / (rect_get_height(&r) - 2 * HSB_HEIGHT) + sb->lower; if (y < HSB_HEIGHT) sb->value -= sb->step_increment; else if (y > rect_get_height(&r) - HSB_HEIGHT) sb->value += sb->step_increment; else if (yt < sb->value) sb->value -= sb->page_increment; else if (yt > sb->value) sb->value += sb->page_increment; if (sb->value < sb->lower) sb->value = sb->lower; if (sb->value > sb->upper) sb->value = sb->upper; } pos = dv->view->visible_position(); if (sb->value != pos.y) { pos.y = sb->value; dv->view->set_visible_position(pos); dview_set_state(dv, VIEW_STATE_NEEDS_UPDATE, TRUE); } } else if (dview_xy_in_rect(dv, RECT_DVIEW_SIZE, x, y)) { /* on sizing area */ if (clicked) { dv->last_x = mx; dv->last_y = my; set_focus_view(dv); dview_set_state(dv, VIEW_STATE_SIZING, TRUE); } } else if (dview_xy_in_rect(dv, RECT_DVIEW_CLIENT, x, y)) { y -= TITLE_HEIGHT; if (dv->view->cursor_supported() && clicked && y >= 0) { debug_view_xy topleft = dv->view->visible_position(); debug_view_xy newpos; newpos.x = topleft.x + x / debug_font_width; newpos.y = topleft.y + y / debug_font_height; dv->view->set_cursor_position(newpos); dv->view->set_cursor_visible(true); } if (clicked) set_focus_view(dv); } else { handled = FALSE; } dview_set_state(dv, VIEW_STATE_BUTTON, button); return handled; }