bool GeoClip::ClipLine(GeoPoint &a, GeoPoint &b) const { GeoPoint a2 = ImportPoint(a); GeoPoint b2 = ImportPoint(b); if (!ClipPoint(a2, b2) || !ClipPoint(b2, a2)) return false; a = ExportPoint(a2); b = ExportPoint(b2); return true; }
bool Format7DrawingArea::on_button_press_event( GdkEventButton* event ) { gdouble startX = event->x; gdouble startY = event->y; ClipPoint( &startX, &startY ); unsigned int startXOrig = ToOriginal( (float)startX ); unsigned int startYOrig = ToOriginal( (float)startY ); switch ( event->button ) { case 1: // Store the start point m_startX = startXOrig; m_startY = startYOrig; m_leftMBHeld = true; break; case 3: get_window()->set_cursor( m_moveCursor ); // Store the difference between the start point and the left/top m_offsetX = m_left - startXOrig; m_offsetY = m_top - startYOrig; m_rightMBHeld = true; break; } return true; }
BOOL Clip2D( int *ix0, int *iy0, int *ix1, int *iy1 ) { BOOL visible; FLOAT te, tl; FLOAT dx, dy; FLOAT x0, y0, x1, y1; x0 = (FLOAT)*ix0; x1 = (FLOAT)*ix1; y0 = (FLOAT)*iy0; y1 = (FLOAT)*iy1; dx = x1-x0; dy = y1-y0; visible = FALSE; if ( dx == 0.0 && dy == 0.0 && ClipPoint(*ix0,*iy0) ) visible = TRUE; else { te = 0.0f; tl = 1.0f; if ( Clipt( dx, (FLOAT)giClipXMin-x0, &te, &tl ) ) { if ( Clipt(-dx, x0-(FLOAT)giClipXMax, &te, &tl ) ) { if ( Clipt(dy, (FLOAT)giClipYMin-y0, &te, &tl ) ) { if ( Clipt(-dy, y0-(FLOAT)giClipYMax, &te, &tl ) ) { visible = TRUE; if ( tl < 1.0f ) { x1 = x0 + tl*dx; y1 = y0 + tl*dy; } if ( te > 0 ) { x0 = x0 + te*dx; y0 = y0 + te*dy; } } } } } } *ix0 = (int)x0; *ix1 = (int)x1; *iy0 = (int)y0; *iy1 = (int)y1; return( visible ); }
void NS_DIM_PREFIX UgCenteredText (COORD_POINT point, const char *s, INT mode) { INT reject; SHORT_POINT out; #ifdef ModelP if (me != master) return; #endif ClipPoint(point,&out,&reject); if (!reject) { (*CurrentOutputDevice->CenteredText)(out,s,mode); } }
void NS_DIM_PREFIX UgInvPolymark (COORD_POINT *points, INT n) { INT k,reject; SHORT_POINT out; #ifdef ModelP if (me != master) return; #endif for (k=0; k<n; k++) { ClipPoint (points[k],&out,&reject); if (!reject) (*CurrentOutputDevice->InvPolymark)(1,&out); } }
void ControlPointsWidget::mouseReleaseEvent( QMouseEvent * evnt ) { if ( evnt->button() == Qt::LeftButton ) { if ( m_bDragging ) { QRect rcBounds = m_rcChartPlotArea.adjusted(0,0,1,1); QPoint pt = ClipPoint( rcBounds, evnt->pos() ); // Convert screen coordinates back to CPOINT coordinates. m_Points[m_nFocusPoint].lP = SnapX(UnscaleX(pt.x())); m_Points[m_nFocusPoint].dwLog = SnapY(UnscaleY(pt.y())); m_bChanged = true; CalculateWorkingData(); update(); m_bDragging = false; SetMouseCursor( evnt->pos() ); //ReleaseCapture(); } } }
bool Format7DrawingArea::on_button_release_event( GdkEventButton* event ) { gdouble endX = event->x; gdouble endY = event->y; ClipPoint( &endX, &endY ); const unsigned int endXOrig = ToOriginal( (float)endX ); const unsigned int endYOrig = ToOriginal( (float)endY ); switch ( event->button ) { case 1: m_left = std::min(m_startX, endXOrig); m_top = std::min(m_startY, endYOrig); m_width = std::max(m_startX, endXOrig) - m_left; m_height = std::max(m_startY, endYOrig) - m_top; ClampAllValues(); m_imageSizeChanged = true; m_leftMBHeld = false; break; case 3: get_window()->set_cursor(); m_rightMBHeld = false; break; } queue_draw(); return true; }
bool Format7DrawingArea::on_motion_notify_event( GdkEventMotion* event ) { gdouble currX = event->x; gdouble currY = event->y; // This may actually be negative if the mouse is dragged to the // left or top of the image, so ints should be used instead of // unsigned ints to prevent overflow int currXOrig = 0; int currYOrig = 0; if ( m_leftMBHeld == true ) { ClipPoint( &currX, &currY ); currXOrig = ToOriginal( static_cast<float>(currX) ); currYOrig = ToOriginal( static_cast<float>(currY) ); if ( currXOrig <= static_cast<int>(m_startX) ) { m_left = currXOrig; m_width = m_startX - m_left; } else { m_left = m_startX; m_width = currXOrig - m_left; } if ( currYOrig <= static_cast<int>(m_startY) ) { m_top = currYOrig; m_height = m_startY - m_top; } else { m_top = m_startY; m_height = currYOrig - m_top; } ClampAllValues(); m_imageSizeChanged = true; } else if ( m_rightMBHeld == true ) { currXOrig = ToOriginal( static_cast<float>(currX) ); currYOrig = ToOriginal( static_cast<float>(currY) ); // Perform some initial calculations to make sure that the // left and top values are not overflowing if ( currXOrig + m_offsetX < 0 ) { m_left = 0; } else { m_left = currXOrig + m_offsetX; } if ( currYOrig + m_offsetY < 0 ) { m_top = 0; } else { m_top = currYOrig + m_offsetY; } ClampAllValues(); // Ensure we are still within the boundaries if ( m_left + m_width > m_maxWidth ) { m_left = m_maxWidth - m_width; } else if ( m_left + m_width < m_width ) { m_left = 0; } if ( m_top + m_height > m_maxHeight ) { m_top = m_maxHeight - m_height; } else if ( m_top + m_height < m_height ) { m_top = 0; } m_imageSizeChanged = true; } else { ClipPoint( &currX, &currY ); currXOrig = ToOriginal( static_cast<float>(currX) ); currYOrig = ToOriginal( static_cast<float>(currY) ); } // Store the current cursor coordinates m_currX = currXOrig; m_currY = currYOrig; queue_draw(); return true; }
static inline void drawpoint(CoreGfxBase *CoreGfxBase, CRastPort *rp, INT32 x, INT32 y) { if (ClipPoint(rp, x, y)) rp->crp_PixMap->_DrawPixel(rp, x, y, rp->crp_Foreground); }
void ControlPointsWidget::mouseMoveEvent ( QMouseEvent * evnt ) { QPoint pt = evnt->pos(); if ( !m_bDragging ) { SetMouseCursor( pt ); } else { QRect rcBounds = m_rcChartPlotArea.adjusted(0,0,1,1); if ( !rcBounds.contains(pt) ) { // Cursor trying to move out of area pt = ClipPoint( rcBounds, pt ); } // Invalidate the rectangle that bounds the old point and joining line segments. //int x = ScaleX(m_Points[m_nFocusPoint].lP); //int y = ScaleY(m_Points[m_nFocusPoint].dwLog); //x += m_ptDragOffset.x; //y += m_ptDragOffset.y; //x = SnapScreenX(x); //y = SnapY(y); int x = ScaleX(m_ptDragCPoint.x()); int y = ScaleY(m_ptDragCPoint.y()); QRect rcInvalid; if ( m_nFocusPoint == 0 ) { int x1 = ScaleX(m_Points[1].lP); int y1 = ScaleY(m_Points[1].dwLog); QRect rc1(x-3,y-3,x+3,y+3 ); QRect rc2(x1-3,y1-3,x1+3,y1+3 ); rc1 = rc1.normalized(); rc2 = rc2.normalized(); rc1.adjust(-1,-1,1,1); rc2.adjust(-1,-1,1,1); rcInvalid = rc1.united( rc2 ); } else if ( m_nFocusPoint == (int)m_Points.size()-1 ) { int x1 = ScaleX(m_Points[m_nFocusPoint-1].lP); int y1 = ScaleY(m_Points[m_nFocusPoint-1].dwLog); QRect rc1(x-3,y-3,x+3,y+3 ); QRect rc2(x1-3,y1-3,x1+3,y1+3 ); rc1 = rc1.normalized(); rc2 = rc2.normalized(); rc1.adjust(-1,-1,1,1); rc2.adjust(-1,-1,1,1); rcInvalid = rc1.united( rc2 ); } else { QRect rc1(x-3,y-3,x+3,y+3 ); rc1 = rc1.normalized(); rc1.adjust(-1,-1,1,1); int x1 = ScaleX(m_Points[m_nFocusPoint-1].lP); int y1 = ScaleY(m_Points[m_nFocusPoint-1].dwLog); QRect rc2(x1-3,y1-3,x1+3,y1+3 ); rc2 = rc2.normalized(); rc2.adjust(-1,-1,1,1); x1 = ScaleX(m_Points[m_nFocusPoint+1].lP); y1 = ScaleY(m_Points[m_nFocusPoint+1].dwLog); QRect rc3(x1-3,y1-3,x1+3,y1+3 ); rc3 = rc3.normalized(); rc3.adjust(-1,-1,1,1); QRect temp; temp = rc1.united(rc2); rcInvalid = temp.united( rc3 ); } // Update the drag offset. This will be repainted in the paint routine. //m_ptDragOffset = pt - m_ptDragPickup; m_ptDragCPoint.setX( SnapX(UnscaleX(pt.x())) ); m_ptDragCPoint.setY( SnapY(UnscaleY(pt.y())) ); update( rcInvalid ); } //CRect rcBounds(m_rcChartPlotArea.left, m_rcChartPlotArea.top, m_rcChartPlotArea.right+1, m_rcChartPlotArea.bottom + 1 ); //if ( rcBounds.PtInRect(pt) ) //{ // int x = UnscaleX( SnapScreenX(pt.x )); // int y = UnscaleY( SnapY(pt.y )); // TRACE("%d, %d\n", x, y ); //} if ( m_rcChartPlotArea.contains( pt ) ) emit mousePositionChanged( SnapX(UnscaleX(pt.x())), SnapX(UnscaleY(pt.y())) ); }
void NS_DIM_PREFIX UgText (const char *s, INT mode) { INT reject; SHORT_POINT out; char *p,*next,*move; short baseline; short TextSize; #ifdef ModelP if (me != master) return; #endif ClipPoint(CurrCursor,&out,&reject); if (reject) return; switch (mode) { case TEXT_INDEXED : strcpy(buffer,s); p = buffer; baseline = out.y; TextSize = CurrTextSize; next = strchr(p,INDEXCHAR); if (next!=NULL) *next = '\0'; move = strchr(p,MOVECHAR); if (move!=NULL) *move = '\0'; (*CurrentOutputDevice->Move)(out); (*CurrentOutputDevice->DrawText)(p,TEXT_REGULAR); while (next!=NULL) { /* shift cursor to end of last string */ if (move!=NULL) out.x += REL_CHARWIDTH * CurrTextSize * strlen(p) * CurrentOutputDevice->signx; p = next; next = strchr(++p,INDEXCHAR); if (next!=NULL) *next = '\0'; move = strchr(p,MOVECHAR); if (move!=NULL) *move = '\0'; switch (*p) { case 'N' : UgSetTextSize(TextSize); out.y = baseline; break; case 'H' : UgSetTextSize(REL_INDEXSIZE*TextSize); out.y = baseline + 0.5*TextSize*CurrentOutputDevice->signy; break; case 'T' : UgSetTextSize(REL_INDEXSIZE*TextSize); out.y = baseline - 0.5*TextSize*CurrentOutputDevice->signy; break; } p++; (*CurrentOutputDevice->Move)(out); (*CurrentOutputDevice->DrawText)(p,TEXT_REGULAR); } return; case TEXT_REGULAR : case TEXT_INVERSE : (*CurrentOutputDevice->Move)(out); (*CurrentOutputDevice->DrawText)(s,mode); } }