Mercurial > dwindows
comparison dwtest.c @ 2360:98d0873d9c05
Rewrite the render code to use the new dw_render_redraw() to trigger expose
events instead of calling the expose function directly. This is cleaner and
allows GTK4 and GTK3 with Wayland to draw in a single pass.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 12 Mar 2021 15:00:03 +0000 |
parents | dfb52d2bddaa |
children | 7d54728064a3 |
comparison
equal
deleted
inserted
replaced
2359:707836e00e5e | 2360:98d0873d9c05 |
---|---|
121 labelarray[MAX_WIDGETS], | 121 labelarray[MAX_WIDGETS], |
122 entryarray[MAX_WIDGETS], | 122 entryarray[MAX_WIDGETS], |
123 filetoolbarbox; | 123 filetoolbarbox; |
124 | 124 |
125 HMENUI mainmenubar,changeable_menu; | 125 HMENUI mainmenubar,changeable_menu; |
126 #define CHECKABLE_MENUITEMID 2001 | 126 #define CHECKABLE_MENUITEMID 2001 |
127 #define NONCHECKABLE_MENUITEMID 2002 | 127 #define NONCHECKABLE_MENUITEMID 2002 |
128 | 128 |
129 #define SHAPES_DOUBLE_BUFFERED 0 | |
130 #define SHAPES_DIRECT 1 | |
131 #define DRAW_FILE 2 | |
132 | |
129 void *containerinfo; | 133 void *containerinfo; |
130 | |
131 | 134 |
132 int menu_enabled = 1; | 135 int menu_enabled = 1; |
133 | 136 |
134 HPIXMAP text1pm,text2pm,image; | 137 HPIXMAP text1pm,text2pm,image; |
135 HICN fileicon,foldericon; | 138 HICN fileicon,foldericon; |
143 int timerid; | 146 int timerid; |
144 int num_lines=0; | 147 int num_lines=0; |
145 int max_linewidth=0; | 148 int max_linewidth=0; |
146 int current_row=0,current_col=0; | 149 int current_row=0,current_col=0; |
147 int cursor_arrow = 1; | 150 int cursor_arrow = 1; |
148 int render_type = 0; | 151 int render_type = SHAPES_DOUBLE_BUFFERED; |
149 | 152 |
150 FILE *fp=NULL; | 153 FILE *fp=NULL; |
151 char **lp; | 154 char **lp; |
152 | 155 |
153 char *resolve_keyname( int vk ) | 156 char *resolve_keyname( int vk ) |
260 void update_render(void); | 263 void update_render(void); |
261 | 264 |
262 /* This gets called when a part of the graph needs to be repainted. */ | 265 /* This gets called when a part of the graph needs to be repainted. */ |
263 int DWSIGNAL text_expose(HWND hwnd, DWExpose *exp, void *data) | 266 int DWSIGNAL text_expose(HWND hwnd, DWExpose *exp, void *data) |
264 { | 267 { |
265 if(render_type != 1) | 268 if(render_type != SHAPES_DIRECT) |
266 { | 269 { |
267 HPIXMAP hpm; | 270 HPIXMAP hpm; |
268 unsigned long width,height; | 271 unsigned long width,height; |
269 | 272 |
270 if ( hwnd == textbox1 ) | 273 if ( hwnd == textbox1 ) |
342 sprintf( buf, "%6.6d", i+row ); | 345 sprintf( buf, "%6.6d", i+row ); |
343 dw_draw_text( 0, text1pm, 0, y, buf); | 346 dw_draw_text( 0, text1pm, 0, y, buf); |
344 } | 347 } |
345 pLine = lp[i+row]; | 348 pLine = lp[i+row]; |
346 dw_draw_text( 0, hpm, 0, y, pLine+col ); | 349 dw_draw_text( 0, hpm, 0, y, pLine+col ); |
347 } | |
348 if(!hpma) | |
349 { | |
350 text_expose( textbox1, NULL, NULL); | |
351 text_expose( textbox2, NULL, NULL); | |
352 } | 350 } |
353 } | 351 } |
354 } | 352 } |
355 | 353 |
356 /* When hpma is not NULL we are printing.. so handle things differently */ | 354 /* When hpma is not NULL we are printing.. so handle things differently */ |
394 if(image_stretch) | 392 if(image_stretch) |
395 dw_pixmap_stretch_bitblt(window, pixmap, 10, 10, width - 20, height - 20, 0, image, 0, 0, (int)DW_PIXMAP_WIDTH(image), (int)DW_PIXMAP_HEIGHT(image)); | 393 dw_pixmap_stretch_bitblt(window, pixmap, 10, 10, width - 20, height - 20, 0, image, 0, 0, (int)DW_PIXMAP_WIDTH(image), (int)DW_PIXMAP_HEIGHT(image)); |
396 else | 394 else |
397 dw_pixmap_bitblt(window, pixmap, image_x, image_y, (int)DW_PIXMAP_WIDTH(image), (int)DW_PIXMAP_HEIGHT(image), 0, image, 0, 0); | 395 dw_pixmap_bitblt(window, pixmap, image_x, image_y, (int)DW_PIXMAP_WIDTH(image), (int)DW_PIXMAP_HEIGHT(image), 0, image, 0, 0); |
398 } | 396 } |
399 | |
400 /* If we aren't drawing direct do a bitblt */ | |
401 if(!direct && !hpma) | |
402 { | |
403 text_expose( textbox2, NULL, NULL); | |
404 } | |
405 } | 397 } |
406 | 398 |
407 void update_render(void) | 399 void update_render(void) |
408 { | 400 { |
409 switch(render_type) | 401 switch(render_type) |
410 { | 402 { |
411 case 0: | 403 case SHAPES_DOUBLE_BUFFERED: |
412 draw_shapes(FALSE, NULL); | 404 draw_shapes(FALSE, NULL); |
413 break; | 405 break; |
414 case 1: | 406 case SHAPES_DIRECT: |
415 draw_shapes(TRUE, NULL); | 407 draw_shapes(TRUE, NULL); |
416 break; | 408 break; |
417 case 2: | 409 case DRAW_FILE: |
418 draw_file(current_row, current_col, rows, font_height, NULL); | 410 draw_file(current_row, current_col, rows, font_height, NULL); |
419 break; | 411 break; |
420 } | 412 } |
413 } | |
414 | |
415 /* Request that the render widgets redraw... | |
416 * If not using direct rendering, call update_render() to | |
417 * redraw the in memory pixmaps. Then trigger the expose events. | |
418 * Expose will call update_render() to draw directly or bitblt the pixmaps. | |
419 */ | |
420 void render_draw(void) | |
421 { | |
422 /* If we are double buffered, draw to the pixmaps */ | |
423 if(render_type != SHAPES_DIRECT) | |
424 update_render(); | |
425 /* Trigger expose event */ | |
426 dw_render_redraw(textbox1); | |
427 dw_render_redraw(textbox2); | |
421 } | 428 } |
422 | 429 |
423 int DWSIGNAL draw_page(HPRINT print, HPIXMAP pixmap, int page_num, void *data) | 430 int DWSIGNAL draw_page(HPRINT print, HPIXMAP pixmap, int page_num, void *data) |
424 { | 431 { |
425 dw_pixmap_set_font(pixmap, FIXEDFONT); | 432 dw_pixmap_set_font(pixmap, FIXEDFONT); |
470 return FALSE; | 477 return FALSE; |
471 } | 478 } |
472 | 479 |
473 int DWSIGNAL refresh_callback(HWND window, void *data) | 480 int DWSIGNAL refresh_callback(HWND window, void *data) |
474 { | 481 { |
475 update_render(); | 482 render_draw(); |
476 return FALSE; | 483 return FALSE; |
477 } | 484 } |
478 | 485 |
479 int DWSIGNAL render_select_event_callback(HWND window, int index) | 486 int DWSIGNAL render_select_event_callback(HWND window, int index) |
480 { | 487 { |
481 if(index != render_type) | 488 if(index != render_type) |
482 { | 489 { |
483 if(index == 2) | 490 if(index == DRAW_FILE) |
484 { | 491 { |
485 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); | 492 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); |
486 dw_scrollbar_set_pos(hscrollbar, 0); | 493 dw_scrollbar_set_pos(hscrollbar, 0); |
487 dw_scrollbar_set_range(vscrollbar, num_lines, rows); | 494 dw_scrollbar_set_range(vscrollbar, num_lines, rows); |
488 dw_scrollbar_set_pos(vscrollbar, 0); | 495 dw_scrollbar_set_pos(vscrollbar, 0); |
494 dw_scrollbar_set_pos(hscrollbar, 0); | 501 dw_scrollbar_set_pos(hscrollbar, 0); |
495 dw_scrollbar_set_range(vscrollbar, 0, 0); | 502 dw_scrollbar_set_range(vscrollbar, 0, 0); |
496 dw_scrollbar_set_pos(vscrollbar, 0); | 503 dw_scrollbar_set_pos(vscrollbar, 0); |
497 } | 504 } |
498 render_type = index; | 505 render_type = index; |
499 update_render(); | 506 render_draw(); |
500 } | 507 } |
501 return FALSE; | 508 return FALSE; |
502 } | 509 } |
503 | 510 |
504 int DWSIGNAL colorchoose_callback(HWND window, void *data) | 511 int DWSIGNAL colorchoose_callback(HWND window, void *data) |
609 } | 616 } |
610 current_file = tmp; | 617 current_file = tmp; |
611 dw_window_set_text( entryfield, current_file ); | 618 dw_window_set_text( entryfield, current_file ); |
612 read_file(); | 619 read_file(); |
613 current_col = current_row = 0; | 620 current_col = current_row = 0; |
614 update_render(); | 621 render_draw(); |
615 dw_signal_connect(notification, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(notification_clicked_callback), NULL); | 622 dw_signal_connect(notification, DW_SIGNAL_CLICKED, DW_SIGNAL_FUNC(notification_clicked_callback), NULL); |
616 dw_notification_send(notification); | 623 dw_notification_send(notification); |
617 } | 624 } |
618 dw_window_set_focus(copypastefield); | 625 dw_window_set_focus(copypastefield); |
619 return 0; | 626 return 0; |
694 { | 701 { |
695 if(data) | 702 if(data) |
696 { | 703 { |
697 HWND stext = (HWND)data; | 704 HWND stext = (HWND)data; |
698 char tmpbuf[100]; | 705 char tmpbuf[100]; |
706 | |
699 if ( hwnd == vscrollbar ) | 707 if ( hwnd == vscrollbar ) |
700 { | 708 { |
701 current_row = value; | 709 current_row = value; |
702 } | 710 } |
703 else | 711 else |
704 { | 712 { |
705 current_col = value; | 713 current_col = value; |
706 } | 714 } |
707 sprintf(tmpbuf, "Row:%d Col:%d Lines:%d Cols:%d", current_row,current_col,num_lines,max_linewidth); | 715 sprintf(tmpbuf, "Row:%d Col:%d Lines:%d Cols:%d", current_row,current_col,num_lines,max_linewidth); |
708 dw_window_set_text(stext, tmpbuf); | 716 dw_window_set_text(stext, tmpbuf); |
709 update_render(); | 717 render_draw(); |
710 } | 718 } |
711 } | 719 } |
712 | 720 |
713 /* Callback to handle user selection of the spinbutton position */ | 721 /* Callback to handle user selection of the spinbutton position */ |
714 void DWSIGNAL spinbutton_valuechanged_callback(HWND hwnd, int value, void *data) | 722 void DWSIGNAL spinbutton_valuechanged_callback(HWND hwnd, int value, void *data) |
745 | 753 |
746 /* Update scrollbar ranges with new values */ | 754 /* Update scrollbar ranges with new values */ |
747 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); | 755 dw_scrollbar_set_range(hscrollbar, max_linewidth, cols); |
748 dw_scrollbar_set_range(vscrollbar, num_lines, rows); | 756 dw_scrollbar_set_range(vscrollbar, num_lines, rows); |
749 | 757 |
750 /* Redraw the window */ | 758 /* Redraw the render widgets */ |
751 update_render(); | 759 render_draw(); |
752 return TRUE; | 760 return TRUE; |
753 } | 761 } |
754 | 762 |
755 int DWSIGNAL item_enter_cb( HWND window, char *text, void *data, void *itemdata ) | 763 int DWSIGNAL item_enter_cb( HWND window, char *text, void *data, void *itemdata ) |
756 { | 764 { |