Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified
Accepted Solution

Drawing Polygons....drawFilledPath

Storm 4.7

 

I had been writing a useful library consisting of 2 parts. The main one was missing and faster math functions which I have coded and debugged. The second was polygon drawing as everyone was complaining that there was no fast polygon fils. I coded a quick set of such functions but then realized that it's already in existance.

 

If you look at Blackberry's net.rim.device.api.ui.Graphics class.

 

There are 2 functions named as follows:

 

drawPathOutline and drawFilledPath

 

There are also a few variants. Not only do these functions draw the outline of a polygon and a filled polygon respectively but also multiple polygons threaded together using an offset array.

Also, because they are blackberry coded, I'm guessing they also use hardware accelleration in the qualcomm chip.

 

Has anyone on this forum used these functions?

 

Thanks

-Donald

Developer
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified

Re: Drawing Polygons....drawFilledPath

I just got it to work. I had to use a BitmapField and call the screen's invalidate function after I drew inside the Bitmap.

Is the way to handle polygons using BB API.

Developer
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified

Re: Drawing Polygons....drawFilledPath

Big discovery....

 

I created my library to use the drawFilledPath.

These polygons can be filled at a rate of 2000 polygons a second. I used 8-vertex polygons with a mix of concave and convex vertices.

 

This is quite good for java.

-D

Regular Contributor
Posts: 69
Registered: ‎04-05-2010
My Device: Storm
My Carrier: BSNL

Re: Drawing Polygons....drawFilledPath

What if we have the difference in two points less that one. I have the following path to be drawn. X : 121.01613 Y: 692.28 PointType: 0 X : 121.01613 Y: 698.5196 PointType: 0 X : 121.973076 Y: 698.5196 PointType: 0 X : 121.973076 Y: 692.99976 PointType: 0 X : 125.32969 Y: 692.99976 PointType: 0 X : 125.32969 Y: 692.28 PointType: 0 X : 121.01613 Y: 692.28 PointType: 0 It is actually a "L" english letter. I am not getting the final expected output. I tried using Fixed32, but no use.
Developer
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified

Re: Drawing Polygons....drawFilledPath

If you send me your email address I can send you my graphics library that has both my fast math and my graphics libraries.....all in one lib....

 

Thx

-D

Regular Contributor
Posts: 69
Registered: ‎04-05-2010
My Device: Storm
My Carrier: BSNL

Re: Drawing Polygons....drawFilledPath

sandeep.vaidya@celstream.com

 

Thanks

Regular Contributor
Posts: 69
Registered: ‎04-05-2010
My Device: Storm
My Carrier: BSNL

Re: Drawing Polygons....drawFilledPath

Do we have any option to draw paths with points having floating point numbers.

 

e.g I have x = 10.546789 & y = 23.873452

 

I tried using the Fixed32

 

NewX = Fixed32.tenThouToFP((int) x * 10000); NewY = Fixed32.tenThouToFP((int) y * 10000);

 

However it does not work.

 

Thanks in advance.

Developer
Posts: 17,012
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: Drawing Polygons....drawFilledPath

how should that work? do you want to use subpixels instead of existing pixels?

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Highlighted
Developer
Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.3.2.858, Z10 (STL100-3)-10.3.1.2576, Z30 (STA100-5)-10.3.1.2582, Passport (SQW100-1)-10.3.1.2576, PlayBook (16GB)-2.1.0.1917
My Carrier: Verizon

Re: Drawing Polygons....drawFilledPath

It is a normal operation on all desktop and some mobile devices. It is something I need to do as well but couldn't find a way to do it so I need to resort to either rounding the values or spending the time making a SVG and rendering that.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Developer
Posts: 558
Registered: ‎11-25-2008
My Device: Not Specified

Re: Drawing Polygons....drawFilledPath

Here is some code I used way back when, when I wrote that library that I've given to some of you. If you can, can you post it here for others to use.....thanks.....

In this example, you can see how drawFilledPath is used. It uses regular ints....

 

 

        // Button handler selects next test
        FieldChangeListener bhandler = new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                ++m_testnum;        // Next test
                m_g.clear();    // Clear graphics area
                m_p = new IpPolygon(m_g);
                m_p.addVertex(50,50);
                m_p.addVertex(100,50);
                m_p.addVertex(200,100);
                m_p.addVertex(150,150);
                m_p.addVertex(100,170);
                m_p.addVertex(110,75);
                switch (m_testnum)  // execute the test
                {
                    case 0:         // Impossible
                        break;
                    
                    case 1:         // Draw Polygon
                        int x0[] = { 50, 100, 75 };
                        int y0[] = { 50, 100, 150};
                        m_g.setBackgroundColor(0x00ffffff); // white
                        m_g.setDrawingStyle(m_g.DRAWSTYLE_AAPOLYGONS, true);
                        m_g.setColor(0x00ff0000);   // red
                        m_g.drawPathOutline(x0,y0,null,null,true);
                        invalidate(m_bm.getLeft(), m_bm.getTop(), m_bm.getWidth(), m_bm.getHeight());
                        //IpPolygon p = new IpPolygon(x,y);
                        //p.draw(m_g);   // Draw the polygon
                        break;
                    case 2:
                        int x1[] = { 50, 100, 75 };
                        int y1[] = { 50, 100, 150};
                        m_g.setColor(0x0000ff00);
                        m_g.drawFilledPath(x1,y1,null,null);
                        invalidate(m_bm.getLeft(), m_bm.getTop(), m_bm.getWidth(), m_bm.getHeight());
                        //p.fill(m_g);   // Fill the polygon
                        break;
                    case 3:
                        
                        m_g.setColor(Color.INDIGO);
                        m_p.draw();
                        invalidate();
                        break;
                    
                    case 4:
                        //m_p.clean();
                        m_g.setColor(Color.BLUE);
                        m_p.fill();
                        invalidate();
                        break;
                    
        // Button handler selects next test
        FieldChangeListener bhandler = new FieldChangeListener()
        {
            public void fieldChanged(Field field, int context)
            {
                ++m_testnum;        // Next test
                m_g.clear();    // Clear graphics area
                m_p = new IpPolygon(m_g);
                m_p.addVertex(50,50);
                m_p.addVertex(100,50);
                m_p.addVertex(200,100);
                m_p.addVertex(150,150);
                m_p.addVertex(100,170);
                m_p.addVertex(110,75);
                switch (m_testnum)  // execute the test
                {
                    case 0:         // Impossible
                        break;
                    
                    case 1:         // Draw Polygon
                        int x0[] = { 50, 100, 75 };
                        int y0[] = { 50, 100, 150};
                        m_g.setBackgroundColor(0x00ffffff); // white
                        m_g.setDrawingStyle(m_g.DRAWSTYLE_AAPOLYGONS, true);
                        m_g.setColor(0x00ff0000);   // red
                        m_g.drawPathOutline(x0,y0,null,null,true);
                        invalidate(m_bm.getLeft(), m_bm.getTop(), m_bm.getWidth(), m_bm.getHeight());
                        //IpPolygon p = new IpPolygon(x,y);
                        //p.draw(m_g);   // Draw the polygon
                        break;

                    case 2:
                        int x1[] = { 50, 100, 75 };
                        int y1[] = { 50, 100, 150};
                        m_g.setColor(0x0000ff00);
                        m_g.drawFilledPath(x1,y1,null,null);
                        invalidate(m_bm.getLeft(), m_bm.getTop(), m_bm.getWidth(), m_bm.getHeight());
                        //p.fill(m_g);   // Fill the polygon
                        break;

                    case 3:
                        
                        m_g.setColor(Color.INDIGO);
                        m_p.draw();
                        invalidate();
                        break;
                    
                    case 4:
                        //m_p.clean();
                        m_g.setColor(Color.BLUE);
                        m_p.fill();
                        invalidate();
                        break;