CS001113 - Drawing a line with RGA
From Forum Nokia Wiki
| ID | CS001113 | Creation date | October 1, 2008 |
| Platform | S60 3rd Edition | Tested on devices | Nokia N93, Nokia N95 |
| Category | Open C/C++ | Subcategory | RGA |
| Keywords (APIs, classes, methods, functions): |
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
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Listbox drawing Problem in E Series | ashutosh12 | Symbian User Interface | 1 | 2008-07-18 05:10 |
| how to can read from text file line by line and show them in a listbox | masoud_bayat | General Symbian C++ | 5 | 2008-09-23 10:39 |
| series 40 vs 60 perfomance | rbialach | Mobile Java General | 9 | 2003-11-25 15:27 |
| CAknColumnListBox: Not transparent when empty | nadav70 | Symbian User Interface | 7 | 2008-06-23 09:42 |
| application running at the background..? | julie_777 | General Symbian C++ | 17 | 2005-07-22 17:50 |

