コード例 #1
0
ファイル: button.cpp プロジェクト: cubemoon/game-editor
void KrButton::SetMode( int m )
{
	if (    Engine() 
		 && m != mode )
	{
		if ( ( m & DOWN ) && !( mode & DOWN ) )			// down transition
		{
			PublishEvent( ACTIVATED, 0, 0, 0, 0 );		
			if ( IsSelectable() )
			{
				mode = m;		// Prevent from recursion.
				KrEventManager::Instance()->SelectMe( this );
			}
		}
		else if ( !( m & DOWN ) && ( mode & DOWN ) )	// up transition
		{
			PublishEvent( DEACTIVATED, 0, 0, 0, 0 );
		}
		mode = m;

		KrColorTransform color;

		if ( mode == ( OVER ) )
		{
			color = scheme.CalcHiSec();
			bevel.DrawOut();
			if ( icon )
				icon->SetPos( iconX, iconY );
		}
		else if ( mode & DOWN )
		{		
			if ( mode & OVER )
				color = scheme.CalcDarkSec();
			else
				color = scheme.CalcDark();

			bevel.DrawIn();
			if ( icon )
				icon->SetPos( iconX+1, iconY+1 );
		}
		else
		{
			bevel.DrawOut();
			if ( icon )
				icon->SetPos( iconX, iconY );
		}

		plate->SetColor( color );
	}
}
コード例 #2
0
BOOL CDiagramEntity::IsSelected() const
/* ============================================================
	Function :		CDiagramEntity::IsSelected
	Description :	Checks if the object is selected.
					
	Return :		BOOL	-	TRUE if the object is selected.
	Parameters :	none

	Usage :			Call to see if the object is selected.

   ============================================================*/
{
	if (!IsSelectable()) return FALSE;
	return m_selected;

}
コード例 #3
0
void
TSigTextView::MessageReceived(BMessage *msg)
{
	char		type[B_FILE_NAME_LENGTH];
	char		*text;
	int32		end;
	int32		start;
	BFile		file;
	BNodeInfo	*node;
	entry_ref	ref;
	off_t		size;

	switch (msg->what) {
		case B_SIMPLE_DATA:
			if (msg->HasRef("refs")) {
				msg->FindRef("refs", &ref);
				file.SetTo(&ref, O_RDONLY);
				if (file.InitCheck() == B_NO_ERROR) {
					node = new BNodeInfo(&file);
					node->GetType(type);
					delete node;
					file.GetSize(&size);
					if ((!strncasecmp(type, "text/", 5)) && (size)) {
						text = (char *)malloc(size);
						file.Read(text, size);
						Delete();
						GetSelection(&start, &end);
						Insert(text, size);
						Select(start, start + size);
						free(text);
					}
				}
			}
			else
				BTextView::MessageReceived(msg);
			break;

		case M_SELECT:
			if (IsSelectable())
				Select(0, TextLength());
			break;

		default:
			BTextView::MessageReceived(msg);
	}
}
コード例 #4
0
void SelectNextActor()
{
   NxU32 nbActors = gScene->getNbActors();
   NxActor** actors = gScene->getActors();
   for(NxU32 i = 0; i < nbActors; i++)
   {
       if (actors[i] == gSelectedActor)
       {
           NxU32 j = 1;
           gSelectedActor = actors[(i+j)%nbActors];
           while (!IsSelectable(gSelectedActor))
           {
               j++;
               gSelectedActor = actors[(i+j)%nbActors];
           }
           break;
       }
   }
}
コード例 #5
0
unsigned int CTListBox::Process( UINT uiMsg,WPARAM wParam,LPARAM lParam )
{
	if( !IsVision() ) return 0;

	POINT ptMouse = { LOWORD(lParam), HIWORD(lParam ) };

	if( uiMsg == WM_LBUTTONDOWN )
		int mm = 0;
	
	if( IsSelectable() && ProcessSelectable( uiMsg , wParam, lParam ) )
		return m_iControlID;


	if( (uiMsg == WM_LBUTTONDOWN || uiMsg == WM_LBUTTONDBLCLK ) && IsInside( ptMouse.x, ptMouse.y ) && IsSelectable() )
	{
		int iExtent = m_nMaxLnCnt;
		int iCount  = 0;
		RECT rcHitTest = {0,0,0,0};
	


		if( m_nPutLnNum  + m_nMaxLnCnt >= (int)m_ITM.size() )///리스트의 최대범위밖으로 안나가도록 수정 
			iExtent = (int)m_ITM.size() - m_nPutLnNum;


		for( int i = m_nPutLnNum; i < m_nPutLnNum + iExtent ; ++i , ++iCount)
		{
			rcHitTest.left		= m_sPosition.x ; 
			rcHitTest.top		= m_sPosition.y  + iCount * ( m_iLineSpace + m_iCharHeight );
			rcHitTest.right		= rcHitTest.left + m_iWidth;
			rcHitTest.bottom	= rcHitTest.top  + m_iCharHeight;
			if( PtInRect( &rcHitTest, ptMouse ))
			{
				m_iSelectedItem = i;
				return GetControlID();
			}
		}
//		m_iSelectedItem = -1;
	}
	return 0;
}
コード例 #6
0
ファイル: QtArc2D.cpp プロジェクト: BenediktKohl/psketcher
void QtArc2D::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * /* widget */) 
{
	double level_of_detail = QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
  
	DisplayProperties current_properties;

	// @fixme the way radius_properties is defined in the following if statement block will prevent the user from changing the display properties of the radius dimension or the points at run time since the DisplayProperties constructor is used to set these properties
	DisplayProperties radius_properties; 

	if(option->state & QStyle::State_MouseOver && IsSelectable())
	{
		current_properties = GetMouseHoverProperties();
		radius_properties = DisplayProperties(HoverAnnotation);
	} else if (option->state & QStyle::State_Selected) {
		current_properties = GetSelectedProperties();
		radius_properties = DisplayProperties(SelectedAnnotation);
	} else {
		current_properties = GetProperties();
		radius_properties = DisplayProperties(Annotation);
	}
	
	double leader_gap = current_properties.GetLeaderGap()/level_of_detail;
	double leader_extension = current_properties.GetLeaderExtension()/level_of_detail;

	double leader_extension_angle = ((leader_extension/GetRadius()->GetValue())*(180.0/mmcPI))/level_of_detail;
	double leader_gap_angle = ((leader_gap/GetRadius()->GetValue())*(180.0/mmcPI))/level_of_detail;

	double radius = GetRadius()->GetValue();
	QRectF rect(QPointF(GetSCenter()->GetValue()-radius,-GetTCenter()->GetValue()-radius),
 				QPointF(GetSCenter()->GetValue()+radius,-GetTCenter()->GetValue()+radius));

	double angle1 = GetTheta1()->GetValue()*((180.0)/(mmcPI));
	double angle2 = GetTheta2()->GetValue()*((180.0)/(mmcPI));
	double text_angle = GetTextAngle()*((180.0)/(mmcPI));

    // put angle1 and angle2 into a preditable form
    // angle2 > angle1 and angle2 - angle1 < 360.0
    if(angle1 > angle2)
    {
        double temp;
        temp = angle1;
        angle1 = angle2;
        angle2 = temp;
    }
    if(angle2-angle1 >= 360.0)
        angle2 = angle2 - floor((angle2-angle1)/(360.0))*360.0;
    if(text_angle-angle1 >= 360.0)
        text_angle = text_angle - floor((text_angle-angle1)/(360.0))*360.0;
    else if(angle2 - text_angle >= 360.0)
        text_angle = text_angle + floor((angle2-text_angle)/(360.0))*360.0;

	// create the radius dimension if necessary
	// Only display the radius if it is not a free parameter
	// If it is a free parameter, it is not really a constraint and should not be displayed as such
	if( ! radius_->IsFree())
	{
		painter->setPen(radius_properties.GetPen(level_of_detail));
		painter->setBrush(radius_properties.GetBrush());

		QPolygonF radius_arrow = GetArrowPolygon(s_center_->GetValue(),-t_center_->GetValue(),s_center_->GetValue()+radius_->GetValue()*cos(GetTextAngle()),
							   -(t_center_->GetValue()+radius_->GetValue()*sin(GetTextAngle())), 15.0/level_of_detail,12.0/level_of_detail);
		painter->drawPolygon(radius_arrow);

		// extend arc to radius arrow if radius arrow is outside the arc
		if(text_angle < angle1)
		{
			painter->drawArc(rect,(text_angle-leader_extension_angle)*16.0, ((angle1-leader_gap_angle)-(text_angle-leader_extension_angle))*16.0);
		} else if(text_angle > angle2) {
			painter->drawArc(rect,(angle2+leader_gap_angle)*16.0,((text_angle+leader_extension_angle)-(angle2+leader_gap_angle))*16.0);
		}

		// draw a line from the arc center point to the text location in case the text is outside of the arc
		painter->drawLine(QPointF(s_center_->GetValue(),-t_center_->GetValue()),
					      QPointF(s_center_->GetValue()+GetTextRadius()*cos(GetTextAngle()),-(t_center_->GetValue()+GetTextRadius()*sin(GetTextAngle()))));

		// create the line edit widget graphics item
		if(radius_widget_ == 0)
		{
			// @fixme need to make sure the following dyname_cast won't create a pointer that is need used even if this shared_ptr class is freed from memory
			radius_widget_ = new QtArc2DWidget(shared_from_this(),dynamic_cast<QGraphicsItem*>(const_cast<QtArc2D*>(this)));
		}
		radius_widget_->UpdateGeometry(level_of_detail);
	}

	painter->setPen(current_properties.GetPen(level_of_detail));
	painter->setBrush(current_properties.GetBrush());

	// paint the actual arc
	QPainterPath arc_selection_path;
	painter->drawPath(GetArcAndSelectionPath(GetSCenter()->GetValue(), -GetTCenter()->GetValue(), radius, angle1*(mmcPI/180.0), angle2*(mmcPI/180.0), arc_selection_path, level_of_detail));
	current_shape_ = arc_selection_path;
}
コード例 #7
0
// ----------------------------------------------------------------------------
// Name : MouseMessage()
// Desc :
// ----------------------------------------------------------------------------
WMSG_RESULT CUIListBoxMultiCol::MouseMessage( MSG *pMsg )
{
	// If list box is disabled
	if( !IsEnabled() )
		return WMSG_FAIL;

	// Mouse point
	int	nX = LOWORD( pMsg->lParam );
	int	nY = HIWORD( pMsg->lParam );

	// Mouse message
	switch( pMsg->message )
	{
	case WM_MOUSEMOVE:
		{
			if( m_bSelectList )
			{
				m_nOverList = -1;

				if( IsInside( nX, nY ) )
				{
					int	nAbsY = GetAbsPosY();
					m_nOverList = ( nY - nAbsY - m_nTextSY + m_nSelectOffsetY ) / m_nLineHeight;

					return WMSG_SUCCESS;
				}
			}

			if( m_bScrollBar )
			{
				if( m_sbScrollBar.MouseMessage( pMsg ) != WMSG_FAIL )
					return WMSG_SUCCESS;
			}
		}
		break;

	case WM_LBUTTONDOWN:
		{
			if( m_bSelectList )
			{
				if( IsInside( nX, nY ) )
				{
					int	nAbsY = GetAbsPosY();
					m_nOverList = ( nY - nAbsY - m_nTextSY + m_nSelectOffsetY ) / m_nLineHeight;

					int	nRealSel = m_nOverList + m_sbScrollBar.GetScrollPos();
					if( nRealSel >= 0 && nRealSel < m_sbScrollBar.GetCurItemCount()
						&& IsSelectable(nRealSel) )
					{
						m_nSelectList = nRealSel;
						return WMSG_COMMAND;
					}
					else if(!m_bAtLeastOneSelect)
					{
						m_nSelectList = -1;
					}

					return WMSG_SUCCESS;
				}
			}

			if( m_bScrollBar )
			{
				if( m_sbScrollBar.MouseMessage( pMsg ) != WMSG_FAIL )
					return WMSG_SUCCESS;
			}
		}
		break;

	case WM_LBUTTONUP:
		{
			if( m_bScrollBar )
			{
				if( m_sbScrollBar.MouseMessage( pMsg ) != WMSG_FAIL )
					return WMSG_SUCCESS;
			}
		}
		break;

	case WM_LBUTTONDBLCLK:
		{
			if( m_bSelectList )
			{
				if( IsInside( nX, nY ) )
				{
					int	nAbsY = GetAbsPosY();
					m_nOverList = ( nY - nAbsY - m_nTextSY + m_nSelectOffsetY ) / m_nLineHeight;

					int	nRealSel = m_nOverList + m_sbScrollBar.GetScrollPos();
					if( nRealSel >= 0 && nRealSel < m_sbScrollBar.GetCurItemCount()
						&& IsSelectable(nRealSel) )
					{
						m_nSelectList = nRealSel;
						return WMSG_COMMAND;
					}

					return WMSG_SUCCESS;
				}
			}

			if( m_bScrollBar )
			{
				if( m_sbScrollBar.MouseMessage( pMsg ) != WMSG_FAIL )
					return WMSG_SUCCESS;
			}
		}
		break;

	case WM_MOUSEWHEEL:
		{
			if( m_bScrollBar )
			{
				if( m_sbScrollBar.MouseMessage( pMsg ) != WMSG_FAIL )
					return WMSG_SUCCESS;
			}
		}
		break;
	}

	return WMSG_FAIL;
}
コード例 #8
0
// ----------------------------------------------------------------------------
// Name : Render()
// Desc :
// ----------------------------------------------------------------------------
void CUIListBoxMultiCol::Render()
{
	// Get position
	int	nX, nY;
	GetAbsPos( nX, nY );

	// Add render regions
	// Selection bar
	if( m_bShowSelectBar && m_nSelectList >= 0 )
	{
		int	nSelLine = m_nSelectList - m_sbScrollBar.GetScrollPos();
		
		if( nSelLine >= 0 )
		{
			if( !m_bScrollBar || nSelLine < m_sbScrollBar.GetScrollRange() )
			{
				int	nBarY = nY + m_nTextSY + nSelLine * m_nLineHeight;
				CUIManager::getSingleton()->GetDrawPort()->AddTexture( nX + m_rcSelectOver.Left, nBarY + m_rcSelectOver.Top,
													nX + m_rcSelectOver.Right, nBarY + m_rcSelectOver.Bottom,
													m_rtSelectOver.U0, m_rtSelectOver.V0,
													m_rtSelectOver.U1, m_rtSelectOver.V1,
													0xFFFFFFFF );
			}
		}
	}

	// Scroll bar
	if( m_bScrollBar )
		m_sbScrollBar.Render();

	// Text in list box
	int		nTextY = nY;// + m_nTextSY;

	int	nRowS = m_sbScrollBar.GetScrollPos();
	int	nRowE = nRowS + m_nLinePerPage;
	if( nRowE > m_vecString.size())
		nRowE = m_vecString.size();

	for( int nCol = nRowS; nCol < nRowE; nCol++ )
	{
		if ( m_vecString[nCol].vecString.empty())
			continue;
		
		COLOR	colText = 0x00000000;		
		int		nSelList = -1, nOverList = -1;
		if( m_bSelectList )
		{
			nSelList = m_nSelectList;
			nOverList = nRowS + m_nOverList;
		}

		int		nTextX = nX;	

		for( int nList = 0; nList < m_nRowCount; nList++ )
		{
			if( !m_vecSelectable.empty() && m_vecSelectable.size () > nCol && IsSelectable(nCol) )
			{
				if( nCol == nSelList )
					colText = m_colSelectList;
				else if( nCol == nOverList )
					colText = m_colOverList;
				else
				{
					if ( nList < m_vecColor[nCol].vecColor.size())
						colText = m_vecColor[nCol].vecColor[nList];
					
				}
			}
			else
			{
				if ( nList < m_vecColor[nCol].vecColor.size())
						colText = m_vecColor[nCol].vecColor[nList];
			}

			if ( m_vecAlign.size() > nList )
			{			
				DrawText ( nCol, nList,nTextX, nTextY, m_vecAlign[nList], colText );
			}
			else
				DrawText ( nCol, nList,nTextX, nTextY, TEXT_LEFT, colText );
			
			if ( m_vecRowWidht.size () > nList )
				nTextX += m_vecRowWidht[nList];
			else 
				nTextX += _pUIFontTexMgr->GetFontWidth()* 20;
		}
		nTextY += m_nLineHeight;
	}
}
コード例 #9
0
void QtAngleLine2D::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * /* widget */)
{
    // @fixme need to handle the case where one of the lines has zero length (make sure there are no divide by zeros)

    double level_of_detail = QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());

    DisplayProperties current_properties;

    if(option->state & QStyle::State_MouseOver && IsSelectable())
    {
        current_properties = GetMouseHoverProperties();
    } else if (option->state & QStyle::State_Selected) {
        current_properties = GetSelectedProperties();
    } else {
        current_properties = GetProperties();
    }

    painter->setPen(current_properties.GetPen(level_of_detail));
    painter->setBrush(current_properties.GetBrush());

    double leader_gap = current_properties.GetLeaderGap()/level_of_detail;
    double leader_extension = current_properties.GetLeaderExtension()/level_of_detail;

    // first determine the intersection point of the two lines
    double x1 = GetLine1()->GetPoint1()->GetSValue();
    double x2 = GetLine1()->GetPoint2()->GetSValue();
    double x3 = GetLine2()->GetPoint1()->GetSValue();
    double x4 = GetLine2()->GetPoint2()->GetSValue();

    double y1 = GetLine1()->GetPoint1()->GetTValue();
    double y2 = GetLine1()->GetPoint2()->GetTValue();
    double y3 = GetLine2()->GetPoint1()->GetTValue();
    double y4 = GetLine2()->GetPoint2()->GetTValue();

    double denominator = (x1-x2)*(y3-y4)-(x3-x4)*(y1-y2);

    double text_x, text_y;
    double x_center, y_center;
    bool lines_parallel = false;
    double arrow_tip_x1;
    double arrow_tip_x2;
    double arrow_tip_y1;
    double arrow_tip_y2;

    if(denominator == 0.0)
    {
        // Lines are parallel
        lines_parallel = true;

        text_x = text_s_->GetValue();
        text_y = text_t_->GetValue();
    } else {
        // lines do intersect
        // finish calculating the intersection point
        double temp1 = x1*y2-y1*x2;
        double temp2 = x3*y4-x4*y3;

        x_center = (temp1*(x3-x4)-temp2*(x1-x2))/denominator;
        y_center = (temp1*(y3-y4)-temp2*(y1-y2))/denominator;

        text_x = x_center + GetTextRadius()*cos(GetTextAngle());
        text_y = y_center + GetTextRadius()*sin(GetTextAngle());
    }

    if(!lines_parallel)
    {
        // normal case where lines are not parallel
        double line1_theta = atan2(y2-y1, x2-x1);
        double line2_theta = atan2(y4-y3, x4-x3);
        if(line2_theta < line1_theta)
            line2_theta += 2.0*mmcPI;

        double theta;
        bool theta_is_interior;

        if(line2_theta - line1_theta > mmcPI)
        {
            theta_is_interior = false;
            theta = line2_theta - line1_theta - mmcPI;
        } else {
            theta_is_interior = true;
            theta = line2_theta - line1_theta;
        }

        double alpha1 = line1_theta;

        double alpha2 = alpha1 + theta;
        double alpha3 = alpha1 + mmcPI;
        double alpha4 = alpha1 + mmcPI + theta;
        double alpha5 = alpha1 + 2.0*mmcPI;

        double text_theta = GetTextAngle();

        // determine which sector the text is nearest too
        // first increment text_theta so that it is greater then alpha1 and less then alpha5
        if(text_theta < alpha1)
        {
            while (text_theta < alpha1)
                text_theta += 2.0*mmcPI;
        } else if (text_theta > alpha5) {
            while (text_theta > alpha5)
                text_theta -= 2.0*mmcPI;
        }

        double arrow_arc_theta1;
        double arrow_arc_theta2;
        if(IsInteriorAngle() && theta_is_interior || !IsInteriorAngle() && !theta_is_interior)
        {
            // either sector 1 or sector 3 for an interior angle
            double sector_1_delta = fabs((alpha1+alpha2)*0.5-text_theta);
            double sector_3_delta = fabs((alpha3+alpha4)*0.5-text_theta);

            if(sector_1_delta < sector_3_delta)
            {
                arrow_arc_theta1 = alpha1;
                arrow_arc_theta2 = alpha2;
            } else {
                arrow_arc_theta1 = alpha3;
                arrow_arc_theta2 = alpha4;
            }

            // theta1 correspnds to line1
            arrow_tip_x1 = x_center + GetTextRadius()*cos(arrow_arc_theta1);
            arrow_tip_y1 = y_center + GetTextRadius()*sin(arrow_arc_theta1);

            arrow_tip_x2 = x_center + GetTextRadius()*cos(arrow_arc_theta2);
            arrow_tip_y2 = y_center + GetTextRadius()*sin(arrow_arc_theta2);

        } else {
            // either sector 2 or sector 4 for an exterior angle
            double sector_2_delta = fabs((alpha2+alpha3)*0.5-text_theta);
            double sector_4_delta = fabs((alpha4+alpha5)*0.5-text_theta);

            if(sector_2_delta < sector_4_delta)
            {
                arrow_arc_theta1 = alpha2;
                arrow_arc_theta2 = alpha3;
            } else {
                arrow_arc_theta1 = alpha4;
                arrow_arc_theta2 = alpha5;
            }

            // theta1 correspnds to line2
            arrow_tip_x2 = x_center + GetTextRadius()*cos(arrow_arc_theta1);
            arrow_tip_y2 = y_center + GetTextRadius()*sin(arrow_arc_theta1);

            arrow_tip_x1 = x_center + GetTextRadius()*cos(arrow_arc_theta2);
            arrow_tip_y1 = y_center + GetTextRadius()*sin(arrow_arc_theta2);
        }

        // display the arrow arc
        QPainterPath selection_path;
        QPainterPath arrow_arc = GetArcArrowPathAndSelectionPath(x_center, -y_center, GetTextRadius(),arrow_arc_theta1,arrow_arc_theta2,15.0/level_of_detail,12.0/level_of_detail,selection_path,level_of_detail);
        painter->drawPath(arrow_arc);
        current_shape_ = selection_path;

        // draw an additional arc to the text if text is outside of the arrow arc
        QRectF rect(QPointF(x_center-GetTextRadius(),-y_center-GetTextRadius()),
                    QPointF(x_center+GetTextRadius(),-y_center+GetTextRadius()));
        if(text_theta < arrow_arc_theta1)
            painter->drawArc(rect,(text_theta)*(180.0/mmcPI)*16.0,(arrow_arc_theta1-text_theta)*(180.0/mmcPI)*16.0);
        else if (text_theta > arrow_arc_theta2)
            painter->drawArc(rect,(arrow_arc_theta2)*(180.0/mmcPI)*16.0,((text_theta)-(arrow_arc_theta2))*(180.0/mmcPI)*16.0);

        // display the editable text
        // create the line edit widget graphics item
        if(angle_widget_ == 0)
        {
            // @fixme need to make sure the following dyname_cast won't create a pointer that is need used even if this shared_ptr class is freed from memory
            angle_widget_ = new QtAngleLine2DWidget(shared_from_this(),dynamic_cast<QGraphicsItem*>(const_cast<QtAngleLine2D*>(this)));
        }
        angle_widget_->UpdateGeometry(text_x, text_y, level_of_detail);

        // create leader for line1 if necessary
        double delta1, delta2;
        double line1_length = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
        delta1 = sqrt((arrow_tip_x1-x1)*(arrow_tip_x1-x1)+(arrow_tip_y1-y1)*(arrow_tip_y1-y1));
        delta2 = sqrt((arrow_tip_x1-x2)*(arrow_tip_x1-x2)+(arrow_tip_y1-y2)*(arrow_tip_y1-y2));
        if(delta1 > line1_length && delta1 > delta2)
        {
            double direction_x = arrow_tip_x1-x1;
            double direction_y = arrow_tip_y1-y1;
            double direction_length = sqrt(direction_x*direction_x + direction_y*direction_y);
            direction_x = direction_x / direction_length;
            direction_y = direction_y / direction_length;

            painter->drawLine(QPointF(x2+leader_gap*direction_x,-(y2+leader_gap*direction_y)),
                              QPointF(x1+(delta1+leader_extension)*direction_x,-(y1+(delta1+leader_extension)*direction_y)));
        } else if (delta2 > line1_length) {
            double direction_x = arrow_tip_x1-x2;
            double direction_y = arrow_tip_y1-y2;
            double direction_length = sqrt(direction_x*direction_x + direction_y*direction_y);
            direction_x = direction_x / direction_length;
            direction_y = direction_y / direction_length;

            painter->drawLine(QPointF(x1+leader_gap*direction_x,-(y1+leader_gap*direction_y)),
                              QPointF(x2+(delta2+leader_extension)*direction_x,-(y2+(delta2+leader_extension)*direction_y)));
        }

        // create leader for line2 if necessary
        double line2_length = sqrt((x3-x4)*(x3-x4)+(y3-y4)*(y3-y4));
        delta1 = sqrt((arrow_tip_x2-x3)*(arrow_tip_x2-x3)+(arrow_tip_y2-y3)*(arrow_tip_y2-y3));
        delta2 = sqrt((arrow_tip_x2-x4)*(arrow_tip_x2-x4)+(arrow_tip_y2-y4)*(arrow_tip_y2-y4));
        if(delta1 > line2_length && delta1 > delta2)
        {
            double direction_x = arrow_tip_x2-x3;
            double direction_y = arrow_tip_y2-y3;
            double direction_length = sqrt(direction_x*direction_x + direction_y*direction_y);
            direction_x = direction_x / direction_length;
            direction_y = direction_y / direction_length;

            painter->drawLine(QPointF(x4+leader_gap*direction_x,-(y4+leader_gap*direction_y)),
                              QPointF(x3+(delta1+leader_extension)*direction_x,-(y3+(delta1+leader_extension)*direction_y)));
        } else if (delta2 > line2_length) {
            double direction_x = arrow_tip_x2-x4;
            double direction_y = arrow_tip_y2-y4;
            double direction_length = sqrt(direction_x*direction_x + direction_y*direction_y);
            direction_x = direction_x / direction_length;
            direction_y = direction_y / direction_length;

            painter->drawLine(QPointF(x3+leader_gap*direction_x,-(y3+leader_gap*direction_y)),
                              QPointF(x4+(delta2+leader_extension)*direction_x,-(y4+(delta2+leader_extension)*direction_y)));
        }

    } else {
        // the case where the lines are parallel

        // display an arrow to the center point of each of the lines
        QPainterPath selection_path;

        QPolygonF arrow1 = GetArrowPolygonAndSelectionPath(text_x, -text_y, 0.5*(x1+x2), -0.5*(y1+y2),15.0/level_of_detail,12.0/level_of_detail,selection_path,level_of_detail);
        painter->drawPolygon(arrow1);
        current_shape_ = selection_path;

        QPolygonF arrow2 = GetArrowPolygonAndSelectionPath(text_x, -text_y, 0.5*(x3+x4), -0.5*(y3+y4),15.0/level_of_detail,12.0/level_of_detail,selection_path,level_of_detail);
        painter->drawPolygon(arrow2);
        current_shape_.addPath(selection_path);

        // display the editable text
        // create the line edit widget graphics item
        if(angle_widget_ == 0)
        {
            // @fixme need to make sure the following dyname_cast won't create a pointer that is need used even if this shared_ptr class is freed from memory
            angle_widget_ = new QtAngleLine2DWidget(shared_from_this(),dynamic_cast<QGraphicsItem*>(const_cast<QtAngleLine2D*>(this)));
        }
        angle_widget_->UpdateGeometry(text_x, text_y, level_of_detail);

    } // if(!lines_parallel)

}
コード例 #10
0
ファイル: QtPoint2D.cpp プロジェクト: BenediktKohl/psketcher
void QtPoint2D::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * /* widget */) 
{
	double level_of_detail = QStyleOptionGraphicsItem::levelOfDetailFromTransform(painter->worldTransform());
	
	DisplayProperties current_properties;

	// @fixme the way constraint_properties is defined in the following if statement block will prevent the user from changing the display properties of the point constraints at run time since the DisplayProperties constructor is used to set these properties
	DisplayProperties constraint_properties;

	if(option->state & QStyle::State_MouseOver && IsSelectable())
	{
		current_properties = GetMouseHoverProperties();
		constraint_properties = DisplayProperties(HoverAnnotation);
	} else if (option->state & QStyle::State_Selected) {
		current_properties = GetSelectedProperties();
		constraint_properties = DisplayProperties(SelectedAnnotation);
	} else {
		current_properties = GetProperties();
		constraint_properties = DisplayProperties(Annotation);
	}

	painter->setPen(current_properties.GetPen(level_of_detail));
	painter->setBrush(current_properties.GetBrush());	

	QPainterPath point_path;
	PaintPointAndSelectionPath(painter, option, GetSValue(), -GetTValue(),point_path);

	// if point is constrained, draw the constraints
	if(! SIsFree() || ! TIsFree())
	{
		painter->setPen(constraint_properties.GetPen(level_of_detail));
		painter->setBrush(constraint_properties.GetBrush());
		
		double radius = 5.0/level_of_detail;

		if((! SIsFree() && ! GetSDOF()->IsDependent() )  && (! TIsFree() && ! GetTDOF()->IsDependent() ))
		{
			QRectF rect(QPointF(GetSValue()-radius,-(GetTValue()-radius)),
			QPointF(GetSValue()+radius,-(GetTValue()+radius)));
			painter->setBrush(Qt::NoBrush);
			painter->drawEllipse(rect);

		} else if((! SIsFree() && ! GetSDOF()->IsDependent() )) {

			painter->drawLine(QPointF(GetSValue()-radius,-(GetTValue()-radius)),
			QPointF(GetSValue()-radius,-(GetTValue()+radius)));

			painter->drawLine(QPointF(GetSValue()+radius,-(GetTValue()-radius)),
			QPointF(GetSValue()+radius,-(GetTValue()+radius)));

		} else if((! TIsFree() && ! GetTDOF()->IsDependent() )) {

			painter->drawLine(QPointF(GetSValue()+radius,-(GetTValue()+radius)),
			QPointF(GetSValue()-radius,-(GetTValue()+radius)));

			painter->drawLine(QPointF(GetSValue()-radius,-(GetTValue()-radius)),
			QPointF(GetSValue()+radius,-(GetTValue()-radius)));
		}
	}
	

	current_shape_ = point_path;
}
コード例 #11
0
void
ETextEditable::KeyDown(const char *bytes, eint32 numBytes)
{
	if(!IsEnabled() || !(IsEditable() || IsSelectable()) || !IsFocus() || numBytes < 1) return;
	if(bytes[0] == E_ENTER) return;

	EWindow *win = Window();
	if(!win) return;

	EMessage *msg = win->CurrentMessage();
	if(!msg || !(msg->what == E_KEY_DOWN || msg->what == E_UNMAPPED_KEY_DOWN)) return;

	eint32 modifiers = 0;
	msg->FindInt32("modifiers", &modifiers);
	if((modifiers & E_CONTROL_KEY) || (modifiers & E_COMMAND_KEY) ||
	   (modifiers & E_MENU_KEY) || (modifiers & E_OPTION_KEY)) return;

	bool shift_only = false;
	if(IsSelectable())
	{
		modifiers &= ~(E_CAPS_LOCK | E_SCROLL_LOCK | E_NUM_LOCK | E_LEFT_SHIFT_KEY | E_RIGHT_SHIFT_KEY);
		if(modifiers == E_SHIFT_KEY) shift_only = true;
	}

	if(numBytes == 1)
	{
		switch(bytes[0])
		{
			case E_ESCAPE:
				if(IsSelectable() && (fSelectTracking > 0 || IsSelected()))
				{
					fSelectTracking = -1;
					fSelectStart = fSelectEnd = -1;

					// call virtual function
					Select(fSelectStart, fSelectEnd);

					Invalidate();
				}
				break;

			case E_UP_ARROW:
			case E_DOWN_ARROW:
				break;

			case E_LEFT_ARROW:
				{
					bool redraw = false;

					eint32 oldStart = fSelectStart;
					eint32 oldEnd = fSelectEnd;
					if(IsSelectable() && shift_only)
					{
						if(fSelectTracking < 0)
						{
							if(IsSelected() && fSelectStart == fPosition)
							{
								fSelectTracking = fSelectEnd + 1;
								if(fPosition > 0) fSelectStart = fPosition - 1;
							}
							else
							{
								fSelectTracking = fPosition;
								fSelectStart = fSelectEnd = fPosition - 1;
							}
						}
						else if(fPosition > 0)
						{
							if(fPosition <= fSelectTracking)
							{
								fSelectStart = fPosition - 1;
								fSelectEnd = fSelectTracking - 1;
							}
							else
							{
								fSelectStart = fSelectTracking;
								fSelectEnd = fPosition - 2;
							}
						}
					}
					else if(IsSelectable())
					{
						fSelectStart = fSelectEnd = -1;
					}

					if(oldStart != fSelectStart || oldEnd != fSelectEnd)
					{
						// call virtual function
						Select(fSelectStart, fSelectEnd);
						redraw = true;
					}

					if(fPosition > 0)
					{
						fPosition = fPosition - 1;
						redraw = true;
					}

					if(redraw) Invalidate();
				}
				break;

			case E_RIGHT_ARROW:
				{
					bool redraw = false;

					eint32 oldStart = fSelectStart;
					eint32 oldEnd = fSelectEnd;
					if(IsSelectable() && shift_only)
					{
						if(fSelectTracking < 0)
						{
							if(IsSelected() && fSelectEnd == fPosition - 1)
							{
								fSelectTracking = fSelectStart;
								if(fPosition < fCount) fSelectEnd = fPosition;
							}
							else
							{
								fSelectTracking = fPosition;
								fSelectStart = fSelectEnd = fPosition;
							}
						}
						else if(fPosition < fCount)
						{
							if(fPosition >= fSelectTracking)
							{
								fSelectStart = fSelectTracking;
								fSelectEnd = fPosition;
							}
							else
							{
								fSelectStart = fPosition + 1;
								fSelectEnd = fSelectTracking - 1;
							}
						}
					}
					else if(IsSelectable())
					{
						fSelectStart = fSelectEnd = -1;
					}

					if(oldStart != fSelectStart || oldEnd != fSelectEnd)
					{
						// call virtual function
						Select(fSelectStart, fSelectEnd);
						redraw = true;
					}

					if(fPosition < fCount)
					{
						fPosition = fPosition + 1;
						redraw = true;
					}

					if(redraw) Invalidate();
				}
				break;

			case E_DELETE:
				if(IsSelectable() && IsEditable() && IsSelected())
				{
					eint32 oldPos = fSelectStart;
					RemoveText(fSelectStart, fSelectEnd);
					SetPosition(oldPos);
				}
				else if(fPosition < fCount && fPosition >= 0 && IsEditable())
				{
					RemoveText(fPosition, fPosition);
				}
				break;

			case E_BACKSPACE:
				if(IsSelectable() && IsEditable() && IsSelected())
				{
					eint32 oldPos = fSelectStart;
					RemoveText(fSelectStart, fSelectEnd);
					SetPosition(oldPos);
				}
				else if(fPosition > 0 && fPosition <= fCount && IsEditable())
				{
					eint32 oldCount = fCount;
					eint32 oldPos = fPosition;
					RemoveText(fPosition - 1, fPosition - 1);
					if(fCount < oldCount && oldPos == fPosition) SetPosition(oldPos - 1);
				}
				break;

			case E_HOME:
				{
					bool redraw = false;

					eint32 oldStart = fSelectStart;
					eint32 oldEnd = fSelectEnd;
					if(IsSelectable() && shift_only)
					{
						if(fSelectTracking < 0)
						{
							if(IsSelected() && fSelectStart == fPosition)
								fSelectTracking = fSelectEnd + 1;
							else
								fSelectTracking = fPosition;
						}
						fSelectStart = 0;
						fSelectEnd = fSelectTracking - 1;
					}
					else if(IsSelectable())
					{
						fSelectStart = fSelectEnd = -1;
					}

					if(oldStart != fSelectStart || oldEnd != fSelectEnd)
					{
						// call virtual function
						Select(fSelectStart, fSelectEnd);
						redraw = true;
					}

					if(fPosition != 0)
					{
						fPosition = 0;
						redraw = true;
					}

					if(redraw) Invalidate();
				}
				break;

			case E_END:
				{
					bool redraw = false;

					eint32 oldStart = fSelectStart;
					eint32 oldEnd = fSelectEnd;
					if(IsSelectable() && shift_only)
					{
						if(fSelectTracking < 0)
						{
							if(IsSelected() && fSelectEnd == fPosition - 1)
								fSelectTracking = fSelectStart;
							else
								fSelectTracking = fPosition;
						}
						fSelectStart = fSelectTracking;
						fSelectEnd = fCount - 1;
					}
					else if(IsSelectable())
					{
						fSelectStart = fSelectEnd = -1;
					}

					if(oldStart != fSelectStart || oldEnd != fSelectEnd)
					{
						// call virtual function
						Select(fSelectStart, fSelectEnd);
						redraw = true;
					}

					if(fPosition != fCount)
					{
						fPosition = fCount;
						redraw = true;
					}

					if(redraw) Invalidate();
				}
				break;

			default:
				if(bytes[0] >= 0x20 && bytes[0] <= 0x7e && IsEditable()) // printable
				{
					if(IsSelectable() && IsSelected())
					{
						eint32 oldPos = fSelectStart;
						RemoveText(fSelectStart, fSelectEnd);
						InsertText(bytes, 1, oldPos);
						SetPosition(oldPos + 1);
					}
					else
					{
						eint32 oldCount = fCount;
						eint32 oldPos = fPosition;
						InsertText(bytes, 1, fPosition);
						if(fCount > oldCount && oldPos == fPosition) SetPosition(oldPos + 1);
					}
				}
				break;
		}
	}
	else
	{
		if(IsEditable())
		{
			eint32 len = e_utf8_strlen(bytes);
			if(len > 0)
			{
				if(IsSelectable() && IsSelected())
				{
					eint32 oldPos = fSelectStart;
					RemoveText(fSelectStart, fSelectEnd);
					InsertText(bytes, len, oldPos);
					SetPosition(oldPos + len);
				}
				else
				{
					eint32 oldCount = fCount;
					eint32 oldPos = fPosition;
					InsertText(bytes, len, fPosition);
					if(fCount > oldCount && oldPos == fPosition) SetPosition(oldPos + len);
				}
			}
		}

		// TODO: input method
	}
}
コード例 #12
0
void
ETextEditable::MouseMoved(EPoint where, euint32 code, const EMessage *a_message)
{
	ERect rect = Frame().OffsetToSelf(E_ORIGIN);
	rect.left += fMargins.left;
	rect.top += fMargins.top;
	rect.right -= fMargins.right;
	rect.bottom -= fMargins.bottom;

	if(rect.Contains(where) == false || code == E_EXITED_VIEW)
	{
		etk_app->SetCursor(E_CURSOR_SYSTEM_DEFAULT, false);
		return;
	}

	etk_app->SetCursor(E_CURSOR_I_BEAM, false);

	if(!IsEnabled() || !IsSelectable() || fSelectTracking < 0) return;

	EWindow *win = Window();
	if(!win) return;

	if(!VisibleBounds().Contains(where)) return;
	if(!(IsEditable() || IsSelectable())) return;

	EFont font;
	GetFont(&font);

	float x = 0;
	if(!GetCharLocation(0, &x, NULL, &font)) return;

	eint32 pos = 0;

	if(where.x > x)
	{
		for(eint32 i = 0; i <= fCount; i++)
		{
			if(i == fCount)
			{
				pos = fCount;
			}
			else
			{
				x += (float)ceil((double)fCharWidths[i]);
				if(where.x < x)
				{
					pos = i;
					break;
				}
				x += (float)ceil((double)(font.Spacing() * font.Size()));
				if(where.x < x)
				{
					pos = i + 1;
					break;
				}
			}
		}
	}

	bool redraw = false;

	eint32 oldStart = fSelectStart;
	eint32 oldEnd = fSelectEnd;
	if(pos == fSelectTracking)
	{
		if(IsSelected()) redraw = true;
		fSelectStart = fSelectEnd = -1;
	}
	else if(pos > fSelectTracking)
	{
		fSelectStart = fSelectTracking;
		fSelectEnd = pos - 1;
	}
	else // pos < fSelectTracking
	{
		fSelectStart = pos;
		fSelectEnd = fSelectTracking - 1;
	}

	if(oldStart != fSelectStart || oldEnd != fSelectEnd)
	{
		// call virtual function
		Select(fSelectStart, fSelectEnd);
		redraw = true;
	}

	if(fPosition != pos)
	{
		fPosition = pos;
		redraw = true;
	}

	if(redraw) Invalidate();
}
コード例 #13
0
void
ETextEditable::MouseDown(EPoint where)
{
	ERect rect = Frame().OffsetToSelf(E_ORIGIN);
	rect.left += fMargins.left;
	rect.top += fMargins.top;
	rect.right -= fMargins.right;
	rect.bottom -= fMargins.bottom;

	if(!IsEnabled() || !rect.Contains(where) || !QueryCurrentMouse(true, E_PRIMARY_MOUSE_BUTTON)) return;
	if(!(IsEditable() || IsSelectable())) return;
	if(!IsFocus()) MakeFocus(true);

	EFont font;
	GetFont(&font);

	float x = 0;
	if(!GetCharLocation(0, &x, NULL, &font)) return;

	eint32 pos = 0;

	if(where.x > x)
	{
		for(eint32 i = 0; i <= fCount; i++)
		{
			if(i == fCount)
			{
				pos = fCount;
			}
			else
			{
				x += (float)ceil((double)fCharWidths[i]);
				if(where.x < x)
				{
					pos = i;
					break;
				}
				x += (float)ceil((double)(font.Spacing() * font.Size()));
				if(where.x < x)
				{
					pos = i + 1;
					break;
				}
			}
		}
	}

	bool redraw = IsSelected();

	if(IsFocus() && fSelectTracking < 0)
	{
		if(!(!IsSelectable() || SetPrivateEventMask(E_POINTER_EVENTS, E_LOCK_WINDOW_FOCUS) != E_OK))
		{
			fSelectStart = fSelectEnd = -1;
			fSelectTracking = pos;
		}
		else
		{
			fSelectStart = fSelectEnd = -1;
			fSelectTracking = -1;
		}

		// call virtual function
		Select(fSelectStart, fSelectEnd);
	}

	if(fPosition != pos)
	{
		fPosition = pos;
		redraw = true;
	}

	if(redraw) Invalidate();
}
コード例 #14
0
bool
ETextEditable::GetCharLocation(eint32 pos, float *x, float *y, EFont *tFont)
{
	if(!x) return false;

	ERect rect = Frame().OffsetToSelf(E_ORIGIN);
	rect.left += fMargins.left;
	rect.top += fMargins.top;
	rect.right -= fMargins.right;
	rect.bottom -= fMargins.bottom;

	rect.InsetBy(2, 2);

	if(!rect.IsValid()) return false;

	EFont font;
	e_font_height fontHeight;

	if(tFont) font = *tFont;
	else GetFont(&font);
	font.GetHeight(&fontHeight);
	float sHeight = fontHeight.ascent + fontHeight.descent;
	float strWidth = (fCount <= 0 ? 0.f : max_c(0.f, _StringWidth(font, fText)));
	float fontSpacing = (float)ceil((double)font.Spacing() * font.Size());

	if(fAlignment == E_ALIGN_RIGHT) *x = rect.right - strWidth;
	else if(fAlignment == E_ALIGN_CENTER) *x = rect.Center().x - strWidth / 2.f;
	else *x = rect.left; /* E_ALIGN_LEFT */
	if(y) *y = (rect.Center().y - sHeight/ 2.f + fontHeight.ascent + 1);

	if(strWidth <= rect.Width() || !IsEnabled() ||
	   !(IsEditable() || (IsSelectable() && IsSelected())) ||
	   fPosition < 0 || fPosition > fCount)
	{
		locationOffset = 0;
	}
	else
	{
		float xx = *x + locationOffset;

		if(fPosition > 0 && fPosition < fCount)
		{
			const char *p = e_utf8_at((const char*)fText, fPosition, NULL);
			if(p != NULL)
			{
				EString str;
				str.Append(fText, (eint32)(p - (const char*)fText));
				xx += _StringWidth(font, str.String()) + fontSpacing;
			}
		}
		else if(fPosition == fCount)
		{
			xx += strWidth + fontSpacing;
		}

		if(xx < rect.left)
			locationOffset += (rect.left - xx);
		else if(xx > rect.right)
			locationOffset += (rect.right - xx);
	}

	*x += locationOffset;

	if(pos > 0 && pos < fCount)
	{
		const char *p = e_utf8_at((const char*)fText, pos, NULL);
		if(p != NULL)
		{
			EString str;
			str.Append(fText, (eint32)(p - (const char*)fText));
			*x += _StringWidth(font, str.String()) + fontSpacing;
		}
	}
	else if(pos < 0 || pos >= fCount)
	{
		*x += strWidth + fontSpacing;
	}

	return true;
}
コード例 #15
0
void ProcessInputs()
{
    ProcessForceKeys();

	// Core dump
	if (bCoreDump)
	{
		bool ok = NXU::coreDump(gPhysicsSDK, fnameCD, NXU::FT_XML, true, false);
		if(ok) {
			printf("Output core dump successfully!\n");
		} else {
			printf("Output core dump failed!\n");
		}
		bCoreDump = false;
	}

	// Load core to core container
	if (bLoadCore)
	{
		if(gPhysicsCollection) {
			NXU::releaseCollection(gPhysicsCollection);
			gPhysicsCollection = NULL;
		}
		gPhysicsCollection = LoadCoreDump(fnameCD);
		if(!gPhysicsCollection) {
			printf("Unable to load the core dump, please first save a core dump.\n");
		}
		else
		{
			printf("Core dump has been loaded into container.\n");
		}
		bLoadCore = false;
	}

	// instantiate a core dump
	if(bInstantiateCore) {
		if(gPhysicsCollection) {
			if(gPhysicsSDK) {
				ReleasePhysicsSDK(gPhysicsSDK);
				gPhysicsSDK = CreatePhysics();
			}
			if(InstantiateCoreDump(gPhysicsSDK, gPhysicsCollection)) {
				if(gPhysicsSDK->getNbScenes()) {
					gScene = gPhysicsSDK->getScene(0);
					AddUserDataToActors(gScene);
					NxActor** actors = gScene->getActors();
					gSelectedActor = *actors;
					while(!IsSelectable(gSelectedActor))
					{
						gSelectedActor = *actors++;
					}
				}
				printf("Core dump instantiated\n");
			}
			else
			{
				printf("Error in instantiating the core dump\n");
			}
		}
		else
		{
				printf("Unable to instantiate the core dump with an empty container\n");
		}
		bInstantiateCore = false;
	}

    // Show debug wireframes
	if (bDebugWireframeMode)
	{
		if (gScene)  gDebugRenderer.renderData(*gScene->getDebugRenderable());
	}
}