On 2008-10-12, imacarthur <[EMAIL PROTECTED]> wrote: > > Just a few extra notes to round out Albrecht's suggestions... > > On 12 Oct 2008, at 8:52, Albrecht Schlosser wrote: >> Decide, how to implement your piano widget. I can see two rather >> different approaches: >> (1) use 128 Fl_Buttons, and put then into a Fl_Group >> (2) use one widget, probably derived from Fl_Box, and draw the layout >> yourself. >> >> I assume (2), because (1) seems easier at the first glance, but (2) >> looks more flexible in the way you can do the setup (see below). > > Yes - agree strongly. > > >> Now, derive your own widget from Fl_Box, and write a draw() method to >> draw the keys. This should be rather simple, if you first draw the >> white >> keys and draw the black keys on top of them (maybe you need only >> fl_rect() and fl_rectf() ). > > Yes - I did something similar for a keyboard simulator way back. > Simple rectangles is pretty much all I needed. > >> The active ranges could be drawn below the keys, as in your picture >> (fl_polygon() or similar). >> >> Next, write your handle() method to get the user input (key >> clicks). You >> would need to calculate the position of a key from the x/y mouse >> coordinates, but that should be rather straight forward (test the >> black >> keys first, then the white keys, and this can be done with simple x/y >> range comparisons). > > Based on your box widget's x(), y(), w(), h() and the Fl::event_x(), > event_y() values returned for the mouse click in your handle method. > > Also check out Fl::event_inside(int,int,int,int) which may be a > better option for you. > >> For setting up the ranges, I would suggest to add a radio button group >> somewhere else, to let the user select normal display, or start >> setting >> up range 1-4. >> >> After switching to setup mode for a certain range, you could let the >> user click four keys, and the callbacks from your handle() would >> fire to >> let your application know what s/he clicked. > > If you are handling the clicks yourself in the handle method, you can > do all sorts of clever stuff to set your ranges etc... > >> If you want to let the user drag a range of keys, then IMHO approach 2 >> would be much easier to implement, because your handle() method >> could do >> this. Left click, right click, double click, and the combination could >> also help to decide which of the 4 points of a range the user wants to >> set. Clicking on a previously defined range point and dragging it >> elsewhere would also be nice (left click for normal range, right click >> for fade in/out) ? > > FL_PUSH, FL_RELESE, FL_DRAG. Fl::event_buttons(), ::event_button1() > etc... Fl::event_is_click() might also be handy. >
oh, this looks pretty easy, just draw and handle? well, makes sense, draw something and then handle events on it. do i need damage too? or is that on a lower level? ty, jan _______________________________________________ fltk mailing list [email protected] http://lists.easysw.com/mailman/listinfo/fltk

