Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » problems drawing in Linux (ubuntu 7.10)
problems drawing in Linux (ubuntu 7.10) [message #15181] Mon, 07 April 2008 20:58 Go to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Hi,

I am seeing what appear to be errors in the way that upp under linux handles:
=> Alpha()
=> DrawPolyPolygon()

The alpha function appears to make everything transparent all the time.

The DrawPolyPolygon function appears to not split up the constituent polygons correctly.

Here is my polygon layer drawing function in case I'm doing something wrong but all this code works very nicely in Windows XP.

Nick

void PolygonLayer::DrawLayer(    Draw& w, // info regarding the screen or drawing context
                            ImageBuffer& ibBk, // image that should be updated by each layer
                            void* pView // pointer to the main top window object
                            )
{
    OpenWind* ptr = (OpenWind*)pView;
    
    Rect rc = ptr->MPtoLP(m_rc);

    int alpha = (int)(255.0*m_fAlpha + 0.5);
        
    //check to see if we need to draw at all
    if(ptr->GetClientRect().Intersects(rc))
    {
        if(ptr->DrawAsBackground(this))
        {

            Size sz = ptr->GetClientRect().Size();
            ImageDraw id(sz);
            id.DrawRect(sz,White);
            id.Alpha().DrawRect(sz,Black);

            // every time we draw this we need to convert from MP to LP so its ok to convert from 
            // a friendly data structure to a not so friendly one at the same time
        
            Point* vertices = new Point[GetTotalPoints()];
            int* subpolygon_counts = new int[10000];
            Point pt;
            Color colFill = m_bFill ? m_colFill : Null;
            Color colOutline = m_bLine ? m_colLine : Null;
            Font font(m_fontLabel.GetFace(),(int)(m_fontLabel.GetHeight()*ptr->GetTextMultiplier()));
        
            for(int k=0;k<m_polys.GetCount();k++)
            {
                rc = ptr->MPtoLP(m_polys[k].m_rc);
                if(!rc.Intersects(ptr->GetClientRect()))
                    continue; // i.e. dont draw this object - see if next one is in view
                
                int vertex_count = GetTotalPoints(k);
                int subpolygon_count_count = m_polys[k].m_loops.GetCount();
                int nWidth = m_nWidth;
                uint64 pattern = 0;
                int c=0;
                
                for(int i=0;i<subpolygon_count_count;i++)
                {
                    const int num = m_polys[k].m_loops[i].GetCount();
                    subpolygon_counts[i] = num;
                    for(int j=0;j<num;j++)
                    {
                        vertices[c++] = ptr->MPtoLP(m_polys[k].m_loops[i][j]);
                    }
                }
                
                // draw
                id.DrawPolyPolygon(vertices, vertex_count, subpolygon_counts,
                                        subpolygon_count_count, colFill, nWidth, colOutline, pattern);
                
                id.Alpha().DrawPolyPolygon(vertices, vertex_count, subpolygon_counts,
                                        subpolygon_count_count, Color((m_bFill ? alpha : 0),0,0), nWidth, Color((m_bLine ? alpha : 0),0,0), pattern);
        
                if(m_bLabel)
                {
                    pt = ptr->MPtoLP(m_polys[k].m_ptCOG);
                    String s;
                    if(m_bLabelField)
                    {
                        s = CUtils::EatSpace(m_polys[k].m_valAt[m_nLabelField].ToString());
                    }
                    else // use object index + 1
                    {
                        s = Format("%d",k+1);
                    }
                    Size tsz = GetTextSize(s,font);
                    id.DrawText(pt.x-tsz.cx/2,pt.y-tsz.cy/2,s,font,m_colLabel);    
                       id.Alpha().DrawText(pt.x-tsz.cx/2,pt.y-tsz.cy/2,s,font,Color(255,0,0));    
                }
            }
            
            delete[] vertices;
            delete[] subpolygon_counts;
        
            Image ib(id);    
            ImageDraw id2(sz);
            id2.DrawImage(0,0,sz.cx,sz.cy,ibBk);
            id2.DrawImage(0,0,ib);
            Image ib2(id2);
            ibBk = ib2;
        }
    }
    
    // always call the base class last
    Layer::DrawLayer(w,ibBk,ptr);
}




[Updated on: Mon, 07 April 2008 20:59]

Report message to a moderator

Re: problems drawing in Linux (ubuntu 7.10) [message #15327 is a reply to message #15181] Wed, 16 April 2008 13:31 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
OK, problem no 1. Alpha(): For some weird reason, "g" channel was used instead of r for alpha in X11.

You can easily fix it by using "GrayColor" instead....

Mirek
Re: problems drawing in Linux (ubuntu 7.10) [message #15328 is a reply to message #15327] Wed, 16 April 2008 14:15 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
Fix for the polygon problem:

static void DrawPolyPolyPolygonRaw(Draw& draw, const Point *vertices, int vertex_count,
	const int *subpolygon_counts, int subpolygon_count_count, const int *, int)
{
	DrawLock __;
	Point offset = draw.GetOffset();
	const Point *in = vertices;
	for(int i = 0; i < subpolygon_count_count; i++) {
		int n = subpolygon_counts[i];
		Buffer<XPoint> out_points(n);
		XPoint *t = out_points;
		XPoint *e = t + n;
		while(t < e) {
			t->x = (short)(in->x + offset.x);
			t->y = (short)(in->y + offset.y);
			t++;
			in++;
		}
		XFillPolygon(Xdisplay, draw.GetDrawable(), draw.GetGC(), out_points, n, Nonconvex, CoordModeOrigin);
	}
}



Mirek

[Updated on: Wed, 16 April 2008 14:17]

Report message to a moderator

Re: problems drawing in Linux (ubuntu 7.10) [message #15336 is a reply to message #15328] Wed, 16 April 2008 18:19 Go to previous messageGo to next message
nixnixnix is currently offline  nixnixnix
Messages: 415
Registered: February 2007
Location: Kelowna, British Columbia
Senior Member
Hi Mirek,

The code above appears to just draw each subpolygon as a filled polygon with no reference to the other subpolygons. This means that complex polygons containing holes cannot be drawn correctly. Having searched for information on drawing complex polygons with X11 it seems there is no way to do this. The XFillPolygon documentation talks about complex polygon but gives no way to actually draw one.

Got to say, sometimes Linux makes MS Windows look disappointingly good.

Nick

EDIT: I wonder how slow it would be to fill the polygons myself using line-crossing and an odd-even fill rule. I'll try to make time to look into this.

[Updated on: Wed, 16 April 2008 18:26]

Report message to a moderator

Re: problems drawing in Linux (ubuntu 7.10) [message #15338 is a reply to message #15336] Wed, 16 April 2008 19:38 Go to previous message
mirek is currently offline  mirek
Messages: 12098
Registered: November 2005
Ultimate Member
nixnixnix wrote on Wed, 16 April 2008 12:19

Hi Mirek,

The code above appears to just draw each subpolygon as a filled polygon with no reference to the other subpolygons. This means that complex polygons containing holes cannot be drawn correctly. Having searched for information on drawing complex polygons with X11 it seems there is no way to do this. The XFillPolygon documentation talks about complex polygon but gives no way to actually draw one.



Yes, unfortunately, it seems to be impossible to do directly in X11.

Mirek

Previous Topic: [Bug] Windows UI Refresh Missed.
Next Topic: bug in ImageBuffer::Line() and operator[]
Goto Forum:
  


Current Time: Wed Nov 13 13:06:21 CET 2019

Total time taken to generate the page: 0.01844 seconds