Index: draw.c =================================================================== --- draw.c (revision 25584) +++ draw.c (revision 25585) @@ -1,8 +1,38 @@ #include "main.h" +#include "hid.h" void pcbhl_expose_main(pcb_hid_t *hid, const pcb_hid_expose_ctx_t *region, pcb_xform_t *xform_caller) { + hle_line_t *l; + hle_rtree_it_t it; + hle_rtree_box_t qb; + pcb_hid_gc_t gc; + /* announce start of rendering */ + pcb_gui->render_burst(PCB_HID_BURST_START, ®ion->view); + + /* The canvas needs to be set up (reset) and put in positive drawing mode */ + pcb_gui->set_drawing_mode(PCB_HID_COMP_RESET, 1, ®ion->view); + pcb_gui->set_drawing_mode(PCB_HID_COMP_POSITIVE, 1, ®ion->view); + + /* gc is the pen */ + gc = pcb_gui->make_gc(); + pcb_gui->set_color(gc, pcb_color_black); + + /* do an rtree search on the visible region to see what needs to be drawn */ + qb.x1 = region->view.X1; + qb.y1 = region->view.Y1; + qb.x2 = region->view.X2; + qb.y2 = region->view.Y2; + for(l = hle_rtree_first(&it, &design.lines, &qb); l != NULL; l = hle_rtree_next(&it)) { + pcb_gui->set_line_width(gc, l->thick); + pcb_gui->set_line_cap(gc, pcb_cap_round); + pcb_gui->draw_line(gc, l->x1, l->y1, l->x2, l->y2); + } + + pcb_gui->set_drawing_mode(PCB_HID_COMP_FLUSH, 1, ®ion->view); + pcb_gui->destroy_gc(gc); + pcb_gui->render_burst(PCB_HID_BURST_END, ®ion->view); } void pcbhl_expose_preview(pcb_hid_t *hid, const pcb_hid_expose_ctx_t *e) Index: main.c =================================================================== --- main.c (revision 25584) +++ main.c (revision 25585) @@ -27,6 +27,26 @@ design_t design; +static void gen_lines(void) +{ + int n; + for(n = 0; n < 10; n++) { + hle_line_t *l = malloc(sizeof(hle_line_t)); + l->x1 = PCB_MM_TO_COORD(rand() % 100); + l->y1 = PCB_MM_TO_COORD(rand() % 100); + l->x2 = PCB_MM_TO_COORD(rand() % 100); + l->y2 = PCB_MM_TO_COORD(rand() % 100); + l->thick = PCB_MM_TO_COORD(rand() % 4); + + l->bbox.x1 = MIN(l->x1, l->x2) - l->thick; + l->bbox.y1 = MIN(l->y1, l->y2) - l->thick; + l->bbox.x2 = MAX(l->x1, l->x2) + l->thick; + l->bbox.y2 = MAX(l->y1, l->y2) + l->thick; + + hle_rtree_insert(&design.lines, l, &l->bbox); + } +} + int main(int argc, char *argv[]) { const char *gui_name = "gtk2_gdk"; @@ -34,7 +54,10 @@ design.hidlib.size_x = PCB_MM_TO_COORD(100); design.hidlib.size_y = PCB_MM_TO_COORD(100); design.hidlib.grid = PCB_MM_TO_COORD(1); + hle_rtree_init(&design.lines); + gen_lines(); + pcb_hidlib_init1(conf_core_init); pcb_hidlib_init2(pup_buildins); gui_act_init(); Index: main.h =================================================================== --- main.h (revision 25584) +++ main.h (revision 25585) @@ -3,9 +3,16 @@ #include "global_typedefs.h" #include "hidlib.h" +#include "rtree.h" +typedef struct hle_line_s { + hle_rtree_box_t bbox; + pcb_coord_t x1, y1, x2, y2, thick; +} hle_line_t; + typedef struct { pcb_hidlib_t hidlib; + hle_rtree_t lines; } design_t; extern design_t design;