Re: [fltk.general] Question about Fl_Input
On 6 Mar 2013, at 04:35, edgar wrote: I am using Ubuntu 12.10 but eventually I would like to compile this for Windows7 and OSX. By the way, the code you sent compiled right away and runs nicely. Most of it makes sense to me but I need to check out the draw functions more carefully to get the full picture ;) Well, Ubuntu should be no problem; ISTR they have the Musica font (possibly even version 3.06) in one of their packages, so it ought to be pretty easy to get it installed on your test machine. Failing that, it's pretty easy to install a font for just a single user on linux: - in the home dir of the user, create (if it does not already exist) a dir called .fonts - copy the desired font file, either name.ttf or name.otf, into the .fonts dir - rebuild the fontconfig cache, which, um, I can't remember how to trigger... just log out then back in ought to do it! (Might be fc-cache that does it, I think!) Thereafter, when you run any apps, the font should now be available to you app without doing anything else special. Certainly, works for me! Pretty easy for you to try it on your ubuntu box, see how the font faces look for the various musical glyphs etc. I am knocked out by how helpful the fltk community has been. No worries... Also, I have a very mildly tweaked version of the demo, if anyone is interested, where I have fixed the duff clef scaling I had coded in... ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Question about Fl_Input
On 4 Mar 2013, at 18:32, Greg Ercolano wrote: Ya, technically I'd agree it's best to use a font.. =20 Though from a practical point of view, I've found over time anything you can do to minimize modification of the OS to use an app is often worth doing, even if it's at the expense of = doing what seems right design-wise. If there's a suitable music font installed then it all Just Works = anyway. The only issue is if you want to distribute a font in your app, rather = than installing it - then you get into platform-specific stuff to load = the fonts at runtime... Which is a nuisance. The Win32 is possibly the least hassle as it turns out! Anyway, I tried my code under OSX and linux and it does work - but then = I have the Musica font installed on those test machines, so that's = hardly representative. =20 I'd probably do the same trick for drawing the notes; looking = closely at the 'dots' at the bottom of notes in sheet music, they aren't just an ellipse, but are tweaked on the diagonal too. Tough to = do with FLTK's simple circle functions (though probably easy with svg vector images or cairo). Yup - svg would be nice, or Cairo. But picking the note heads out of the font works nicely too, so... =20 And I was rushing anyway...! =20 Great job on making a nice full on app with a 'game' twist to = it. Thanks! The game aspect wasn't me though, that was just copying what I = *think* Edgar said he was doing... That was exactly what I envisioned. Spot on! =20 I 'played' it for a while until I was quite sure the = EGBDCF/FACE memory trick I learned back in Mrs. Bruninghaus's third grade = music class was still serving me well..! See - these things do stay with you! Yes! Kudos on a nice program. And thanks for the updated version. I actually wiped windows off of my home machine - just running a single boot of Ubuntu I but have access to Win7 and OSX at work and can install Msys at work to run your update. We had a snow day today so I will have to check it out tomorrow. Thanks again. ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Question about Fl_Input
But, I'm still thinking that loading a musical font is the best way to go, and on that basis I was keen to show how to measure a font symbol so that you can render it in the right place. And I was rushing anyway...! Really, I meant for the code to support resizing, but the version I posted doesn't (yet) - though the bits for that are more or less in place. Probably today... OK - lunch break over; here's the revised version. It should now support resizing and do something reasonable. Also; IF you are on a Windows platform, AND you create a folder called fonts under the build folder, AND you place a copy of Musica306.otf in the fonts folder, THEN there's a fair chance that the code will use a real treble clef glyph... Musica306.otf is the font file for version 3.06 of George Douros' Musica font, which looks OK on the screen and is fairly free. I wonder where to download it? Hmm, maybe here? http://users.teilar.gr/~g1951d/Musica306.zip I did this on the wild assumption that Edgar probably has access to a Windows machine... This code (Windows build) tested on Win7 with Msys/mingw, and works nicely. -- // // Test demo - draw a staff // // fltk-config --compile staff-demo.cxx // #ifdef WIN32 // need this dance to make font handling load on Win32 # define _WIN32_WINNT 0x0500 # include windows.h #endif #include FL/Fl.H #include FL/Fl_Group.H #include FL/Fl_Double_Window.H #include FL/Fl_Button.H #include FL/Fl_Box.H #include FL/Fl_Output.H #include FL/fl_draw.H #include stdlib.h #include stdio.h #include time.h // some widgets we will use... static Fl_Double_Window *main_win = 0; static Fl_Button *quit_bt = 0; static Fl_Button *repeat_bt = 0; static Fl_Button *note_bt[8]; // 8 note names is enough for now... static Fl_Output *out_txt = 0; static int score = 0; // Special platfom code to handle app specific fonts under Windows static int have_music_font = 0; /*/ static void load_extra_font(void) { #ifdef WIN32 /* Load the font using the Windows API */ have_music_font = AddFontResourceEx(./fonts/Musica306.otf, FR_PRIVATE, 0); #endif /* setup the extra font */ Fl::set_font(FL_SYMBOL, #ifdef __APPLE__ Musica); #else Musica); #endif } // load_extra_font /**/ static void free_extra_font(void) { #ifdef WIN32 if (have_music_font) { DWORD fl = FR_PRIVATE; PVOID pdv = 0; RemoveFontResourceEx(./media/Musica306/Musica306.otf, fl, pdv); } #endif } // free_extra_font /**/ // class to display the staff class staff_view : public Fl_Box { protected: void draw(); public: // index used to hold the current note. Only 11 values used here, // 0..10, for notes D to G, since I can't be bothered drawing any // ledger lines... // For ease, I have made D == 0 here, but we really want A == 0 later so... yuck.. int note; // constructor staff_view(int X, int Y, int W, int H) : Fl_Box(X, Y, W, H), note(0) { }; }; void staff_view::draw() { static char clef_G[2] = {'G', 0}; // a G clef... sort of... // U_treble_clef = 0x1d11e; Unicode code-point for a treble clef static char treble_clef[5] = {0xF0, 0x9D, 0x84, 0x9E, 0}; // a G clef... as UTF8 Fl_Box::draw(); // draw the base-class box first to give us an outline to fill... // determine some limits for us to draw staff lines into int ww = w(); int hh = h(); int gap = hh / 8; // space between the lines... int ht = gap * 4; // 5 lines, 4 gaps... int yo = y() + (2 * gap); // Y origin int xo = x() + 20; // X origin int len = ww - 40; // staff length int xe = xo + len; // X end fl_color(FL_BLACK); // set the colour first fl_line_style(FL_SOLID, 2); // then set the line style // draw the endcaps... this is not pretty code... // get rid of all these dodgy hard-coded offsets... fl_line(xo, yo, xo, yo + ht); fl_line(xe-8, yo, xe-8, yo + ht); fl_line_style(FL_SOLID, 4); fl_line(xe-2, yo, xe-2, yo + ht); fl_line_style(FL_SOLID, 2); // draw 5 lines for stave int yl = yo; for (int idx = 0; idx 5; ++idx) { fl_line(xo, yl, xe, yl); yl += gap; } // draw the clef - measure the clef symbol, so we can figure out where to draw it... int dx1, dy1, cw1, ch1; // for real clef int dx2, dy2, cw2, ch2; // for fallback clef if(have_music_font) { // get the music font, and ask for it a bit bigger fl_font(FL_SYMBOL, (ht + (gap * 3)));
Re: [fltk.general] Question about Fl_Input
On 03/04/13 01:39, MacArthur, Ian (Selex ES, UK) wrote: Yeah, I had wondered about doing that - particularly given that Edgar intimated he had PNG's for the musical glyphs he was using... But, I'm still thinking that loading a musical font is the best way to go, and on that basis I was keen to show how to measure a font symbol so that you can render it in the right place. Ya, technically I'd agree it's best to use a font.. Though from a practical point of view, I've found over time anything you can do to minimize modification of the OS to use an app is often worth doing, even if it's at the expense of doing what seems right design-wise. I'd probably do the same trick for drawing the notes; looking closely at the 'dots' at the bottom of notes in sheet music, they aren't just an ellipse, but are tweaked on the diagonal too. Tough to do with FLTK's simple circle functions (though probably easy with svg vector images or cairo). Back when linux antialiased fonts were still really up in the air, I seriously considered making my own antialiased font engine for FLTK (the nixieclock program was going to demonstrate this), but thankfully Xft matured before getting to the design phase. And I was rushing anyway...! Great job on making a nice full on app with a 'game' twist to it. I 'played' it for a while until I was quite sure the EGBDCF/FACE memory trick I learned back in Mrs. Bruninghaus's third grade music class was still serving me well..! ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Question about Fl_Input
On 3 Mar 2013, at 04:36, edgar wrote: I am starting with a simple program to show a whole note on a staff with a treble clef. The user is asked to enter the note name. The program should let the user know if their input was correct and display a running score in the window. OK - that seems straightforward. However, as a design point, I'd caution against letting the user input the answer as free text or even natural language since you then have to parse what they enter and see if it makes sense... (e.g. I never say whole note, I'd say semibreve, but both are correct...) Rather, I'd offer a list of answers and allow the user to pick one - that removes the parsing aspect and makes things a lot simpler, with no loss of generality... Here is the basic algorithm: Display window with the following: Instruction header - prompts user to enter note name. staff and clef - (staff is drawn. clef and note are .png) Loop { note is shown on the staff - chosen randomly from a bank of locations. User enters note name Program checks user response, tabulates a score and prints a running score to the window } User selects a quit button which destroys all dynamically allocated widgets. This step is probably unnecessary - if you program is ending, and the process in which it runs is ending, then all the allocated memory will be released by the process anyway... In which case actually making the effort to explicitly destroy allocated widgets is nugatory work... Here is the code I have so far. It compiles and runs with my png files, but I don't know how to: Um... OK. Well, I don't think that's the right way to go about this. There are a few things wrong with this code... Also, it is making your task more complex than in needs to be, which is a Bad Thing. Time permitting, I'll cobble up a demo and post it, of how this might be done in a more fltk'ish way. Might not be today though. 1. Get the user's input to the window instead of the console. I think I can send it to an output box, but I'd like to send it to the window via an invisible box - sort of like the header. This is trivial, but possibly not with the code structured the way you have it. 2. Loop the sequence. I would also like to keep the code which checks the answers separate from the code that implements the GUI. Again, trivial, but we need to look at your program structure and see how you can achieve that. Key points though: - There are better ways to draw lines in fltk; where did you get this approach from? It looks really quite... odd... - If you are going to render a lot of musical symbols, loading a musical font (such as Musica or etc.) will be easier than rendering lots of PNG glyphs, and will also anti-alias and scale automatically. - The way the main window is being created and run here is holding you back. - You need to see how to subclass a box and derive your own draw() method to handle the drawing of your staff. Anyway, I'll try and make a demo, then post it for you to see. There are easier ways to do what you want! ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Question about Fl_Input
Rather, I'd offer a list of answers and allow the user to pick one - = that removes the parsing aspect and makes things a lot simpler, with no = loss of generality... Good idea. I could use buttons labelled with note names... User selects a quit button which destroys all dynamically allocated = widgets. This step is probably unnecessary - if you program is ending, and the = process in which it runs is ending, then all the allocated memory will = be released by the process anyway... In which case actually making the = effort to explicitly destroy allocated widgets is nugatory work... Eventually, I'd like this to be a portion of a larger program. (eg. this would be one choice from a drop down menu... )In that case, is it more important to destroy widgets that go out of scope? Here is the code I have so far. It compiles and runs with my png = files, but I don't know how to: 'll cobble up a demo and post it, of how this might be = done in a more fltk'ish way. Might not be today though. Thanks very much! I never got this kind of response from my C++ prof! Key points though: - There are better ways to draw lines in fltk; where did you get this = approach from? It looks really quite... odd... I took a code snippet from Greg Ercolano's tutorial website. This was the only drawing tutorial I could find - it was written to draw an X that could be resized and it works great for that. I tried to modify the code to meet my needs, but I realized I must be making things more awkward then necessary. - If you are going to render a lot of musical symbols, loading a musical = font (such as Musica or etc.) will be easier than rendering lots of PNG = glyphs, and will also anti-alias and scale automatically. I would really like to learn how to do this. I was using .png files, which worked and didn't look bad, but It doesn't allow resizing and is pretty inflexible. I remember you mentioned Musescore. Do you know of tutorials on the web for loading and implementing font libraries? - The way the main window is being created and run here is holding you = back. - You need to see how to subclass a box and derive your own draw() = method to handle the drawing of your staff. Anyway, I'll try and make a demo, then post it for you to see. There are easier ways to do what you want! Thanks again Ian! ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Question about Fl_Input
Ok, I wrote something, but I'm pressed for time (busy weekend - indeed = busy week coming too) and it is late here, so it is not as nice as I'd = like... To Ian, Albrecht and Greg: Thanks so much for all of the great tips, links and code examples! I will study your examples and get working on this project. Thanks also for taking time to help a beginner like me. I will keep you posted as questions and comments arise. All Best, Edgar ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Question about Fl_Input
So for a Fl_Input you can set the when() as FL_WHEN_ENTER_KEY, then if you hit the enter key, the callback for the input widget should run. I tried that in a test program and it works. Thanks! Can you clarify; I'm not clear what you are asking here, can you outline what you are trying to achieve, then we can suggest some ways you might implement that. I am starting with a simple program to show a whole note on a staff with a treble clef. The user is asked to enter the note name. The program should let the user know if their input was correct and display a running score in the window. Here is the basic algorithm: Display window with the following: Instruction header - prompts user to enter note name. staff and clef - (staff is drawn. clef and note are .png) Loop { note is shown on the staff - chosen randomly from a bank of locations. User enters note name Program checks user response, tabulates a score and prints a running score to the window } User selects a quit button which destroys all dynamically allocated widgets. Here is the code I have so far. It compiles and runs with my png files, but I don't know how to: 1. Get the user's input to the window instead of the console. I think I can send it to an output box, but I'd like to send it to the window via an invisible box - sort of like the header. 2. Loop the sequence. I would also like to keep the code which checks the answers separate from the code that implements the GUI. #include FL/Fl.H #include FL/Fl_Window.H #include FL/Fl_Button.H #include FL/Fl_Return_Button.H #include FL/Fl_Input.H #include FL/Fl_Box.H #include FL/fl_draw.H #include FL/Fl_Shared_Image.H #include FL/Fl_PNG_Image.H #include iostream using namespace std; // SIMPLE WIDGET THAT DRAWS A LINE class DrawLINE : public Fl_Widget { public: DrawLINE(int X, int Y, int W, int H, const char*L=0) : Fl_Widget(X,Y,W,H,L) { } void draw() { // DRAW BLACK LINE fl_color(FL_BLACK); fl_line_style(FL_SOLID, 2); int x1 = x(), y1 = y(), x2 = w(), y2 = h(); fl_line(x1, y1, x2, y2); }// modified from G. Ercolano's cheatsheet (Draw an X) }; // When this is resized it gets funky so I think I don't have it // quite right... class SimpleWindow : public Fl_Window{ public: SimpleWindow(int w, int h, const char* title ); ~SimpleWindow(); Fl_Input* inp; Fl_Return_Button* entr; Fl_Button* quit; Fl_Box* header; Fl_Box* noteBox; Fl_Box* clefBox; Fl_Box* comment; const char* letters; // user response Fl_PNG_Image* note; Fl_PNG_Image* clef; // DrawLINE pointers for drawing the staff DrawLINE* line1; DrawLINE* line2; DrawLINE* line3; DrawLINE* line4; DrawLINE* line5; DrawLINE* vert1; DrawLINE* vert2; DrawLINE* vert3; private: static void cb_getInfo(Fl_Widget*, void*); inline void cb_getInfo_i(); static void cb_quit(Fl_Widget*, void*); inline void cb_quit_i(); }; // int main (){ SimpleWindow win(400,400,Treble Clef Note Identification); return Fl::run(); // I modified the window below from a beginner //fltk tutorial. // The problem I see is that implementation of the SimpleWindow looks // like function main. I really don't want to attempt loops inside // a class implementation } //--From what I understand it is better to have children of a window // dynamically allocated so all the info can be passed via a pointer // and all the children are destroyed when the parent is destroyed. // Is this a correct assumption and good programming practice? SimpleWindow::SimpleWindow(int w, int h, const char* title):Fl_Window(w,h,title){ begin(); // Draw header header = new Fl_Box(100, 20, 200, 30, Type the note name in the box\nbelow and hit enter.); // Draw Staff line1 = new DrawLINE(100, 100, 300, 100); line2 = new DrawLINE(100, 110, 300, 110); line3 = new DrawLINE(100, 120, 300, 120); line4 = new DrawLINE(100, 130, 300, 130); line5 = new DrawLINE(100, 140, 300, 140); vert1 = new DrawLINE(300, 99, 300, 141); vert2 = new DrawLINE(298, 99, 298, 141); vert3 = new DrawLINE(292, 99, 292, 141); fl_register_images(); // Register the images. // Draw clef clefBox = new Fl_Box(95, 80, 55, 85); clef= new Fl_PNG_Image(tc75.png); clefBox-image(clef); // Draw note noteBox = new Fl_Box(200, 101, 30, 30); note= new Fl_PNG_Image(note.png); noteBox-image(note); entr = new Fl_Return_Button(100, 300, 80, 30, Enter); entr-callback( cb_getInfo, this ); quit = new Fl_Button(250, 300, 50, 30, Quit); quit-callback(cb_quit, this); inp = new Fl_Input(200, 190, 30, 30); end(); show(); }
Re: [fltk.general] Question about Fl_Input
On 02/28/13 23:58, edgar wrote: Is it possible to send text typed into an Fl_Input box to another box without using a callback via an enter button? Going to assume you meant not to have the word without in the above. I would like to have the user type an answer into an Input box and then hit the enter key on the keyboard. Sure, just use set the callback() for the input widget to send whatever the user typed to the other box. eg: #include FL/Fl.H #include FL/Fl_Window.H #include FL/Fl_Input.H #include FL/Fl_Box.H // // Demonstrate Fl_Input to use Enter key to trigger callback to change window's title - erco 3/1/13 // void ChangeTitle(Fl_Widget *w, void *data) { Fl_Input *in = (Fl_Input*)w; Fl_Window *win = (Fl_Window*)data; win-label(in-value());// send value of Fl_Input to window's title } int main(int argc,char **argv) { Fl_Window *win = new Fl_Window(300,100); Fl_Input *in = new Fl_Input(140,10,150,25,Type something:); in-callback(ChangeTitle, (void*)win); in-when(FL_WHEN_ENTER_KEY); win-show(); return(Fl::run()); } Also, if I am wanting to loop this series of events, how would I go about this if the Input box and the other text box are dynamically allocated? Should they be destroyed and recreated with each iteration to avoid memory leaks? No, just hide() and show() them as needed. If these widgets are in a dialog, then just hide() and show() the dialog window, and leave the widgets within allocated. Thanks! I will give this a try. I posted my algorithm and starter code for a little program. You guys are great! ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk
Re: [fltk.general] Question about Fl_Input
Is it possible to send text typed into an Fl_Input box to another box without using a callback via an enter button? Sure; pretty much any fltk widget (including the windows themselves) can be associated with a callback. So for a Fl_Input you can set the when() as FL_WHEN_ENTER_KEY, then if you hit the enter key, the callback for the input widget should run. If this can work, what functions would be used and could you provide a short statement for syntax? Also, if I am wanting to loop this series of events, how would I go about this if the Input box and the other text box are dynamically allocated? Should they be destroyed and recreated with each iteration to avoid memory leaks? Can you clarify; I'm not clear what you are asking here, can you outline what you are trying to achieve, then we can suggest some ways you might implement that. Anyway, here's a little fluid file that might show how the enter key stuff works... -- # data file for the Fltk User Interface Designer (fluid) version 1.0302 header_name {.h} code_name {.cxx} decl {\#include stdio.h} {selected private local } Function {} {open } { Fl_Window main_win {open private xywh {856 299 543 337} type Double visible } { Fl_Button quit_bt { label Quit callback {main_win-hide();} private xywh {455 280 80 45} box THIN_UP_BOX } Fl_Browser brws { private xywh {40 80 405 245} box THIN_DOWN_BOX } Fl_Input input_widget { label {input:} callback {printf(Enter key hit: value is %s\\n, input_widget-value()); fflush(stdout); brws-add( input_widget-value());} private xywh {65 31 190 28} box THIN_DOWN_BOX when 10 } } } -- Ian Selex ES Ltd Registered Office: Sigma House, Christopher Martin Road, Basildon, Essex SS14 3EL A company registered in England Wales. Company no. 02426132 This email and any attachments are confidential to the intended recipient and may also be privileged. If you are not the intended recipient please delete it from your system and notify the sender. You should not copy it or use it for any purpose nor disclose or distribute its contents to any other person. ___ fltk mailing list fltk@easysw.com http://lists.easysw.com/mailman/listinfo/fltk