|
Post by alexfish on Nov 17, 2020 20:28:43 GMT 1
Hi All have change stance on the type of lib format now using hug type set up , ran into trouble with finding the bits as a work in progress I had a look at svg paths to cairo just got the demo working , so posting the bits as a work in progress First bits are a bacon toolkit.bac and a svg path to cairo example the svg is from openstreet map svg image 'fishport' <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!-- Created with Inkscape (http://www.inkscape.org/) --> <svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.0" width="120" height="120" id="svg2"> <defs id="defs4" /> <path d="M 57.0625,3.53125 L 49.8125,4.28125 L 42.6875,5.9375 L 35.875,8.40625 L 29.53125,11.75 L 23.84375,15.90625 L 18.9375,20.875 L 14.6875,26.4375 L 10.90625,32.46875 L 7.34375,38.6875 L 11.59375,41.15625 L 13.1875,38.5 L 17,32.4375 L 21.125,26.6875 L 25.84375,21.5 L 31.28125,17.0625 L 37.46875,13.53125 L 44.1875,10.90625 L 51.3125,9.25 L 58.65625,8.59375 L 66.03125,8.9375 L 73.28125,10.28125 L 80.1875,12.625 L 86.53125,15.875 L 92.15625,20.03125 L 96.9375,25 L 100.96875,30.6875 L 104.4375,36.8125 L 107.53125,43.34375 L 110.46875,50 L 116.125,54.28125 L 114.875,47.6875 L 113.0625,40.84375 L 110.34375,34.21875 L 106.71875,28 L 102.28125,22.3125 L 97.09375,17.1875 L 91.34375,12.8125 L 85.0625,9.21875 L 78.40625,6.5 L 71.46875,4.625 L 64.3125,3.65625 L 57.0625,3.53125 z M 6.28125,42.21875 L 4.71875,49.375 L 3.65625,56.375 L 3.5,63.34375 L 4.40625,70.3125 L 5.90625,77.3125 L 32.15625,62.78125 L 38.21875,66.34375 L 44.40625,69.875 L 50.75,73 L 57.40625,75.4375 L 64.34375,76.9375 L 71.4375,77.59375 L 78.625,77.53125 L 85.78125,76.6875 L 92.6875,74.96875 L 99.21875,72.3125 L 105.28125,68.71875 L 110.96875,64.5 L 116.5,59.9375 L 111.1875,55.5625 L 105.5,51.375 L 99.40625,47.875 L 92.84375,45.28125 L 85.90625,43.59375 L 78.75,42.6875 L 71.5625,42.53125 L 64.4375,43.09375 L 57.5,44.5625 L 50.90625,47 L 44.5625,50.25 L 38.34375,53.6875 L 32.15625,57.125 L 6.28125,42.21875 z M 94.5,55 C 97.26,55 99.5,57.24 99.5,60 C 99.5,62.76 97.26,65 94.5,65 C 91.74,65 89.5,62.76 89.5,60 C 89.5,57.24 91.74,55 94.5,55 z M 116.5,65.28125 L 110.46875,69.875 L 109.15625,73.59375 L 106.59375,80.28125 L 103.59375,86.6875 L 99.8125,92.5625 L 95.0625,97.78125 L 89.4375,102.28125 L 83.15625,105.9375 L 76.40625,108.65625 L 69.4375,110.40625 L 62.34375,111.1875 L 55.1875,111 L 48.125,109.8125 L 41.21875,107.71875 L 34.625,104.6875 L 28.5625,100.8125 L 23.28125,96.125 L 18.8125,90.65625 L 15.03125,84.65625 L 11.59375,78.375 L 7.34375,80.84375 L 7.75,81.71875 L 11.03125,88.03125 L 14.78125,94.03125 L 19.28125,99.46875 L 24.59375,104.25 L 30.53125,108.3125 L 36.9375,111.625 L 43.71875,114.0625 L 50.71875,115.75 L 57.84375,116.46875 L 65,116.3125 L 72.03125,115.25 L 78.875,113.25 L 85.40625,110.40625 L 91.625,106.78125 L 97.34375,102.4375 L 102.46875,97.40625 L 106.84375,91.8125 L 110.21875,85.65625 L 112.78125,79.09375 L 114.78125,72.25 L 116.5,65.28125 z" id="path6625" style="fill:#a30075;fill-opacity:1;fill-rule:evenodd;stroke:none" /> </svg>
the code 'svg demo OPTION PARSE FALSE
INCLUDE "toolkit.bac"
DECLARE width=120 TYPE int DECLARE height= 120 TYPE int
DECLARE SVG$ = "M 57.0625,3.53125 L 49.8125,4.28125 L 42.6875,5.9375 L 35.875,8.40625 L 29.53125,11.75 L 23.84375,15.90625 L 18.9375,20.875 L 14.6875,26.4375 L 10.90625,32.46875 L 7.34375,38.6875 L 11.59375,41.15625 L 13.1875,38.5 L 17,32.4375 L 21.125,26.6875 L 25.84375,21.5 L 31.28125,17.0625 L 37.46875,13.53125 L 44.1875,10.90625 L 51.3125,9.25 L 58.65625,8.59375 L 66.03125,8.9375 L 73.28125,10.28125 L 80.1875,12.625 L 86.53125,15.875 L 92.15625,20.03125 L 96.9375,25 L 100.96875,30.6875 L 104.4375,36.8125 L 107.53125,43.34375 L 110.46875,50 L 116.125,54.28125 L 114.875,47.6875 L 113.0625,40.84375 L 110.34375,34.21875 L 106.71875,28 L 102.28125,22.3125 L 97.09375,17.1875 L 91.34375,12.8125 L 85.0625,9.21875 L 78.40625,6.5 L 71.46875,4.625 L 64.3125,3.65625 L 57.0625,3.53125 z M 6.28125,42.21875 L 4.71875,49.375 L 3.65625,56.375 L 3.5,63.34375 L 4.40625,70.3125 L 5.90625,77.3125 L 32.15625,62.78125 L 38.21875,66.34375 L 44.40625,69.875 L 50.75,73 L 57.40625,75.4375 L 64.34375,76.9375 L 71.4375,77.59375 L 78.625,77.53125 L 85.78125,76.6875 L 92.6875,74.96875 L 99.21875,72.3125 L 105.28125,68.71875 L 110.96875,64.5 L 116.5,59.9375 L 111.1875,55.5625 L 105.5,51.375 L 99.40625,47.875 L 92.84375,45.28125 L 85.90625,43.59375 L 78.75,42.6875 L 71.5625,42.53125 L 64.4375,43.09375 L 57.5,44.5625 L 50.90625,47 L 44.5625,50.25 L 38.34375,53.6875 L 32.15625,57.125 L 6.28125,42.21875 z M 94.5,55 C 97.26,55 99.5,57.24 99.5,60 C 99.5,62.76 97.26,65 94.5,65 C 91.74,65 89.5,62.76 89.5,60 C 89.5,57.24 91.74,55 94.5,55 z M 116.5,65.28125 L 110.46875,69.875 L 109.15625,73.59375 L 106.59375,80.28125 L 103.59375,86.6875 L 99.8125,92.5625 L 95.0625,97.78125 L 89.4375,102.28125 L 83.15625,105.9375 L 76.40625,108.65625 L 69.4375,110.40625 L 62.34375,111.1875 L 55.1875,111 L 48.125,109.8125 L 41.21875,107.71875 L 34.625,104.6875 L 28.5625,100.8125 L 23.28125,96.125 L 18.8125,90.65625 L 15.03125,84.65625 L 11.59375,78.375 L 7.34375,80.84375 L 7.75,81.71875 L 11.03125,88.03125 L 14.78125,94.03125 L 19.28125,99.46875 L 24.59375,104.25 L 30.53125,108.3125 L 36.9375,111.625 L 43.71875,114.0625 L 50.71875,115.75 L 57.84375,116.46875 L 65,116.3125 L 72.03125,115.25 L 78.875,113.25 L 85.40625,110.40625 L 91.625,106.78125 L 97.34375,102.4375 L 102.46875,97.40625 L 106.84375,91.8125 L 110.21875,85.65625 L 112.78125,79.09375 L 114.78125,72.25 L 116.5,65.28125 z" TYPE STRING 'C 97.26, 55 99.5, 57.24 99.5, 60
SUB RENDER_PATH(Window win,STRING svg$,int xpos,int ypos,char r,char g,char b, char a) LOCAL dimention , dim2
SPLIT svg$ BY NL$ TO SVGARRAY$ SIZE dimention LOCAL c1 TYPE cairo_t * LOCAL c TYPE cairo_t * c1=cairo_create(bac_widget_context(STR$(win)))
c=cairo_create(bac_widget_drawable(STR$(win))) 'start drawing xpos ypos using translate : Not cairo_move_to for start of drawing pos cairo_translate (c, xpos, ypos) FOR t = 0 TO dimention -1 A$ = CHOP$(SVGARRAY$[t]) SELECT A$
CASE "M" INCR t A$ = CHOP$(SVGARRAY$[t]) SPLIT A$ BY "," TO BITS$ SIZE dim2 IF dim2 =2 THEN cairo_move_to (c,VAL(BITS$[0]),VAL(BITS$[1])) END IF
CASE "L" INCR t A$ = CHOP$(SVGARRAY$[t]) SPLIT A$ BY "," TO BITS$ SIZE dim2 IF dim2 =2 THEN cairo_set_rgba(c,255,255,255,255) cairo_line_to(c,VAL(BITS$[0]),VAL(BITS$[1])) cairo_set_rgba(c,r,g,b,a) cairo_line_to(c,VAL(BITS$[0]),VAL(BITS$[1])) END IF
CASE "C" INCR t A$ = CHOP$(SVGARRAY$[t]) A$ = REPLACE$(A$," ",",") SPLIT A$ BY "," TO BITS$ SIZE dim2 IF dim2 =6 THEN cairo_set_rgba(c,255,255,255,255) cairo_curve_to (c,VAL(BITS$[0]),VAL(BITS$[1]),VAL(BITS$[2]),VAL(BITS$[3]),VAL(BITS$[4]),VAL(BITS$[5])) cairo_set_rgba(c,r,g,b,a) cairo_curve_to (c,VAL(BITS$[0]),VAL(BITS$[1]),VAL(BITS$[2]),VAL(BITS$[3]),VAL(BITS$[4]),VAL(BITS$[5])) END IF
CASE "z" cairo_close_path (c)
END SELECT
NEXT
cairo_fill (c) cairo_set_source_surface (c1,bac_widget_drawable(STR$(win)),0,0) cairo_paint(c1) cairo_show_page(c1) bac_widget_render(STR$(win))=0 cairo_destroy(c) cairo_destroy(c1)
END SUB
IF INSTR(SVG$," ") THEN SVG$=REPLACE$(SVG$," "," ") END IF IF INSTR(SVG$," ") THEN SVG$=REPLACE$(SVG$," "," ") END IF IF INSTR(SVG$," ") THEN SVG$=REPLACE$(SVG$," "," ") END IF SVG$= SVG$ & "0" SVG$=REPLACE$(SVG$,"M",NL$ & "M" & NL$) SVG$=REPLACE$(SVG$,"L",NL$ & "L" & NL$) SVG$=REPLACE$(SVG$,"C",NL$ & "C" & NL$) SVG$=REPLACE$(SVG$,"z",NL$ & "z" & NL$)
DECLARE window,container,layout TYPE Window window = WINDOW("test",640,400)
' default window is RESIZEWIN(*,*,FALSE) RESIZEWIN(window,640,400,TRUE) layout = LAYOUT(window,1,1,636,396,1) ' container for widgets this one is fixed , but here going to draw on it container = FIXED(layout,10,10,616,376,1)
WHILE (1) XNextEvent(d, &e)
IF (e.type == Expose) THEN expose = (XExposeEvent *)&(e) IF expose->count = 0 THEN Geometry(bac_widget_window(STR$(expose->window))) Check_Expose() RENDER_PATH(container,SVG$,5,5,163,0,117,150) RENDER_PATH(container,SVG$,200,5,0,163,117,150)
END IF
END IF
IF (e.type == ClientMessage) THEN client_message = (XClientMessageEvent *)&(e) 'PRINT "Closing Down" IF bac_widget_window_delete(STR$(client_message->window))=1 THEN IF ((Atom)e.xclient.data.l[0] == wm_delete_window) THEN PRINT "EXIT" FREE_SURFACES() XFlush(d) XCloseDisplay(d) BREAK END IF END IF END IF
WEND toolkit.bac in archive and as said a work in progress and some of the bits need re wording + svg bits need to be added in the path , as seen only using UPPER case Have Fun + BR Alex Attachments:toolkit.bac.bz2 (4.55 KB)
|
|