Drawing a line with RGA
The article is believed to be still valid for the original topic scope.
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.


(no comments yet)