New topic: DrawLine expects Integer values
<http://forums.realsoftware.com/viewtopic.php?t=46863> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message torrid Post subject: DrawLine expects Integer valuesPosted: Thu Feb 07, 2013 2:46 pm Joined: Sat Jun 04, 2011 8:29 am Posts: 378 I have a custom graph drawing routine. Before drawing the bar graph onto a rectangular canvas, I get the canvas width, and divide by the number of bars to draw. Thus sometimes the width is something like 27.33333 Pass that into DrawLine eventually and it gets chopped to Integer of 27... thus the final result is a big GAP on the right side of all the bars... it doesn't "fit" to the size of the canvas. is there some way to make it more accurate so it gets closer to the edge of the canvas? It's like I need finer control that Integer will provide. _________________ Currently using: Windows XP Pro SP3 Real Studio 2011 Release 4.3 Enterprise and Mac OS 10.7.4 Real Studio 2011 Release 4.3 Enterprise (finally also compiled on Mac) Top kermit Post subject: Re: DrawLine expects Integer valuesPosted: Thu Feb 07, 2013 3:10 pm Joined: Mon May 30, 2011 12:56 am Posts: 603 Quote:Thus sometimes the width is something like 27.33333 Pass that into DrawLine eventually and it gets chopped to Integer of 27... thus the final result is a big GAP on the right side of all the bars... it doesn't "fit" to the size of the canvas. Hmm.. dim BarWidth as integer BarWidth = Canvas1.width / NumberOfBars //lets say 27 dim BarTotal as integer BarTotal = NumberOfBars * BarWidth dim StartPos as integer StartPos = (Canvas1.width - BarTotal)/2 //now start drawing bars at StartPos, with width of BarWidth //This puts the spaces (if any) either side, neat and tidy Top torrid Post subject: Re: DrawLine expects Integer valuesPosted: Thu Feb 07, 2013 4:11 pm Joined: Sat Jun 04, 2011 8:29 am Posts: 378 Kermit yes that might be a little more symmetrical when viewing but .. Due to some other features of this custom graph... the first bar must start at 0. Too long of an explanation... It's like I need to widen the bars but can't due to integer restriction. I do a test to see if I can add one more pixel to every bar, but that typically fails... testing total width of the wider bar vs. total canvas width. Top charonn0 Post subject: Re: DrawLine expects Integer valuesPosted: Thu Feb 07, 2013 4:33 pm Joined: Mon Apr 02, 2007 2:08 am Posts: 1111 Location: San Francisco, CA, USA Something like this should be adaptable to columns instead of rows: Sub DrawRows(Buffer As Picture, Count As Integer) 'Warning: Quick and dirty forum code Dim W As Integer = Buffer.Width Dim H As Integer = Buffer.Height Dim rowheight As Integer = H \ Count 'Height of each row Dim gapHeight As Integer = H Mod Count / rowheight 'Height of gap between rows If gapHeight <= 0 Then gapHeight = 1 For Y As Integer = 0 To H Step rowheight + gapHeight Buffer.Graphics.FillRect(0, Y, W, rowheight) Next End Sub _________________ Boredom Software 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]
