Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Drawing a line with RGA

From Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.


Article Metadata
Tested with
Devices(s): Nokia N93, Nokia N95
Compatibility
Platform(s): S60 3rd Edition
Article
Created: stolik (26 Sep 2008)
Last edited: lpvalente (18 Sep 2012)

Contents

Overview

This snippet shows how to draw a line using the RGA API. RGA does not have a function for drawing lines.

Note: In order to use this code, you need to install the Open C plug-in.

Preconditions

This example relies on the RGA API ngi framework to draw a pixel (IGraphicsContext:: SetPixel()).

To run this snippet you need to create a project according to Using RGA with Carbide.c++ and create a simple application like this Simple RGA application. You can also modify the existing examples provided with Open C/C++ Plug-ins for S60 3rd Edition.

MMP file

The following capabilities and libraries are required:

CAPABILITY SwEvent
STATICLIBRARY libcrt0.lib
LIBRARY euser.lib
LIBRARY runtime.lib
LIBRARY libc.lib
LIBRARY libm.lib
LIBRARY libpthread.lib

Note: The snippet itself does not require any special capabilities, but due to the use of RGA API ngi framework, the resulting application requires SwEvent capability. (See also Open C/C++ DLL.)

Source file

#include <graphicscontext.h>    // ngi
#include "helper.h" //examplefw
 
#include <math.h>
int CExamplePage::sgn (long a)
{
if (a > 0)
return +1;
else
if (a < 0)
return -1;
else
return 0;
}
void CExamplePage::Line(IGraphicsContext& aGraphicsContext,
int aX1, int aY1, int aX2, int aY2, int aColor)
{
long u,s,v,d1x,d1y,d2x,d2y,m,n;
int i;
u = aX2-aX1;
v = aY2-aY1;
d1x = sgn(u);
d1y = sgn(v);
d2x = sgn(u);
d2y = 0;
m = abs(u);
n = abs(v);
if (m<=n)
{
d2x = 0;
d2y = sgn(v);
m = abs(v);
n = abs(u);
}
s = (int)(m / 2);
for (i=0;i<round(m);i++)
{
aGraphicsContext.SetPixel(aColor, CPoint(aX1,aY1));
s += n;
if (s >= m)
{
s -= m;
aX1 += d1x;
aY1 += d1y;
}
else
{
aX1 += d2x;
aY1 += d2y;
}
}
}

Postconditions

The function will draw a line from a start point to the end point with the provided color.


See also

This page was last modified on 18 September 2012, at 18:09.
36 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×