New topic: 

Picture Drawing Using Method bug??

<http://forums.realsoftware.com/viewtopic.php?t=47170>

         Page 1 of 1
   [ 4 posts ]                 Previous topic | Next topic          Author  
Message        JimPitchford          Post subject: Picture Drawing Using Method 
bug??Posted: Tue Mar 05, 2013 6:27 pm                         
Joined: Mon Apr 11, 2011 2:01 pm
Posts: 146                I have uncovered an issue which has been frustrating 
me for the last couple of weeks in the poorly documented area of pictures, 
masks and transparency.

It seems that when you draw into the graphics of a picture within the paint 
event of a container control, the graphics draw correctly. But if you extract 
those graphics commands into a method, which is called by the paint event of 
the container control, then the graphics don't draw correctly.

Here's an example.

In ContainerControl1 do:

Sub Paint(g As Graphics, areas() As REALbasic.Rect)
  
  dim p as new picture(me.width, me.height, 32)
  
  //--------------------------------------------
  dim b as color = &c00000000//black
  dim w as color = &cFFFFFF00//white
  
  dim pg as graphics = p.graphics
  dim pmg as graphics = p.mask.graphics
  
  //foreground overlay
  pg.ForeColor = b
  pg.Transparency = 0
  pg.fillRect(0, 0, me.width, me.height)
  
  //background Mask
  pmg.ForeColor = w
  dim gap as integer = 10
  pmg.PenWidth = gap
  dim xcentre as integer = me.width/2
  dim ycentre as integer = me.height/2
  
  for i as integer = 0 to 10  //builds a white transparent mask, starting at 100
  
  pmg.Transparency = 100- i*10
  pmg.drawOval(xcentre-(i+1)*gap, ycentre-(i+1)*gap, 2*(i+1)*gap, 2*(i+1)*gap)
  
  next
  
  pmg.Transparency = 0  //builds a white mask in areas to be transparent
  for i as integer = 11 to 20
  pmg.DrawOval(me.width/2-i,-i, me.width + 2*i, me.height+ 2*i)
  next
  //-------------------------------------------
  
  g.DrawPicture(p, 0,0)
  
  
End Sub


In ContainerControl2 do:
Sub Paint(g As Graphics, areas() As REALbasic.Rect)
  dim p as new picture(me.width,me.height,32)
  
  gDrawInto_Picture(p)
  
  g.DrawPicture(p, 0,0)
  
  
End Sub


With this method:

Private Sub gDrawInto_Picture(p as picture)
  dim b as color = &c00000000//black
  dim w as color = &cFFFFFF00//white
  
  dim pg as graphics = p.graphics
  dim pmg as graphics = p.mask.graphics
  
  //foreground overlay
  pg.ForeColor = b
  pg.Transparency = 0
  pg.fillRect(0, 0, me.width, me.height)
  
  //background Mask
  pmg.ForeColor = w
  dim gap as integer = 10
  pmg.PenWidth = gap
  dim xcentre as integer = me.width/2
  dim ycentre as integer = me.height/2
  
  for i as integer = 0 to 10  //builds a white transparent mask, starting at 100
  
  pmg.Transparency = 100- i*10
  pmg.drawOval(xcentre-(i+1)*gap, ycentre-(i+1)*gap, 2*(i+1)*gap, 2*(i+1)*gap)
  
  next
  
  pmg.Transparency = 0  //builds a white mask in areas to be transparent
  for i as integer = 11 to 20
  pmg.DrawOval(me.width/2-i,-i, me.width + 2*i, me.height+ 2*i)
  next
  
End Sub


The code in the method being exactly the same as extracted from 
ContainerControl1.

The result, ContainerControl1 has the graphics shadings and masks as desired, 
whilst ContainerControl2  is completely black.

I've checked that its not an issue of ByRef or needing a returned picture from 
the method, but nothing seems to change the result.

Bug or am I missing something?

Jim

PS - this is in Cocoa, but I see the same result in Carbon.      
_________________
Jim
OSX 10.8.2, rb2012r2  
                             Top                doofus          Post subject: 
Re: Picture Drawing Using Method bug??Posted: Tue Mar 05, 2013 6:42 pm          
                       
Joined: Thu Sep 10, 2009 2:50 am
Posts: 366
Location: Santa Cruz, CA, USA                I don't have ContainerControls to 
test with but I'm wondering where gDrawInto_Picture is. I mean it uses 
me.Width, me.Height but maybe those are not what you think. Try changing those 
to p.Width, p.Height.   
                             Top                JimPitchford          Post 
subject: Re: Picture Drawing Using Method bug??Posted: Tue Mar 05, 2013 7:37 pm 
                        
Joined: Mon Apr 11, 2011 2:01 pm
Posts: 146                Correction...      
_________________
Jim
OSX 10.8.2, rb2012r2  
                             Top                JimPitchford          Post 
subject: Re: Picture Drawing Using Method bug??Posted: Tue Mar 05, 2013 7:43 pm 
                        
Joined: Mon Apr 11, 2011 2:01 pm
Posts: 146                Correction.. you're right - that was a booboo! Too 
many late nights.

Thanks.

Jim      
_________________
Jim
OSX 10.8.2, rb2012r2  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 4 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to