|
Post by alexfish on Jul 31, 2013 19:01:13 GMT 1
Hi @ ALL BaCon libgfx Beta 1-0.1 Released ::Depends Previous & working Install of latest Bacon or Bacongui + latest hug :: Latest Bacon Beta Depends libgoocanvas-dev =1.0 :: Note 2.* goo_canvas 2* series may not be compatible with gtk2 on which libgfx is based therefore recommend 1.* series Depend libcanberra-dev if error shows when using ALPHA channel , then use latest goocanvas from HERELatest:: Undated as stamped :: January 02 | 2014 :: now requires Bacon 2.4 :: CHECKSUMS GFX COMMANDS and example code :: Visit BaCon Wiki Page : Alexfish-BaCon Wiki PagesKnown bugs : update 11/ JAN 1014 Have Fun & Enjoy Alex See Next post by Vovchik on how to compile to a .so Update:: there is a new extension . the initial part of this is for LIBRSVG there are two FUNCTIONS 'SVG_BUFF' & 'SVG_FROM_FILE' copy the code and save as 'gfx_ext.bac' in same directory as libgfx.bac . the main lib will be updated to include the extension soon :: The "SVG_FROM_FILE" should be able to return a pixbuf from a .svg file , also should be able to import files from INKSCAPE a bit of code first then the extension to the lib . INCLUDE libgfx_import.bac
'@inlude the extentions INCLUDE gfx_ext.bac
root = WINDOW("Menu Image GFX", 400, 400, 1.0) win = GETROOT(root) '@ get a svg pixpuff from file , change the the path to file to suit '@ SVG_FROM_FILE("/path/to/file") svg_1 = SVG_FROM_FILE("gfx.svg")
'@ transfer the image to goocanvas image , once done can maniulate the image same as svg conventions '@ IMAGE(parent,pixbuf,xposition,yposition,width,height svg_image = IMAGE(win, svg_1, 0,0, 120, 48)
' can use the above image as in 'svg_1' but when finish with the object has to be UNREF'd use G_UNREF G_UNREF(svg_1)
DISPLAY the extension '@ file gfx_ext.bac CONST EXT_MAX_LIB_SEQ = 50 '@ will need to check system for the 'librsvg-*.so*' name as appropiate CONST rsvg$ = "librsvg-2.so.2"
IMPORT "rsvg_handle_close(long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_handle_get_pixbuf(long)" FROM rsvg$ TYPE long IMPORT "rsvg_handle_new()" FROM rsvg$ TYPE long IMPORT "rsvg_handle_write(long,char*,long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_init()" FROM rsvg$ TYPE void IMPORT "rsvg_term()" FROM rsvg$ TYPE void
FUNCTION Get_Gobject() : REM INCLUDE
LOCAL g_lib$ LOCAL hug_sequence = -1 IF INSTR(OS$, "Darwin") THEN g_lib$ = "/opt/local/lib/libgobject-2.0.0.dylib" IF NOT(FILEEXISTS(g_lib$)) THEN g_lib$ = "/Library/Frameworks/Glib.framework/Libraries/libgobject-2.0.0.dylib" END IF ELIF INSTR(OS$, "CYGWIN") THEN g_lib$ = "cyggobject-2.0-0.dll" END IF
CATCH GOTO Redo_Import
LABEL Redo_Import INCR hug_sequence IF hug_sequence = EXT_MAX_LIB_SEQ THEN GOTO Print_Error IF NOT(INSTR(g_lib$, "dylib")) AND NOT (INSTR(g_lib$, "dll")) THEN g_lib$ = CONCAT$("libgobject-2.0.so.", STR$(hug_sequence)) IMPORT "g_object_unref(long)" FROM g_lib$ TYPE void
RETURN g_lib$
LABEL Print_Error PRINT "Gobject library not found!" END
END FUNCTION REM ----------------------------------- FUNCTION SVG_BUFF(STRING new$)
LOCAL mysvg, mypixbuf rsvg_init() mysvg = rsvg_handle_new() svi = rsvg_handle_write(mysvg, new$, LEN(new$), 0) svi = rsvg_handle_close(mysvg, 0) mypixbuf = rsvg_handle_get_pixbuf(mysvg) rsvg_term() g_object_unref(mysvg) RETURN mypixbuf END FUNCTION REM --------------------------- FUNCTION SVG_FROM_FILE(STRING file$) LOCAL svg$ , txt$ LOCAL svg_image IF FILEEXISTS(file$) THEN OPEN file$ FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO READLN txt$ FROM myfile IF NOT(ENDFILE(myfile)) THEN svg$=svg$&txt$&NL$ ENDIF WEND CLOSE FILE myfile ELSE PRINT "File not Exist : ",file$ END IF svg_image=SVG_BUFF(svg$) RETURN svg_image END FUNCTION
REM---------------------------------------- extglib$=Get_Gobject()
libgfx:: Attachments:gfx.tar.bz2 (19.24 KB)
|
|
|
Post by vovchik on Jul 31, 2013 19:15:47 GMT 1
Dear Alex,
Let me be the first to congratulate you on this first beta release. Users will discover that the lib is fast, flexible and capable of a great deal. No excuse now to beat your progs with an ugly stick:) First you want to compile the lib. Do so as follows:
bacon -f libgfx
This create a libgfx.so file. You will need that because it contains functions that will be called via the next lines, which should be at the start of at the start of your program:
INCLUDE "libgfx_import.bac" INIT
And away you go. We will be posting demos and examples shortly....
With kind regards, vovchik
|
|
|
Post by vovchik on Jul 31, 2013 20:14:50 GMT 1
Dear All,
Just a little rotating svg....
with kind regards, vovchik
' *********************** ' INCLUDES ' ***********************
INCLUDE "libgfx_import.bac"
' *********************** ' END INCLUDES ' ***********************
' *********************** ' DECLARATIONS ' ***********************
CONST rsvg$ = "librsvg-2.so.2" DECLARE icon$ TYPE STRING INIT icon$ = CONCAT$("<svg width='100' height='100' transform='scale(1.5625)'>" \ "<defs>" \ "<linearGradient id='l1'>" \ "<stop offset='0' style='stop-color:red;stop-opacity:1'/>" \ "<stop offset='1' style='stop-color:pink;stop-opacity:0'/>" \ "</linearGradient>" \ "<radialGradient fx='-2798.4968' fy='138.56735' cx='-2798.4968' cy='138.56735' gradientTransform='matrix(-7.4772937e-7,-1.2181465,0.91248059,-5.6009974e-7,-2953.1402,-3278.6131)' r='184.35258' id='r1' xlink:href='#l1' gradientUnits='userSpaceOnUse'/>" \ "<filter color-interpolation-filters='sRGB' id='f1'>" \ "<feGaussianBlur stdDeviation='7.9327614' id='g1'/>" \ "</filter>" \ "<linearGradient gradientTransform='matrix(1.116294,0,0,1.1492663,1348.4919,1558.6057)' id='l2' xlink:href='#l4' y1='-189.98889' x1='-2771.5366' y2='166.76128' x2='-2914.9534' gradientUnits='userSpaceOnUse'/>" \ "<linearGradient id='l4'>" \ "<stop offset='0' style='stop-color:white;stop-opacity:1'/>" \ "<stop offset='1' style='stop-color:white;stop-opacity:0'/>" \ "</linearGradient>" \ "<linearGradient gradientTransform='matrix(1.116294,0,0,1.1492663,1348.4919,1558.6057)' id='l2' xlink:href='#l4' y1='-189.98889' y2='166.76128' x1='-2771.5366' x2='-2914.9534' gradientUnits='userSpaceOnUse'/>" \ "</defs>" \ "<g transform='matrix(0.16405474,0,0,0.17678507,332.44127,-253.32611)'>" \ "<path style='fill:mycol3;fill-opacity:1;stroke:none' id='p1' d='m -2674.7299,44.856693 c 0,83.167467 -74.6442,150.588017 -166.7225,150.588017 -92.0783,0 -166.7224,-67.42055 -166.7224,-150.588017 0,-83.167463 74.6441,-150.588013 166.7224,-150.588013 92.0783,0 166.7225,67.42055 166.7225,150.588013 z' transform='matrix(1.1075269,0,0,1.1075269,1317.8538,1563.2636)'/>" \ "<path style='fill:url(#r1);fill-opacity:1;stroke:none;filter:url(#f1)' id='p2' d='m -2674.7299,44.856693 c 0,83.167467 -74.6442,150.588017 -166.7225,150.588017 -92.0783,0 -166.7224,-67.42055 -166.7224,-150.588017 0,-83.167463 74.6441,-150.588013 166.7224,-150.588013 92.0783,0 166.7225,67.42055 166.7225,150.588013 z' transform='matrix(0.92601987,0,0,0.92601987,799.76637,1577.018)'/>" \ "<path style='fill:url(#l2);fill-opacity:1;stroke:none' d='m -1829.3102,1460.5053 c -54.6929,0.6794 -106.9174,31.4167 -136.3438,77.0625 55.7131,57.783 136.0054,87.0562 215.3116,90.6989 29.0455,2.0929 58.0908,4.286 87.1572,6.1136 12.4731,-74.5308 -41.6762,-150.4654 -113.4376,-168.9687 -17.1306,-4.4989 -35.0401,-5.1371 -52.6874,-4.9063 z'/>" \ "</g>" \ "</svg>")
' *********************** ' END DECLARATIONS ' ***********************
' *********************** ' IMPORTS ' ***********************
' rsvg IMPORT "rsvg_handle_close(long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_handle_get_pixbuf(long)" FROM rsvg$ TYPE long IMPORT "rsvg_handle_new()" FROM rsvg$ TYPE long IMPORT "rsvg_handle_write(long,char*,long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_init()" FROM rsvg$ TYPE void IMPORT "rsvg_term()" FROM rsvg$ TYPE void IMPORT "g_object_unref(long)" FROM "libgobject-2.0.so" TYPE void
' *********************** ' END IMPORTS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ FUNCTION SVG_BUFF(STRING new$) ' ------------------ ' create pixbuf from inline svg string LOCAL mysvg, mypixbuf rsvg_init() mysvg = rsvg_handle_new() svi = rsvg_handle_write(mysvg, new$, LEN(new$), 0) svi = rsvg_handle_close(mysvg, 0) mypixbuf = rsvg_handle_get_pixbuf(mysvg) rsvg_term() g_object_unref(mysvg) RETURN mypixbuf END FUNCTION
' ------------------ SUB MK_GUI() ' ------------------ root = WINDOW("Bacon GFX ", 200, 200, 1.0) win = GETROOT(root) b = AREA(win, 50, 50, 100, 100) pixy = SVG_BUFF(icon$) a = SQUAREPIX(b, pixy, 0, 0, 100, 100, 0) c = SQUAREPIX(b, pixy, 0, 0, 100, 100, 0) ROTATE(c, 45, 50, 50) TOG = 0 FOR t = 0 TO 360 ROTATE(b, 1, 100, 100) TOG = NOT(TOG) PRINT "Tog: ", TOG IF TOG = 0 THEN HIDE(c) SHOW(a) ELSE SHOW(c) HIDE(a) END IF SYNC SLEEP 150 NEXT t END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY
' *********************** ' END MAIN ' ***********************
|
|
|
Post by Pjot on Jul 31, 2013 20:31:05 GMT 1
Folks,
Very nice! The include file and the demo from vovchik worked without modification (though I had to install libcanberra first, of course).
I am going to study GOO, canberra and SVG a little bit more, a lot of cool things can be done with these libraries....
Thanks! Peter
|
|
|
Post by alexfish on Jul 31, 2013 23:00:31 GMT 1
Hi @ All
here is a little demo to demo the differences in GFX to Hug as regards the values
HSLIDER , VSLIDER + SPIN = decimal point capable PROGRESS reads in Whole Number as in %
in the lib the is a CONSTANT called GET_DOUBLE , tis will return the true values of the widgets
GET_DOUBLE is a Convenience aid to save having to remember to Static passing
as in (double)my_value or (int)my_value
So here we Go
INCLUDE "libgfx.bac" '@ if using libgfx.so 'INCLUDE "libgfx_import.bac" 'INITSUB
get_progress() PRINT "PROG"
END SUB
SUB get_spin()
GET_DOUBLE = GET(my_spin) TEXT(entry_2,STR$(GET_DOUBLE))
END SUB
SUB get_slide()
GET_DOUBLE=GET(my_Hslider) TEXT(entry_3,STR$(GET_DOUBLE)) SET(my_progress,GET_DOUBLE) GET_DOUBLE = GET(my_progress) TEXT(entry_1,CONCAT$(STR$(GET_DOUBLE)," %")) TEXT(my_progress,CONCAT$(STR$(GET_DOUBLE)," %"))
END SUB
'@ WINDOW("title",width,height,opacity) root=WINDOW("Bacon GFX",600,500,1.0)
'@ get the root of the WINDOW win=GETROOT(root)
'@ add TEXTBOX old name = ENTRY entry_1=TEXTBOX() ATTACH(win,entry_1,50,50,100,30)
entry_2=TEXTBOX() ATTACH(win,entry_2,50,100,100,30)
entry_3=TEXTBOX() ATTACH(win,entry_3,50,150,100,30)
my_progress=PROGRESSBAR("progress bar") ATTACH(win,my_progress,200,50,300,30)
my_spin=SPIN(0,100,0.1) ATTACH(win,my_spin,200,100,75,30) CALLBACK(my_spin,get_spin)
my_Hslider=HSLIDER(0,100,0.5) ATTACH(win,my_Hslider,200,150,300,60) CALLBACK(my_Hslider,get_slide)
DISPLAY
IE to SET a Progressbar SET(my_progressbar , 50) = SET to 50%
Have Fun Alex
|
|
|
Post by bigbass on Aug 1, 2013 5:25:14 GMT 1
Hey Alex great work! you really got busy coding that I love what you did with the DEF FN I had to follow vovchik's advice about using the lib.so instead for your first and second code example to compile very minor adjustments I think when you pasted the code the format changed I see a great new way to add more options to BaCon congratulations! Joe first example edit this 'INCLUDE "libgfx.bac" INCLUDE "libgfx_import.bac" INIT SUB zoom() second example edit this 'INCLUDE "libgfx.bac" '@ if using libgfx.so INCLUDE "libgfx_import.bac" INIT
'--SUB '-----get_progress() '-----PRINT "PROG" '--END SUB
|
|
|
Post by vovchik on Aug 1, 2013 11:33:53 GMT 1
Dear All,
Another little sample here....
With kind regards, vovchik
PS. Isn't this fun?
' *********************** ' INCLUDES ' ***********************
INCLUDE "libgfx_import.bac"
' *********************** ' END INCLUDES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
INIT ALIAS g_object_set TO G_SET CONST rsvg$ = "librsvg-2.so.2" DECLARE icon1$, incon2$ TYPE STRING DECLARE a, b, c icon1$ = CONCAT$("<svg width='100' height='100' transform='scale(4.166666667)'>" \ " <defs>" \ " <radialGradient cx='44.699' cy='42.721' " \ " gradientTransform='scale(1.02247 .97802)' " \ " id='rg' r='12.239' gradientUnits='userSpaceOnUse'>" \ " <stop offset='0' stop-color='#ffffff' stop-opacity='.733'/>" \ " <stop offset='1' stop-color='#ffffff' stop-opacity='0'/>" \ " </radialGradient>" \ " </defs>" \ " <g fill-rule='evenodd' transform='matrix(.51969 0 0 .51605 -13.71409 -12.53148)'>" \ " <path fill='red' stroke-linejoin='round' fill-opacity='.981' " \ " stroke-width='1.308' d='m68.5629,51.1803c0,11.889-9.6491,21.5381-21.5381," \ " 21.5381-11.889,0-21.5381-9.6491-21.5381-21.5381 0-11.889 9.6491-21.5381 " \ " 21.5381-21.5381 11.889,0 21.5381,9.6491 21.5381,21.5381z' " \ " transform='matrix(.96493 0 0 .94588 4.5275 -.75584)'/>" \ " <path fill='url(#rg)' stroke-width='1.25' " \ " d='m58.2181,41.7819c0,6.6075-5.6063,11.9701-12.5142,11.9701-6.9078," \ " 0-12.5142-5.3626-12.5142-11.9701 0-6.6075 5.6063-11.9701 12.5142-11.9701 " \ " 6.9078,0 12.5142,5.3626 12.5142,11.9701z'/>" \ " </g>" \ "</svg>") flash = TRUE
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' IMPORTS ' ***********************
' rsvg IMPORT "rsvg_handle_close(long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_handle_get_pixbuf(long)" FROM rsvg$ TYPE long IMPORT "rsvg_handle_new()" FROM rsvg$ TYPE long IMPORT "rsvg_handle_write(long,char*,long,int)" FROM rsvg$ TYPE int IMPORT "rsvg_init()" FROM rsvg$ TYPE void IMPORT "rsvg_term()" FROM rsvg$ TYPE void IMPORT "g_object_unref(long)" FROM "libgobject-2.0.so" TYPE void
' *********************** ' END IMPORTS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ FUNCTION SVG_BUFF(STRING new$) ' ------------------ ' create pixbuf from inline svg string LOCAL mysvg, mypixbuf rsvg_init() mysvg = rsvg_handle_new() svi = rsvg_handle_write(mysvg, new$, LEN(new$), 0) svi = rsvg_handle_close(mysvg, 0) mypixbuf = rsvg_handle_get_pixbuf(mysvg) rsvg_term() g_object_unref(mysvg) RETURN mypixbuf END FUNCTION
' ------------------ SUB FLASH(long pic, int rate) ' ------------------ WHILE flash DO SHOW(pic) SLEEP rate SYNC HIDE(pic) SLEEP rate SYNC WEND END SUB
' ------------------ SUB START_STOP() ' ------------------ flash = NOT(flash) FLASH(b, 150) SHOW(b) END SUB
' ------------------ SUB MK_GUI() ' ------------------ root = WINDOW("Bacon GFX ", 200, 200, 1.0) win = GETROOT(root) rad = RADIAL(200, 200, 75, 100, 200, 300) ADD_COLOR_STOP(rad, 0.0, 1.0, 1.0, 1.0, 0.8) ADD_COLOR_STOP(rad, 0.45, 0.9, 0.0, 0.0, 0.8) ADD_COLOR_STOP(rad, 1, 0.1, 0.1, 0.1, 0.8) rect_item = RECTANGLE(win, 1, 1, 1, 1, CLASS, ITEM_RECTANGLE, "can-focus", 1, "line-width", 1.0, "radius-x", 6.0, "radius-y", 6.0, "fill_pattern", rad, "stroke-color", "white", "antialias", 3, 0) DRAW(win, rect_item, 0, 0, 200, 200) a = AREA(win, 50, 50, 100, 100) G_SET(a, "fill_pattern", rad, "antialias", 3, NULL) p1 = SVG_BUFF(icon1$) b = SQUAREPIX(a, p1, 0, 0, 100, 100, 0) G_UNREF(p1) G_SET(root, "tooltip-text", "Click to start/stop animation", NULL) goo_label1 = PANGO_LABEL(win, "GOO", 30, 5, 100, 80, "font", "Sans Bold 40", "use-markup", TRUE, "fill_pattern", rad) goo_label2 = PANGO_LABEL(win, "BAC", 30, 138, 100, 80, "font", "Sans Bold 40", "use-markup", TRUE, "fill_pattern", rad) goo_label3 = PANGO_LABEL(win, "GFX", 5, 5, 100, 80, "font", "Sans Bold 40", "use-markup", TRUE, "fill_pattern", rad) ROTATE(goo_label3, 90, 79, 125) CALLBACK(root, START_STOP) FLASH(b, 150) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY
' *********************** ' END MAIN ' ***********************
|
|
|
Post by alexfish on Aug 1, 2013 17:31:15 GMT 1
Hi All @ Joe
Here is one way to add USER widgets Here going to CREATE a SIMPLE BUTTON
Joe is always wanting MORE WIDGETS
Here We Goo
'INCLUDE "libgfx.bac"'@ if using libgfx.so INCLUDE "libgfx_import.bac" INIT
SUB NOTIFY_ENTER() ' Lets Show something which indicates it has been entered PRINT " ENTER"
SETPROPERTY(my_button, "line-width",(double)2.0) END SUB
SUB NOTIFY_LEAVE()
PRINT " LEAVE" SETPROPERTY(my_button, "line-width",(double)0.0)
END SUB
SUB DO_IT()
PRINT " MOVE IT" '@ to move the button , need to move the area(may be that one could add a mark or pango_label to same) ' the all need to move via the group as in AREA '@ move the button area MOVE(button_area,100,100) END SUB
'@ WINDOW("title",width,height,opacity) root=WINDOW("Bacon GFX",600,500,1.0)
'@ get the root of the WINDOW win=GETROOT(root)
'@ CREATE MY BUTTON 100 pixels wide * 50 pixel high 'create a linear Pattern at x=0 y = 0 by 100*50 ' Make a linear pattern '@ ensure the pattern is vert down "looks horizontal" by specifing the last arg to '50' this is 50 pixels down in the my_linear=LINEAR(0,0,0,50)
' add some colors using ADD_COLOR_STOP , the color_stop use RGBA so can add OPACITY '@ it is easy to add RGBA , if have BACONGUI menu there is a Options/Background color.... select it ' Now U see the color_chooser ,pick a color and take the Red , Green & Blue Values , ' after getting the values click CANCEL IF the value > 0 then devide each like so If 0 the = 0 DECLARE RED TYPE double DECLARE GREEN TYPE double DECLARE BLUE TYPE double RED=164 RED=RED/255 GREEN=111 GREEN=111/255 BLUE=111 BLUE=BLUE/255
'ADD_COLOR_STOP(offset,red,green,blue,Alpa) where offset , red,green, blue & Alpha are values between 0 and 1 ADD_COLOR_STOP(my_linear,0.9,RED,GREEN, BLUE,0.2) ADD_COLOR_STOP(my_linear,0,0.9,0.9,0.9,1.0) '@ if just want white the each rgb value = 1.0 button_area=AREA(win,0,0,100,50) 'Create the Actual button and register it , can do this all in one using the Macro '@ type Class and item type have to be registered else can not perform or comunicate the Two bits here are "CLASS, ITEM_RECTANGLE" my_button = RECTANGLE(button_area,1,1, 1, 1, CLASS, ITEM_RECTANGLE, "can-focus", 1, "line-width", 1.0, "radius-x", 6.0, "radius-y", 6.0, "fill_pattern", my_linear, "stroke-color", "red", "line-width", 0,0 , "antialias", 3, 0)
' Now the button is Registered can do things with it
'@ now Draw the button to size DRAW(button_area , my_button,0,0,100,50) '@ see if it can Comunicate G_CONNECT(my_button,"enter-notify-event",NOTIFY_ENTER) G_CONNECT(my_button,"leave-notify-event",NOTIFY_LEAVE)
'@ does the callback work CALLBACK(my_button,DO_IT)
DISPLAY
|
|
|
Post by vovchik on Aug 3, 2013 0:39:19 GMT 1
Dear All,
Just a little elaboration on Alex's user-defined button....
With kind regards, vovchik
' *********************** ' INCLUDES ' ***********************
INCLUDE "libgfx_import.bac" INIT
' *********************** ' END INCLUDES ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ FUNCTION WHERE_IS(long item, int dim) ' ------------------ LOCAL x, y TYPE double GETPROPERTY(item, "x", ADDRESS(x), "y", ADDRESS(y)) IF dim = 0 THEN RETURN x ELIF dim = 1 THEN RETURN y END IF END FUNCTION
' ------------------ FUNCTION HOW_BIG(long item, int dim) ' ------------------ LOCAL w, h TYPE double GETPROPERTY(item, "width", ADDRESS(w), "height", ADDRESS(h)) IF dim = 0 THEN RETURN w ELIF dim = 1 THEN RETURN h END IF END FUNCTION ' ------------------ SUB NOTIFY_ENTER() ' ------------------ ' Let's show something that shows hovering PRINT "Hovering over widget..." SETPROPERTY(my_button, "line-width", 5.0) SETPROPERTY(goo_label1, "text", "<span color='white' font='Sans Bold 22'>GFX</span>") END SUB
' ------------------ SUB NOTIFY_LEAVE() ' ------------------ PRINT "Leaving widget..." SETPROPERTY(my_button, "line-width", 0.0) SETPROPERTY(goo_label1, "text", "<span font='Sans Bold 20'>GOO</span>", "fill-color", "black") END SUB
' ------------------ SUB DO_IT() ' ------------------ PRINT "Moving widget..." MOVE(button_area, RANDOM(200), RANDOM(250)) PRINT "Button location: ", WHERE_IS(button_area, 0), ":", WHERE_IS(button_area, 1) END SUB
' ------------------ SUB ADD_HEX_STOP(long item, double offset, STRING colour$, double alpha ) ' ------------------ LOCAL r, g, b TYPE double colour$ = UCASE$(colour$) r = (double)(DEC(MID$(colour$, 2, 2)) / 255.0) g = (double)(DEC(MID$(colour$, 4, 2)) / 255.0) b = (double)(DEC(MID$(colour$, 6, 2)) / 255.0) PRINT "rgb: ", (double)r, " ", (double)g, " ", (double)b ADD_COLOR_STOP(item, offset, r, g, b, alpha) END SUB
' ------------------ SUB MK_GUI ' ------------------ root = WINDOW("Bacon GFX", 300, 300, 1.0) SETPROPERTY(root, "tooltip-text", "Click or hover over button") win = GETROOT(root) rad = RADIAL(0, 0, 150, 400, 400, 150) ADD_HEX_STOP(rad, 0.0, "#000000", 0.7) ADD_HEX_STOP(rad, 0.8, "#FF0000", 1.0) SETPROPERTY(win, "fill_pattern", rad) bg = RECTANGLE(win, 1, 1, 1, 1, CLASS, ITEM_RECTANGLE, "can-focus", 1, \ "line-width", 0.0, "fill_pattern", rad, "stroke-color", "none", \ "antialias", 3, 0) DRAW(win, bg, 0, 0, 300, 300) lin = LINEAR(0, 0, 0, 50) ADD_HEX_STOP(lin, 0.0, "#D3FFFF", 0.7) ADD_HEX_STOP(lin, 0.5, "#8CB4DA", 0.9) button_area = AREA(win, 0, 0, 100, 50) my_button = RECTANGLE(button_area, 1, 1, 1, 1, CLASS, ITEM_RECTANGLE, \ "can-focus", 1, "line-width", 0.0, "radius-x", 10.0, "radius-y", 10.0, \ "fill_pattern", lin, "stroke-color", "white", \ "line-width", 0,0 , "antialias", 3, NULL) goo_label1 = PANGO_LABEL(button_area, "GOO", 15, 10, 100, 50, \ "font", "Sans Bold 20", "use-markup", TRUE, "fill-color", "black") PRINT "Area size : ", HOW_BIG(button_area, 0), ":", HOW_BIG(button_area, 1) DRAW(button_area, my_button, 0, 0, 100, 50) G_CONNECT(my_button, "enter-notify-event", NOTIFY_ENTER) G_CONNECT(my_button, "leave-notify-event", NOTIFY_LEAVE) CALLBACK(my_button, DO_IT) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI() DISPLAY
' *********************** ' END MAIN ' ***********************
|
|
|
Post by alexfish on Aug 3, 2013 0:54:48 GMT 1
hey @ all & Vovchic > nice demo Here is a Screen Shot BR Alex Attachments:
|
|
|
Post by alexfish on Aug 3, 2013 1:42:00 GMT 1
This is for Joe Need some HILP... ;D BR Alex Attachments:
|
|
|
Post by vovchik on Aug 5, 2013 20:32:28 GMT 1
Dear All, This remake of Peter's fractal program, which is posted on the main Bacon site, but using Alex's libgfx. I decided to give the fractal an "astroturf" appearance, just for fun With kind regards, vovchik ' ***************************************************** ' PROGRAM: mandel-pve-gfx.bac ' PURPOSE: demo of PvE's fractal prog using goo gfx ' AUTHOR: vovchik (Puppy Linux forum) ' MODDED: ' DEPENDS: gcc, bacon, Alex's libgfx ' PLATFORM: Puppy Linux (actually, any *nix) ' DATE: 05-08-2013 ' *****************************************************
' *********************** ' INCLUDES ' ***********************
INCLUDE "libgfx_import.bac" INIT
' *********************** ' END INCLUDES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
CONST MaxIters = 100 CONST xSize = 480 CONST ySize = 330 CONST Black = -1 CONST Left = -2.0 CONST Right = 1.0 CONST Top = 1.0 CONST Bottom = -1.0 DECLARE canvas, win, labl, quit_but, clear_but, start_but, pixel, root, fill_rad, bg
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB CLEAR_FRACTAL() ' ------------------ PRINT "Clear canvas" HIDE(canvas) PRINT "Change label" TEXT(labl, "<span color='firebrick'><b>GFX for BaCon!</b></span>") END SUB
' ------------------ SUB QUIT_PROG() ' ------------------ QUIT END SUB
' ------------------ SUB ADD_HEX_STOP(long item, double offset, STRING colour$, double alpha ) ' ------------------ LOCAL r, g, b TYPE double colour$ = UCASE$(colour$) r = (double)(DEC(MID$(colour$, 2, 2)) / 255.0) g = (double)(DEC(MID$(colour$, 4, 2)) / 255.0) b = (double)(DEC(MID$(colour$, 6, 2)) / 255.0) PRINT "rgb: ", (double)r, " ", (double)g, " ", (double)b ADD_COLOR_STOP(item, offset, r, g, b, alpha) END SUB
' ------------------ SUB DRAW_FRACTAL() ' ------------------ LOCAL x, y, count TYPE short LOCAL zr, zi, cr, ci TYPE long double LOCAL rsquared, isquared TYPE long double LOCAL mycol$ TYPE STRING HIDE(canvas) DISABLE(start_but) DISABLE(clear_but) ' Information for user PRINT "Drawing fractal" TEXT(labl, "<span color='firebrick'><b>Please wait...</b></span>") SYNC FOR y = 0 TO ySize FOR x = 0 TO xSize zr = 0.0 zi = 0.0 cr = Left + x * (Right - Left) / xSize ci = Top + y * (Bottom - Top) / ySize rsquared = zr * zr isquared = zi * zi FOR count = 0 TO MaxIters zi = zr * zi * 2 zi = zi + ci zr = rsquared - isquared zr = zr + cr rsquared = zr * zr isquared = zi * zi NEXT count IF rsquared + isquared <= 4.0 THEN mycol$ = CONCAT$("#", \ RIGHT$("00" & HEX$(RANDOM(128)), 2), \ RIGHT$("00" & HEX$(RANDOM(256)), 2), \ RIGHT$("00" & HEX$(RANDOM(64)), 2)) pixel = PIXEL(canvas, mycol$, x, y) SETPROPERTY(pixel, "antialias", 3) END IF NEXT xSize NEXT ySize PRINT "Display drawing" SHOW(canvas) ' Indicate that drawing is ready PRINT "Indicate that fractal is ready" TEXT(labl, "<span color='firebrick'><b>Fractal ready.</b></span>") ENABLE(clear_but) ENABLE(start_but) END SUB
' ------------------ SUB MK_GUI() ' ------------------ ' Create GUI root = WINDOW("Fractal - Bacon GFX", 500, 400, 1.0) ' Get root of window win = GETROOT(root) fill_rad = RADIAL(0, 0, 50, 500, 400, 150) ADD_HEX_STOP(fill_rad, 0.0, "#000000", 0.8) ADD_HEX_STOP(fill_rad, 0.4, "#131007", 0.7) ADD_HEX_STOP(fill_rad, 0.8, "#f4f400", 1.0) ' Fill background with radial gradient bg = RECTANGLE(win, 1, 1, 1, 1, CLASS, ITEM_RECTANGLE, "can-focus", 1, \ "line-width", 0.0, "fill_pattern", fill_rad, "stroke-color", "none", \ "antialias", 3, 0) DRAW(win, bg, 0, 0, 500, 400) ' Make frame frame = FRAME(NULL) ATTACH (win, frame, 5, 5, 490, 340) PRINT "Frame created" ' Create canvas for drawing canvas = AREA(win, 10, 10, 480, 330) PRINT "Canvas created" ' Create buttons and callbacks start_but = BUTTON("Go") SETPROPERTY(start_but, "tooltip-text", " Draw fractal. ") ATTACH(win, start_but, 5, 352, 100, 40) CALLBACK (start_but, DRAW_FRACTAL) clear_but = BUTTON("Clear") SETPROPERTY(clear_but, "tooltip-text", " Clear canvas of drawing. ") ATTACH(win, clear_but, 120, 352, 100, 40) CALLBACK (clear_but, CLEAR_FRACTAL) labl = MARK("") SETPROPERTY(labl, "use-markup", TRUE) TEXT(labl, "<span color='firebrick'><b>GFX for BaCon!</b></span>") ATTACH(win, labl, 240, 352, 120, 40) PRINT "Label created" quit_but = BUTTON("Quit") SETPROPERTY(quit_but, "tooltip-text", " Quit fractal program. ") ATTACH(win, quit_but, 395, 352, 100, 40) CALLBACK (quit_but, QUIT_PROG) PRINT "Buttons created" END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY
' *********************** ' END MAIN ' ***********************
Attachments:
|
|
|
Post by vovchik on Aug 5, 2013 20:59:10 GMT 1
And this is a simpler version, basically a clone of Peter's demo.
' ***************************************************** ' PROGRAM: mandel-pve-gfx-simple.bac ' PURPOSE: demo of PvE's fractal prog using goo gfx ' AUTHOR: vovchik (Puppy Linux forum) ' MODDED: ' DEPENDS: gcc, bacon, libgfx ' PLATFORM: Puppy Linux (actually, any *nix) ' DATE: 05-08-2013 ' *****************************************************
' *********************** ' INCLUDES ' ***********************
INCLUDE "libgfx_import.bac" INIT
' *********************** ' END INCLUDES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
CONST MaxIters = 100 CONST xSize = 480 CONST ySize = 330 CONST Black = -1 CONST Left = -2.0 CONST Right = 1.0 CONST Top = 1.0 CONST Bottom = -1.0 ' define array with 17 colours DECLARE PixelCol$[] = { "#800000", "#800080", "#8000FF", "#808000", "#808080", \ "#8080FF", "#80FF00", "#80FF80", "#80FFFF", "#FF0000", "#FF0080", \ "#FF00FF", "#FF8000", "#FF8080", "#FF80FF", "#FFFF00", "#000000" } TYPE STRING DECLARE canvas, win, labl, quit_but, clear_but, start_but, pixel, root, fill_rad, bg
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB CLEAR_FRACTAL() ' ------------------ PRINT "Clear canvas" HIDE(canvas) PRINT "Change label" TEXT(labl, "<span color='firebrick'><b>GFX for BaCon!</b></span>") END SUB
' ------------------ SUB QUIT_PROG() ' ------------------ QUIT END SUB
' ------------------ SUB ADD_HEX_STOP(long item, double offset, STRING colour$, double alpha ) ' ------------------ LOCAL r, g, b TYPE double colour$ = UCASE$(colour$) r = (double)(DEC(MID$(colour$, 2, 2)) / 255.0) g = (double)(DEC(MID$(colour$, 4, 2)) / 255.0) b = (double)(DEC(MID$(colour$, 6, 2)) / 255.0) PRINT "rgb: ", (double)r, " ", (double)g, " ", (double)b ADD_COLOR_STOP(item, offset, r, g, b, alpha) END SUB
' ------------------ SUB DRAW_FRACTAL() ' ------------------ LOCAL x, y, count TYPE short LOCAL zr, zi, cr, ci TYPE long double LOCAL rsquared, isquared TYPE long double HIDE(canvas) DISABLE(start_but) DISABLE(clear_but) ' Information for user PRINT "Drawing fractal" TEXT(labl, "<span color='firebrick'><b>Please wait...</b></span>") SYNC FOR y = 0 TO ySize FOR x = 0 TO xSize zr = 0.0 zi = 0.0 cr = Left + x * (Right - Left) / xSize ci = Top + y * (Bottom - Top) / ySize rsquared = zr * zr isquared = zi * zi FOR count = 0 TO MaxIters zi = zr * zi * 2 zi = zi + ci zr = rsquared - isquared zr = zr + cr rsquared = zr * zr isquared = zi * zi NEXT count IF rsquared + isquared <= 4.0 THEN pixel = PIXEL(canvas, PixelCol$[ROUND((rsquared + isquared)*4)], x, y) END IF NEXT xSize NEXT ySize PRINT "Display drawing" SHOW(canvas) ' Indicate that drawing is ready PRINT "Indicate that fractal is ready" TEXT(labl, "<span color='firebrick'><b>Fractal ready.</b></span>") ENABLE(clear_but) ENABLE(start_but) END SUB
' ------------------ SUB MK_GUI() ' ------------------ ' Create GUI root = WINDOW("Fractal - Bacon GFX", 500, 400, 1.0) win = GETROOT(root) fill_rad = RADIAL(0, 0, 50, 500, 400, 150) ADD_HEX_STOP(fill_rad, 0.0, "#000000", 0.3) ADD_HEX_STOP(fill_rad, 0.4, "#888888", 0.7) ADD_HEX_STOP(fill_rad, 0.8, "#e4e4e4", 1.0) ' Fill background with radial gradient bg = RECTANGLE(win, 1, 1, 1, 1, CLASS, ITEM_RECTANGLE, "can-focus", 1, \ "line-width", 0.0, "fill_pattern", fill_rad, "stroke-color", "none", \ "antialias", 3, 0) DRAW(win, bg, 0, 0, 500, 400) ' Make frame frame = FRAME(NULL) ATTACH (win, frame, 5, 5, 490, 340) PRINT "Frame created" ' Create canvas for drawing canvas = AREA(win, 10, 10, 480, 330) PRINT "Canvas created" ' Create buttons and callbacks start_but = BUTTON("Go") ATTACH(win, start_but, 5, 352, 100, 40) CALLBACK (start_but, DRAW_FRACTAL) clear_but = BUTTON("Clear") ATTACH(win, clear_but, 120, 352, 100, 40) CALLBACK (clear_but, CLEAR_FRACTAL) labl = MARK("") SETPROPERTY(labl, "use-markup", TRUE) TEXT(labl, "<span color='firebrick'><b>GFX for BaCon!</b></span>") ATTACH(win, labl, 240, 352, 120, 40) PRINT "Label created" quit_but = BUTTON("Quit") ATTACH(win, quit_but, 395, 352, 100, 40) CALLBACK (quit_but, QUIT_PROG) PRINT "Buttons created" END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY
' *********************** ' END MAIN ' ***********************
|
|
|
Post by Pjot on Aug 5, 2013 21:43:42 GMT 1
|
|
|
Post by vovchik on Aug 6, 2013 12:44:50 GMT 1
@ Peter, Thanks Dear All, Here is a little tree fractal done using Alex's gfxlib and some bits I ported from rosetta code. Looks nice, but takes some time to draw, as with all fractals. With kind regards, vovchik ' ***************************************************** ' PROGRAM: fractal-tree.bac ' PURPOSE: demo of fractal tree using goo gfx ' AUTHOR: vovchik (Puppy Linux forum) ' NOTES: ported example from rosetta code ' DEPENDS: gcc, bacon, Alex's libgfx ' PLATFORM: Puppy Linux (actually, any *nix) ' DATE: 05-08-2013 ' *****************************************************
' *********************** ' INCLUDES ' ***********************
INCLUDE "libgfx_import.bac" INIT
' *********************** ' END INCLUDES ' ***********************
' *********************** ' INITIALIZATION ' ***********************
' constants which determine shape CONST A1 = PI/27 CONST A2 = PI/8 CONST C1 = 0.7 CONST C2 = 0.85 DECLARE level TYPE int DECLARE xs[13], TYPE double DECLARE ys[13] TYPE double DECLARE rotation TYPE double DECLARE len TYPE double DECLARE x, y TYPE double level = 12 rotation = (double)(PI/2) len = 63 x = 230.0 y = 285.0
' *********************** ' END INITIALIZATION ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB QUIT_PROG() ' ------------------ QUIT END SUB
' ------------------ SUB ADD_HEX_STOP(long item, double offset, STRING colour$, double alpha ) ' ------------------ LOCAL r, g, b TYPE double colour$ = UCASE$(colour$) r = (double)(DEC(MID$(colour$, 2, 2)) / 255.0) g = (double)(DEC(MID$(colour$, 4, 2)) / 255.0) b = (double)(DEC(MID$(colour$, 6, 2)) / 255.0) PRINT "rgb: ", (double)r, " ", (double)g, " ", (double)b ADD_COLOR_STOP(item, offset, r, g, b, alpha) END SUB
' ------------------ SUB PUT_LINE() ' ------------------ LOCAL xn, yn TYPE double yn = -SIN(rotation) * len + y xn = COS(rotation) * len + x col$ = CONCAT$("#", \ RIGHT$("00" & HEX$(RANDOM(128)), 2), \ RIGHT$("00" & HEX$(RANDOM(256)), 2), \ RIGHT$("00" & HEX$(RANDOM(64)), 2)) l = LINE(canvas, col$, x, y, xn, yn) SETPROPERTY(l, "antialias", 3) x = xn y = yn END SUB
' ------------------ SUB TREE() ' ------------------ xs[level] = x ys[level] = y PUT_LINE SYNC IF level > 0 THEN level = level - 1 len = len * C1 rotation = rotation - A1 CALL TREE SYNC len = len / C1 * C2 rotation = rotation + A1 + A2 CALL TREE HIDE(labl) SYNC rotation = rotation - A2 len = len / C2 level = level + 1 END IF x = xs[level] y = ys[level] SHOW(labl) END SUB
' ------------------ SUB DRAW_FRACTAL() ' ------------------ DISABLE(start_but) ' Information for user PRINT "Drawing fractal" TEXT(labl, "<span color='firebrick'><b>Wait...</b></span>") SYNC TREE PRINT "Drawing fractal.." 'Indicate that drawing is ready PRINT "Done." TEXT(labl, "<span color='firebrick'><b>Done</b></span>") SYNC END SUB
' ------------------ SUB MK_GUI() ' ------------------ ' Create GUI root = WINDOW("Tree Fractal - Bacon GFX", 315, 350, 1.0) ' Get root of window win = GETROOT(root) fill_rad = RADIAL(0, 0, 150, 315, 350, 150) ADD_HEX_STOP(fill_rad, 0.0, "#c0c0c0", 0.8) ADD_HEX_STOP(fill_rad, 0.3, "#66441D", 0.8) ADD_HEX_STOP(fill_rad, 0.4, "#FFD700", 0.7) ADD_HEX_STOP(fill_rad, 0.7, "#1E1A16", 0.9) ' Fill background with radial gradient bg = RECTANGLE(win, 1, 1, 1, 1, CLASS, ITEM_RECTANGLE, "can-focus", 1, \ "line-width", 0.0, "fill_pattern", fill_rad, "stroke-color", "none", \ "antialias", 3, 0) DRAW(win, bg, 0, 0, 315, 360) ' Make frame frame = FRAME(NULL) ATTACH (win, frame, 5, 5, 305, 305) PRINT "Frame created" ' Create canvas for drawing canvas = AREA(win, 10, 10, 310, 310) PRINT "Canvas created" ' Create buttons and callbacks start_but = BUTTON("Go") SETPROPERTY(start_but, "tooltip-text", " Draw fractal. ") ATTACH(win, start_but, 5, 315, 80, 30) CALLBACK (start_but, DRAW_FRACTAL) labl = MARK("") SETPROPERTY(labl, "use-markup", TRUE) TEXT(labl, "<span color='firebrick'><b>GFX</b></span>") ATTACH(win, labl, 80, 315, 150, 30) PRINT "Label created" quit_but = BUTTON("Quit") SETPROPERTY(quit_but, "tooltip-text", " Quit fractal program. ") ATTACH(win, quit_but, 230, 315, 80, 30) CALLBACK (quit_but, QUIT_PROG) PRINT "Buttons created" END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY
' *********************** ' END MAIN ' ***********************
|
|