New topic: 

Trying to simply my mouse-down event for canvas

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

       Page 1 of 1
   [ 2 posts ]                 Previous topic | Next topic         Author  
Message       Kyan           Post subject: Trying to simply my mouse-down event 
for canvasPosted: Wed Oct 14, 2009 12:38 am                        
Joined: Tue Aug 14, 2007 8:44 am
Posts: 292              I've put together a custom canvas that basically is a 
groupbox with a custom top border/margin and which can have buttons on the 
right. So far, this is my code:
Code://top
Graphics.DrawPicture Bluebar_leftcap, 0, 0, Bluebar_leftcap.Width, 
20,0,0,Bluebar_leftcap.Width,20
Graphics.DrawPicture BlueBar_middle, 
Bluebar_leftcap.Width,0,me.Width-Bluebar_leftcap.Width-Bluebar_rightcap.Width,20,0,0,1,20
Graphics.DrawPicture Bluebar_rightcap, 
me.width-Bluebar_rightcap.width,0,Bluebar_rightcap.Width,20,0,0,Bluebar_rightcap.Width,Bluebar_rightcap.Height

Select Case me.Buttons
Case 0//No buttons
  
Case 1//One right-facing arrow
  Graphics.DrawPicture Bluebar_arrowright, me.width-20,0,13,18,0,0,13,18
Case 2//One left-facing arrow
  Graphics.DrawPicture Bluebar_arrowleft, me.width-20,0,13,18,0,0,13,18
Case 3//Left and right-facing arrows
  Graphics.DrawPicture Bluebar_arrowleft, me.width-35,0,13,18,0,0,13,18
  Graphics.DrawPicture Bluebar_arrowright, me.width-20,0,13,18,0,0,13,18
Case 4//Add (plus) button
  Graphics.DrawPicture Bluebar_add, me.width-20,0,13,18,0,0,13,18
end

//middle
Graphics.DrawPicture Whitebox_left, 0, 20, 10, me.Height-30, 0,0,10,1
Graphics.ForeColor = &cFFFFFF
Graphics.FillRect 10,20,me.Width-20,me.Height-30
Graphics.DrawPicture Whitebox_right, me.width-10, 20, 10, me.Height-30, 0,0,10,1
//bottom
Graphics.DrawPicture Whitebox_bottomleft, 0,me.Height-10,10,10,0,0,10,10
Graphics.DrawPicture Whitebox_bottommiddle, 
10,me.Height-10,me.width-20,10,0,0,1,10
Graphics.DrawPicture Whitebox_bottomright, 
me.width-10,me.Height-10,10,10,0,0,10,10

//Text
Graphics.TextFont="System"
Graphics.Bold=me.Bold
Graphics.TextSize=11
Graphics.ForeColor = &c000000
Graphics.Drawstring me.text, LMargin, 15, me.width-40, True
Graphics.ForeColor = &cFFFFFF
Graphics.Drawstring me.text, LMargin, 14, me.width-40, True


And it has four properties:
Code:Bold As Boolean
Buttons As Integer
LMargin As Integer
Text As String



Now my next step is to simplify the mouse down bit, as so far, every instance 
of the canvas has some code to tell what to do when the button on the right is 
clicked. For example:
Code:if y < 20 Then
  if x < me.width-20 Then
  WindowSkills.Show
  else
  WindowDataEntry.Show
  end
else
end


Of course, when one opens, I set the properties as needed like  this:
Code:me.Buttons = 1
me.Text = "Base heart rate"


Now, how can I put much of the code for the mouse down event into the class? 
And how can I vary it to account for the different numbers of buttons? Or 
should I just keep writing individual code for each instance of the canvas?

For example, in most cases my canvasses will have just one button, the right 
most one which is a right pointing arrow and the user knows it will open a new 
window for data entry related to the canvas while clicking anywhere else in the 
"title bar" will open a related data display window.

But in the data display areas, it's common for me to have left- and 
right-facing arrows which move the data set a week/day forwards/back, which 
means I need to account for the mouse down event happening in three areas.

I'm think of something Select Case -wise in the mouse down event, that would 
call a method in the window where the canvas is located. but before ploughing 
ahead, I want to get some other opinions.   
                            Top               Phil M           Post subject: 
Re: Trying to simply my mouse-down event for canvasPosted: Wed Oct 14, 2009 
12:59 am                        
Joined: Fri Sep 30, 2005 12:18 pm
Posts: 100              First of all, most button behavior fires on the MouseUp 
not the MouseDown.  You can use MouseDown to record the location the user's 
mouse was, toggle a mouseIsDown Boolean and then return True for that Event.  
You can optionally do a RefreshRect for the area of that button and draw a 
darker version of the button to make it appear like a button has been clicked 
and has "moved" into 3D space a bit (a little nice user feedback).

Why handle in MouseUp?  Because you don't know if the user clicked, dragged and 
is now outside the "area" for your button.  Dragging out, "cancels" the button 
click.  If you don't do this, then the behavior of your button is not the same 
as other buttons in the operating system and even in your own program, and it 
will just confuse the user.

As far as your main question... how to handle specific code for each instance / 
use of your custom canvas control.  Answer: Create an event (New Event 
Definition).  In your case it could be something like "ButtonPressed( index As 
Integer ).  Then when you drag your control to your window, put all your 
specific code in the new event you created -- just like you put code into the 
events of existing controls.  If you can, try to model your method names and 
style on the existing REALbasic controls so that your control integrates more 
seamlessly, and its harder to forget how your control works when you decide to 
add it to a project 2 years from now.   
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 2 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