|
Post by vovchik on Jan 18, 2018 20:49:35 GMT 1
Dear Joe (and all), Thanks a MILLION. Here I was scratching my head and trying to write to an offscreen buffer (which may later p[rove useful), because I couldn't get the circles to show. Two minds are manifestly better than one. Now we can produce similar commands for all the other drawing commands (there are a few nice ones, including pies I fixed the last source above with your mods. Here is a little progess report: ' Demonstrate how to draw a line in fltk
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/x.H> PRAGMA INCLUDE <FL/Fl_Widget.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Group.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/fl_draw.H> PRAGMA OPTIONS -Wno-deprecated PRAGMA LDFLAGS -lfltk -lbacon++ -s PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fno-strict-aliasing -fpermissive OPTION PARSE FALSE
USEH #define USECPLUS extern "C" { #define ENDCPLUS } USECPLUS class Fl_Line : public Fl_Widget { public: Fl_Line(int X, int Y, int W, int H, const char*L=0) : Fl_Widget(X,Y,W,H,L) { } void draw() { fl_color(color()); // style is first argument, width is second argument fl_line_style(labelcolor(), labelsize(), 0); int x1 = x(), y1 = y(); int x2 = w(), y2 = h(); fl_line(x1, y1, x2, y2); } }; class Fl_Circle : public Fl_Widget { public: Fl_Circle(double X, double Y, double W, const char*L=0) : Fl_Widget(X,Y,W,0,L) { } void draw() { fl_color(color()); // style is first argument, width is second argument fl_line_style(labelcolor(), labelsize(), 0); double x1 = x(), y1 = y(); double x2 = w(); fl_circle(x1, y1, x2); } }; class Fl_Point : public Fl_Widget { public: Fl_Point(int X, int Y, const char*L=0) : Fl_Widget(X,Y,0,0,L) { } void draw() { fl_color(color()); // style is first argument, width is second argument 'fl_line_style(labelcolor(), labelsize(), 0); int x1 = x(), y1 = y(); //double x2 = w(); fl_point(x1, y1); } }; class Fl_Rect : public Fl_Widget { public: Fl_Rect(int X, int Y, int W, int H, const char*L=0) : Fl_Widget(X,Y,W,H,L) { } void draw() { fl_color(color()); // style is first argument, width is second argument fl_line_style(labelcolor(), labelsize(), 0); int x1 = x(), y1 = y(); int x2 = w(), y2 = h(); fl_rect(x1, y1, x2, y2); } }; class Fl_Rectf : public Fl_Widget { public: Fl_Rectf(int X, int Y, int W, int H, const char*L=0) : Fl_Widget(X,Y,W,H,L) { } void draw() { fl_color(color()); // style is first argument, width is second argument fl_line_style(labelcolor(), labelsize(), 0); int x1 = x(), y1 = y(); int x2 = w(), y2 = h(); fl_rectf(x1, y1, x2, y2); } }; ; ENDCPLUS END USEH
' widget declarations DECLARE win TYPE Fl_Double_Window* DECLARE box, menubar TYPE Fl_Box* DECLARE but0, but1 TYPE Fl_Button* DECLARE canvas TYPE Fl_Group* DECLARE canvas_w, canvas_h TYPE int canvas_w = 300 canvas_h = 300
' ------------------ SUB PIXEL(int x, int y, Fl_Color col) ' ------------------ LOCAL mypoint TYPE Fl_Point* mypoint = new Fl_Point(x, y) mypoint->color(col) ' label does not show, so it can be used to store some extra info mypoint->copy_label("Label") 'myline->labelsize(thick) 'myline->labelcolor(style) END SUB
' ------------------ SUB LINE(int lx1, int ly1, int lx2, int ly2, Fl_Color col, int thick, int style) ' ------------------ LOCAL myline TYPE Fl_Line* myline = new Fl_Line(lx1, ly1, lx2, ly2) myline->color(col) ' label does not show, so it can be used to store some extra info myline->copy_label("Label") myline->labelsize(thick) myline->labelcolor(style) END SUB
' ------------------ SUB SQUARE(int lx1, int ly1, int lx2, int ly2, Fl_Color col, int thick, int style, int fill) ' ------------------ LOCAL myrect TYPE Fl_Rectf* LOCAL myrectf TYPE Fl_Rectf* IF fill THEN myrectf = new Fl_Rectf(lx1, ly1, lx2, ly2) myrectf = new Fl_Rect(lx1, ly1, lx2, ly2) myrectf->color(col) ' label does not show, so it can be used to store some extra info myrectf->copy_label("Label") myrectf->labelsize(thick) myrectf->labelcolor(style) ELSE myrect = new Fl_Rect(lx1, ly1, lx2, ly2) myrect->color(col) ' label does not show, so it can be used to store some extra info myrect->copy_label("Label") myrect->labelsize(thick) myrect->labelcolor(style) END IF END SUB
' ------------------ SUB CIRCLE(double x, double y, double r, Fl_Color col, int thick, int style) ' ------------------ LOCAL mycircle TYPE Fl_Circle* mycircle = new Fl_Circle(x, y, r, 0) mycircle->color(col) ' label does not show, so it can be used to store some extra info mycircle->copy_label("Label") mycircle->labelsize(thick) mycircle->labelcolor(style) END SUB
' ------------------ SUB QUIT_CB(Fl_Widget* widget, void* data) ' ------------------ PRINT "Exiting..." END END SUB
' ------------------ SUB DRAW_CB(Fl_Widget* widget, void* data) ' ------------------ PRINT "Start DRAW_CB" IF NOT(canvas->visible()) THEN PRINT "Show drawing" canvas->show() but0->copy_label("Hide") win->redraw() ELSE PRINT "Hide drawing" canvas->hide() but0->copy_label("Show") win->redraw() END IF END SUB
' main Fl::scheme("plastic") win = new Fl_Double_Window (canvas_w, canvas_h + 50, "Draw something") box = new Fl_Box(FL_FLAT_BOX, 0, 0, canvas_w, canvas_h, "") box->color(FL_WHITE) menubar = new Fl_Box(FL_GLEAM_UP_BOX, 0, canvas_w, canvas_h, 50, "") menubar->color(FL_DARK_RED) but0 = new Fl_Button(10, (win->h() - 40), 50, 30, "Draw") but0->callback(DRAW_CB, NULL) but0->show() but1 = new Fl_Button((win->w() - 60), (win->h() - 40), 50, 30, "Exit") but1->callback(QUIT_CB, NULL) but1->show() canvas = new Fl_Group(0, 0, canvas_w, canvas_h) LINE(20, 20, 150, 150, FL_DARK_GREEN, 18, FL_CAP_ROUND) LINE(30, 30, 150, 240, FL_DARK_RED, 10, FL_DASH|FL_CAP_ROUND) LINE(box->w()/2, 20, box->w()/2, 150, FL_YELLOW, 20, FL_CAP_ROUND) CIRCLE(80, 80, 30, FL_GREEN, 50, 0) CIRCLE(120, 120, 20, FL_RED, 10, 0) PIXEL(280, 280, FL_BLACK) PIXEL(281, 280, FL_BLACK) PIXEL(282, 280, FL_BLACK) PIXEL(283, 280, FL_BLACK) PIXEL(284, 280, FL_BLACK) PIXEL(285, 280, FL_BLACK) PIXEL(286, 280, FL_BLACK) PIXEL(283, 277, FL_BLACK) PIXEL(283, 278, FL_BLACK) PIXEL(283, 279, FL_BLACK) PIXEL(283, 280, FL_BLACK) PIXEL(283, 281, FL_BLACK) PIXEL(283, 282, FL_BLACK) PIXEL(283, 283, FL_BLACK) SQUARE(10, 240, 40, 35, FL_GREEN, 20, 0, 1) SQUARE(70, 240, 40, 35, FL_RED, 5, FL_CAP_ROUND, 0) win->resizable(canvas) win->redraw() canvas->end() win->show() Fl::run()
With kind regards, vovchik
|
|
|
Post by bigbass on Jan 19, 2018 8:50:37 GMT 1
Hey vovchik
I really like how you are going about the HUG fltk
I am just adding a test tool that looks at it another way (c++ has a lot of abstraction and many different ways to see things ) arrow operators are a shorthand way to solve the problem of assigning values inside the class from the Bacon userland
documents use this
void fl_line(int x, int y, int x1, int y1, int x2, int y2)
I used this so we wont clobber values
fl_line(argx ,argy, argx1 ,argy1 ,argx2 ,argy2 );
Joe
'--- DEMONSTRATE HOW TO DRAW
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/fl_draw.H> PRAGMA INCLUDE <FL/Fl_Group.H> PRAGMA INCLUDE <math.h> PRAGMA INCLUDE <stdlib.h> PRAGMA INCLUDE <iostream> PRAGMA LDFLAGS -lfltk -lfltk_images -L. -lbacon++ PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
'--- test bits for animation and debugging the class and callbacks
USEH #define USECPLUS extern "C" { #define ENDCPLUS }
USECPLUS
class Fl_Line : public Fl_Group { public: // placed LINE args in the public class to keep the bacon callbacks simple int argx ,argy, argx1 ,argy1 ,argx2 ,argy2 ;
Fl_Line(int X, int Y, int W, int H, const char*L=0) : Fl_Group(X,Y,W,H,L) { } void draw() { Fl_Group::draw(); fl_color(FL_RED); // width is second argument
fl_line_style(0, 3, 0); fl_line(argx ,argy, argx1 ,argy1 ,argx2 ,argy2 );
} };
ENDCPLUS END USEH
f = 7 t = 220 SUB LINE(void *) f = f + 7 t = t - 7
'---will update fl_line values in the class '---t moves up the image and f moves it down '---assign some values excellent for testing the class '---and check the callbacks too
disp->argx = t disp->argy = t disp->argx1 = t disp->argy1 = t disp->argx2 = FL_RED disp->argy2 = t win->redraw()
IF f > 220 THEN f = 7 ENDIF
IF t < 7 THEN t = 220 win->redraw() ENDIF
PRINT f
Fl::repeat_timeout(.1, LINE) END SUB
'--- TEST THE ABOVE CLASS '--- Send to the class using a timer. DECLARE disp TYPE Fl_Line* DECLARE win TYPE Fl_Double_Window*
win = new Fl_Double_Window(240,240) disp = new Fl_Line(20,20,240-40,240-40) 'disp->box(FL_BORDER_BOX) Fl::add_timeout(.7, LINE) win->show() Fl::run()
|
|
|
Post by vovchik on Jan 19, 2018 14:15:45 GMT 1
Dear Joe,
Thanks for that very useful code/demo. It's a great way of having a draw object under the programmer's control and callable at any time. And it would be useful to pass parameters such as size, style and color. In the fltk draw documentation, they also recommend co-opting certain widget fields (boxtype and labeltype) for storing values (e.g. line width and line style). I think that would be a good idea. I am now playing around and thinking how direct drawing and draw objects could be implemented in hug-fltk.
With kind regards, vovchik
|
|
|
Post by vovchik on Jan 19, 2018 22:04:26 GMT 1
Dear Joe,
Thanks. Working nicely, as expected. With that animation routine, you could also make a little throbber. It would mean drawing an asterisk or something like that with a few line segments and rotating those segments in place around an axis. Throbbers are useful when some process is underway and you want the user to know that (e.g. in Hanoi or Newton when the drawing is taking place).
With kind regards, vovchik
|
|
|
Post by bigbass on Jan 20, 2018 20:32:25 GMT 1
Hey vovchik
I like the way you went about it and how you adapted the args congratulations on all of your hard work and progress
this is the best of both worlds we can use the fltk class and clean it up and make it less abstract and easier to read
And use the bacon/HUG syntax that we are used to seeing and also have the ability to communicate from bacon to the c++ class and assign values
The class is a great idea when you can see how self contained it is and with the ability to do functions from inside the class and declare everything now we dont need to port c++ classes we can just use them and gain the advantages they bring which I will call the very low level code part
Because fltk uses classes for all their widgets we are forced to ajust how to take the fltk documentaion and make use of it and how to get that code to not only just compile but communicate /interact between the class and the bacon userland
Then we use HUG type syntax (by making our own customized functions )
all that is still part of the low level bacon implementation so that the final result will be a fltk HUG userland
When its all done we can just code in the simple HUG syntax
and we got a simple canvas too along the way!
It took a lot of steps to get to here but finally all is coming together nicely
and most importanly it is fun
I am working on a new mental math to drawing images to visualize all the new features and have some basic doumentation to make use of it all
Joe
|
|
|
Post by vovchik on Jan 23, 2018 10:22:59 GMT 1
Dear Joe (and all), Here is a little sample of 10 programs now ported to hug-fltk. Still more work to do on hug-fltk, but you will see that the code is pretty clean and easy to follow. I have also ported scrabble but will put that in another post, since the dictionary part is very large. With kind regards, vovchik UPDATED: modded hug-fltk to include Fl_Chart and added a hug port of Joe's chart demo (see next post), and a port of an animated font display I had done earlier. Attachments:hug-fltk-sampler.tar.gz (274.55 KB)
|
|
|
Post by bigbass on Jan 23, 2018 17:16:12 GMT 1
Hey vovchik Thanks for all of those excellent demos ported to hug-fltk! a lot of fun now with this And a lot to learn from reading through your code I ported a nice widget the "CHART" we will be able to do many cool things with this one as far as feedback from values without plotting a lot of drawing commands manually P.S I was doing some plotting manually and it took me several of hours to derive the formulas learned a lot in the process but this is much easier with a built in CHART widget I will still do a mental math demo about plotting at later time Joe source code ported from here seriss.com/people/erco/fltk/#Fl_Chart '--- CHART DEMO
'---Demonstration of how to use Fl_Chart -- erco 11/20/08 '---Ported to BaCon by bigbass and cleaned up the math using the golden ratio
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Chart.H> PRAGMA INCLUDE <FL/Fl_Widget.H> PRAGMA INCLUDE <FL/Fl_Button.H> PRAGMA INCLUDE <FL/Fl_Box.H> PRAGMA INCLUDE <FL/Fl_Group.H> PRAGMA INCLUDE <FL/Fl_Window.H> PRAGMA INCLUDE <FL/fl_draw.H> PRAGMA INCLUDE <stdio.h> PRAGMA INCLUDE <math.h> PRAGMA OPTIONS -Wno-deprecated PRAGMA LDFLAGS -lfltk -lbacon++ -s PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith -fno-strict-aliasing -fpermissive OPTION PARSE FALSE
DECLARE win TYPE Fl_Window* DECLARE chart TYPE Fl_Chart* DECLARE val TYPE double DECLARE val_str[20] TYPE char DECLARE t TYPE double
win = new Fl_Window(440+22+44, 220+22+44) chart = new Fl_Chart(22, 22, win->w()-44, win->h()-44, "Chart") chart->bounds(-110.0, 110.0) FOR t = 0 TO 15 STEP 0.01 t = t + 0.1 val = SIN(t)* 110.0 printf( "%.0lf", val) chart->add(val, val_str, (val < 0) ? FL_RED : FL_GREEN) NEXT win->resizable(win) win->show() Fl::run()
|
|
|
Post by bigbass on Jan 25, 2018 17:18:02 GMT 1
Hey vovchik
EDIT I am glad you had ported a lot of code into hug-fltk there is a common ground now between hug and fltk of course there are differences that we get when using a new GUI language and a compiling in c++ but this is still a bridge to make the code more bacon like I know we are hacking away through the jungle trying to make a new road and it all may look unconventional but I think we are doing it the right way showing the steps and mistakes we made along the way you have no problem reading the bacon version of my stand alone demos and I am able to see the HUG syntax versions of all your cool programs that you have done for bacon but now ported again which is a great test of hug-fltk we have many widgets to port and sort out the problems first then get it all rolled up in one place so that we can build this as we go
P.S interesting how you worked this line
CHART_ADD(chart, val, val_str, IIF(val < 0, FL_RED, FL_GREEN))
I was surprised I got this line to compile in bacon
chart->add(val, val_str, (val < 0) ? FL_RED : FL_GREEN)
I wanted to modify some of the fltk widgets and at the same time use direct draw
We could have a little progress bar that displays on the bottom of the active window without a pop-up in front of the window that then disappears quietly when a heavy cpu action is done
This is what I wanted to do before but now have the math worked out correctly just need to make it an official widget for us to use
Joe
'--- DEMONSTRATE HOW TO DRAW '--- How to make a progessbar widget
PRAGMA INCLUDE <FL/Fl.H> PRAGMA INCLUDE <FL/Fl_Double_Window.H> PRAGMA INCLUDE <FL/fl_draw.H> PRAGMA INCLUDE <FL/Fl_Group.H> PRAGMA INCLUDE <math.h> PRAGMA INCLUDE <stdlib.h> PRAGMA INCLUDE <iostream> PRAGMA LDFLAGS -lfltk -lfltk_images -L. -lbacon++ PRAGMA COMPILER g++ PRAGMA OPTIONS -Wno-write-strings -Wno-pointer-arith OPTION PARSE FALSE
'--- test bits for animation and debugging the class and callbacks
USEH #define USECPLUS extern "C" { #define ENDCPLUS }
USECPLUS
class Fl_Line : public Fl_Group { public: // placed LINE args in the public class to keep the bacon callbacks simple int argx ,argy, argx1 ,argy1 ,argx2 ,argy2 ; int line_style, line_width; int line_color;
Fl_Line(int X, int Y, int W, int H, const char*L=0) : Fl_Group(X,Y,W,H,L) { } void draw() { Fl_Group::draw(); fl_color(line_color); // X Y W H
fl_line_style(line_style, line_width,0 ); fl_line(argx ,argy, argx1 ,argy1 );
} };
ENDCPLUS END USEH
f = 22 t = 200 SUB PROGRESS_WINDOW(void *) f = f + 11 t = t - 11
progress->line_style = FL_DOT progress->line_width = 11 progress->line_color = FL_BLUE
'---will update fl_line values in the class '---t moves up the image and f moves it down '---assign some values excellent for testing the class '---and check the callbacks too
progress->argx = 22 progress->argy = 220 progress->argx1 = f progress->argy1 = 220 win->redraw()
IF f > 220 THEN f = 22
ENDIF
IF t < 22 THEN t = 200
win->redraw() ENDIF
PRINT f
Fl::repeat_timeout(.2, PROGRESS_WINDOW) END SUB
'--- TEST THE ABOVE CLASS '--- Send to the class using a timer. DECLARE progress TYPE Fl_Line* DECLARE win TYPE Fl_Double_Window* Fl::scheme("gleam") win = new Fl_Double_Window(240,240)
progress = new Fl_Line(20,20,220,220)
Fl::add_timeout(.7, PROGRESS_WINDOW) win->show() Fl::run()
|
|
|
Post by vovchik on Jan 25, 2018 21:19:59 GMT 1
Dear Joe, Thanks for the progress bar. It is a very useful addition, and I like the way it gets incorporated as a normal fltk widget. Today must be International Widget Day. I have included an HTML label, allowing for html markup in widget->label(). Needs some work still, and would be nice to include it in the USEH section of hug-fltk (can you have a look?). I also rendered the progress bar in a hug context, but had to change Fl_Line to Fl_Line1 in the USEH so as to avoid hug conflicts (for the moment). In addition to html labels, I will also create TEXT_SVG and TEXT_PANGO widgets. TEXT_SVG will allow for rotation and the application of all sorts of svg filter effects. TEXT_PANGO will allow for pango markup plus rotation. I may start on those two bits tomorrow. With kind regards, vovchik Attachments:html-label-src.tar.gz (18.44 KB)
|
|
|
Post by vovchik on Jan 26, 2018 17:16:05 GMT 1
Dear Joe (and all), Here is a little demo of TEXT_SVG. Not everything is done yet (exact widget size calculation for placement purposes and rotation), but you will get the idea. You can achieve stunning text effects if you want to, and rotation will be useful. Once I do those things, they will aslo go into hug-fltk. Install the 1960s Hippie font (in the archive) before running the demo. With kind regards, vovchik UPDATED: Did a little work at autosizing the bounding box - and it seems to work. Still fiddling to make it better. UPDATED AGAIN: A few enhancements - but still working on calculating bounding box size properly. Attachments:svg-text.tar.gz (31.1 KB)
|
|