Esempio n. 1
0
    void applyStrokeStyle()
    {
        if (strokeStyle == DottedStroke) {
            VGfloat vgFloatArray[2] = { 1.0, 1.0 };
            vgSetfv(VG_STROKE_DASH_PATTERN, 2, vgFloatArray);
            vgSetf(VG_STROKE_DASH_PHASE, 0.0);
        } else if (strokeStyle == DashedStroke) {
            if (!strokeDashArray.size()) {
                VGfloat vgFloatArray[2] = { 4.0, 3.0 };
                vgSetfv(VG_STROKE_DASH_PATTERN, 2, vgFloatArray);
            } else {
                Vector<VGfloat> vgFloatArray(strokeDashArray.size());
                for (int i = 0; i < strokeDashArray.size(); ++i)
                    vgFloatArray[i] = strokeDashArray[i];

                vgSetfv(VG_STROKE_DASH_PATTERN, vgFloatArray.size(), vgFloatArray.data());
            }
            vgSetf(VG_STROKE_DASH_PHASE, strokeDashOffset);
        } else {
            vgSetfv(VG_STROKE_DASH_PATTERN, 0, 0);
            vgSetf(VG_STROKE_DASH_PHASE, 0.0);
        }

        ASSERT_VG_NO_ERROR();
    }
Esempio n. 2
0
void InitializeOpenVGContext() {
	vgSeti(VG_PIXEL_LAYOUT, vgGeti(VG_SCREEN_LAYOUT));

	vgSetf(VG_STROKE_LINE_WIDTH, 4);
	vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_SQUARE);
	vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL);
}
Esempio n. 3
0
//Display functions
void display(float interval)
{
  int i;
  const VGfloat *style;
  VGfloat clearColor[] = {1,1,1,1};
  
  if (animate) {
    ang += interval * 360 * 0.1f;
    if (ang > 360) ang -= 360;
  }
  
  vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
  vgClear(0,0,testWidth(),testHeight());
  
  vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
  vgLoadIdentity();
  vgTranslate(testWidth()/2 + tx,testHeight()/2 + ty);
  vgScale(sx, sy);
  vgRotate(ang);
  
  for (i=0; i<pathCount; ++i) {
    
    style = styleArrays[i];
    vgSetParameterfv(tigerStroke, VG_PAINT_COLOR, 4, &style[0]);
    vgSetParameterfv(tigerFill, VG_PAINT_COLOR, 4, &style[4]);
    vgSetf(VG_STROKE_LINE_WIDTH, style[8]);
    vgDrawPath(tigerPaths[i], (VGint)style[9]); // Bingo!!, Draw it!! 
  }
  vgFlush();
}
Esempio n. 4
0
/*******************************************************************************
 * Function Name  : InitView
 * Inputs		  : uWidth, uHeight
 * Returns        : true if no error occured
 * Description    : Code in InitView() will be called by the Shell upon a change
 *					in the rendering context.
 *					Used to initialise variables that are dependent on the rendering
 *					context (e.g. textures, vertex buffers, etc.)
 *******************************************************************************/
bool CTransforms::InitView()
{
	// Create paths
	CreatePaths();

	// Create paint
	m_vgPaint = vgCreatePaint();
	vgSetParameteri(m_vgPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_vgPaint, PVRTRGBA(255, 255, 170, 255));

	vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
	vgSetf(VG_STROKE_LINE_WIDTH, 2.5f / PVRShellGet(prefHeight));

	/*
	The clear colour will be used whenever calling vgClear(). The colour is given
	as non-premultiplied sRGBA.
	*/
	VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f };
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	// Initialise custom text drawing
	m_PrintVG.Initialize(PVRShellGet(prefWidth), PVRShellGet(prefHeight));

	m_ui32StartTime = PVRShellGetTime();

	return true;
}
void CTSmallWindowOpenVG::RenderL()
	{
	CTWindow::RenderL();

	// Make sure that this egl status is active
	eglMakeCurrent(iDisplay, iSurface, iSurface, iContextVG);

    VGfloat clearColor[4] = {0.1f, 0.2f, 0.4f, 1.f};
    VGfloat scaleFactor = Size().iWidth/200.f;
    if (Size().iHeight/200.f < scaleFactor)
        {
        scaleFactor = Size().iHeight/200.f;
        }        

    iCurrentRotation = iTime;

    if (iCurrentRotation >= 360.f)
        {
        iCurrentRotation -= 360.f;
        }

    vgSetfv(VG_CLEAR_COLOR, 4, clearColor);
    vgClear(0, 0, Size().iWidth, Size().iHeight);

    vgLoadIdentity();
    vgTranslate((float)Size().iHeight / 2, (float)Size().iHeight / 2);
    vgScale(scaleFactor, scaleFactor);
    vgRotate(iCurrentRotation);
    vgTranslate(-50.f, -50.f);

    vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
    vgSeti(VG_FILL_RULE, VG_EVEN_ODD);

    vgSetPaint(iFillPaint, VG_FILL_PATH);

    vgSetf(VG_STROKE_LINE_WIDTH, 10.f);
    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND);
    vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
    vgSetf(VG_STROKE_MITER_LIMIT, 0.f);
    vgSetPaint(iStrokePaint, VG_STROKE_PATH);

    vgDrawPath(iPath, VG_FILL_PATH | VG_STROKE_PATH);

	iTime++;
	eglSwapBuffers(iDisplay, iSurface);
	}
Esempio n. 6
0
void PainterOpenVG::setStrokeThickness(float thickness)
{
    ASSERT(m_state);
    m_surface->makeCurrent();

    m_state->strokeThickness = thickness;
    vgSetf(VG_STROKE_LINE_WIDTH, thickness);
    ASSERT_VG_NO_ERROR();
}
Esempio n. 7
0
void PainterOpenVG::setMiterLimit(float miterLimit)
{
    ASSERT(m_state);
    m_surface->makeCurrent();

    m_state->strokeMiterLimit = miterLimit;
    vgSetf(VG_STROKE_MITER_LIMIT, miterLimit);
    ASSERT_VG_NO_ERROR();
}
Esempio n. 8
0
	// C function:: void vgSetf (VGParamType type, VGfloat value);
	JNIEXPORT jint JNICALL 
	Java_com_example_startvg_VG11_vgSetf( 
	  JNIEnv* env, jobject obj, 
		jint type, jfloat value ){
	  
		vgSetf (
		(VGParamType) type, 
		(VGfloat) value
		);		
	}
Esempio n. 9
0
    void applyState(PainterOpenVG* painter)
    {
        ASSERT(painter);

        setVGSolidColor(VG_FILL_PATH, fillColor);
        setVGSolidColor(VG_STROKE_PATH, strokeColor);

        vgSetf(VG_STROKE_LINE_WIDTH, strokeThickness);
        vgSeti(VG_STROKE_CAP_STYLE, toVGCapStyle(strokeLineCap));
        vgSeti(VG_STROKE_JOIN_STYLE, toVGJoinStyle(strokeLineJoin));
        vgSetf(VG_STROKE_MITER_LIMIT, strokeMiterLimit);

        if (antialiasingEnabled)
            vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_FASTER);
        else
            vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_NONANTIALIASED);

        applyBlending(painter);
        applyStrokeStyle();

        applyTransformationMatrix(painter);
        applyScissorRect();
    }
Esempio n. 10
0
void PS_render(PS* ps)
{
	int i;
	assert(ps);
	vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);

	for(i=0;i<ps->m_numPaths;i++)
	{
		vgSeti(VG_FILL_RULE, ps->m_paths[i].m_fillRule);
		vgSetPaint(ps->m_paths[i].m_fillPaint, VG_FILL_PATH);

		if(ps->m_paths[i].m_paintMode & VG_STROKE_PATH)
		{
			vgSetf(VG_STROKE_LINE_WIDTH, ps->m_paths[i].m_strokeWidth);
			vgSeti(VG_STROKE_CAP_STYLE, ps->m_paths[i].m_capStyle);
			vgSeti(VG_STROKE_JOIN_STYLE, ps->m_paths[i].m_joinStyle);
			vgSetf(VG_STROKE_MITER_LIMIT, ps->m_paths[i].m_miterLimit);
			vgSetPaint(ps->m_paths[i].m_strokePaint, VG_STROKE_PATH);
		}

		vgDrawPath(ps->m_paths[i].m_path, ps->m_paths[i].m_paintMode);
	}
	assert(vgGetError() == VG_NO_ERROR);
}
Esempio n. 11
0
static void
init(void)
{
   static const VGubyte sqrCmds[5] = {VG_MOVE_TO_ABS, VG_HLINE_TO_ABS, VG_VLINE_TO_ABS, VG_HLINE_TO_ABS, VG_CLOSE_PATH};
   static const VGfloat sqrCoords[5]   = {50.0f, 50.0f, 250.0f, 250.0f, 50.0f};
   path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
                       VG_PATH_CAPABILITY_APPEND_TO);
   vgAppendPathData(path, 5, sqrCmds, sqrCoords);

   fill = vgCreatePaint();
   vgSetParameterfv(fill, VG_PAINT_COLOR, 4, color);
   vgSetPaint(fill, VG_FILL_PATH);

   vgSetfv(VG_CLEAR_COLOR, 4, white_color);
   vgSetf(VG_STROKE_LINE_WIDTH, 10);
   vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT);
   vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
   vgSetf(VG_STROKE_MITER_LIMIT, 4.0f);

   vgSeti(VG_MASKING, VG_TRUE);

   vgMask(VG_INVALID_HANDLE, VG_CLEAR_MASK,
          25, 25, 100, 100);
}
Esempio n. 12
0
static void
draw(void)
{
    VGPath line;
    VGPaint fillPaint;
    VGubyte lineCommands[3] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_LINE_TO_ABS};
    VGfloat lineCoords[] =   {-2.0f,-1.0f, 0.0f,0.0f, -1.0f, -2.0f};
    VGfloat clearColor[] = {0.0f, 0.0f, 0.0f, 1.0f};/* black color */
    VGfloat fillColor[] = {1.0f, 1.0f, 1.0f, 1.0f};/* white color */
    //VGfloat testRadius = 60.0f;
    VGfloat testRadius = 10.0f;
    int WINDSIZEX = window_width();
    int WINDSIZEY = window_height();

    line = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F,
                        1.0f, 0.0f, 0, 0, VG_PATH_CAPABILITY_ALL);
    fillPaint = vgCreatePaint();

    vgSetf(VG_STROKE_LINE_WIDTH, 1.0f);
    //vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_ROUND);
    vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT);
    vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_ROUND);
    //vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_BEVEL);

    vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);

    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
    vgLoadIdentity();
    vgTranslate(60, 60);
    vgScale(testRadius * 2, testRadius * 2);

    vgAppendPathData(line, 3, lineCommands, lineCoords);

    vgSetfv(VG_CLEAR_COLOR, 4, clearColor);

    vgSetPaint(fillPaint, VG_STROKE_PATH);

    vgSetParameterfv(fillPaint, VG_PAINT_COLOR, 4, fillColor);
    vgSetParameteri( fillPaint, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);

    vgClear(0, 0, WINDSIZEX, WINDSIZEY);
    vgDrawPath(line, VG_STROKE_PATH);

    vgDestroyPath(line);
    vgDestroyPaint(fillPaint);
}
Esempio n. 13
0
void OpenVG_SVGHandler::draw_recursive( group_t& group ) {

    // push the group matrix onto the stack
    pushTransform( group.transform );
    vgLoadMatrix( topTransform().m );

    for ( list<path_object_t>::iterator it = group.path_objects.begin(); it != group.path_objects.end(); it++ ) {
        path_object_t& po = *it;
        uint32_t draw_params = 0;
        if ( po.fill ) {
            vgSetPaint( po.fill, VG_FILL_PATH );
            draw_params |= VG_FILL_PATH;
        }

        if ( po.stroke ) {
            vgSetPaint( po.stroke, VG_STROKE_PATH );
            vgSetf( VG_STROKE_LINE_WIDTH, po.stroke_width );
            draw_params |= VG_STROKE_PATH;
        }

        if( draw_params == 0 ) {	// if no stroke or fill use the default black fill
            vgSetPaint( _blackBackFill, VG_FILL_PATH );
            draw_params |= VG_FILL_PATH;
        }

        // set the fill rule
        vgSeti( VG_FILL_RULE, po.fill_rule );
        // trasnform
        pushTransform( po.transform );
        vgLoadMatrix( topTransform().m );
        vgDrawPath( po.path, draw_params );
        popTransform();
        vgLoadMatrix( topTransform().m );
    }

    for ( list<group_t>::iterator it = group.children.begin(); it != group.children.end(); it++ ) {
        draw_recursive( *it );
    }

    popTransform();
    vgLoadMatrix( topTransform().m );
}
Esempio n. 14
0
File: svg2.c Progetto: dschmenk/SEGL
int main(int argc, char **argv)
{
    float rotate, color[4] = {0.0, 0.33, 0.33, 1.0};
    VGPath path;
    VGPaint paintStroke;
    VGubyte pathSegments[] = {VG_MOVE_TO_ABS, VG_LINE_TO_ABS, VG_CLOSE_PATH};
    float   pathData[] = {200.0, 300.0, 100.0, 100.0};
    float   incData[]  = {  1.0,   2.0,  -2.5,  -0.5};

    EGLDisplayState *eglState = eglOpenDisplay(0 /* min win dimension */,
                                               8 /* min color component size */,
                                               8 /* min alpha size */,
                                               0 /* min Z depth */,
                                               EGL_OPENVG_BIT /* render type */);
    path = vgCreatePath(VG_PATH_FORMAT_STANDARD,
                        VG_PATH_DATATYPE_F,
                        1.0, 0.0,
                        0,   0,
                        VG_PATH_CAPABILITY_APPEND_TO | VG_PATH_CAPABILITY_MODIFY);
    vgAppendPathData(path, 3, pathSegments, pathData);
    paintStroke = vgCreatePaint();
    vgSetColor(paintStroke, 0x00FF00FF);
    vgSetParameteri(paintStroke, VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
    vgSetPaint(paintStroke, VG_STROKE_PATH | VG_FILL_PATH);
    vgSetf(VG_STROKE_LINE_WIDTH, 5.0);
    vgLoadIdentity();
    for (rotate = 0.0; rotate < 1000.0; rotate++) {
        color[0] = rotate / 1000.0;
        vgSetfv(VG_CLEAR_COLOR, 4, color);
        vgClear(0, 0, eglState->win.width, eglState->win.height);
        bounce(2, pathData, incData, eglState->win.width, eglState->win.height);
        vgModifyPathCoords(path, 0, 3, pathData);
        vgDrawPath(path, VG_STROKE_PATH);
        eglUpdateDisplay(eglState);
    }
    eglCloseDisplay(eglState);
}
Esempio n. 15
0
LRESULT OnPaint(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{

	VGPaint strokePaint = vgCreatePaint();
	vgSetPaint(strokePaint, VG_STROKE_PATH);

	VGfloat color[4] = { 1.0f, 0.0f, 0.0f, 1.0f };
	vgSetParameterfv(strokePaint, VG_PAINT_COLOR, 4, &color[0]);

	VGPath line = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL);
	vguLine(line, 20, 20, 130, 130);

	VGPath square = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0, VG_PATH_CAPABILITY_ALL);
	vguRect(square, 10.0f, 10.0f, 130.0f, 50.0f);

	vgSetf(VG_STROKE_LINE_WIDTH, 7.0f);
	vgDrawPath(line, VG_STROKE_PATH);
	vgDrawPath(square, VG_STROKE_PATH);



	::ValidateRect(hWnd, NULL);
	return 0;
}
Esempio n. 16
0
static void update_display(envelope_render_internal_t *renderer)
{
    // Calculate scale
    envelope_t *envelope = renderer->definition.envelope;
    int32_t total_duration = 0;

    envelope_stage_t *stage = envelope->stages;
    for (int i = 0; i < envelope->stage_count; i++, stage++)
    {
        if (stage->duration == DURATION_HELD)
        {
            total_duration += HELD_DURATION_LENGTH;
        }
        else
        {
            total_duration += stage->duration;
        }
    }

    float horizontal_scale = (float)(renderer->definition.width - 1) / (float) total_duration;
    float vertical_scale = (float)(renderer->definition.height - 1) / (float)envelope->peak;

    // Build path segments from envelope stages
    int command_index = 0;
    int coord_index = 0;

    int32_t	last_level = -1;
    int32_t	elapsed_duration = 0;

    stage = envelope->stages;
    for (int i = 0; i < envelope->stage_count; i++, stage++)
    {
        if (last_level != stage->start_level && stage->start_level != LEVEL_CURRENT)
        {
            commands[command_index++] = VG_MOVE_TO_ABS;
            coords[coord_index++] = (float)elapsed_duration * horizontal_scale;
            coords[coord_index++] = (float)stage->start_level * vertical_scale;
        }

        last_level = stage->end_level;
        if (stage->duration == DURATION_HELD)
        {
            elapsed_duration += HELD_DURATION_LENGTH;
        }
        else
        {
            elapsed_duration += stage->duration;
        }

        commands[command_index++] = VG_LINE_TO_ABS;
        coords[coord_index++] = (float)elapsed_duration * horizontal_scale;
        coords[coord_index++] = (float)stage->end_level * vertical_scale;
    }

    vgAppendPathData(renderer->state.path, command_index, commands, coords);

    // Render it out
    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
    vgLoadIdentity();
    vgSetfv(VG_CLEAR_COLOR, 4, renderer->definition.background_colour);
    vgClear(renderer->definition.x, renderer->definition.y,
            renderer->definition.width, renderer->definition.height);

    vgSetf(VG_STROKE_LINE_WIDTH, renderer->definition.line_width);
    vgSeti(VG_STROKE_CAP_STYLE, renderer->definition.line_cap_style);
    vgSeti(VG_STROKE_JOIN_STYLE, renderer->definition.line_join_style);
    vgSetPaint(renderer->state.line_paint, VG_STROKE_PATH);
    vgSeti(VG_RENDERING_QUALITY, renderer->definition.rendering_quality);
    vgTranslate(renderer->definition.x, renderer->definition.y);
    vgDrawPath(renderer->state.path, VG_STROKE_PATH);
    vgClearPath(renderer->state.path, VG_PATH_CAPABILITY_APPEND_TO);

    vgSeti(VG_RENDERING_QUALITY, renderer->definition.text_quality);
    vgSetPaint(renderer->state.text_paint, VG_FILL_PATH);
    gfx_render_text(0, renderer->definition.height - 12, renderer->definition.text, &gfx_font_sans, 9);
}
Esempio n. 17
0
// StrokeWidth sets the stroke width
void StrokeWidth(VGfloat width) {
	vgSetf(VG_STROKE_LINE_WIDTH, width);
	vgSeti(VG_STROKE_CAP_STYLE, VG_CAP_BUTT);
	vgSeti(VG_STROKE_JOIN_STYLE, VG_JOIN_MITER);
}
Esempio n. 18
0
/*******************************************************************************
 * Function Name  : InitView
 * Returns        : true if no error occured
 * Description    : Code in InitView() will be called by the Shell upon a change
 *					in the rendering context.
 *					Used to initialise variables that are dependent on the rendering
 *					context (e.g. textures, vertex buffers, etc.)
 *******************************************************************************/
bool OVGMaskLayer::InitView()
{
	// Get screen dimensions
	m_ui32ScreenWidth = PVRShellGet(prefWidth);
	m_ui32ScreenHeight= PVRShellGet(prefHeight);

	// Create the paths so we have something to look at.
	CreatePath();

	// Set the render quality so the stroke borders have some form of anti-aliasing
	vgSeti(VG_RENDERING_QUALITY, VG_RENDERING_QUALITY_BETTER);

	// Create the paints that the paths will use
	m_avgColourPaint[0] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[0], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[0], PVRTRGBA(255,255,15,255));

	m_avgColourPaint[1] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[1], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[1], PVRTRGBA(255,50,0, 255));

	m_avgColourPaint[2] = vgCreatePaint();
	vgSetParameteri(m_avgColourPaint[2], VG_PAINT_TYPE, VG_PAINT_TYPE_COLOR);
	vgSetColor(m_avgColourPaint[2], PVRTRGBA(50,250,15, 255));

	/*
		Load the images we're going to use to modify the mask layer.

		For more details on masking please refer to our OVGMasking training course
	*/

	// Create the VGImages.
	VGImage vgMaskImg, vgMaskImg2;

	// Using the PVR Tools we're going to load the mask data from a pvr file
	if(PVRTImageLoadFromPVR(c_szMask1File, &vgMaskImg) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to open mask1.pvr.");
		return false;
	}

	if(PVRTImageLoadFromPVR(c_szMask2File, &vgMaskImg2) != PVR_SUCCESS)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to open mask2.pvr.");
		return false;
	}

	/*
		Create a mask layer

		A VGMaskLayer is an object that allows you to store and manipulate the drawing surface's mask layer
	*/

	m_vgMaskLayer[0] = vgCreateMaskLayer(m_ui32ScreenWidth, m_ui32ScreenHeight);

	if(m_vgMaskLayer[0] == 0)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to create mask layer.");
		return false;
	}

	// Tile the first image in the drawing surface's masking layer
	TileImageInMask(vgMaskImg, VG_SET_MASK);

	/*
		Copy the contents of the drawing surface mask layer into our mask layer object

		vgCopyMask has the following parameters

		VGMaskLayer maskLayer, VGint dx, VGint dy, VGint sx, VGint sy, VGint width, VGint height)

		where

		masklayer is the masklayer to copy to
		dx, dy are the coordinates to start the copy at in the masklayer
		sx, sy are the coordinates to start the copy from in the source mask layer
		width and the height are the width and height of the region you wish to copy.

		In our case we're copying the full mask layer.
	*/

	vgCopyMask(m_vgMaskLayer[0], 0, 0, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Create the second mask layer
	m_vgMaskLayer[1] = vgCreateMaskLayer(m_ui32ScreenWidth, m_ui32ScreenHeight);

	if(m_vgMaskLayer[1] == 0)
	{
		PVRShellSet(prefExitMessage, "Error: Failed to create mask layer.");
		return false;
	}

	// Replace the contents of the mask by tiling the second image
	TileImageInMask(vgMaskImg2, VG_SET_MASK);

	// Copy the contents of the mask into the second mask layer
	vgCopyMask(m_vgMaskLayer[1], 0, 0, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Destroy the images as they are no longer needed
	vgDestroyImage(vgMaskImg);
	vgDestroyImage(vgMaskImg2);

	// Set the mask to ones
	vgMask(VG_INVALID_HANDLE, VG_FILL_MASK, 0, 0, m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Init PrintVG
	m_PrintVG.Initialize(m_ui32ScreenWidth, m_ui32ScreenHeight);

	// Setup the transformation to scale the paths to fit the screen
	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();

	vgScale((float) m_ui32ScreenWidth, (float) m_ui32ScreenHeight);

	// Reduce the stroke size to compensate for our scaling
	vgSetf(VG_STROKE_LINE_WIDTH, 1.0f / m_ui32ScreenHeight);

	//Create and set the clear colour
	VGfloat afClearColour[] = { 0.6f, 0.8f, 1.0f, 1.0f };
	vgSetfv(VG_CLEAR_COLOR, 4, afClearColour);

	return true;
}
Esempio n. 19
0
/*******************************************************************************
 * Function Name  : RenderScene
 * Returns		  : true if no error occured
 * Description    : Main rendering loop function of the program. The shell will
 *					call this function every frame.
 *******************************************************************************/
bool CStrokeStyles::RenderScene()
{
	/*
		If the left or right arrow keys are pressed then change the
		CapStyle or JoinStyle or DashStyle depending on which one is
		selected.
	*/
	if(PVRShellIsKeyPressed(PVRShellKeyNameLEFT))
	{
		switch(m_i32Selected)
		{
			case 0: m_i32CapStyle  = (m_i32CapStyle +  2) % 3; break;
			case 1: m_i32JoinStyle = (m_i32JoinStyle + 2) % 3; break;
			case 2: m_i32DashStyle = (m_i32DashStyle + 2) % 3; break;
		}
	}
	if(PVRShellIsKeyPressed(PVRShellKeyNameRIGHT))
	{
		switch(m_i32Selected)
		{
			case 0: m_i32CapStyle  = (m_i32CapStyle +  1) % 3; break;
			case 1: m_i32JoinStyle = (m_i32JoinStyle + 1) % 3; break;
			case 2: m_i32DashStyle = (m_i32DashStyle + 1) % 3; break;
		}
	}

	/*
		If the up or down arrow is pressed then change which item is
		selected.
	*/
	if(PVRShellIsKeyPressed(PVRShellKeyNameUP))
		m_i32Selected = (m_i32Selected + 2) % 3;

	if(PVRShellIsKeyPressed(PVRShellKeyNameDOWN))
		m_i32Selected = (m_i32Selected + 1) % 3;

	vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
	vgLoadIdentity();
	vgScale((float)PVRShellGet(prefWidth), (float)PVRShellGet(prefHeight));

	// Clear the screen with clear colour.
	vgClear(0, 0, PVRShellGet(prefWidth), PVRShellGet(prefHeight));

	// Draw the path with the stroke styles that we want
	vgSeti(VG_STROKE_CAP_STYLE  , VG_CAP_BUTT   + m_i32CapStyle);
	vgSeti(VG_STROKE_JOIN_STYLE , VG_JOIN_MITER + m_i32JoinStyle);
	vgSetf(VG_STROKE_MITER_LIMIT, m_fMiterLimit * PVRShellGet(prefHeight));

	if(m_i32DashStyle > 0)
	{
		vgSetf(VG_STROKE_DASH_PHASE, m_fDashPhase);

		static float s_afDashes[] = { 0.1f, 0.15f, 0.23f, 0.11f };
		vgSetfv(VG_STROKE_DASH_PATTERN, 4, s_afDashes);

		if(m_i32DashStyle == 2)
			m_fDashPhase += 0.01f;
	}
	else
	{
		vgSetfv(VG_STROKE_DASH_PATTERN, 0, NULL);
	}

	vgSetf(VG_STROKE_LINE_WIDTH, 20.0f / PVRShellGet(prefHeight));

	vgDrawPath(m_vgPath, VG_STROKE_PATH);

	/*	Draw the text.

		If one of the pieces of text is currently selected then it will be
		drawn in yellow.
	*/

	static char* apszCapStrings[]  = { "Butt", "Round", "Square" };
	static char* apszJoinStrings[] = { "Miter", "Round", "Bevel" };
	static char* apszDashStrings[] = { "None", "Pattern", "Moving" };

	m_PrintVG.DisplayDefaultTitle("StrokeStyles", "", ePVRTPrint3DLogoIMG);

	float fHeight = PVRShellGet(prefHeight) - 40.0f;

	/*
		Draw the Cap text.
	*/
	m_PrintVG.DrawString(2.0f , fHeight, 0.6f, "Cap:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszCapStrings[m_i32CapStyle],
			m_i32Selected == 0 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	/*
		Draw the Join text.
	*/
	fHeight -= 20.0f;
	m_PrintVG.DrawString(2.0f, fHeight, 0.6f, "Join:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszJoinStrings[m_i32JoinStyle],
			m_i32Selected == 1 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	/*
		Draw the Dash text.
	*/
	fHeight -= 20.0f;
	m_PrintVG.DrawString(2.0f,fHeight, 0.6f, "Dash:", (int) PVRTRGBA(204,204,204,255));
	m_PrintVG.DrawShadowString(65.0f, fHeight, 0.6f, apszDashStrings[m_i32DashStyle],
			m_i32Selected == 2 ? (int) PVRTRGBA(255,255,0,255) : (int) PVRTRGBA(255,255,255,255));

	return true;
}
Esempio n. 20
0
TInt CNVGCSIcon::DoDrawL(const TSize aSize)
    {
    TInt ret = KErrNone;
    
    vgSetPaint(iFillPaint,   VG_FILL_PATH);
    vgSetPaint(iStrokePaint, VG_STROKE_PATH);
    iLastFillPaintColor     = 0;
    iLastStrkePaintColor    = 0;
    iLastFillPaintType      = 0;
    iLastStrokePaintType    = 0;

    VGfloat lCurrentPathMatrix[9];
    vgGetMatrix(lCurrentPathMatrix);
    
    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);  
    vgLoadMatrix(lCurrentPathMatrix);
    SetRotation();
#ifdef __MIRROR_    
    vgScale(1.0f, -1.0f);
    vgTranslate(0, (VGfloat)(-aSize.iHeight) );
#endif
    
    SetViewBoxToViewTransformationL(aSize);
   
    
    vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
    
    VGfloat currentMatrix[9];
    
    vgGetMatrix(currentMatrix);
    
    iNVGIconData->BeginRead();

    while (!iNVGIconData->EOF())
        {
        switch (iNVGIconData->ReadInt32L())
            {
            case EPath:
                {
                VGPath path = (VGPath)iNVGIconData->ReadInt32L();
                VGPaintMode paintMode = (VGPaintMode)iNVGIconData->ReadInt32L();

                if (path == VG_INVALID_HANDLE)
                    {
                    vgDrawPath(iPath, paintMode);
                    }
                else
                    {
                    vgDrawPath(path, paintMode);
                    }
                
                break;
                }
            case EPathData:
                {                
                if (iPath != VG_INVALID_HANDLE)
                    {
                    VGint numSegments;
                    VGubyte * pathSegments = 0;
                    VGubyte * pathData = 0;
                    
                    numSegments  = iNVGIconData->ReadInt32L();
                    pathSegments = new (ELeave) VGubyte[numSegments];
                    CleanupStack::PushL(TCleanupItem(CleanupArray, pathSegments));
                    if (pathSegments)
                        {
                        iNVGIconData->ReadL(pathSegments, numSegments);
                        VGint coordinateCount = iNVGIconData->ReadInt32L();
                        pathData = new (ELeave) VGubyte[coordinateCount * 4];
                        if (pathData)
                            {
                            CleanupStack::PushL(TCleanupItem(CleanupArray, pathData));
                            iNVGIconData->ReadL(pathData, coordinateCount * 4);
                            vgClearPath(iPath, VG_PATH_CAPABILITY_APPEND_TO);
                            vgAppendPathData(iPath, numSegments, pathSegments, pathData);
                            CleanupStack::PopAndDestroy();
                            }                        
                        }
                    CleanupStack::PopAndDestroy();
                    }
                break;
                }
            case EPaint:
                {
                DrawPaintL(iFillPaint, VG_MATRIX_FILL_PAINT_TO_USER, iLastFillPaintType, iLastFillPaintColor, VG_FILL_PATH);
                break;
                }
            case EColorRamp:
                {
                iNVGIconData->ReadInt32L();
                break;
                }
            case ETransform:
                {
                TInt flag;
                VGfloat transformMatrix[9];
                
                TPtr8 tmPtr((TUint8 *)transformMatrix, 9 * sizeof(VGfloat));
                
                iNVGIconData->ReadL(tmPtr, 9 * sizeof(VGfloat));
                flag = iNVGIconData->ReadInt32L();
                
                vgLoadMatrix(currentMatrix);
                if (flag)
                    {
                    vgMultMatrix(transformMatrix);
                    }
                }
                break;
            case EStrokeWidth:
                {
                VGfloat strokeWidth = iNVGIconData->ReadReal32L();
                vgSetf(VG_STROKE_LINE_WIDTH, strokeWidth);
                break;
                }
            case EStrokeMiterLimit:
                {
                VGfloat miterLimit = iNVGIconData->ReadReal32L();
                vgSetf(VG_STROKE_MITER_LIMIT, miterLimit);
                break;
                }
            case EStrokeLineJoinCap:
                {
                VGint lineJoin = iNVGIconData->ReadInt32L();
                VGint cap = iNVGIconData->ReadInt32L();
                
                vgSeti(VG_STROKE_JOIN_STYLE, (VGJoinStyle)lineJoin);
                vgSeti(VG_STROKE_CAP_STYLE, (VGCapStyle)cap);
                break;
                }
            case EStrokePaint:
                {
                DrawPaintL(iStrokePaint, VG_MATRIX_STROKE_PAINT_TO_USER, iLastStrokePaintType, iLastStrkePaintColor, VG_STROKE_PATH);
                break;
                }
            case EStrokeColorRamp:
                {
                iNVGIconData->ReadInt32L();
                break;
                }
            default:
                {
                User::Leave(KErrCorrupt);
                break;
                }
            }
        }
    
    iNVGIconData->EndRead();
    
    return ret;
    }
Esempio n. 21
0
/*!***************************************************************************
 @Function		Draw
 @Input			i32StartPath Path to start drawing from
 @Input			i32EndPath	Path to end drawing on
 @Returns		True on success
 @Description	Draw a set of the paths loaded from the file. If no argument
				is specified this function will draw all paths.
*****************************************************************************/
bool CPVRTPVGObject::Draw(int i32StartPath, int i32EndPath)
{
	if (!m_bInitialized)
	{
		// This set has not been initialised so return.
		return false;
	}

	if(i32EndPath < i32StartPath)
	{
		i32EndPath = m_i32NumPaths;
	}

	i32StartPath = PVRT_MAX(0, i32StartPath);
	i32EndPath = PVRT_MIN(i32EndPath, m_i32NumPaths);

	for(int i = i32StartPath; i < i32EndPath; ++i)
	{
		// Set the blending options. PVG files only support standard translucency.
		if(m_pPaths[i].m_bNeedsBlending)
		{
			vgSeti(VG_BLEND_MODE, VG_BLEND_SRC_OVER);
		}
		else
		{
			vgSeti(VG_BLEND_MODE, VG_BLEND_SRC);
		}

		// Check whether this one is a path without fill or stroke and ignore it.
		if(m_pPaths[i].m_paintMode == 0)
		{
			continue;
		}

		// Fill the parameters for the current Fill Paint
		// Check if the paint is present, if it is different than the previous one or if it is the first one.
		if(((m_pPaths[i].m_paintMode & VG_FILL_PATH) && m_pPaths[i].m_bIsNewFill) || (i==i32StartPath))
		{
			vgSeti(VG_FILL_RULE, m_pPaths[i].m_fillRule);

			vgSetPaint(m_pPaths[i].m_fillPaint, VG_FILL_PATH);
		}

		// Fill the parameters for the current Stroke Paint
		if(((m_pPaths[i].m_paintMode & VG_STROKE_PATH) && m_pPaths[i].m_bIsNewStroke) || (i==i32StartPath))
        {
			vgSetf(VG_STROKE_LINE_WIDTH, m_pPaths[i].m_fStrokeWidth);
			vgSeti(VG_STROKE_CAP_STYLE,	 m_pPaths[i].m_capStyle);
			vgSeti(VG_STROKE_JOIN_STYLE, m_pPaths[i].m_joinStyle);
			vgSetf(VG_STROKE_MITER_LIMIT,m_pPaths[i].m_fMiterLimit);

			// Get current stroke 'dash' if any
			if (m_pPaths[i].m_ui32DashID != 666)
			{
				vgSetf(VG_STROKE_DASH_PHASE, m_pPaths[i].m_fDashPhase);
				vgSetfv(VG_STROKE_DASH_PATTERN, m_pPaths[i].m_ui32NumDashes, m_pPaths[i].m_fDashValues);
			}
			else
			{
				vgSetfv(VG_STROKE_DASH_PATTERN, 0, (VGfloat *) 0); // disable dashes
			}

 			vgSetPaint(m_pPaths[i].m_strokePaint, VG_STROKE_PATH);
        }

		// Draw this path.
		vgDrawPath(m_pPaths[i].m_path, m_pPaths[i].m_paintMode);
	}

	// Success!
	return true;
}