Browse code

Make "Click on a printout" to go to that line in the main editor window

Dario Rodriguez authored on 01/12/2022 14:34:38
Showing 1 changed files
... ...
@@ -69,6 +69,7 @@ typedef struct printout_t {
69 69
         int originline;
70 70
         int origincol;
71 71
         int showonlyn;
72
+        int mouseselactive;
72 73
         int dirty;
73 74
 } printout_t;
74 75
 
... ...
@@ -310,6 +311,7 @@ fprintf(stderr,"RENDER\n");
310 311
                           || (event.type==SDL_TEXTEDITING && (windowID=event.edit.windowID)!=SDL_GetWindowID(re->ui->win))
311 312
                           || (event.type==SDL_TEXTINPUT && (windowID=event.text.windowID)!=SDL_GetWindowID(re->ui->win))
312 313
                           || (event.type==SDL_MOUSEWHEEL && (windowID=event.text.windowID)!=SDL_GetWindowID(re->ui->win))
314
+                          || ((event.type==SDL_MOUSEBUTTONDOWN || event.type==SDL_MOUSEMOTION || event.type==SDL_MOUSEBUTTONUP) && (windowID=event.text.windowID)!=SDL_GetWindowID(re->ui->win))
313 315
                           ) {
314 316
                                 printout_t *printout;
315 317
                                 for(i=0;i<re->sizeprints;i++) {
... ...
@@ -376,6 +378,32 @@ fprintf(stderr,"RENDER\n");
376 378
                                                         printout->dirty=1;
377 379
                                                 }
378 380
                                                 break;
381
+                                        case SDL_MOUSEBUTTONDOWN:
382
+                                        case SDL_MOUSEBUTTONUP:
383
+                                        case SDL_MOUSEMOTION:
384
+                                                if(!(event.type==SDL_MOUSEMOTION && re->mouseselactive==0)) {
385
+                                                        int mx,my;
386
+                                                        int newposx,newposy;
387
+                                                        long tmppos;
388
+                                                        if(event.type==SDL_MOUSEBUTTONDOWN && event.button.button==SDL_BUTTON_LEFT) {
389
+                                                                printout->mouseselactive=1;
390
+                                                        } else if( event.type==SDL_MOUSEBUTTONUP && event.button.button==SDL_BUTTON_LEFT) {
391
+                                                                printout->mouseselactive=0;
392
+                                                        }
393
+                                                        mx=(event.type!=SDL_MOUSEMOTION)?event.button.x:event.motion.x;
394
+                                                        my=(event.type!=SDL_MOUSEMOTION)?event.button.y:event.motion.y;
395
+                                                        newposx=(mx-(printout->ui->fontwidth*8+printout->ui->fontwidth/2))/printout->ui->fontwidth;
396
+                                                        newposx=(newposx<0)?0:newposx;
397
+                                                        newposy=my/printout->ui->fontheight;
398
+                                                        if(redata_linecol2pos(re->data, printout->originline+newposy, printout->origincol+newposx,&tmppos,NULL)==0) {
399
+                                                                re->curline=printout->originline+newposy;
400
+                                                                re->curcol=printout->origincol+newposx;
401
+                                                                re->headerdirty=1;
402
+                                                                re->contentsdirty=1;
403
+                                                                re_fixorigin_center(re);                                                        }
404
+                                                }
405
+                                                break;
406
+
379 407
                                 }
380 408
                                 continue; /* only want window events from printouts */
381 409
                         }