Browse Source

cmGrDevCtx.h/c Added cmGrDcPoint/RectIsVisible()

master
kevin 11 years ago
parent
commit
390cedeac6
2 changed files with 46 additions and 1 deletions
  1. 40
    1
      cmGrDevCtx.c
  2. 6
    0
      cmGrDevCtx.h

+ 40
- 1
cmGrDevCtx.c View File

@@ -497,8 +497,33 @@ void   cmGrDcDrawTextJustifyPt(  cmGrDcH_t h, unsigned fontId, unsigned size, un
497 497
     else
498 498
       y = yy + sz.h/2;
499 499
 
500
-  cmGrDcDrawText(h, text, x+.5, y+.5 );  
501 500
 
501
+
502
+  cmGrPExt_t r;
503
+  cmGrPExtSet(&r,x,y,sz.w,sz.h);
504
+
505
+  // Note: Checking for visibility should not be necessary however
506
+  // there appears to be a problem with the FLTK text output whereby
507
+  // text coordinates over 0xffff wrap around and may appear in the
508
+  // visible region.
509
+  if( cmGrDcRectIsVisible(h,&r) )
510
+  {
511
+    /*
512
+    if( text!=NULL && (strncmp(text,"loc:138",7)==0 || strcmp(text,"loc:8 ")==0))
513
+    {
514
+      printf("%s %i %i %i %i\n",text,x,y,sz.w,xx);
515
+      cmGrPExtPrint(text,&r);
516
+      cmGrDc_t* p = _cmGrDcHandleToPtr(h);  
517
+      cmGrPExt_t res;
518
+      cmGrPExtIntersect(&res,&p->pext,&r );
519
+      cmGrPExtPrint(text,&p->pext);
520
+      cmGrPExtPrint("isect:",&res);
521
+      printf("%i\n",cmGrPExtIsNotNullOrEmpty(&res));
522
+    }
523
+    */
524
+
525
+    cmGrDcDrawText(h, text, x+.5, y+.5 );  
526
+  }
502 527
   //cmGrPExt_t pext;
503 528
   //cmGrDcDrawTextJustifyRect(h, fontId, size, style, text, flags, xx, yy, &pext );
504 529
   //cmGrDcDrawRectPExt(h,&pext);
@@ -528,3 +553,17 @@ void   cmGrDcDrawTextJustifyRect( cmGrDcH_t h, unsigned fontId, unsigned size, u
528 553
 
529 554
   cmGrPExtSet( pext, x, y-sz.h, sz.w+1, sz.h );
530 555
 }
556
+
557
+bool            cmGrDcPointIsVisible( cmGrDcH_t h, int x, int y )
558
+{
559
+  cmGrDc_t* p = _cmGrDcHandleToPtr(h);  
560
+  return cmGrVExtIsXyInside(&p->pext,x,y);
561
+}
562
+
563
+bool            cmGrDcRectIsVisible(  cmGrDcH_t h, const cmGrPExt_t* r )
564
+{
565
+  cmGrPExt_t res;
566
+  cmGrDc_t* p = _cmGrDcHandleToPtr(h);  
567
+  cmGrPExtIntersect(&res,&p->pext,r );
568
+  return cmGrPExtIsNotNullOrEmpty(&res);
569
+}

+ 6
- 0
cmGrDevCtx.h View File

@@ -189,6 +189,12 @@ extern "C" {
189 189
   // Return the rectangle around the text but do not display the text.
190 190
   void            cmGrDcDrawTextJustifyRect( cmGrDcH_t h, unsigned fontId, unsigned size, unsigned style, const cmChar_t* text, unsigned flags, int x, int y, cmGrPExt_t* pext );
191 191
 
192
+  // Is the point x,y visible in this drawing context.
193
+  bool            cmGrDcPointIsVisible( cmGrDcH_t h, int x, int y );
194
+
195
+  // Is any of the rectangle visible in this drawing context.
196
+  bool            cmGrDcRectIsVisible(  cmGrDcH_t h, const cmGrPExt_t* r );
197
+
192 198
 #ifdef __cplusplus
193 199
 }
194 200
 #endif

Loading…
Cancel
Save