コード例 #1
0
void CIppsSignalDC::Create(CDC* pDC, CIppsSignal* pSignal, int initialWidth)
{
   m_pSignal = pSignal;
   m_InitialWidth = initialWidth;
   if (!CreateCompatibleDC(pDC)) return;
   m_pBitmap = new CBitmap;
   if (!m_pBitmap->CreateCompatibleBitmap(pDC,
      GetWidth(), GetHeight())) return;
   SelectObject(m_pBitmap);
   AllocatePoints();
}
コード例 #2
0
ファイル: Curve.cpp プロジェクト: cDoru/projectanarchy
VCurve2DBase::VCurve2DBase(int iNumPoints)
{
  m_fDuration = -1.f;
  m_fMax = -1000000000.f;
  m_iNumCurvePoints = 0;
  m_pPoints = NULL;
  m_fLookupCount = 0.f;
  m_iLookupCount = 0;
  m_pLookupValues = NULL;

  AllocatePoints(iNumPoints);
}
コード例 #3
0
ファイル: Curve.cpp プロジェクト: cDoru/projectanarchy
void VCurve2DBase::SerializeX( VArchive &ar )
{
  char iVersion = 0;
  if (ar.IsLoading())
  {
    int iLookupCount;
    ar >> iVersion; VASSERT(iVersion==0);
    ar >> m_iNumCurvePoints;
    AllocatePoints(m_iNumCurvePoints);
    if (m_iNumCurvePoints>0)
      ar.Read(m_pPoints,m_iNumCurvePoints*sizeof(VCurvePoint2D),"ffffff",m_iNumCurvePoints);
    ar >> m_fDuration >> m_fMax;
    ar >> iLookupCount;
    if (iLookupCount>0)
      CreateLookup(iLookupCount);
  } else
コード例 #4
0
ファイル: Curve.cpp プロジェクト: cDoru/projectanarchy
bool VCurve2DBase::DataExchangeXML(TiXmlElement *pCurveNode, bool bWrite)
{
  if (!pCurveNode)
    return false;
  const char *szPointNodeName = "point";

  // curve points
  int iCount = GetNumPoints();
  XMLHelper::Exchange_Int(pCurveNode,"numpoints",iCount,bWrite);
  if (bWrite)
  {
    // write out points
    VCurvePoint2D *p = m_pPoints;
    for (int i=0;i<iCount;i++,p++)
    {
      TiXmlElement *pPointNode = XMLHelper::SubNode(pCurveNode,szPointNodeName,bWrite);
      p->DataExchangeXML(pPointNode,bWrite);
    }
  }
  else
  {
    // allocate and read points
    AllocatePoints(iCount);
    int iIndex = 0;   
    TiXmlNode *pFirstPoint = pCurveNode->FirstChild(szPointNodeName);
    if (pFirstPoint)
    {
	    for (TiXmlElement *pPoint=pFirstPoint->ToElement(); pPoint!=NULL; pPoint=pPoint->NextSiblingElement(szPointNodeName),iIndex++)
      {
        VASSERT(iIndex<iCount && "More point nodes defined than defined via 'numpoints' attribute");
        // First point should have x = 0.f
        if (iIndex == 0)
          m_pPoints[iIndex].m_vPos.x = 0.f;
        if (iIndex<iCount)
          m_pPoints[iIndex].DataExchangeXML(pPoint,bWrite);
      }
    }
    UpdateCurve();
  }

  return true;
}
コード例 #5
0
ファイル: Curve.hpp プロジェクト: cDoru/projectanarchy
  ///\brief
	///Copies the passed array of points
	///
	///\param pPoints
	///SOurce array to copy
	///
	///\param iNumPoints
	///Number of source points, will be allocated by this operation
	///
	inline void SetPoints(VCurvePoint2D* pPoints, int iNumPoints) 
  { 
    AllocatePoints(iNumPoints);
    memcpy(m_pPoints, pPoints, iNumPoints*sizeof(VCurvePoint2D));
  }
コード例 #6
0
ファイル: Stroke.c プロジェクト: idunham/dtextra
static void Input (Widget W, StrokeStatePtr State, XEvent *event)
{
	/*
	   fprintf(stderr, "Input(%s,%i) - %s %i %i %i %i\n",
	   XtName(State->widget),
	   event->xany.type,
	   XtName(W),
	   event->xbutton.x,
	   event->xbutton.y,
	   event->xbutton.x_root,
	   event->xbutton.y_root);
	 */
	switch (event->xany.type)
	{
	case KeyRelease:
	case ButtonRelease:
		if (State->InStroke)
		{
			int i;

			if (!State->Debug)
			{
				for (i = 1; i < State->npoints; i++)
				{
					XDrawLine(XtDisplay(W),
						  event->xbutton.root,
						  State->gc,
						  State->points[i - 1].x,
						  State->points[i - 1].y,
						  State->points[i].x,
						  State->points[i].y);
					/*
					   XDrawRectangle(XtDisplay(State->widget),
					   XtWindow(State->widget),
					   State->gc,
					   State->points[State->npoints].x - 2,
					   State->points[State->npoints].y - 2,
					   4,
					   4);
					 */
				}
			}
			XtUngrabPointer(W, event->xbutton.time);
			XUngrabServer(XtDisplay(W));
			DoStroke(event, State);
			State->InStroke = False;
			State->npoints = 0;
		}
		break;
	case KeyPress:
	case ButtonPress:
		if (!State->InStroke)
		{
			State->widget = W;
			State->npoints = 0;
			AllocatePoints(State);
			/*
			   TranslateCoords(W, State->widget,
			   &((XButtonPressedEvent *)event)->x,
			   &((XButtonPressedEvent *)event)->y);
			 */
			State->points[State->npoints].x = event->xbutton.x_root;
			State->points[State->npoints].y = event->xbutton.y_root;
			State->xmin = State->points[State->npoints].x;
			State->ymin = State->points[State->npoints].y;
			State->xmax = State->points[State->npoints].x;
			State->ymax = State->points[State->npoints].y;
			State->npoints++;
			State->InStroke = True;
			XGrabServer(XtDisplay(W));
			XtGrabPointer(W, 
				False,
				ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
				GrabModeAsync, GrabModeAsync, None, None, event->xbutton.time);
		}
		break;
	case MotionNotify:
		if (State->gc == (GC)NULL)
		{
			Pixel Background;

			State->gc = XCreateGC(XtDisplay(State->widget),
					      XtWindow(State->widget),
					      0, NULL);
			XtVaGetValues(State->widget,
				      XtNbackground, &Background,
				      NULL);
			XSetForeground(XtDisplay(State->widget),
				       State->gc,
				       Background);
			XSetFunction(XtDisplay(State->widget), State->gc, GXxor);
			XSetSubwindowMode(XtDisplay(State->widget), State->gc, IncludeInferiors);
		}
		if (State->InStroke)
		{
			int dx = State->points[State->npoints - 1].x - event->xmotion.x_root;
			int dy = State->points[State->npoints - 1].y - event->xmotion.y_root;

			if (dx * dx + dy * dy > State->slop)
			{
				AllocatePoints(State);
				State->points[State->npoints].x = event->xmotion.x_root;
				State->points[State->npoints].y = event->xmotion.y_root;
				XDrawLine(XtDisplay(State->widget),
					  event->xmotion.root,
					  State->gc,
					  State->points[State->npoints - 1].x,
					  State->points[State->npoints - 1].y,
					  State->points[State->npoints].x,
					  State->points[State->npoints].y);
				State->xmin = State->xmin < State->points[State->npoints].x ? State->xmin : State->points[State->npoints].x;
				State->xmax = State->xmax > State->points[State->npoints].x ? State->xmax : State->points[State->npoints].x;
				State->ymin = State->ymin < State->points[State->npoints].y ? State->ymin : State->points[State->npoints].y;
				State->ymax = State->ymax > State->points[State->npoints].y ? State->ymax : State->points[State->npoints].y;
				State->npoints++;
			}
		}
		break;
	default:
		fprintf(stderr, "%s(%i): Input(%s) - %s Unknown event type %i\n",
			__FILE__,
			__LINE__,
			XtName(State->widget),
			XtName(W),
			event->type);
	}
}
コード例 #7
0
ファイル: Stroke.c プロジェクト: idunham/dtextra
static void 
DoStroke(XEvent *event, StrokeStatePtr State)
{
	int i;
	int xtol;
	int ytol;
	int LastBox;
	int BoxWidth;
	int BoxHeight;
	int x0, x1, x2, x3;
	int y0, y1, y2, y3;
	String action;
	StrokeMapPtr *tmp = State->Map;
	int FinalPoints;

	/*
	   fprintf(stderr, "DoStroke(%s) - %i %i %i %i\n",
	   XtName(State->widget),
	   State->xmin, State->ymin,
	   State->xmax, State->ymax);
	 */
	if (State->npoints < 2)
		return;

	BoxWidth = State->xmax - State->xmin;
	BoxHeight = State->ymax - State->ymin;
	x0 = State->xmin;
	x1 = State->xmin + (1 * BoxWidth / 3);
	x2 = State->xmin + (2 * BoxWidth / 3);
	x3 = State->xmin + (3 * BoxWidth / 3);
	xtol = BoxWidth / State->slop;
	y0 = State->ymin;
	y1 = State->ymin + (1 * BoxHeight / 3);
	y2 = State->ymin + (2 * BoxHeight / 3);
	y3 = State->ymin + (3 * BoxHeight / 3);
	ytol = BoxHeight / State->slop;
	if (x3 - x0 < 20)
	{
		x1 = x0 - 1;
		x2 = x3 + 1;
	}
	if (y3 - y0 < 20)
	{
		y1 = y0 - 1;
		y2 = y3 + 1;
	}

	if (State->Debug)
	{
		XDrawRectangle(XtDisplay(State->widget),
			       event->xbutton.root,
			       State->gc,
			       x0, y0,
			       BoxWidth,
			       BoxHeight);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x1, y0,
			  x1, y3);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x1 - xtol, y0,
			  x1 - xtol, y3);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x1 + xtol, y0,
			  x1 + xtol, y3);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x2, y0,
			  x2, y3);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x2 - xtol, y0,
			  x2 - xtol, y3);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x2 + xtol, y0,
			  x2 + xtol, y3);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x0, y1,
			  x3, y1);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x0, y1 - ytol,
			  x3, y1 - ytol);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x0, y1 + ytol,
			  x3, y1 + ytol);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x0, y2,
			  x3, y2);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x0, y2 - ytol,
			  x3, y2 - ytol);
		XDrawLine(XtDisplay(State->widget),
			  event->xbutton.root,
			  State->gc,
			  x0, y2 + ytol,
			  x3, y2 + ytol);
	}
	for (i = 1; i < State->npoints; i++)
	{
		int dx = State->points[i - 1].x - State->points[i].x;
		int dy = State->points[i - 1].y - State->points[i].y;
		int maxx = (x2 - xtol) - (x1 + xtol);
		int maxy = (y2 - ytol) - (y1 + ytol);

		if (((dx * dx) >= (maxx * maxx)) || ((dy * dy) >= (maxy * maxy)))
		{
			int j;

			AllocatePoints(State);
			for (j = State->npoints; j > i; j--)
			{
				State->points[j].x = State->points[j - 1].x;
				State->points[j].y = State->points[j - 1].y;
			}
			State->npoints++;
			State->points[i].x = State->points[i - 1].x + (State->points[i].x - State->points[i - 1].x) / 2;
			State->points[i].y = State->points[i - 1].y + (State->points[i].y - State->points[i - 1].y) / 2;
			/*
			   XDrawRectangle(XtDisplay(State->widget),
			   XtWindow(State->widget),
			   State->gc,
			   State->points[i].x - 4,
			   State->points[i].y - 4,
			   8,
			   8);
			 */
			i--;
		}
	}
	for (i = 0; i < State->npoints; i++)
	{
		if ((State->points[i].x >= x0 && State->points[i].x < x1 - xtol) &&
		  (State->points[i].y >= y0 && State->points[i].y < y1 - ytol))
		{
			State->box[i] = 1;
		}
		else if ((State->points[i].x >= x1 + xtol && State->points[i].x < x2 - xtol) &&
		  (State->points[i].y >= y0 && State->points[i].y < y1 - ytol))
		{
			State->box[i] = 2;
		}
		else if ((State->points[i].x >= x2 + xtol && State->points[i].x <= x3) &&
		  (State->points[i].y >= y0 && State->points[i].y < y1 - ytol))
		{
			State->box[i] = 3;
		}
		else if ((State->points[i].x >= x0 && State->points[i].x < x1 - xtol) &&
			 (State->points[i].y >= y1 + ytol && State->points[i].y < y2 - ytol))
		{
			State->box[i] = 4;
		}
		else if ((State->points[i].x >= x1 + xtol && State->points[i].x < x2 - xtol) &&
			 (State->points[i].y >= y1 + ytol && State->points[i].y < y2 - ytol))
		{
			State->box[i] = 5;
		}
		else if ((State->points[i].x >= x2 + xtol && State->points[i].x <= x3) &&
			 (State->points[i].y >= y1 + ytol && State->points[i].y < y2 - ytol))
		{
			State->box[i] = 6;
		}
		else if ((State->points[i].x >= x0 && State->points[i].x < x1 - xtol) &&
		 (State->points[i].y >= y2 + ytol && State->points[i].y <= y3))
		{
			State->box[i] = 7;
		}
		else if ((State->points[i].x >= x1 + xtol && State->points[i].x < x2 - xtol) &&
		 (State->points[i].y >= y2 + ytol && State->points[i].y <= y3))
		{
			State->box[i] = 8;
		}
		else if ((State->points[i].x >= x2 + xtol && State->points[i].x <= x3) &&
		 (State->points[i].y >= y2 + ytol && State->points[i].y <= y3))
		{
			State->box[i] = 9;
		}
		else
		{
			State->box[i] = 0;
		}
	}
	LastBox = 0;
	FinalPoints = 0;
	action = XtNewString("Stroke-");
	for (i = 0; i < State->npoints; i++)
	{
		if ((State->box[i] != 0) && (State->box[i] != LastBox))
		{
			action = XtRealloc(action, 2 + strlen(action));
			sprintf(&action[strlen(action)], "%i", State->box[i]);
			LastBox = State->box[i];
			FinalPoints++;
		}
	}
	{
		StrokeStatePtr WidgetState;

		WidgetState = StrokeGetMap(State->widget);
		tmp = WidgetState->Map;
	}
	while (tmp != NULL && (*tmp) != NULL && FinalPoints > 2)
	{
		if (strcmp(&action[7], (*tmp)->Stroke) == 0)
		{
			if (State->Debug)
			{
				fprintf(stderr, "%s(%i) - %s Calling action >%s<\n",
					__FILE__, __LINE__,
					XtName(State->widget),
					(*tmp)->Action);
			}
			if (State->Sound != NULL)
			{
				XtCallActionProc(State->widget, "PlaySound", NULL, &State->Sound, 1);
			}
			XtCallActionProc(State->widget, (*tmp)->Action, event, NULL, 0);
			break;
		}
		tmp++;
	}
	if (((tmp == NULL) || ((*tmp) == NULL)) && FinalPoints > 2)
	{
		if (State->Debug)
		{
			fprintf(stderr, "%s(%i) - %s Calling action >%s<\n",
				__FILE__,
				__LINE__,
				XtName(State->widget),
				action);
		}
		XtCallActionProc(State->widget, action, event, NULL, 0);
	}
	XtFree(action);
}