Exemplo n.º 1
0
void DrawPage(void)
{
	int i;
	display_line = DISPLAY_LINE_START;
	DRAW_RECT(0.5000, 0.5000, 1.0000, 1.0000, 0, 0, 0, 90);
	DRAW_RECT(WINDOW_X_CENTRE, window_height_centre, WINDOW_WIDTH+0.004f, window_height+0.006f, r, g, b, 255);
	DRAW_RECT(WINDOW_X_CENTRE, window_height_centre, WINDOW_WIDTH, window_height, 0, 0, 0, 255);
	
	SET_TEXT_SCALE(TEXT_W, TEXT_H);
	SET_TEXT_COLOUR(r, g, b, 255);
	SET_TEXT_DROPSHADOW(FALSE, 0, 0, 0, 255);
	SET_TEXT_WRAP(WINDOW_LEFT, WINDOW_LEFT+WINDOW_WIDTH);
	SET_TEXT_CENTRE(TRUE);
	DISPLAY_TEXT_WITH_LITERAL_STRING(WINDOW_X_CENTRE, TEXT_TOP, "STRING", page_title );

	for ( i = 0; i < num_items; ++i )
	{
		SET_TEXT_SCALE(TEXT_W, TEXT_H);
		SET_TEXT_DROPSHADOW(FALSE, 0, 0, 0, 255);
		
		if ( selection == i )
		{
			SET_TEXT_COLOUR(0, 0, 0, 255);
			DRAW_RECT(WINDOW_X_CENTRE, display_line+(TEXT_LINE_SPACING/2), WINDOW_WIDTH, TEXT_LINE_SPACING, r, g, b, 255);
		}
		else SET_TEXT_COLOUR(r, g, b, 255);
		DISPLAY_TEXT_WITH_LITERAL_STRING(TEXT_LEFT, display_line, "STRING", item[i].desc );

		if ( item[i].type == TYPE_TOGGLE) // toggle displayer
		{
			SET_TEXT_SCALE(TEXT_W, TEXT_H);
			SET_TEXT_DROPSHADOW(FALSE, 0, 0, 0, 255);
			if ( item[i].value )
			{
				if ( selection == i )
				{
					SET_TEXT_COLOUR(0, 0, 0, 255);
				}
				else 
				{
					SET_TEXT_COLOUR(r, g, b, 255);
					//DISPLAY_TEXT_WITH_LITERAL_STRING(TEXT_RIGHT, display_line, "STRING", "On");
				}
			}
		}

		display_line += TEXT_LINE_SPACING;
	}
}
Exemplo n.º 2
0
bool GiGraphics::drawEllipse(const GiContext* ctx, const Point2d& center, 
                             float rx, float ry, bool modelUnit)
{
    if (rx < _MGZERO || isStopping())
        return false;
    
    bool ret = false;
    Matrix2d matD(S2D(xf(), modelUnit));

    if (ry < _MGZERO) {
        ry = (Vector2d(rx, rx) * matD).x;
        ry = fabsf((Vector2d(ry, ry) * matD.inverse()).y);
    }

    const Box2d extent (center, rx*2.f, ry*2.f);            // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (mgIsZero(matD.m12) && mgIsZero(matD.m21)) {
        Point2d cen (center * matD);
        rx *= fabsf(matD.m11);
        ry *= fabsf(matD.m22);
        ret = rawEllipse(ctx, cen.x - rx, cen.y - ry, 2 * rx, 2 * ry);
    } else {
        Point2d pxs[13];
        mgcurv::ellipseToBezier(pxs, center, rx, ry);
        matD.transformPoints(13, pxs);

        ret = rawBeziers(ctx, pxs, 13, true);
    }

    return ret;
}
Exemplo n.º 3
0
bool GiGraphics::drawPath(const GiContext* ctx, int count, 
                          const Point2d* points, const UInt8* types, 
                          bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 2 
        || points == NULL || types == NULL)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    if (count > 0x2000)
        count = 0x2000;

    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                     // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    vector<Point2d> pxpoints;
    pxpoints.resize(count);
    Point2d *pxs = &pxpoints.front();

    for (int i = 0; i < count; i++)
        pxs[i] = points[i] * matD;

    return rawPath(ctx, count, pxs, types);
}
Exemplo n.º 4
0
IPlugEffect::IPlugEffect(IPlugInstanceInfo instanceInfo)
  :	IPLUG_CTOR(kNumPublicParams, kNumPrivateParams, kNumPrograms, instanceInfo)
{
  TRACE;

  //arguments are: name, defaultVal, minVal, maxVal, step, label
  GetParam(kGain)->InitDouble("Gain", 50., 0., 100.0, 0.01, "%");
  GetParam(kGain)->SetShape(2.);

  IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);

  pGraphics->AttachPanelBackground(&COLOR_GRAY);
  
  IBitmap* knob = pGraphics->LoadPointerToBitmap(KNOB_ID, KNOB_FN, kKnobFrames);
  pGraphics->AttachControl(new IKnobMultiControl(this, kGainX, kGainY, kGain, knob));
   
 
  IColor textColor = IColor(255, 0, 0, 0);
  IText textProps4(24, &textColor, "Arial", IText::kStyleNormal, IText::kAlignCenter, 0, IText::kQualityDefault);
  pGraphics->AttachControl(new ITextControl(this, DRAW_RECT(80, 44, 220, 84), &textProps4, "Hello IPlug!"));
  
  AttachGraphics(pGraphics);

  //MakePreset("preset 1", ... );
  MakeDefaultPreset((char *) "-", kNumPrograms);
}
Exemplo n.º 5
0
bool GiGraphics::drawClosedBSplines(const GiContext* ctx, 
                                    int count, 
                                    const Point2d* ctlpts, 
                                    bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 3 || ctlpts == NULL)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    count = mgMin(count, static_cast<int>((0x2000 - 1) / 3));

    const Box2d extent (count, ctlpts);              // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    int i;
    Point2d pt1, pt2, pt3, pt4;
    float d6 = 1.f / 6.f;
    vector<Point2d> pxpoints;
    Matrix2d matD(S2D(xf(), modelUnit));

    // 开辟整形像素坐标数组
    pxpoints.resize(1 + count * 3);
    Point2d *pxs = &pxpoints.front();

    // 计算第一个曲线段
    pt1 = ctlpts[0] * matD;
    pt2 = ctlpts[1] * matD;
    pt3 = ctlpts[2] * matD;
    pt4 = ctlpts[3 % count] * matD;
    (*pxs++).set((pt1.x + 4 * pt2.x + pt3.x)*d6, (pt1.y + 4 * pt2.y + pt3.y)*d6);
    (*pxs++).set((4 * pt2.x + 2 * pt3.x)    *d6, (4 * pt2.y + 2 * pt3.y)    *d6);
    (*pxs++).set((2 * pt2.x + 4 * pt3.x)    *d6, (2 * pt2.y + 4 * pt3.y)    *d6);
    (*pxs++).set((pt2.x + 4 * pt3.x + pt4.x)*d6, (pt2.y + 4 * pt3.y + pt4.y)*d6);

    // 计算其余曲线段
    for (i = 4; i < count + 3; i++)
    {
        pt1 = pt2;
        pt2 = pt3;
        pt3 = pt4;
        pt4 = ctlpts[i % count] * matD;
        (*pxs++).set((4 * pt2.x + 2 * pt3.x)    *d6, (4 * pt2.y + 2 * pt3.y)    *d6);
        (*pxs++).set((2 * pt2.x + 4 * pt3.x)    *d6, (2 * pt2.y + 4 * pt3.y)    *d6);
        (*pxs++).set((pt2.x + 4 * pt3.x + pt4.x)*d6, (pt2.y + 4 * pt3.y + pt4.y)*d6);
    }

    // 绘图
    bool ret = rawBeginPath();
    if (ret)
    {
        ret = rawMoveTo(pxs[0].x, pxs[0].y);
        ret = rawBezierTo(pxs + 1, getSize(pxpoints) - 1);
        ret = rawClosePath();
        ret = rawEndPath(ctx, true);
    }

    return ret;
}
IPlugEffectGUILiveEdit::IPlugEffectGUILiveEdit(IPlugInstanceInfo instanceInfo)
	: IPLUG_CTOR(kNumPublicParams, kNumPrivateParams, kNumPrograms, instanceInfo)
{
	TRACE;

	//arguments are: name, defaultVal, minVal, maxVal, step, label
	GetParam(kGain)->InitDouble("Gain", 50., 0., 100.0, 0.01, "%");
	GetParam(kGain)->SetShape(2.);

	IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight);

	// Here we are attaching our GUI resize control ------------------------------------------------------------------------------
	// It is important to create on top of all controls!
	AttachGUIResize(new IPlugGUIResize(this, pGraphics, true, 16, 16));
	// ---------------------------------------------------------------------------------------------------------------------------

	pGraphics->AttachPanelBackground(&COLOR_GRAY);

	// Start Live GUI edit
	GUI_EDIT_START;

	NEW_LAYER;
	IRECT knobPosition = DRAW_RECT(80, 110, 128, 158);
	IBitmap* knob = pGraphics->LoadPointerToBitmap(KNOB_ID, KNOB_FN, kKnobFrames);
	pGraphics->AttachControl(new IKnobMultiControl(this, knobPosition.L, knobPosition.T, kGain, knob));
	END;

	NEW_LAYER;
	IColor textColor = IColor(255, 0, 0, 0);
	IText textProps(24, &textColor, "Arial", IText::kStyleNormal, IText::kAlignCenter, 0, IText::kQualityDefault);
	pGraphics->AttachControl(new ITextControl(this, DRAW_RECT(50, 20, 190, 60), &textProps, "Hello IPlug!"));
	END;

	// End Live GUI edit
	GUI_EDIT_FINISH;

	// Attach GUI live edit control. Use __FILE__ macro to get source file path. You can remove it after you edit your GUI. 
	pGraphics->AttachControl(new IPlugGUILiveEdit(this, __FILE__, 10));

	AttachGraphics(pGraphics);

	//MakePreset("preset 1", ... );
	MakeDefaultPreset((char *) "-", kNumPrograms);
}
Exemplo n.º 7
0
bool GiGraphics::drawBeziers(const GiContext* ctx, int count, 
                             const Point2d* points, bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 4 || points == NULL)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    if (count > 0x2000)
        count = 0x2000;
    count = 1 + (count - 1) / 3 * 3;

    bool ret = false;
    vector<Point2d> pxpoints;
    vector<Point2d> pointBuf;
    int i, j, n, si, ei;
    Point2d * pxs;
    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                 // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (DRAW_MAXR(m_impl, modelUnit).contains(extent))  // 全部在显示区域内
    {
        pxpoints.resize(count);
        pxs = &pxpoints.front();
        for (i = 0; i < count; i++)
            pxs[i] = points[i] * matD;
        ret = rawBeziers(ctx, pxs, count);
    }
    else
    {        
        pointBuf.resize(count);
        for (i = 0; i < count; i++)                 // 转换到像素坐标
            pointBuf[i] = points[i] * matD;
        Point2d* pts = &pointBuf.front();

        si = ei = 0;
        for (i = 3; i < count; i += 3)
        {
            for ( ; i < count
                && m_impl->rectDraw.isIntersect(Box2d(4, &pts[ei])); i += 3)
                ei = i;
            n = ei - si + 1;
            if (n > 1)
            {
                pxpoints.resize(n);
                pxs = &pxpoints.front();
                for (j=0; j<n; j++)
                    pxs[j] = pts[si + j];
                ret = rawBeziers(ctx, pxs, n);
            }
            si = ei = i;
        }
    }
    return ret;
}
Exemplo n.º 8
0
bool GiGraphics::drawBeziers(const GiContext* ctx, int count, 
                             const Point2d* points, bool closed, bool modelUnit)
{
    if (count < 4 || !points || isStopping())
        return false;
    if (count > 0x2000)
        count = 0x2000;
    count = 1 + (count - 1) / 3 * 3;

    bool ret = false;
    vector<Point2d> pxpoints;
    vector<Point2d> pointBuf;
    int i, j, n, si, ei;
    Point2d * pxs;
    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                 // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;
    
    if (closed) {
        pxpoints.resize(count);
        pxs = &pxpoints.front();
        for (i = 0; i < count; i++)
            pxs[i] = points[i] * matD;
        ret = rawBeziers(ctx, pxs, count, closed);
    }
    else if (DRAW_MAXR(m_impl, modelUnit).contains(extent)) {   // 全部在显示区域内
        pxpoints.resize(count);
        pxs = &pxpoints.front();
        for (i = 0; i < count; i++)
            pxs[i] = points[i] * matD;
        ret = rawBeziers(ctx, pxs, count);
    } else {
        pointBuf.resize(count);
        for (i = 0; i < count; i++)                 // 转换到像素坐标
            pointBuf[i] = points[i] * matD;
        Point2d* pts = &pointBuf.front();

        for (i = 0; i + 3 < count;) {
            for (; i + 3 < count && !m_impl->rectDraw.isIntersect(Box2d(4, &pts[i])); i += 3) ;
            si = ei = i;
            for (; i + 3 < count && m_impl->rectDraw.isIntersect(Box2d(4, &pts[i])); i += 3)
                ei = i + 3;
            if (ei > si) {
                n = ei - si + 1;
                pxpoints.resize(n);
                pxs = &pxpoints.front();
                for (j=0; j<n; j++)
                    pxs[j] = pts[si + j];
                ret = rawBeziers(ctx, pxs, n);
            }
        }
    }
    return ret;
}
Exemplo n.º 9
0
bool GiGraphics::drawLines(const GiContext* ctx, int count, 
                           const Point2d* points, bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 2 || points == NULL)
        return false;
    if (count > 0x2000)
        count = 0x2000;
    GiLock lock (&m_impl->drawRefcnt);

    int i;
    Point2d pt1, pt2, ptLast;
    vector<Point2d> pxpoints;
    vector<Point2d> pointBuf;
    bool ret = false;
    Matrix2d matD(S2D(xf(), modelUnit));

    const Box2d extent (count, points);                 // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (DRAW_MAXR(m_impl, modelUnit).contains(extent))  // 全部在显示区域内
    {
        pxpoints.resize(count);
        Point2d* pxs = &pxpoints.front();
        int n = 0;
        for (i = 0; i < count; i++)
        {
            pt2 = points[i] * matD;
            if (i == 0 || fabs(pt1.x - pt2.x) > 2 || fabs(pt1.y - pt2.y) > 2)
            {
                pt1 = pt2;
                pxs[n++] = pt2;
            }
        }
        ret = rawLines(ctx, pxs, n);
    }
    else                                            // 部分在显示区域内
    {
        pointBuf.resize(count);
        for (i = 0; i < count; i++)                 // 转换到像素坐标
            pointBuf[i] = points[i] * matD;
        Point2d* pts = &pointBuf.front();

        ptLast = pts[0];
        PolylineAux aux(this, ctx);
        for (i = 0; i < count - 1; i++)
        {
            ret = DrawEdge(count, i, pts, ptLast, aux, m_impl->rectDraw) || ret;
        }
    }

    return ret;
}
Exemplo n.º 10
0
bool GiGraphics::drawRoundRect(const GiContext* ctx, 
                               const Box2d& rect, float rx, float ry, 
                               bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || rect.isEmpty())
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    bool ret = false;

    if (ry < _MGZERO)
        ry = rx;

    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(rect))  // 全部在显示区域外
        return false;

    if (rx < _MGZERO)
    {
        Point2d points[4] = {
            rect.leftBottom(), rect.rightBottom(), 
            rect.rightTop(), rect.leftTop()
        };
        return drawPolygon(ctx, 4, points);
    }
    else
    {
        Point2d points[16];

        mgRoundRectToBeziers(points, rect, rx, ry);
        S2D(xf(), modelUnit).TransformPoints(16, points);

        ret = rawBeginPath();
        if (ret)
        {
            ret = rawMoveTo(points[0].x, points[0].y);
            ret = rawBezierTo(&points[1], 3);

            ret = rawLineTo(points[4].x, points[4].y);
            ret = rawBezierTo(&points[5], 3);

            ret = rawLineTo(points[8].x, points[8].y);
            ret = rawBezierTo(&points[9], 3);

            ret = rawLineTo(points[12].x, points[12].y);
            ret = rawBezierTo(&points[13], 3);

            ret = rawClosePath();
            ret = rawEndPath(ctx, true);
        }
    }

    return ret;
}
Exemplo n.º 11
0
bool GiGraphics::drawLine(const GiContext* ctx, const Point2d& startPt,
                          const Point2d& endPt, bool modelUnit)
{
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(Box2d(startPt, endPt)))
        return false;

    Point2d pts[2] = { startPt * S2D(xf(), modelUnit), endPt * S2D(xf(), modelUnit) };

    if (!mglnrel::clipLine(pts[0], pts[1], m_impl->rectDraw))
        return false;

    return rawLine(ctx, pts[0].x, pts[0].y, pts[1].x, pts[1].y);
}
Exemplo n.º 12
0
bool GiGraphics::drawBSplines(const GiContext* ctx, int count, const Point2d* ctlpts,
                              bool closed, bool modelUnit)
{
    if (closed) {
        if (count < 3 || !ctlpts || isStopping())
            return false;
        count = mgMin(count, static_cast<int>((0x2000 - 1) / 3));
    } else {
        if (count < 4 || !ctlpts || isStopping())
            return false;
        count = mgMin(count, static_cast<int>(3 + (0x2000 - 1) / 3));
    }
    
    const Box2d extent (count, ctlpts);                     // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    int i;
    Point2d pt1, pt2, pt3, pt4;
    float d6 = 1.f / 6.f;
    vector<Point2d> pxpoints;
    Matrix2d matD(S2D(xf(), modelUnit));

    // 开辟像素坐标数组
    pxpoints.resize(1 + (closed ? count : (count - 3)) * 3);
    Point2d *pxs = &pxpoints.front();

    // 计算第一个曲线段
    pt1 = ctlpts[0] * matD;
    pt2 = ctlpts[1] * matD;
    pt3 = ctlpts[2] * matD;
    pt4 = ctlpts[3 % count] * matD;
    (*pxs++).set((pt1.x + 4 * pt2.x + pt3.x)*d6, (pt1.y + 4 * pt2.y + pt3.y)*d6);
    (*pxs++).set((4 * pt2.x + 2 * pt3.x)    *d6,  (4 * pt2.y + 2 * pt3.y)   *d6);
    (*pxs++).set((2 * pt2.x + 4 * pt3.x)    *d6,  (2 * pt2.y + 4 * pt3.y)   *d6);
    (*pxs++).set((pt2.x + 4 * pt3.x + pt4.x)*d6, (pt2.y + 4 * pt3.y + pt4.y)*d6);

    // 计算其余曲线段
    for (i = 4; i < (closed ? (count + 3) : count); i++) {
        pt1 = pt2;
        pt2 = pt3;
        pt3 = pt4;
        pt4 = ctlpts[i % count] * matD;
        (*pxs++).set((4 * pt2.x + 2 * pt3.x)    *d6, (4 * pt2.y + 2 * pt3.y)   *d6);
        (*pxs++).set((2 * pt2.x + 4 * pt3.x)    *d6, (2 * pt2.y + 4 * pt3.y)   *d6);
        (*pxs++).set((pt2.x + 4 * pt3.x + pt4.x)*d6,(pt2.y + 4 * pt3.y + pt4.y)*d6);
    }

    // 绘图
    return rawBeziers(ctx, &pxpoints.front(), getSize(pxpoints), closed);
}
Exemplo n.º 13
0
bool GiGraphics::drawRoundRect(const GiContext* ctx, 
                               const Box2d& rect, float rx, float ry, 
                               bool modelUnit)
{
    if (rect.isEmpty() || isStopping())
        return false;
    bool ret = false;

    if (ry < _MGZERO)
        ry = rx;

    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(rect))  // 全部在显示区域外
        return false;

    if (rx < _MGZERO) {
        Point2d points[4] = {
            rect.leftBottom(), rect.rightBottom(), 
            rect.rightTop(), rect.leftTop()
        };
        return drawPolygon(ctx, 4, points);
    } else {
        Point2d pxs[16];

        mgcurv::roundRectToBeziers(pxs, rect, rx, ry);
        S2D(xf(), modelUnit).transformPoints(16, pxs);

        ret = rawBeginPath();
        if (ret) {
            rawMoveTo(pxs[0].x, pxs[0].y);
            rawBezierTo(pxs[1].x, pxs[1].y, pxs[2].x, pxs[2].y, pxs[3].x, pxs[3].y);

            rawLineTo(pxs[4].x, pxs[4].y);
            rawBezierTo(pxs[5].x, pxs[5].y, pxs[6].x, pxs[6].y, pxs[7].x, pxs[7].y);

            rawLineTo(pxs[8].x, pxs[8].y);
            rawBezierTo(pxs[9].x, pxs[9].y, pxs[10].x, pxs[10].y, pxs[11].x, pxs[11].y);

            rawLineTo(pxs[12].x, pxs[12].y);
            rawBezierTo(pxs[13].x, pxs[13].y, pxs[14].x, pxs[14].y, pxs[15].x, pxs[15].y);

            rawClosePath();
            ret = rawEndPath(ctx, true);
        }
    }

    return ret;
}
Exemplo n.º 14
0
bool GiGraphics::drawEllipse(const GiContext* ctx, const Point2d& center, 
                             float rx, float ry, bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || rx < _MGZERO)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    bool ret = false;
    Matrix2d matD(S2D(xf(), modelUnit));

    if (ry < _MGZERO) {
        ry = (Vector2d(rx, rx) * matD).x;
        ry = fabsf((Vector2d(ry, ry) * matD.inverse()).y);
    }

    const Box2d extent (center, rx*2.f, ry*2.f);            // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (mgIsZero(matD.m12) && mgIsZero(matD.m21))
    {
        Point2d cen (center * matD);
        rx *= fabsf(matD.m11);
        ry *= fabsf(matD.m22);

        ret = rawEllipse(ctx, cen.x - rx, cen.y - ry, 2 * rx, 2 * ry);
    }
    else
    {
        Point2d pxs[13];
        mgcurv::ellipseToBezier(pxs, center, rx, ry);
        matD.TransformPoints(13, pxs);

        ret = rawBeginPath();
        if (ret)
        {
            rawMoveTo(pxs[0].x, pxs[0].y);
            for (int i = 1; i + 2 < 13; i += 3) {
                rawBezierTo(pxs[i].x, pxs[i].y,
                    pxs[i+1].x, pxs[i+1].y, pxs[i+2].x, pxs[i+2].y);
            }
            rawClosePath();
            ret = rawEndPath(ctx, true);
        }
    }

    return ret;
}
Exemplo n.º 15
0
bool GiGraphics::drawPolygon(const GiContext* ctx, int count, 
                             const Point2d* points, bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || count < 2 || points == NULL)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    if (count > 0x2000)
        count = 0x2000;

    bool ret = false;

    const Box2d extent (count, points);                 // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (DRAW_MAXR(m_impl, modelUnit).contains(extent))  // 全部在显示区域内
    {
        ret = _DrawPolygon(m_impl->canvas, ctx, 
            count, points, true, true, true, modelUnit);
    }
    else                                                // 部分在显示区域内
    {
        PolygonClip clip (m_impl->rectDraw);
        if (!clip.clip(count, points, &S2D(xf(), modelUnit)))  // 多边形剪裁
            return false;
        count = clip.getCount();
        points = clip.getPoints();

        ret = _DrawPolygon(m_impl->canvas, ctx, 
            count, points, false, true, false, modelUnit);

        int ienter = findInvisibleEdge(clip);
        if (ienter == count)
        {
            ret = _DrawPolygon(m_impl->canvas, ctx, count, points, 
                false, false, true, modelUnit) || ret;
        }
        else
        {
            ret = drawPolygonEdge(PolylineAux(this, ctx), count, clip, ienter) || ret;
        }
    }

    return ret;
}
Exemplo n.º 16
0
bool GiGraphics::drawEllipse(const GiContext* ctx, const Point2d& center, 
                             float rx, float ry, bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || rx < _MGZERO)
        return false;
    GiLock lock (&m_impl->drawRefcnt);
    bool ret = false;
    Matrix2d matD(S2D(xf(), modelUnit));

    if (ry < _MGZERO)
        ry = rx;

    const Box2d extent (center, rx*2.f, ry*2.f);            // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    if (mgIsZero(matD.m12) && mgIsZero(matD.m21))
    {
        Point2d cen (center * matD);
        rx *= matD.m11;
        ry *= matD.m22;

        ret = rawEllipse(ctx, cen.x - rx, cen.y - ry, 2 * rx, 2 * ry);
    }
    else
    {
        Point2d points[13];
        mgEllipseToBezier(points, center, rx, ry);
        matD.TransformPoints(13, points);

        ret = rawBeginPath();
        if (ret)
        {
            ret = rawMoveTo(points[0].x, points[0].y);
            ret = rawBezierTo(points + 1, 12);
            ret = rawClosePath();
            ret = rawEndPath(ctx, true);
        }
    }

    return ret;
}
Exemplo n.º 17
0
bool GiGraphics::drawArc(const GiContext* ctx,
                         const Point2d& center, float rx, float ry, 
                         float startAngle, float sweepAngle, 
                         bool modelUnit)
{
    if (rx < _MGZERO || fabsf(sweepAngle) < 1e-5f || isStopping())
        return false;

    if (ry < _MGZERO)
        ry = rx;

    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(Box2d(center, 2 * rx, 2 * ry)))
        return false;

    Point2d points[16];
    int count = mgcurv::arcToBezier(points, center,
        rx, ry, startAngle, sweepAngle);
    S2D(xf(), modelUnit).transformPoints(count, points);

    return count > 3 && rawBeziers(ctx, points, count);
}
Exemplo n.º 18
0
bool GiGraphics::drawArc(const GiContext* ctx, 
                         const Point2d& center, float rx, float ry, 
                         float startAngle, float sweepAngle, 
                         bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || rx < _MGZERO || fabs(sweepAngle) < 1e-5f)
        return false;
    GiLock lock (&m_impl->drawRefcnt);

    if (ry < _MGZERO)
        ry = rx;

    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(Box2d(center, 2 * rx, 2 * ry)))
        return false;

    Point2d points[16];
    int count = mgAngleArcToBezier(points, center,
        rx, ry, startAngle, sweepAngle);
    S2D(xf(), modelUnit).TransformPoints(count, points);

    return count > 3 && rawBeziers(ctx, points, count);
}
Exemplo n.º 19
0
bool GiGraphics::drawPie(const GiContext* ctx, 
                         const Point2d& center, float rx, float ry, 
                         float startAngle, float sweepAngle, 
                         bool modelUnit)
{
    if (m_impl->drawRefcnt == 0 || rx < _MGZERO || fabsf(sweepAngle) < 1e-5f)
        return false;
    GiLock lock (&m_impl->drawRefcnt);

    if (ry < _MGZERO)
        ry = rx;

    const Box2d extent (center, rx*2.f, ry*2.f);            // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;

    Point2d pxs[16];
    int count = mgcurv::arcToBezier(pxs, center,
        rx, ry, startAngle, sweepAngle);
    if (count < 4)
        return false;
    S2D(xf(), modelUnit).TransformPoints(count, pxs);
    Point2d cen(center * S2D(xf(), modelUnit));

    bool ret = rawBeginPath();
    if (ret)
    {
        rawMoveTo(cen.x, cen.y);
        rawLineTo(pxs[0].x, pxs[0].y);
        for (int i = 1; i + 2 < count; i += 3) {
            rawBezierTo(pxs[i].x, pxs[i].y,
                pxs[i+1].x, pxs[i+1].y, pxs[i+2].x, pxs[i+2].y);
        }
        rawClosePath();
        ret = rawEndPath(ctx, true);
    }

    return ret;
}
Exemplo n.º 20
0
bool GiGraphics::drawPolygon(const GiContext* ctx, int count, 
                             const Point2d* points, bool modelUnit)
{
    if (count < 2 || !points || isStopping())
        return false;
    
    count = count > 0x2000 ? 0x2000 : count;
    ctx = ctx ? ctx : &(m_impl->ctx);

    bool ret = false;

    const Box2d extent (count, points);                         // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))      // 全部在显示区域外
        return false;

    if (DRAW_MAXR(m_impl, modelUnit).contains(extent)) {        // 全部在显示区域内
        ret = _drawPolygon(ctx, count, points, true, true, true, modelUnit);
    } else {                                                    // 部分在显示区域内
        PolygonClip clip (m_impl->rectDraw);
        if (!clip.clip(count, points, &S2D(xf(), modelUnit)))   // 多边形剪裁
            return false;
        count = clip.getCount();
        points = clip.getPoints();

        ret = _drawPolygon(ctx, count, points, false, true, false, modelUnit);

        int ienter = findInvisibleEdge(clip);
        if (ienter == count) {
            ret = _drawPolygon(ctx, count, points, false, false, true, modelUnit) || ret;
        } else {
            ret = drawPolygonEdge(PolylineAux(this, ctx), count, clip, ienter) || ret;
        }
    }

    return ret;
}
Exemplo n.º 21
0
void do_menu(void){
	if(show_menu){ //regular xmc mode
		//xmc
		#define pos_x 0.25
		#define start_y 0.14
		INIT_FRONTEND_HELPER_TEXT();
		DRAW_FRONTEND_HELPER_TEXT("LEAVE", "INPUT_F_CANCEL", 0);
		DRAW_FRONTEND_HELPER_TEXT("CONFIRM", "INPUT_F_ACCEPT", 0);
		DRAW_FRONTEND_HELPER_TEXT("SCROLL", "PAD_DPAD_UPDOWN", 0);
	
		if(!xmc_compact){
			HIDE_HELP_TEXT_THIS_FRAME();
			pos_y = start_y;
			
			if(xmc_dim) DRAW_RECT(0.5000, 0.5000, 1.0000, 1.0000, 0, 0, 0, 110);
			
			//draw_title(0.5,0.05,0.6,0.98,s_r,s_g,s_b,255,MENU_TITLE);
			draw_title(0.5,0.05,0.6,0.98,s_r,s_g,s_b,255,footer);
			draw_title(0.5,0.109,0.4,0.50,s_r,s_g,s_b,255,MENU_AUTHOR);
			
			set_up_draw(3,0.35,0.35,255,255,255,255);
			//draw_text("STRING",0.05,0.975,footer);
			
			uint i = 1;
			for(i;i <= item_count;i++){
				r = 255;
				g = 255;
				b = 255;
				a = 255;
				pos_y = pos_y + 0.0375;
				if(item_select == i){
					r = s_r;
					g = s_g;
					b = s_b;
				}
				if(menu[i].type == 1){
					if(menu[i].value){
						set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
						draw_text("STRING",(pos_x + 0.3),pos_y,"On");
					}
					else{
						set_up_draw(3,0.35,0.35,255,255,255,a);
						draw_text("STRING",(pos_x + 0.3),pos_y,"Off");
					}
				}
				if(menu[i].type == 2){
					set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
					draw_text("STRING",(pos_x + 0.3),pos_y,"(");
					
					set_up_draw(3,0.35,0.35,255,255,255,a);				
					draw_number("NUMBR",(pos_x + 0.305),pos_y,menu[i].value);
					
					set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
					if(menu[i].value > 99)
						draw_text("STRING",(pos_x + 0.345),pos_y,")");
					else if(menu[i].value > 9)
						draw_text("STRING",(pos_x + 0.33),pos_y,")");
					else
						draw_text("STRING",(pos_x + 0.315),pos_y,")");
				}
				if(menu[i].type == 3){
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING",pos_x,pos_y,GET_STRING_FROM_TEXT_FILE(GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(menu[i].value)));
				}
				if(menu[i].type == 4){
					if(item_select == i){
						r = s_r;
						g = s_g;
						b = s_b;
					}
					else GET_PLAYER_RGB_COLOUR(menu[i].value,&r,&g,&b);
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING", pos_x, pos_y, menu[i].item_name);
				}
				if(menu[i].type == 5){
					if(!COMPARE_STRING(menu[i].item_name, "")){
						set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
						draw_text("STRING", pos_x - 0.08, pos_y, "Admin");
					}
					if(item_select == i){
						r = s_r;
						g = s_g;
						b = s_b;
					}
					else if(xmc_online_col) GET_PLAYER_RGB_COLOUR(menu[i].value,&r,&g,&b);					
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING", pos_x, pos_y, menu[i].item_name);
				}
				else{
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING",pos_x,pos_y,menu[i].item_name);
				}
			}
			
			
			
			///Buttons
			if(IS_BUTTON_JUST_PRESSED(0,DPAD_UP)){
				if(item_select == 1){
					item_select = item_count;
				}
				else item_select--;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_DOWN)){
				if(item_select == item_count){
					item_select = 1;
				}
				else item_select++;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_RIGHT) && menu[item_select].type == 2){
				if(menu[item_select].value == menu[item_select].maxval)
					menu[item_select].value = 1;
				else
					menu[item_select].value += 1;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_LEFT) && menu[item_select].type == 2){
				if(menu[item_select].value == 1)
					menu[item_select].value = menu[item_select].maxval;
				else
					menu[item_select].value -= 1;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,BUTTON_A)){
				if(menu[item_select].action){
					menu_functions();
				}
				else{
					uint i = 1;
					for(i;i <= item_count;i++){
						menu[i].action = false;
						menu[i].type = 0;
					}
					last_selected[menu_level] = item_select;
					menu_level++;
					menu_setup();
					item_select = 1;
				}
			}
			else if(IS_BUTTON_JUST_PRESSED(0,BUTTON_B)){
				if(menu_level > 0){
					uint i = 1;
					for(i;i <= item_count;i++){
						menu[i].action = false;
						menu[i].type = 0;
					}
					menu_level--;
					item_select = last_selected[menu_level];
					menu_setup();
				}
				else menu_shutdown();
			}
		}
		else{ 
			#define pos_x 0.60
			#define start_y 0.25 				
			#define spacing 0.025
			pos_y = start_y;
			drawWindow();
			s_a = 255;
			set_up_draw(4,0.35,0.35,s_r,s_g,s_b,255);
			draw_text("STRING",pos_x,start_y-.02,footer);
			uint i = 1;
			for(i;i <= item_count;i++){
				r = 255;g = 255;b = 255;a = 255;
				pos_y = pos_y + spacing;
				if(item_select == i){
					r = s_r;
					g = s_g;
					b = s_b;
				}
				if(menu[i].type == 1){
					if(menu[i].value){
						set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
						draw_text("STRING",(pos_x + 0.265),pos_y,"On");
					}
				}
				if(menu[i].type == 2){
					set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
					draw_text("STRING",(pos_x + 0.19),pos_y,"(");
					set_up_draw(3,0.35,0.35,255,255,255,a);				
					draw_number("NUMBR",(pos_x + 0.205),pos_y,menu[i].value);
					set_up_draw(3,0.35,0.35,s_r,s_g,s_b,a);
					if(menu[i].value > 99) draw_text("STRING",(pos_x + 0.245),pos_y,")");
					else if(menu[i].value > 9) draw_text("STRING",(pos_x + 0.23),pos_y,")");
					else draw_text("STRING",(pos_x + 0.215),pos_y,")");
				}
				if(menu[i].type == 3){
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING",pos_x,pos_y,GET_STRING_FROM_TEXT_FILE(GET_DISPLAY_NAME_FROM_VEHICLE_MODEL(menu[i].value)));
				}
				if(menu[i].type == 4){
					if(item_select == i){
						r = s_r;
						g = s_g;
						b = s_b;
					}
					else GET_PLAYER_RGB_COLOUR(menu[i].value,&r,&g,&b);
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING", pos_x, pos_y, menu[i].item_name);
				}
				else{
					set_up_draw(3,0.35,0.35,r,g,b,a);
					draw_text("STRING",pos_x,pos_y,menu[i].item_name);
				}
			}
			
			///Buttons
			if(IS_BUTTON_JUST_PRESSED(0,DPAD_UP)){
				if(item_select == 1){
					item_select = item_count;
				}
				else item_select--;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_DOWN)){
				if(item_select == item_count){
					item_select = 1;
				}
				else item_select++;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_RIGHT) && menu[item_select].type == 2){
				if(menu[item_select].value == menu[item_select].maxval)
					menu[item_select].value = 1;
				else
					menu[item_select].value += 1;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,DPAD_LEFT) && menu[item_select].type == 2){
				if(menu[item_select].value == 1)
					menu[item_select].value = menu[item_select].maxval;
				else
					menu[item_select].value -= 1;
			}
			else if(IS_BUTTON_JUST_PRESSED(0,BUTTON_A)){
				if(menu[item_select].action){
					menu_functions();
				}
				else{
					uint i = 1;
					for(i;i <= item_count;i++){
						menu[i].action = false;
						menu[i].type = 0;
					}
					last_selected[menu_level] = item_select;
					menu_level++;
					menu_setup();
					item_select = 1;
				}
			}
			else if(IS_BUTTON_JUST_PRESSED(0,BUTTON_B)){
				if(menu_level > 0){
					uint i = 1;
					for(i;i <= item_count;i++){
						menu[i].action = false;
						menu[i].type = 0;
					}
					menu_level--;
					item_select = last_selected[menu_level];
					menu_setup();
				}
				else menu_shutdown();
			}
		}
	}
	else if(!xmc_switch && IS_BUTTON_PRESSED(0,BUTTON_LB) && IS_BUTTON_JUST_PRESSED(0,BUTTON_RB)) menu_startup();
	else if(xmc_switch && IS_BUTTON_PRESSED(0,BUTTON_RB) && IS_BUTTON_JUST_PRESSED(0,BUTTON_LB)) menu_startup();
}
Exemplo n.º 22
0
bool GiGraphics::drawBeziers(const GiContext* ctx, int count,
                             const Point2d* knot, const Vector2d* knotvs,
                             bool closed, bool modelUnit)
{
    if (count < 2 || !knot || !knotvs || isStopping())
        return false;
    if (count > 0x1000)
        count = 0x1000;
    
    bool ret = false;
    vector<Point2d> pxpoints;
    vector<Point2d> pointBuf;
    int i, j, n, si, ei;
    Point2d * pxs;
    Matrix2d matD(S2D(xf(), modelUnit));
    
    const Box2d extent (count, knot);                       // 模型坐标范围
    if (!DRAW_RECT(m_impl, modelUnit).isIntersect(extent))  // 全部在显示区域外
        return false;
    
    pointBuf.resize(1 + (count - 1) * 3);
    pxs = &pointBuf.front();
    
    if (closed) {
        pxs[0] = knot[0] * matD;
        for (i = 0, j = 1; i + 1 < count; i++) {
            pxs[j++] = (knot[i] + knotvs[i]) * matD;
            pxs[j++] = (knot[i+1] - knotvs[i+1]) * matD;
            pxs[j++] = knot[i+1] * matD;
        }
        ret = rawBeziers(ctx, pxs, j, closed);
    }
    else if (DRAW_MAXR(m_impl, modelUnit).contains(extent)) {   // 全部在显示区域内
        pxs[0] = knot[0] * matD;
        for (i = 0, j = 1; i + 1 < count; i++) {
            pxs[j++] = (knot[i] + knotvs[i]) * matD;
            pxs[j++] = (knot[i+1] - knotvs[i+1]) * matD;
            pxs[j++] = knot[i+1] * matD;
        }
        ret = rawBeziers(ctx, pxs, j);
    } else {
        pxs[0] = knot[0] * matD;
        for (i = 0, j = 1; i + 1 < count; i++) {
            pxs[j++] = (knot[i] + knotvs[i]) * matD;
            pxs[j++] = (knot[i+1] - knotvs[i+1]) * matD;
            pxs[j++] = knot[i+1] * matD;
        }
        
        Point2d* pts = pxs;
        
        count = 1 + (count - 1) * 3;
        for (i = 0; i + 3 < count;) {
            for (; i + 3 < count && !m_impl->rectDraw.isIntersect(Box2d(4, &pts[i])); i += 3) ;
            si = ei = i;
            for (; i + 3 < count && m_impl->rectDraw.isIntersect(Box2d(4, &pts[i])); i += 3)
                ei = i + 3;
            if (ei > si) {
                n = ei - si + 1;
                pxpoints.resize(n);
                pxs = &pxpoints.front();
                for (j=0; j<n; j++)
                    pxs[j] = pts[si + j];
                ret = rawBeziers(ctx, pxs, n);
            }
        }
    }
    
    return ret;
}