From 390cedeac6059a1834e1f715b9f6db51b62abec0 Mon Sep 17 00:00:00 2001 From: kevin Date: Sun, 13 Jan 2013 16:40:49 -0800 Subject: [PATCH] cmGrDevCtx.h/c Added cmGrDcPoint/RectIsVisible() --- cmGrDevCtx.c | 41 ++++++++++++++++++++++++++++++++++++++++- cmGrDevCtx.h | 6 ++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/cmGrDevCtx.c b/cmGrDevCtx.c index 1736d92..547a8a0 100644 --- a/cmGrDevCtx.c +++ b/cmGrDevCtx.c @@ -497,8 +497,33 @@ void cmGrDcDrawTextJustifyPt( cmGrDcH_t h, unsigned fontId, unsigned size, un else y = yy + sz.h/2; - cmGrDcDrawText(h, text, x+.5, y+.5 ); + + cmGrPExt_t r; + cmGrPExtSet(&r,x,y,sz.w,sz.h); + + // Note: Checking for visibility should not be necessary however + // there appears to be a problem with the FLTK text output whereby + // text coordinates over 0xffff wrap around and may appear in the + // visible region. + if( cmGrDcRectIsVisible(h,&r) ) + { + /* + if( text!=NULL && (strncmp(text,"loc:138",7)==0 || strcmp(text,"loc:8 ")==0)) + { + printf("%s %i %i %i %i\n",text,x,y,sz.w,xx); + cmGrPExtPrint(text,&r); + cmGrDc_t* p = _cmGrDcHandleToPtr(h); + cmGrPExt_t res; + cmGrPExtIntersect(&res,&p->pext,&r ); + cmGrPExtPrint(text,&p->pext); + cmGrPExtPrint("isect:",&res); + printf("%i\n",cmGrPExtIsNotNullOrEmpty(&res)); + } + */ + + cmGrDcDrawText(h, text, x+.5, y+.5 ); + } //cmGrPExt_t pext; //cmGrDcDrawTextJustifyRect(h, fontId, size, style, text, flags, xx, yy, &pext ); //cmGrDcDrawRectPExt(h,&pext); @@ -528,3 +553,17 @@ void cmGrDcDrawTextJustifyRect( cmGrDcH_t h, unsigned fontId, unsigned size, u cmGrPExtSet( pext, x, y-sz.h, sz.w+1, sz.h ); } + +bool cmGrDcPointIsVisible( cmGrDcH_t h, int x, int y ) +{ + cmGrDc_t* p = _cmGrDcHandleToPtr(h); + return cmGrVExtIsXyInside(&p->pext,x,y); +} + +bool cmGrDcRectIsVisible( cmGrDcH_t h, const cmGrPExt_t* r ) +{ + cmGrPExt_t res; + cmGrDc_t* p = _cmGrDcHandleToPtr(h); + cmGrPExtIntersect(&res,&p->pext,r ); + return cmGrPExtIsNotNullOrEmpty(&res); +} diff --git a/cmGrDevCtx.h b/cmGrDevCtx.h index 96f3ae0..3893d09 100644 --- a/cmGrDevCtx.h +++ b/cmGrDevCtx.h @@ -189,6 +189,12 @@ extern "C" { // Return the rectangle around the text but do not display the text. void cmGrDcDrawTextJustifyRect( cmGrDcH_t h, unsigned fontId, unsigned size, unsigned style, const cmChar_t* text, unsigned flags, int x, int y, cmGrPExt_t* pext ); + // Is the point x,y visible in this drawing context. + bool cmGrDcPointIsVisible( cmGrDcH_t h, int x, int y ); + + // Is any of the rectangle visible in this drawing context. + bool cmGrDcRectIsVisible( cmGrDcH_t h, const cmGrPExt_t* r ); + #ifdef __cplusplus } #endif