... | ... |
@@ -48,7 +48,7 @@ static int reui_fillrounded(SDL_Surface *dst, int xo, int yo, int w, int h, int |
48 | 48 |
static int reui_triangle(SDL_Surface *dst, int x, int y, int w, int h, char direction, const char *rgba); |
49 | 49 |
|
50 | 50 |
reui_t * |
51 |
-reui_init(int fontheight) |
|
51 |
+reui_init(int fontheight, reui_t *parent) |
|
52 | 52 |
{ |
53 | 53 |
reui_t *ui; |
54 | 54 |
SDL_Rect screenrect; |
... | ... |
@@ -70,10 +70,16 @@ reui_init(int fontheight) |
70 | 70 |
ui->amask=0xff000000; |
71 | 71 |
#endif |
72 | 72 |
/* video */ |
73 |
- if(SDL_Init(SDL_INIT_VIDEO)<0 |
|
74 |
- || SDL_GetDisplayBounds(0,&screenrect)!=0) { |
|
75 |
- reui_free(ui),ui=NULL; |
|
76 |
- return(NULL); |
|
73 |
+ if(parent==NULL) { |
|
74 |
+ if(SDL_Init(SDL_INIT_VIDEO)<0 |
|
75 |
+ || SDL_GetDisplayBounds(0,&screenrect)!=0) { |
|
76 |
+ reui_free(ui),ui=NULL; |
|
77 |
+ return(NULL); |
|
78 |
+ } |
|
79 |
+ } else { |
|
80 |
+ ui->parent=(void *)parent; |
|
81 |
+ screenrect.w=parent->screenw; |
|
82 |
+ screenrect.h=parent->screenh; |
|
77 | 83 |
} |
78 | 84 |
ui->screenw=screenrect.w; |
79 | 85 |
ui->screenh=screenrect.h; |
... | ... |
@@ -143,7 +149,7 @@ reui_free(reui_t *ui) |
143 | 149 |
SDL_DestroyTexture(ui->onepx),ui->onepx=NULL; |
144 | 150 |
if(ui->font!=NULL) |
145 | 151 |
TTF_CloseFont(ui->font),ui->font=NULL; |
146 |
- if(TTF_WasInit()) |
|
152 |
+ if(ui->parent==NULL && TTF_WasInit()) |
|
147 | 153 |
TTF_Quit(); |
148 | 154 |
if(ui->fontdata!=NULL) |
149 | 155 |
SDL_FreeRW(ui->fontdata),ui->fontdata=NULL; |
... | ... |
@@ -153,7 +159,8 @@ reui_free(reui_t *ui) |
153 | 159 |
SDL_DestroyRenderer(ui->renderer),ui->renderer=NULL; |
154 | 160 |
if(ui->win!=NULL) |
155 | 161 |
SDL_DestroyWindow(ui->win),ui->win=NULL; |
156 |
- SDL_Quit(); |
|
162 |
+ if(ui->parent==NULL) |
|
163 |
+ SDL_Quit(); |
|
157 | 164 |
free(ui),ui=NULL; |
158 | 165 |
} |
159 | 166 |
|
... | ... |
@@ -18,6 +18,7 @@ |
18 | 18 |
|
19 | 19 |
|
20 | 20 |
typedef struct reui_t { |
21 |
+ void *parent; |
|
21 | 22 |
int screenw,screenh; |
22 | 23 |
int w,h; |
23 | 24 |
Uint32 rmask, gmask, bmask, amask; |
... | ... |
@@ -33,7 +34,7 @@ typedef struct reui_t { |
33 | 34 |
int rendererdirty; |
34 | 35 |
} reui_t; |
35 | 36 |
|
36 |
-reui_t *reui_init(int fontheight); |
|
37 |
+reui_t *reui_init(int fontheight, reui_t *parent); |
|
37 | 38 |
void reui_free(reui_t *ui); |
38 | 39 |
|
39 | 40 |
int reui_title(reui_t *ui, char *titlefilename); |
... | ... |
@@ -29,6 +29,7 @@ |
29 | 29 |
#define COMMANDBUFSIZE 1024 |
30 | 30 |
#define DEFAULTFONTHEIGHT 14 |
31 | 31 |
#define SELECTBUFBLOCK 16384 |
32 |
+#define SIZEBLOCKPRINTS 32 |
|
32 | 33 |
|
33 | 34 |
#define COMMAND_WARNING "(!)" |
34 | 35 |
#define COMMAND_INFO "(i)" |
... | ... |
@@ -56,6 +57,14 @@ |
56 | 57 |
#define COLOR_INFOFG "\xee\xee\x46\xff" |
57 | 58 |
#define COLOR_INFOFGLIGHT "\x84\xa4\x4c\xff" |
58 | 59 |
|
60 |
+typedef struct print_t { |
|
61 |
+ reui_t *ui; |
|
62 |
+ redata_t *data; |
|
63 |
+ int originline; |
|
64 |
+ int origincol; |
|
65 |
+ int dirty; |
|
66 |
+} printout_t; |
|
67 |
+ |
|
59 | 68 |
typedef struct re_t { |
60 | 69 |
redata_t *data; |
61 | 70 |
reui_t *ui; |
... | ... |
@@ -82,6 +91,9 @@ typedef struct re_t { |
82 | 91 |
question_t *question; |
83 | 92 |
int showingwarning; |
84 | 93 |
int ignorenkeys; |
94 |
+ int sizeprints; |
|
95 |
+ int usedprints; |
|
96 |
+ printout_t *prints; |
|
85 | 97 |
} re_t; |
86 | 98 |
|
87 | 99 |
volatile int flag_sigint; |
... | ... |
@@ -119,11 +131,13 @@ int re_sel_lincolisend(re_t *re, int line, int col); |
119 | 131 |
int re_selectbuf_resize(re_t *re,long size); |
120 | 132 |
int re_selectbuf_fill(re_t *re,long frompos,long size, int nadditionalspaces); |
121 | 133 |
int re_selectbuf_replace(re_t *re,char *newdata); |
134 |
+int re_addprint(re_t *re); |
|
135 |
+int re_delprint(re_t *re, int nprint); |
|
122 | 136 |
int re_rtrim(re_t *re, long curpos, int *trimmed); |
123 | 137 |
long re_getmatchingbracket(re_t *re,long posini, char originalchar, char *matchingchar); |
124 | 138 |
int re_drawheader_editing(re_t *re); |
125 | 139 |
int re_drawheader_command(re_t *re); |
126 |
-int re_drawcontents(re_t *re); |
|
140 |
+int re_drawcontents(re_t *re, printout_t *printout); |
|
127 | 141 |
|
128 | 142 |
int |
129 | 143 |
main(int argc, char *argv[]) |
... | ... |
@@ -135,6 +149,7 @@ main(int argc, char *argv[]) |
135 | 149 |
int flag_had_events; |
136 | 150 |
time_t lastidle,now; |
137 | 151 |
int load_pending; |
152 |
+ int i; |
|
138 | 153 |
if(argc!=2 || strcmp(argv[argc-1],"--help")==0) { |
139 | 154 |
fprintf(stderr,"Syntax: %s filename\n",argv[0]); |
140 | 155 |
return(1); |
... | ... |
@@ -224,18 +239,64 @@ fprintf(stderr,"REDRAW Header (command)\n"); |
224 | 239 |
} |
225 | 240 |
} |
226 | 241 |
if(re->contentsdirty) |
227 |
- re_drawcontents(re); |
|
242 |
+ re_drawcontents(re,NULL); |
|
228 | 243 |
if(re->ui->rendererdirty) { |
229 | 244 |
#if 0 |
230 | 245 |
fprintf(stderr,"RENDER\n"); |
231 | 246 |
#endif |
232 | 247 |
reui_present(re->ui); |
233 | 248 |
} |
249 |
+ for(i=0;i<re->sizeprints;i++) { |
|
250 |
+ if(re->prints[i].ui==NULL) |
|
251 |
+ continue; |
|
252 |
+ if(re->prints[i].dirty) |
|
253 |
+ re_drawcontents(re,re->prints+i); |
|
254 |
+ if(re->prints[i].ui->rendererdirty) |
|
255 |
+ reui_present(re->prints[i].ui); |
|
256 |
+ } |
|
234 | 257 |
sselect_wait(ssel,(flag_had_events)?10:100); |
235 | 258 |
flag_had_events=(flag_had_events>0)?flag_had_events-1:0; |
236 | 259 |
SDL_PumpEvents(); |
237 | 260 |
while(SDL_PeepEvents(&event,1,SDL_GETEVENT,SDL_FIRSTEVENT,SDL_LASTEVENT)>0) { |
261 |
+ Uint32 windowID; |
|
238 | 262 |
flag_had_events=10; |
263 |
+ /* Process printout events */ |
|
264 |
+ if((event.type==SDL_WINDOWEVENT && (windowID=event.window.windowID)!=SDL_GetWindowID(re->ui->win)) |
|
265 |
+ || (event.type==SDL_KEYDOWN && (windowID=event.key.windowID)!=SDL_GetWindowID(re->ui->win)) |
|
266 |
+ || (event.type==SDL_TEXTEDITING && (windowID=event.edit.windowID)!=SDL_GetWindowID(re->ui->win)) |
|
267 |
+ || (event.type==SDL_TEXTINPUT && (windowID=event.text.windowID)!=SDL_GetWindowID(re->ui->win)) |
|
268 |
+ ) { |
|
269 |
+ for(i=0;i<re->sizeprints;i++) { |
|
270 |
+ if(re->prints[i].ui!=NULL |
|
271 |
+ && windowID==SDL_GetWindowID(re->prints[i].ui->win)) { |
|
272 |
+ break; |
|
273 |
+ } |
|
274 |
+ } |
|
275 |
+ if(i>=re->sizeprints) |
|
276 |
+ continue; /* unknown window */ |
|
277 |
+ switch(event.type) { |
|
278 |
+ case SDL_WINDOWEVENT: |
|
279 |
+ if(event.window.event==SDL_WINDOWEVENT_SHOWN |
|
280 |
+ || event.window.event==SDL_WINDOWEVENT_EXPOSED) { |
|
281 |
+ re->prints[i].dirty=1; |
|
282 |
+ } else if((event.window.event==SDL_WINDOWEVENT_RESIZED |
|
283 |
+ || event.window.event==SDL_WINDOWEVENT_SIZE_CHANGED) |
|
284 |
+ && (event.window.data1!=re->prints[i].ui->w || event.window.data2!=re->prints[i].ui->h)) { |
|
285 |
+ reui_resize(re->prints[i].ui,event.window.data1,event.window.data2); |
|
286 |
+ re->prints[i].dirty=1; |
|
287 |
+ } else if(event.window.event==SDL_WINDOWEVENT_CLOSE) { |
|
288 |
+ re_delprint(re,i); |
|
289 |
+ } |
|
290 |
+ break; |
|
291 |
+ case SDL_KEYDOWN: |
|
292 |
+ if(event.key.keysym.sym==SDLK_ESCAPE) { |
|
293 |
+ re_delprint(re,i); |
|
294 |
+ } |
|
295 |
+ break; |
|
296 |
+ } |
|
297 |
+ continue; /* only want window events from printouts */ |
|
298 |
+ } |
|
299 |
+ /* process main window events */ |
|
239 | 300 |
switch(event.type) { |
240 | 301 |
case SDL_QUIT: |
241 | 302 |
if(redata_needs_saving(re->data)) { |
... | ... |
@@ -370,7 +431,7 @@ re_init(void) |
370 | 431 |
return(NULL); /* insuf. mem. */ |
371 | 432 |
} |
372 | 433 |
re->fontheightpercent=100; |
373 |
- if((re->ui=reui_init(DEFAULTFONTHEIGHT*re->fontheightpercent/100))==NULL) { |
|
434 |
+ if((re->ui=reui_init(DEFAULTFONTHEIGHT*re->fontheightpercent/100,NULL))==NULL) { |
|
374 | 435 |
re_free(re),re=NULL; |
375 | 436 |
return(NULL); /* video init error */ |
376 | 437 |
} |
... | ... |
@@ -380,8 +441,15 @@ re_init(void) |
380 | 441 |
void |
381 | 442 |
re_free(re_t *re) |
382 | 443 |
{ |
444 |
+ int i; |
|
383 | 445 |
if(re==NULL) |
384 | 446 |
return; /* all done */ |
447 |
+ for(i=0;i<re->sizeprints;i++) { |
|
448 |
+ if(re->prints[i].ui!=NULL) |
|
449 |
+ re_delprint(re,i); |
|
450 |
+ } |
|
451 |
+ if(re->prints!=NULL) |
|
452 |
+ free(re->prints),re->prints=NULL,re->sizeprints=re->usedprints=0; |
|
385 | 453 |
if(re->ui!=NULL) |
386 | 454 |
reui_free(re->ui),re->ui=NULL; |
387 | 455 |
if(re->data!=NULL) |
... | ... |
@@ -813,6 +881,8 @@ fprintf(stderr,"SDL_KEYDOWN: BACKSPACE%s\n",(event==&fakeevent)?" (fake)":""); |
813 | 881 |
re->contentsdirty=1; |
814 | 882 |
} |
815 | 883 |
re->ignorenkeys++; |
884 |
+ } else if(re->selactive && event->key.keysym.sym==SDLK_p && (SDL_GetModState()&KMOD_CTRL)!=0) { |
|
885 |
+ re_addprint(re); |
|
816 | 886 |
} |
817 | 887 |
return(0); |
818 | 888 |
} |
... | ... |
@@ -1490,6 +1560,61 @@ re_selectbuf_replace(re_t *re,char *newdata) |
1490 | 1560 |
return(0); |
1491 | 1561 |
} |
1492 | 1562 |
|
1563 |
+int |
|
1564 |
+re_addprint(re_t *re) |
|
1565 |
+{ |
|
1566 |
+ int i; |
|
1567 |
+ long frompos,topos; |
|
1568 |
+ int coldone; |
|
1569 |
+ if(re==NULL || re->selactive==0) |
|
1570 |
+ return(-1); |
|
1571 |
+ /* ensure space for the new printout */ |
|
1572 |
+ if(re->usedprints==re->sizeprints) { |
|
1573 |
+ printout_t *newprints; |
|
1574 |
+ if((newprints=realloc(re->prints,sizeof(printout_t)*(re->sizeprints+SIZEBLOCKPRINTS)))==NULL) |
|
1575 |
+ return(-1); /* insuf. mem. */ |
|
1576 |
+ re->prints=newprints; |
|
1577 |
+ memset(re->prints+re->sizeprints,0,sizeof(printout_t)*SIZEBLOCKPRINTS); |
|
1578 |
+ re->sizeprints+=SIZEBLOCKPRINTS; |
|
1579 |
+ } |
|
1580 |
+ for(i=0;i<re->sizeprints;i++) { |
|
1581 |
+ if(re->prints[i].ui==NULL) |
|
1582 |
+ break; |
|
1583 |
+ } |
|
1584 |
+ if(i>=re->sizeprints) |
|
1585 |
+ return(-1); /* INTERNAL ERROR */ |
|
1586 |
+ /* setup window */ |
|
1587 |
+ if((re->prints[i].ui=reui_init(DEFAULTFONTHEIGHT*re->fontheightpercent/100,re->ui))==NULL) |
|
1588 |
+ return(-1); /* couldn't init window */ |
|
1589 |
+ if((re->prints[i].data=redata_init(redata_highlighter_register,NULL))==NULL) { |
|
1590 |
+ reui_free(re->prints[i].ui),re->prints[i].ui=NULL; |
|
1591 |
+ return(-1); /* couldn't init data store */ |
|
1592 |
+ } |
|
1593 |
+ re->usedprints++; |
|
1594 |
+ /* copy contents (and set clipboard contents and unselect)*/ |
|
1595 |
+ if(redata_linecol2pos(re->data,re->sellinefrom,re->selcolfrom,&frompos,NULL)==0 |
|
1596 |
+ && redata_linecol2pos(re->data,re->sellineto,re->selcolto,&topos,&coldone)==0) { |
|
1597 |
+ re_selectbuf_fill(re,frompos,topos-frompos,re->selcolto-coldone); |
|
1598 |
+ redata_op_add(re->prints[i].data,0,re->selectbuf,strlen(re->selectbuf),NULL); |
|
1599 |
+ SDL_SetClipboardText(re->selectbuf); |
|
1600 |
+ re_sel_toggle(re); |
|
1601 |
+ re->contentsdirty=1; |
|
1602 |
+ } |
|
1603 |
+ re->prints[i].dirty=1; |
|
1604 |
+ return(0); |
|
1605 |
+} |
|
1606 |
+ |
|
1607 |
+int |
|
1608 |
+re_delprint(re_t *re, int nprint) |
|
1609 |
+{ |
|
1610 |
+ if(re==NULL || nprint<0 || nprint>re->sizeprints || re->prints[nprint].ui==NULL) |
|
1611 |
+ return(-1); |
|
1612 |
+ reui_free(re->prints[nprint].ui),re->prints[nprint].ui=NULL; |
|
1613 |
+ if(re->prints[nprint].data!=NULL) |
|
1614 |
+ redata_free(re->prints[nprint].data),re->prints[nprint].data=NULL; |
|
1615 |
+ re->usedprints--; |
|
1616 |
+ return(0); |
|
1617 |
+} |
|
1493 | 1618 |
|
1494 | 1619 |
int |
1495 | 1620 |
re_rtrim(re_t *re, long curpos, int *trimmed) |
... | ... |
@@ -1663,8 +1788,14 @@ re_drawheader_command(re_t *re) |
1663 | 1788 |
|
1664 | 1789 |
|
1665 | 1790 |
int |
1666 |
-re_drawcontents(re_t *re) |
|
1791 |
+re_drawcontents(re_t *re, printout_t *printout) |
|
1667 | 1792 |
{ |
1793 |
+ reui_t *ui; |
|
1794 |
+ redata_t *data; |
|
1795 |
+ int x0,y0,w,h; |
|
1796 |
+ int originline,origincol; |
|
1797 |
+ int curline,curcol; |
|
1798 |
+ int maxcol,maxrow; |
|
1668 | 1799 |
long pos,newpos; |
1669 | 1800 |
char *ptr; |
1670 | 1801 |
int len; |
... | ... |
@@ -1688,42 +1819,71 @@ re_drawcontents(re_t *re) |
1688 | 1819 |
const char *hint; |
1689 | 1820 |
const char selcolornormal[]={"\xde\xcf\x7f\xff"}; |
1690 | 1821 |
const char selcolorcurline[]={"\xf0\xea\xc9\xff"}; |
1691 |
- if(re==NULL) |
|
1822 |
+ if(re==NULL || (printout!=NULL && (printout->ui==NULL || printout->data==NULL))) |
|
1692 | 1823 |
return(-1); |
1693 |
- if(redata_linecol2pos(re->data,re->curline,re->curcol,&cursorpos,NULL)!=0) |
|
1824 |
+ ui=re->ui; |
|
1825 |
+ data=re->data; |
|
1826 |
+ x0=re->x; |
|
1827 |
+ y0=re->y; |
|
1828 |
+ w=re->w; |
|
1829 |
+ h=re->h; |
|
1830 |
+ originline=re->originline; |
|
1831 |
+ origincol=re->origincol; |
|
1832 |
+ curline=re->curline; |
|
1833 |
+ curcol=re->curcol; |
|
1834 |
+ maxcol=re->maxcol; |
|
1835 |
+ maxrow=re->maxrow; |
|
1836 |
+ if(printout!=NULL) { |
|
1837 |
+ ui=printout->ui; |
|
1838 |
+ data=printout->data; |
|
1839 |
+ x0=0; |
|
1840 |
+ y0=0; |
|
1841 |
+ w=ui->w; |
|
1842 |
+ h=ui->h; |
|
1843 |
+ originline=curline=printout->originline; |
|
1844 |
+ origincol=curcol=printout->origincol; |
|
1845 |
+ maxcol=w/ui->fontwidth-1; |
|
1846 |
+ maxrow=h/ui->fontheight-1; |
|
1847 |
+ } |
|
1848 |
+ if(redata_linecol2pos(data,curline,curcol,&cursorpos,NULL)!=0) |
|
1694 | 1849 |
return(0); /* error obtaining position */ |
1695 |
- reui_fill(re->ui,re->x,re->y,re->w,re->h,"\xdf\xdf\xdf\xff"); |
|
1696 |
- row=re->curline-re->originline; |
|
1850 |
+ reui_fill(ui,x0,y0,w,h,"\xdf\xdf\xdf\xff"); |
|
1851 |
+ row=curline-originline; |
|
1697 | 1852 |
pos=cursorpos; |
1698 | 1853 |
while(row>0 && pos>0) { |
1699 |
- if(redata_line_rawinfo(re->data,pos,&newpos,NULL,NULL,&is_continuation)==-1) |
|
1854 |
+ if(redata_line_rawinfo(data,pos,&newpos,NULL,NULL,&is_continuation)==-1) |
|
1700 | 1855 |
return(-1); |
1701 | 1856 |
pos=(newpos>0)?newpos-1:0; |
1702 | 1857 |
if(!is_continuation) |
1703 | 1858 |
row--; |
1704 | 1859 |
} |
1705 |
- /* highlight current line */ |
|
1706 |
- reui_fill(re->ui,re->x,re->y+(re->curline-re->originline)*re->ui->fontheight,re->w,re->ui->fontheight+1,"\xef\xef\xef\xff"); |
|
1860 |
+ /* highlight current line (in printouts, highlight alternating lines) */ |
|
1861 |
+ if(printout==NULL) { |
|
1862 |
+ reui_fill(ui,x0,y0+(curline-originline)*ui->fontheight,w,ui->fontheight+1,"\xef\xef\xef\xff"); |
|
1863 |
+ } else { |
|
1864 |
+ for(y=y0;y<(y0+h);y+=ui->fontheight*2) |
|
1865 |
+ reui_fill(ui,x0,y,w,ui->fontheight+1,"\xef\xef\xef\xff"); |
|
1866 |
+ } |
|
1707 | 1867 |
/* highlight the selection */ |
1708 |
- if(re->selactive) { |
|
1868 |
+ if(printout==NULL && re->selactive) { |
|
1709 | 1869 |
const char *selcolor; |
1710 | 1870 |
tmprow=row; |
1711 |
- for(y=re->y;y<(re->y+re->h);y+=re->ui->fontheight,row++) { |
|
1712 |
- selcolor=(row==(re->curline-re->originline))?selcolorcurline:selcolornormal; |
|
1713 |
- if((re->originline+row)==re->sellinefrom && (re->originline+row)==re->sellineto) { |
|
1714 |
- reui_fill(re->ui,re->x+(re->selcolfrom-re->origincol)*re->ui->fontwidth,re->y+row*re->ui->fontheight,(re->selcolto-re->selcolfrom)*re->ui->fontwidth,re->ui->fontheight+1,selcolor); |
|
1715 |
- } else if((re->originline+row)==re->sellinefrom) { |
|
1871 |
+ for(y=y0;y<(y0+h);y+=ui->fontheight,row++) { |
|
1872 |
+ selcolor=(row==(curline-originline))?selcolorcurline:selcolornormal; |
|
1873 |
+ if((originline+row)==re->sellinefrom && (originline+row)==re->sellineto) { |
|
1874 |
+ reui_fill(ui,x0+(re->selcolfrom-origincol)*ui->fontwidth,y0+row*ui->fontheight,(re->selcolto-re->selcolfrom)*ui->fontwidth,ui->fontheight+1,selcolor); |
|
1875 |
+ } else if((originline+row)==re->sellinefrom) { |
|
1716 | 1876 |
int x1; |
1717 |
- x1=re->x+(re->selcolfrom-re->origincol)*re->ui->fontwidth; |
|
1718 |
- if(x1<(re->x+re->w)) |
|
1719 |
- reui_fill(re->ui,x1,re->y+row*re->ui->fontheight,re->w-x1,re->ui->fontheight+1,selcolor); |
|
1720 |
- } else if((re->originline+row)>re->sellinefrom && (re->originline+row)<re->sellineto) { |
|
1721 |
- reui_fill(re->ui,re->x,re->y+row*re->ui->fontheight,re->w,re->ui->fontheight+1,selcolor); |
|
1722 |
- } else if((re->originline+row)==re->sellineto) { |
|
1877 |
+ x1=x0+(re->selcolfrom-origincol)*ui->fontwidth; |
|
1878 |
+ if(x1<(x0+w)) |
|
1879 |
+ reui_fill(ui,x1,y0+row*ui->fontheight,w-x1,ui->fontheight+1,selcolor); |
|
1880 |
+ } else if((originline+row)>re->sellinefrom && (originline+row)<re->sellineto) { |
|
1881 |
+ reui_fill(ui,x0,y0+row*ui->fontheight,w,ui->fontheight+1,selcolor); |
|
1882 |
+ } else if((originline+row)==re->sellineto) { |
|
1723 | 1883 |
int x2; |
1724 |
- x2=re->x+(re->selcolto-re->origincol)*re->ui->fontwidth; |
|
1725 |
- if(x2>(re->x)) |
|
1726 |
- reui_fill(re->ui,re->x,re->y+row*re->ui->fontheight,x2-re->x,re->ui->fontheight+1,selcolor); |
|
1884 |
+ x2=x0+(re->selcolto-origincol)*ui->fontwidth; |
|
1885 |
+ if(x2>(x0)) |
|
1886 |
+ reui_fill(ui,x0,y0+row*ui->fontheight,x2-x0,ui->fontheight+1,selcolor); |
|
1727 | 1887 |
} |
1728 | 1888 |
|
1729 | 1889 |
} |
... | ... |
@@ -1731,23 +1891,23 @@ re_drawcontents(re_t *re) |
1731 | 1891 |
} |
1732 | 1892 |
/* draw the lines */ |
1733 | 1893 |
drawn_cursor=0; |
1734 |
- colors=redata_highlighter_getcolors(re->data,&ncolors); |
|
1894 |
+ colors=redata_highlighter_getcolors(data,&ncolors); |
|
1735 | 1895 |
matchingpos=-1; |
1736 | 1896 |
matchingchar='\0'; |
1737 |
- for(y=re->y;y<(re->y+re->h);y+=re->ui->fontheight,row++) { |
|
1897 |
+ for(y=y0;y<(y0+h);y+=ui->fontheight,row++) { |
|
1738 | 1898 |
/* definition of vars for tracking linecolor usage */ |
1739 | 1899 |
int curlinecolor; /* current linecolor */ |
1740 | 1900 |
int usedlenlinecolor; /* number of bytes of current linecolor already drawn */ |
1741 | 1901 |
/* end of definitions */ |
1742 |
- if(redata_line_realstart(re->data,pos,&realstart)==-1 || redata_line_realend(re->data,pos,&realend)==-1) { |
|
1902 |
+ if(redata_line_realstart(data,pos,&realstart)==-1 || redata_line_realend(data,pos,&realend)==-1) { |
|
1743 | 1903 |
break; /* couldn't get real start/end */ |
1744 | 1904 |
} |
1745 | 1905 |
in_error=0; |
1746 |
- linecolors=(colors==NULL)?NULL:redata_highlighter_getline(re->data,re->originline+row,&nlinecolors); |
|
1906 |
+ linecolors=(colors==NULL)?NULL:redata_highlighter_getline(data,originline+row,&nlinecolors); |
|
1747 | 1907 |
curlinecolor=0; |
1748 | 1908 |
usedlenlinecolor=0; |
1749 |
- for(tmpcol=0,pos=realstart,availcol=0;tmpcol<(re->origincol+re->maxcol) && pos<=realend;pos=newpos+len,tmpcol+=availcol) { |
|
1750 |
- if(redata_line_rawinfo(re->data,pos,&newpos,&ptr,&len,&is_continuation)==-1) { |
|
1909 |
+ for(tmpcol=0,pos=realstart,availcol=0;tmpcol<(origincol+maxcol) && pos<=realend;pos=newpos+len,tmpcol+=availcol) { |
|
1910 |
+ if(redata_line_rawinfo(data,pos,&newpos,&ptr,&len,&is_continuation)==-1) { |
|
1751 | 1911 |
in_error=1; |
1752 | 1912 |
break; /* couldn't get this line part info */ |
1753 | 1913 |
} |
... | ... |
@@ -1759,7 +1919,7 @@ re_drawcontents(re_t *re) |
1759 | 1919 |
used=usedcol=0; |
1760 | 1920 |
/* while the avail text is larger than the linecolor len */ |
1761 | 1921 |
while(curlinecolor<nlinecolors && (len-has_nl-used)>=(linecolors[curlinecolor].len-usedlenlinecolor)) { |
1762 |
- reui_write(re->ui,re->x+(tmpcol-re->origincol+usedcol)*re->ui->fontwidth,y,colors[linecolors[curlinecolor].color].rgba,ptr+used,linecolors[curlinecolor].len-usedlenlinecolor); |
|
1922 |
+ reui_write(ui,x0+(tmpcol-origincol+usedcol)*ui->fontwidth,y,colors[linecolors[curlinecolor].color].rgba,ptr+used,linecolors[curlinecolor].len-usedlenlinecolor); |
|
1763 | 1923 |
usedcol+=redata_generic_utf8len(ptr+used,linecolors[curlinecolor].len-usedlenlinecolor); |
1764 | 1924 |
used+=linecolors[curlinecolor].len-usedlenlinecolor; |
1765 | 1925 |
curlinecolor++; |
... | ... |
@@ -1767,68 +1927,75 @@ re_drawcontents(re_t *re) |
1767 | 1927 |
} |
1768 | 1928 |
/* for the last bytes of avail text, after writing them we save how many bytes we have processed of that linecolor to be able to continue later */ |
1769 | 1929 |
if(curlinecolor<nlinecolors && (len-has_nl-used)>0 && (linecolors[curlinecolor].len-usedlenlinecolor)>(len-has_nl-used)) { |
1770 |
- reui_write(re->ui,re->x+(tmpcol-re->origincol+usedcol)*re->ui->fontwidth,y,colors[linecolors[curlinecolor].color].rgba,ptr+used,(len-has_nl-used)); |
|
1930 |
+ reui_write(ui,x0+(tmpcol-origincol+usedcol)*ui->fontwidth,y,colors[linecolors[curlinecolor].color].rgba,ptr+used,(len-has_nl-used)); |
|
1771 | 1931 |
usedcol+=redata_generic_utf8len(ptr+used,(len-has_nl-used)); |
1772 | 1932 |
usedlenlinecolor+=(len-has_nl-used); |
1773 | 1933 |
used+=(len-has_nl-used); |
1774 | 1934 |
} |
1775 | 1935 |
} else { |
1776 |
- reui_write(re->ui,re->x+(tmpcol-re->origincol)*re->ui->fontwidth,y,"\x00\x00\x00\xff",ptr,len-has_nl); |
|
1936 |
+ reui_write(ui,x0+(tmpcol-origincol)*ui->fontwidth,y,"\x00\x00\x00\xff",ptr,len-has_nl); |
|
1777 | 1937 |
} |
1778 |
- if(row==(re->curline-re->originline)) { |
|
1779 |
- if(re->curcol>=tmpcol && re->curcol<(tmpcol+availcol)) { |
|
1938 |
+ if(row==(curline-originline)) { |
|
1939 |
+ if(curcol>=tmpcol && curcol<(tmpcol+availcol)) { |
|
1780 | 1940 |
int utf8charlen; |
1781 | 1941 |
/* draw cursor */ |
1782 |
- reui_fill(re->ui,re->x+re->ui->fontwidth*(re->curcol-re->origincol),y,re->ui->fontwidth,re->ui->fontheight+1,"\x00\x00\x00\xff"); |
|
1942 |
+ reui_fill(ui,x0+ui->fontwidth*(curcol-origincol),y,ui->fontwidth,ui->fontheight+1,"\x00\x00\x00\xff"); |
|
1783 | 1943 |
drawn_cursor=1; |
1784 |
- curptr=redata_generic_utf8col(ptr,len-has_nl,re->curcol-tmpcol); |
|
1944 |
+ curptr=redata_generic_utf8col(ptr,len-has_nl,curcol-tmpcol); |
|
1785 | 1945 |
curptrlen=(curptr==NULL)?0:(len-has_nl)-(curptr-ptr); |
1786 | 1946 |
utf8charlen=redata_generic_utf8charlen(curptr,curptrlen); |
1787 |
- reui_write(re->ui,re->x+re->ui->fontwidth*(re->curcol-re->origincol),y,"\xff\xff\xff\xff",curptr,utf8charlen); |
|
1947 |
+ reui_write(ui,x0+ui->fontwidth*(curcol-origincol),y,"\xff\xff\xff\xff",curptr,utf8charlen); |
|
1788 | 1948 |
/* get matching braces/parens/anglebracket/curlybraces for highlighting */ |
1789 | 1949 |
if(utf8charlen==1 && strchr("[]{}<>()",*curptr)!=NULL) |
1790 | 1950 |
matchingpos=re_getmatchingbracket(re,cursorpos,*curptr,&matchingchar); |
1791 | 1951 |
} |
1792 | 1952 |
} |
1793 | 1953 |
} |
1794 |
- if(row==(re->curline-re->originline) && !drawn_cursor) |
|
1795 |
- reui_fill(re->ui,re->x+re->ui->fontwidth*(re->curcol-re->origincol),y,re->ui->fontwidth,re->ui->fontheight+1,"\x00\x00\x00\xff"); |
|
1954 |
+ if(row==(curline-originline) && !drawn_cursor) |
|
1955 |
+ reui_fill(ui,x0+ui->fontwidth*(curcol-origincol),y,ui->fontwidth,ui->fontheight+1,"\x00\x00\x00\xff"); |
|
1796 | 1956 |
if(in_error) |
1797 | 1957 |
break; |
1798 | 1958 |
pos=realend+1; |
1799 |
-/*LONG LINE LEFT FOR DEBUGGING PURPOSES: reui_write(re->ui,re->x+re->ui->fontwidth*(re->curcol-re->origincol),y,"\xff\xff\xff\xff",curptr,redata_generic_utf8charlen(ptr,curptrlen));*/ |
|
1959 |
+/*LONG LINE LEFT FOR DEBUGGING PURPOSES: reui_write(ui,x0+ui->fontwidth*(curcol-origincol),y,"\xff\xff\xff\xff",curptr,redata_generic_utf8charlen(ptr,curptrlen));*/ |
|
1800 | 1960 |
} |
1801 | 1961 |
/* highlight matching parens/brace/... if applicable */ |
1802 |
- if(matchingpos!=-1 && redata_pos2linecol(re->data,matchingpos,&mline,&mcol)!=-1) { |
|
1962 |
+ if(printout==NULL && matchingpos!=-1 && redata_pos2linecol(data,matchingpos,&mline,&mcol)!=-1) { |
|
1803 | 1963 |
int x,y; |
1804 | 1964 |
char *fg="\xff\x00\x00\x80"; |
1805 | 1965 |
char *bg="\xff\xff\xff\xaf"; |
1806 |
- x=re->x+(mcol-re->origincol)*re->ui->fontwidth+(re->ui->fontwidth/2); |
|
1807 |
- x=(x<re->x)?re->x:(x>=(re->x+re->w))?(re->x+re->w-1):x; |
|
1808 |
- y=re->y+(mline-re->originline)*re->ui->fontheight+(re->ui->fontheight/2); |
|
1809 |
- y=(y<re->y)?re->y:(y>=(re->y+re->h))?(re->y+re->h-1):y; |
|
1810 |
- if(mline<re->originline) |
|
1811 |
- reui_balloon(re->ui, 'n', x, re->y, fg, bg, &matchingchar,1); |
|
1812 |
- else if(mline>=(re->originline+re->maxrow)) |
|
1813 |
- reui_balloon(re->ui, 's', x, re->y+re->h-1, fg, bg, &matchingchar,1); |
|
1814 |
- else if(mcol<re->origincol) |
|
1815 |
- reui_balloon(re->ui, 'w', re->x, y, fg, bg, &matchingchar,1); |
|
1816 |
- else if(mcol>=(re->origincol+re->maxcol)) |
|
1817 |
- reui_balloon(re->ui, 'e', re->x+re->w-1,y, fg, bg, &matchingchar,1); |
|
1966 |
+ x=x0+(mcol-origincol)*ui->fontwidth+(ui->fontwidth/2); |
|
1967 |
+ x=(x<x0)?x0:(x>=(x0+w))?(x0+w-1):x; |
|
1968 |
+ y=y0+(mline-originline)*ui->fontheight+(ui->fontheight/2); |
|
1969 |
+ y=(y<y0)?y0:(y>=(y0+h))?(y0+h-1):y; |
|
1970 |
+ if(mline<originline) |
|
1971 |
+ reui_balloon(ui, 'n', x, y0, fg, bg, &matchingchar,1); |
|
1972 |
+ else if(mline>=(originline+maxrow)) |
|
1973 |
+ reui_balloon(ui, 's', x, y0+h-1, fg, bg, &matchingchar,1); |
|
1974 |
+ else if(mcol<origincol) |
|
1975 |
+ reui_balloon(ui, 'w', x0, y, fg, bg, &matchingchar,1); |
|
1976 |
+ else if(mcol>=(origincol+maxcol)) |
|
1977 |
+ reui_balloon(ui, 'e', x0+w-1,y, fg, bg, &matchingchar,1); |
|
1818 | 1978 |
else |
1819 |
- reui_balloon(re->ui, '\0', x,y, fg, bg, &matchingchar,1); |
|
1979 |
+ reui_balloon(ui, '\0', x,y, fg, bg, &matchingchar,1); |
|
1820 | 1980 |
} |
1821 | 1981 |
/* display prototypes info if applicable */ |
1822 |
- hint=redata_prototypes_get(re->data, cursorpos); |
|
1823 |
- if(hint!=NULL) { |
|
1824 |
- if((re->curline-re->originline)>=(re->maxrow/2)) |
|
1825 |
- reui_balloon(re->ui, '\0', re->x+re->w/2, re->y+re->ui->fontheight*3/2, "\x80\x80\x80\xff", "\xff\xff\xff\xcf",(char *) hint,strlen(hint)); |
|
1826 |
- else |
|
1827 |
- reui_balloon(re->ui, '\0', re->x+re->w/2, re->y+re->h-re->ui->fontheight*3/2, "\x80\x80\x80\xff", "\xff\xff\xff\xcf",(char *)hint,strlen(hint)); |
|
1982 |
+ if(printout==NULL) { |
|
1983 |
+ hint=redata_prototypes_get(data, cursorpos); |
|
1984 |
+ if(hint!=NULL) { |
|
1985 |
+ if((curline-originline)>=(maxrow/2)) |
|
1986 |
+ reui_balloon(ui, '\0', x0+w/2, y0+ui->fontheight*3/2, "\x80\x80\x80\xff", "\xff\xff\xff\xcf",(char *) hint,strlen(hint)); |
|
1987 |
+ else |
|
1988 |
+ reui_balloon(ui, '\0', x0+w/2, y0+h-ui->fontheight*3/2, "\x80\x80\x80\xff", "\xff\xff\xff\xcf",(char *)hint,strlen(hint)); |
|
1989 |
+ } |
|
1828 | 1990 |
} |
1829 | 1991 |
/* all done */ |
1830 |
- re->contentsdirty=0; |
|
1831 |
- re->ui->rendererdirty=1; |
|
1992 |
+ if(printout==NULL) { |
|
1993 |
+ re->contentsdirty=0; |
|
1994 |
+ ui->rendererdirty=1; |
|
1995 |
+ } else { |
|
1996 |
+ printout->dirty=0; |
|
1997 |
+ printout->ui->rendererdirty=1; |
|
1998 |
+ } |
|
1832 | 1999 |
return(0); |
1833 | 2000 |
} |
1834 | 2001 |
|