|
Post by alexfish on Mar 28, 2023 17:59:40 GMT 1
Hi Peter
The Combo bits
from the gtk server
FUNCTION_NAME = gtk_combo_box_new_text, changed, WIDGET, 0 FUNCTION_NAME = gtk_combo_box_text_new, changed, WIDGET, 0 FUNCTION_NAME = gtk_combo_box_append_text, NONE, NONE, 2, WIDGET, STRING FUNCTION_NAME = gtk_combo_box_text_append_text, NONE, NONE, 2, WIDGET, STRING FUNCTION_NAME = gtk_combo_box_insert_text, NONE, NONE, 3, WIDGET, INT, STRING FUNCTION_NAME = gtk_combo_box_prepend_text, NONE, NONE, 2, WIDGET, STRING FUNCTION_NAME = gtk_combo_box_remove_text, NONE, NONE, 2, WIDGET, INT FUNCTION_NAME = gtk_combo_box_get_active, NONE, INT, 1, WIDGET FUNCTION_NAME = gtk_combo_box_set_active, NONE, NONE, 2, WIDGET, INT FUNCTION_NAME = gtk_combo_box_get_active_text, NONE, STRING, 1, WIDGET FUNCTION_NAME = gtk_combo_box_text_get_active_text, NONE, STRING, 1, WIDGET
from hug
IF HUGGTK3 THEN ' TODO ISOLATE IF GTK3 REPLACE WITH ?=========================== PRINT "COMBO start"
' TODO apply fixes ======================================== IMPORT "gtk_combo_box_text_append(long,char*)" FROM hug_Gtk$ TYPE void
IMPORT "gtk_combo_box_text_get_active_text(long)" FROM hug_Gtk$ TYPE char*
IMPORT "gtk_combo_box_text_new" FROM hug_Gtk$ TYPE long
' IMPORT "gtkcombo_box_remove_text(long,int)" FROM hug_Gtk$ TYPE void IMPORT "gtk_combo_box_text_remove(long,int)" FROM hug_Gtk$ TYPE void PRINT "COMBO"
ELSE the remove text not tested
internal prior to the get libs gtk four searches are done x11 .so gdk.so + gtk3.so and the gdk.so sorted IF wide then defaults to gtk3 if it need to be done that way since can not pass reference other than do this in the header
'DECLARE HUGGTK3 =1 'DECLARE HUGGTK3 =0 if know of a way to pass hugoption, then ... anyway the two 4 libs example
FUNCTION hug_Get_Gtk$ : REM INCLUDE
LOCAL hug_lib$ LOCAL hug_sequence = -1
IF INSTR(OS$, "Darwin") THEN hug_lib$ = "/opt/local/lib/libgtk-x11-2.0.0.dylib" IF NOT(FILEEXISTS(hug_lib$)) THEN hug_lib$ = "/Library/Frameworks/Gtk.framework/Libraries/libgtk-quartz-2.0.0.dylib" END IF ELIF INSTR(OS$, "CYGWIN") THEN hug_lib$ = "cyggtk-x11-2.0-0.dll" END IF
CATCH GOTO Redo_Import
LABEL Redo_Import INCR hug_sequence 'TODO =================== IF hug_sequence = HUG_MAX_LIB_SEQ THEN GOTO Print_Error IF HUGGTK3 THEN IF NOT(INSTR(hug_lib$, "dylib")) AND NOT (INSTR(hug_lib$, "dll")) THEN hug_lib$ = CONCAT$("libgtk-3.so.", STR$(hug_sequence)) ELSE
IF NOT(INSTR(hug_lib$, "dylib")) AND NOT (INSTR(hug_lib$, "dll")) THEN hug_lib$ = CONCAT$("libgtk-x11-2.0.so.", STR$(hug_sequence))
END IF '==================================================================================== IMPORT "gtk_init(int*,void*)" FROM hug_lib$ TYPE void
RETURN hug_lib$
LABEL Print_Error PRINT "Gtk library not found!" END
END FUNCTION
REM -------------------------------------------------------------------------------------------------- 'TODO FUNCTION hug_Get_Gdk$ : REM INCLUDE
LOCAL hug_lib$ LOCAL hug_sequence = -1
IF INSTR(OS$, "Darwin") THEN hug_lib$ = "/opt/local/lib/libgdk-x11-2.0.0.dylib" IF NOT(FILEEXISTS(hug_lib$)) THEN hug_lib$ = "/Library/Frameworks/Gtk.framework/Libraries/libgdk-quartz-2.0.0.dylib" END IF ELIF INSTR(OS$, "CYGWIN") THEN hug_lib$ = "cyggdk-x11-2.0-0.dll" END IF
CATCH GOTO Redo_Import
LABEL Redo_Import INCR hug_sequence IF hug_sequence = HUG_MAX_LIB_SEQ THEN GOTO Print_Error IF HUGGTK3 THEN IF NOT(INSTR(hug_lib$, "dylib")) AND NOT (INSTR(hug_lib$, "dll")) THEN hug_lib$ = CONCAT$("libgdk-3.so.", STR$(hug_sequence)) ELSE IF NOT(INSTR(hug_lib$, "dylib")) AND NOT (INSTR(hug_lib$, "dll")) THEN hug_lib$ = CONCAT$("libgdk-x11-2.0.so.", STR$(hug_sequence)) END IF IMPORT "gdk_atom_intern(char*,int)" FROM hug_lib$ TYPE long
RETURN hug_lib$
LABEL Print_Error PRINT "Gdk library not found!" END
END FUNCTION
obvious CYGWIN & Darwin need to be soted..
BR Alex
|
|
|
Post by alexfish on Mar 29, 2023 6:49:30 GMT 1
Further to the SVG wrighter
I am not new to such a thing
looking through some of the Howto in the toolkits Circa 2012
' ---------------------------------------------------------------------------------------- ' PROGRAM: Rad test-bed ' ---------------------------------------------------------------------------------------- ' built on BaCon ' © Peter van Eerten. ' http://www.basic-converter.org ' http://basic-converter.proboards.com ' ---------------------------------------------------------------------------------------- ' PURPOSE: test-bed `testing rw-svg` ' AUTHOR: (alexfish) ah.cisabfone@gmail.com ' MODDED: not yet ' DEPENDS: gcc, bacon (1.26), gtk, rsvg, HUG (0.79) ' Version 0.10 ' PLATFORM: Ubuntu Linux (or , any *nix) ' DATE: 10-07-2012 ' May 2012 - 17-07-2012 ' LICENSE: GPL3 '----------------------------------------------------------------------------------------- 'exeptions If it breaks you get to keep both bits ' including the eggs ' ----------------------------------------------------------------------------------------
REM ------------------------------------------------------------------------------------------------ ' should be in home enviroment , Best in folder on desktop , svg is save on the run,! ' or comment the CALL ENVIRONMENT ' read the read me
FUNCTION rw(int width,int height,int x_pos,int y_pos,int rect_x_size,int rect_y_size,int radi,int stroke,int R1,int G1,int B1,int ST_R2,int ST_G2,int ST_B2) ' "' ry='",STR$(radi),' width='" R_Square$=CONCAT$("<svg width='",STR$(width),"' height='",STR$(height),"'> <rect x='",STR$(x_pos),"' y='", STR$(y_pos),"' ry='",STR$(radi),"' width='",STR$(rect_x_size) ,"' height='", STR$(rect_y_size), "' style='fill:rgb(",STR$(R1),",",STR$(G1),",",STR$(B1), ");stroke-width:",STR$(stroke),";stroke:rgb(",STR$(ST_R2),",",STR$(ST_G2),",",STR$(ST_B2),")'/> </svg>" ) TRAP LOCAL OPEN "mgimg" FOR WRITING AS myfile WRITELN R_Square$ TO myfile CLOSE FILE myfile t=GET(auotwipe) IF t = 1 THEN SQUARE("#FFFFFF", 0, 0, 600, 400, TRUE) SYNC PICTURE("mgimg",0,0,600,400) SYNC RETURN TRUE END FUNCTION
part of the text function
label$=CONCAT$("<span font='",STR$(16),"' foreground='",txt2$,"'>MARK with 16 point pango text.</span>") BR Alex
|
|
|
Post by alexfish on Mar 29, 2023 7:52:09 GMT 1
And So To I striped the bits down can test play with the bits to find your feet make a mess ?? wipe it Have fun BR Alex INCLUDE "hug.bac"
gtk$ = HUGLIB$("gtk") gdk$ = HUGLIB$("gdk") HUGOPTIONS("NOSCALING")
FUNCTION rw(int width,int height,int x_pos,int y_pos,int rect_x_size,int rect_y_size,int radi,int stroke,int R1,int G1,int B1,int ST_R2,int ST_G2,int ST_B2) ' "' ry='",STR$(radi),' width='" R_Square$=CONCAT$("<svg width='",STR$(width),"' height='",STR$(height),"'> <rect x='",STR$(x_pos),"' y='", STR$(y_pos),"' ry='",STR$(radi),"' width='",STR$(rect_x_size) ,"' height='", STR$(rect_y_size), "' style='fill:rgb(",STR$(R1),",",STR$(G1),",",STR$(B1), ");stroke-width:",STR$(stroke),";stroke:rgb(",STR$(ST_R2),",",STR$(ST_G2),",",STR$(ST_B2),")'/> </svg>" ) TRAP LOCAL OPEN "mgimg" FOR WRITING AS myfile WRITELN R_Square$ TO myfile CLOSE FILE myfile t=GET(auotwipe) IF t = 1 THEN SQUARE("#FFFFFF", 0, 0, 600, 400, TRUE) SYNC PICTURE("mgimg",0,0,600,400) SYNC RETURN TRUE END FUNCTION
FUNCTION wiper SYNC SQUARE("#FFFFFF", 0, 0, 600, 400, TRUE) PICTURE("mgimg",0,0,600,400) SYNC RETURN TRUE END FUNCTION
FUNCTION set_col stroke=GET(spin_rect_stroke_width) x_pos=GET(spin_x) y_pos=GET(spin_y) radi=GET(spin_rect_radius) rect_x_size=GET(spin_rec_width) rect_y_size=GET(spin_rect_height) r1=GET(spin_r1) r2=GET(spin_r2) r3=GET(spin_r3) rd1=GET(spin_rd1) rd2=GET(spin_rd2) rd3=GET(spin_rd3) h1$=HEX$(r1) h2$=HEX$(r2) h3$=HEX$(r3) IF LEN(h1$) = 1 THEN h1$=CONCAT$("0",h1$) IF LEN(h2$) = 1 THEN h2$=CONCAT$("0",h2$) IF LEN(h3$) = 1 THEN h3$=CONCAT$("0",h3$) txt$=CONCAT$("#",h3$,h2$,h1$) txt2$=CONCAT$("#",h1$,h2$,h3$) TEXT(txt1,txt$) TEXT(text3,txt2$) label$=CONCAT$("<span font='",STR$(16),"' foreground='",txt2$,"'>MARK with 16 point pango text.</span>") TEXT(text2,label$) TEXT(Label_1,label$) 'read_write_image(600,400,20,20,400,200,r1,r2,r3,190,179,151) CALL rw(600,400,x_pos,y_pos,rect_x_size,rect_y_size,radi,stroke,r1,r2,r3,rd1,rd2,rd3) RETURN TRUE END FUNCTION ' ------------------ 'MAIN '------------------ win = WINDOW("Rad test-bed , `sq` peg' into a round hole", 600, 400) can = CANVAS(600,245) ATTACH(win,can,0,0) '--------------------------------------------------------------- '@ SPINs width DONE passed spin_x=SPIN(75,25,0,600,1) ATTACH(win,spin_x,450,250) CALLBACK(spin_x,set_col) '@ SPINs height DONE passed spin_y=SPIN(75,25,0,600,1) ATTACH(win,spin_y,525,250) CALLBACK(spin_y,set_col) '------------------------------------------------------- '@ SPINs rect width DONE passed spin_rec_width=SPIN(75,25,1,1000,1) ATTACH(win,spin_rec_width,450,275) CALLBACK(spin_rec_width,set_col) SET(spin_rec_width,25) '@ SPINs height DONE passed spin_rect_height=SPIN(75,25,1,1000,1) ATTACH(win,spin_rect_height,525,275) CALLBACK(spin_rect_height,set_col) SET(spin_rect_height,25) '-------------------------------------------------------------------------- '@ SPINs radius DONE passed spin_rect_radius=SPIN(75,25,0,1000,1) ATTACH(win,spin_rect_radius,450,300) CALLBACK(spin_rect_radius,set_col) SET(spin_rect_radius,5) '@ SPINs stroke width spin_rect_stroke_width=SPIN(75,25,0,100,1) ATTACH(win,spin_rect_stroke_width,525,300) SET(spin_rect_stroke_width,3) CALLBACK(spin_rect_stroke_width,set_col)
'@ SPINs R DONE passed spin_rd1=SPIN(75,25,0,255,1) ATTACH(win,spin_rd1,375,325) CALLBACK(spin_rd1,set_col) SET(spin_rd1,0) '@ SPINs G DONE passed spin_rd2=SPIN(75,25,0,255,1) ATTACH(win,spin_rd2,450,325) CALLBACK(spin_rd2,set_col) SET(spin_rd2,0) '@ SPINs B DONE passed spin_rd3=SPIN(75,25,0,255,1) ATTACH(win,spin_rd3,525,325) CALLBACK(spin_rd3,set_col) SET(spin_rd3,255)
'@ SPINs R DONE passed spin_r1=SPIN(75,25,0,255,1) ATTACH(win,spin_r1,375,350) CALLBACK(spin_r1,set_col) '@ SPINs G spin_r2=SPIN(75,25,0,255,1) ATTACH(win,spin_r2,450,350) CALLBACK(spin_r2,set_col) '@ SPINs B DONE passed spin_r3=SPIN(75,25,0,255,1) ATTACH(win,spin_r3,525,350) SET(spin_r3,50) CALLBACK(spin_r3,set_col) wipe=BUTTON("Wipe",100,25) ATTACH(win,wipe,5,350) CALLBACK(wipe,wiper) auotwipe=CHECK("Autowipe",100,25) ATTACH(win,auotwipe,105,350) txt1=ENTRY("",85,25) ATTACH(win,txt1,284,350) Label_1=MARK("<span font='16' foreground='#000000'>MARK 16 point pango text.</span>", 325, 20) ATTACH(win,Label_1,10,275) text2=ENTRY("",600,25) ATTACH(win,text2,0,375) text3=ENTRY("",85,25) ATTACH(win,text3,198,350)
DISPLAY The last screenshot of the rect/oval saved svg <svg width='600' height='400'> <rect x='129' y='54' ry='298' width='393' height='189' style='fill:rgb(25,235,52);stroke-width:3;stroke:rgb(53,114,255)'/> </svg>
|
|
|
Post by alexfish on Mar 31, 2023 18:05:50 GMT 1
Hi All in with this some of those bits GTK3 wise need to test things like sourceview edit & a terminal sourceview works:: as far s the terminal goes , deciphering the api anyway now got a success the code , + form now posting Joes hug3.bac . there are a couple of extra fixes in there INCLUDE hug3.bac
CALL INITvte
'=================================================================================== FUNCTION hug_Get_Vte$ : REM INCLUDE LOCAL hug_lib$ LOCAL hug_sequence = -1
CATCH GOTO Redo_Import
LABEL Redo_Import INCR hug_sequence IF hug_sequence = HUG_MAX_LIB_SEQ THEN GOTO Print_Error hug_lib$ = "libvte-2.91.so." & STR$(hug_sequence) IMPORT "vte_terminal_new" FROM hug_lib$ TYPE long
RETURN hug_lib$
LABEL Print_Error PRINT "notfound" END
END FUNCTION '=================================================================================== SUB INITvte LOCAL hug_Vte$
' Max sequence number in lib naming CONST HUG_MAX_LIB_SEQ = 50 hug_Vte$ = hug_Get_Vte$() IMPORT "vte_terminal_feed_child(long, char *, unsigned int)" FROM hug_Vte$ TYPE void IMPORT "vte_terminal_set_scrollback_lines (long,int)" FROM hug_Vte$ TYPE void IMPORT "vte_terminal_spawn_async(long, int, char *, char **, char **,int , void*,void* ,void*,int,void*, void*, void*)" FROM hug_Vte$ TYPE int IMPORT "vte_terminal_set_scroll_on_keystroke(long, int)" FROM hug_Vte$ TYPE void END SUB '=================================================================================== SUB TERMEXEC(long hug_widget) 'set working dir$ HOME$ = GETENVIRON$("HOME") 'choose shell LOCAL cmd[] = {"bash", NULL} TYPE STRING vte_terminal_spawn_async(hug_widget,0, HOME$, cmd, NULL, 0 , NULL,NULL ,NULL,-1,NULL,NULL,NULL) END SUB '=================================================================================== FUNCTION TERMINAL (int hug_xsize, int hug_ysize) ' a very Basic Terminal term = vte_terminal_new() vte_terminal_set_scrollback_lines(term,-1) scrolled = gtk_scrolled_window_new(0, 0) gtk_scrolled_window_set_policy(scrolled, 1, 1) gtk_scrolled_window_set_shadow_type(scrolled, 3) gtk_container_add(scrolled, term)
gtk_widget_show_all(scrolled)
hug_widget_xsize(STR$(scrolled)) = hug_xsize hug_widget_ysize(STR$(scrolled)) = hug_ysize hug_widget_signal(STR$(scrolled)) = 5 hug_widget_type$(STR$(scrolled)) = "edit" hug_widget_focus(STR$(scrolled)) = term g_signal_connect_data(term,"realize",TERMEXEC,0,0,0) RETURN scrolled
ENDFUNCTION '===================================================================================
win = WINDOW("HUG Gtk3 terminal",600,400)
termy = TERMINAL(600,400) ATTACH(win,termy,0,0)
DISPLAY FULL update file at POST #1 HAVE FUN +BR Alex Attachments:hug3.bac.bz2 (14.9 KB)
|
|
|
Post by alexfish on Apr 6, 2023 22:25:03 GMT 1
Hi All
SEDIT libgtksourceview 3 Using hug3 from above post assume have bacon gui gtk3 and lang bacon is in /.local/share/gtksourceview-3.0
INCLUDE hug3.bac
CALL INITsedit
'=================================================================================== FUNCTION hug_Get_Sedit$ : REM INCLUDE LOCAL hug_lib$ LOCAL hug_sequence = -1
CATCH GOTO Redo_Import
LABEL Redo_Import INCR hug_sequence IF hug_sequence = HUG_MAX_LIB_SEQ THEN GOTO Print_Error hug_lib$ = "libgtksourceview-3.0.so." & STR$(hug_sequence) IMPORT "gtk_source_view_new_with_buffer(long)" FROM hug_lib$ TYPE long RETURN hug_lib$
LABEL Print_Error PRINT "libgtksourceview Not found" END
END FUNCTION '=================================================================================== SUB INITsedit LOCAL hug_Vte$
' Max sequence number in lib naming CONST HUG_MAX_LIB_SEQ = 50 hug_sedit$ = hug_Get_Sedit$() IMPORT "gtk_source_style_scheme_manager_get_default(void)" FROM hug_sedit$ TYPE long IMPORT "gtk_source_style_scheme_manager_get_scheme(long,char*)" FROM hug_sedit$ TYPE long IMPORT "gtk_source_buffer_set_style_scheme(long, long)" FROM hug_sedit$ TYPE const char* const* IMPORT "gtk_source_buffer_can_undo(long)" FROM hug_sedit$ TYPE int IMPORT "gtk_source_buffer_set_highlight_matching_brackets(long,int)" FROM hug_sedit$ TYPE void IMPORT "gtk_source_buffer_undo(long)" FROM hug_sedit$ TYPE void IMPORT "gtk_source_language_manager_get_default" FROM hug_sedit$ TYPE long IMPORT "gtk_source_language_manager_get_language(long,char*)" FROM hug_sedit$ TYPE long IMPORT "gtk_source_view_set_auto_indent(long,int)" FROM hug_sedit$ TYPE void IMPORT "gtk_source_view_set_show_line_numbers(long,int)" FROM hug_sedit$ TYPE void IMPORT "gtk_source_view_set_tab_width(long,int)" FROM hug_sedit$ TYPE void IMPORT "gtk_source_buffer_new_with_language(long)" FROM hug_sedit$ TYPE long END SUB
FUNCTION SEDIT (int hug_xsize, int hug_ysize)
' Create language manager lm = gtk_source_language_manager_get_default() ' Define language lang = gtk_source_language_manager_get_language(lm, "bacon") ' Setup buffer and viewer using BaCon as language buffer = gtk_source_buffer_new_with_language(lang) view = gtk_source_view_new_with_buffer(buffer) ' contributed by Joe/BigBass line numb/matching brks gtk_source_view_set_show_line_numbers (view,TRUE) gtk_source_buffer_set_highlight_matching_brackets(buffer,1) '------------------------------------------------------- ' SET SCHEME TO dark blue /nearest to terminal black ' CAN SET OWN OR UNCOMMENT scman = gtk_source_style_scheme_manager_get_default() theme = gtk_source_style_scheme_manager_get_scheme(scman, "cobalt") gtk_source_buffer_set_style_scheme(buffer,theme) ' Create scrolled window scrolled = gtk_scrolled_window_new(0, 0) gtk_scrolled_window_set_policy(scrolled, 1, 1) gtk_scrolled_window_set_shadow_type(scrolled, 3) gtk_container_add(scrolled, view) gtk_text_view_set_editable(view, 1) gtk_text_view_set_wrap_mode(view, 3)
gtk_widget_show_all(scrolled)
hug_widget_xsize(STR$(scrolled)) = hug_xsize hug_widget_ysize(STR$(scrolled)) = hug_ysize hug_widget_signal(STR$(scrolled)) = 5 hug_widget_s_widget(STR$(scrolled)) = buffer
hug_widget_type$(STR$(scrolled)) = "edit" hug_widget_font(STR$(scrolled)) = view hug_widget_focus(STR$(scrolled)) = view
RETURN scrolled
END FUNCTION
win = WINDOW("Sedit",600,400)
ed=SEDIT(585,600) ATTACH(win,ed,0,0)
DISPLAY
BR Alex
|
|
|
Post by alexfish on Apr 7, 2023 20:50:01 GMT 1
Hi All Left the hug CANVAS as id got the id from image = hug_widget_image(STR$(canvas)) as a test load an image buf = gdk_pixbuf_new_from_file("/path/to/imagefile", 0) set the PICTURE gtk_image_set_from_pixbuf (image,buf) Viola Not Far Away Now test code win = WINDOW("testing_gtk3",1200,600) sed = SEDIT(600,300) FONT(sed,"Monospace 12px") ATTACH(win,sed,600,0) terms=TERMINAL(600,300) ATTACH(win,terms,600,300) but = BUTTON("Feed term",100,25) ATTACH(win,but,3,3) CALLBACK (but,feed_child) can = CANVAS(600,300) ATTACH(win,can,0,26) DISPLAY BR Alex Picky of hug3 Canvas, Sedit, and Teminal@ test feed child Attachments:
|
|
|
Post by alexfish on Apr 9, 2023 0:37:43 GMT 1
Hi All Progress:: the back ends of HUG IMAGER now Incorporated into hug3 , CANVAS wise need to sort TABLE so hence to quote "more on that one later" Re Alpha this optional by length of the colour string to complete are CIRCLE,PIXEL and OUT ADDED CLS & CLSC CLSC used at CANVAS create CLS used to ACCESS the CLSC(context) the CLSC FUNCTION SUB CLSC(long pixbuf, unsigned int col) PIXFILL(pixbuf,col) END SUB notation is Ox with ALPHA IE WHITE, CLSC(context,0xFFFFFFFF) example code = write as one would do in original hug INCLUDE hug3.bac HUGOPTIONS("NOSCALING") win = WINDOW("text Canvas",600,450) but = BUTTON("Click",100,25) ATTACH(win,but,3,3) can = CANVAS(600-6,400) ATTACH(win,can,3,45) ' keep drawing within the bound of the canvas LINE("#FF0000FF",0,0,600-6,400) LINE("#FFFF00FF",0,400,600-6,0) DISPLAY so a peak atC the CANVAS and LINE FUNCTION no color check in cairo since default color = BLACK FUNCTION CANVAS (int hug_xsize, int hug_ysize)
LOCAL image, ebox, hug_gdkwin, pix, context, gdkcol, glcfg,pixbuf
LOCAL attrlist[] = { GDK_GL_RGBA, GDK_GL_RED_SIZE, 1, GDK_GL_GREEN_SIZE, 1, GDK_GL_BLUE_SIZE, 1, GDK_GL_DOUBLEBUFFER, GDK_GL_NONE } TYPE int
IF HUG_CANVAS_TYPE = 1 THEN IF hug_gui_properties.gl$ = "GLAREA" THEN image = gtk_gl_area_new(ADDRESS(attrlist)) g_signal_connect_data(image, "expose-event", hug_glcanvas_expose, 0, 0, 0) pix = image ELSE gtk_gl_init(0, 0) image = gtk_drawing_area_new() glcfg = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB|GDK_GL_MODE_DOUBLE|GDK_GL_MODE_DEPTH) gtk_widget_set_gl_capability(image, glcfg, 0, 1, GDK_GL_RGBA_TYPE) g_signal_connect_data(image, "expose-event", hug_glcanvas_expose, 0, 0, 0) pix = image END IF ELIF HUG_CANVAS_TYPE = 2 THEN image = goo_canvas_new() goo_canvas_set_bounds(image, 0, 0, hug_xsize, hug_ysize) pix = image ELSE
image = gtk_image_new() pix = image context=PIXBUF_NEW(hug_xsize, hug_ysize) CLSC(context,0xFFFFFFFF) gtk_image_set_from_pixbuf (image,context) hug_gdkwin = gdk_get_default_root_window() IF INSTR(hug_gui_properties.options$, "TABLE") THEN '!pix = gdk_pixmap_new(hug_gdkwin, gdk_screen_get_width(gdk_screen_get_default()), gdk_screen_height(gdk_screen_get_default()), -1) ELSE '!pix = gdk_pixmap_new(hug_gdkwin, hug_xsize, hug_ysize, -1) END IF
gtk_misc_set_alignment(image, 0, 0) IF INSTR(hug_gui_properties.options$, "TABLE") THEN '!gdk_draw_rectangle(pix, context, 1, 0, 0, gdk_screen_get_width(gdk_screen_get_default()), gdk_screen_height(gdk_screen_get_default()) ) ELSE '!gdk_draw_rectangle(pix, context, 1, 0, 0, hug_xsize, hug_ysize) END IF gtk_widget_queue_draw(image) hug_widget_context(STR$(pix)) = context END IF
ebox = gtk_event_box_new() gtk_widget_set_events(ebox, GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK) g_signal_connect_data(ebox, "button-press-event", hug_mouse_event, 20, 0, 0) g_signal_connect_data(ebox, "button-release-event", hug_mouse_event, 40, 0, 0) g_signal_connect_data(ebox, "motion-notify-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "scroll-event", hug_mouse_event, 10, 0, G_CONNECT_AFTER) g_signal_connect_data(ebox, "leave-notify-event", hug_mouse_event, 30, 0, 0)
gtk_container_add(ebox, image)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(ebox)
hug_widget_pix(STR$(image)) = pix
hug_widget_color(STR$(pix)) = gdkcol hug_widget_ebox(STR$(pix)) = ebox
hug_widget_image(STR$(ebox)) = image hug_widget_xsize(STR$(ebox)) = hug_xsize hug_widget_ysize(STR$(ebox)) = hug_ysize hug_widget_signal(STR$(ebox)) = 4 hug_widget_s_widget(STR$(ebox)) = ebox hug_widget_type$(STR$(ebox)) = "canvas"
REM Define this as default drawing canvas hug_gui_properties.canvas = pix WIDGET = ebox
RETURN ebox
END FUNCTION
SUB LINE (STRING hug_color$, int hug_xstart, int hug_ystart, int hug_xend, int hug_yend)
LOCAL pix, context, ebox, glcontext, gldraw
REM Get the associated canvas pix = hug_gui_properties.canvas
ebox = hug_widget_ebox(STR$(pix)) IF HUG_CANVAS_TYPE = 1 THEN IF NOT(hug_gui_properties.freeze) THEN IF hug_gui_properties.gl$ = "GLAREA" THEN gtk_gl_area_make_current(hug_gui_properties.canvas) ELSE glcontext = gtk_widget_get_gl_context(hug_gui_properties.canvas) gldraw = gtk_widget_get_gl_window(hug_gui_properties.canvas) gdk_gl_drawable_gl_begin(gldraw, glcontext) END IF END IF
glMatrixMode(GL_PROJECTION) glLoadIdentity glOrtho(0, hug_widget_xsize(STR$(ebox)), hug_widget_ysize(STR$(ebox)), 0, 0, 1) glMatrixMode(GL_MODELVIEW) glLoadIdentity glTranslatef(0.375, 0.375, 0)
IF LEN(hug_color$) = 7 THEN glColor3ub(DEC(MID$(hug_color$, 2, 2)), DEC(MID$(hug_color$, 4, 2)), DEC(MID$(hug_color$, 6, 2)) ) ELSE glColor3ub(0, 0, 0) END IF
glBegin(GL_LINES) glVertex2i(hug_xstart, hug_ystart) glVertex2i(hug_xend, hug_yend) glEnd
IF NOT(hug_gui_properties.freeze) THEN IF hug_gui_properties.gl$ = "GLAREA" THEN gtk_gl_area_swap_buffers(hug_gui_properties.canvas) ELSE gdk_gl_drawable_swap_buffers(gldraw) gdk_gl_drawable_gl_end(gldraw) END IF END IF ELIF HUG_CANVAS_TYPE = 2 THEN context = goo_canvas_get_root_item(pix)
WIDGET = goo_canvas_polyline_new_line(context, hug_xstart, hug_ystart, hug_xend, hug_yend, "stroke-color", hug_color$, "line-width", 1.0, NULL) ELSE context = hug_widget_context(STR$(pix))
LOCAL newpix,cs,cr,buf,wd,ht LOCAL data TYPE unsigned char * LOCAL r,g,b,a TYPE double cs = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,gdk_pixbuf_get_width(context), gdk_pixbuf_get_height(context)) cr = cairo_create (cs)
IF LEN(hug_color$) = 7 THEN IF ENDIAN THEN b = DEC(MID$(hug_color$, 2, 2))/255.0 g = DEC(MID$(hug_color$, 4, 2))/255.0 r = DEC(MID$(hug_color$, 6, 2))/255.0 ELSE r = DEC(MID$(hug_color$, 2, 2))/255.0 g = DEC(MID$(hug_color$, 4, 2))/255.0 b = DEC(MID$(hug_color$, 6, 2))/255.0 END IF cairo_set_source_rgb(cr,r ,g,b) END IF
IF LEN(hug_color$) = 9 THEN IF ENDIAN THEN b = DEC(MID$(hug_color$, 2, 2))/255.0 g = DEC(MID$(hug_color$, 4, 2))/255.0 r = DEC(MID$(hug_color$, 6, 2))/255.0 ELSE r = DEC(MID$(hug_color$, 2, 2))/255.0 g = DEC(MID$(hug_color$, 4, 2))/255.0 b = DEC(MID$(hug_color$, 6, 2))/255.0 END IF a = DEC(MID$(hug_color$, 8, 2))/255.0 cairo_set_source_rgba(cr,r ,g,b,a) END IF cairo_set_line_width (cr,1) cairo_move_to (cr,hug_xstart,hug_ystart) cairo_line_to(cr,hug_xend,hug_yend)
cairo_stroke(cr) cairo_destroy(cr) cairo_surface_flush(cs) data = cairo_image_surface_get_data (cs) buf = gdk_pixbuf_new_from_data(data, 0,TRUE,8,cairo_image_surface_get_width(cs),cairo_image_surface_get_height(cs) ,cairo_image_surface_get_stride (cs),0,0) gdk_pixbuf_composite(buf,context, 0,0, cairo_image_surface_get_width(cs), cairo_image_surface_get_height(cs), 0,0, 1,1, 0,255)
g_object_unref(buf) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) END IF
END SUB BR Alex Attachments:
|
|
|
Post by alexfish on Apr 9, 2023 21:21:23 GMT 1
Hi All Now at end of trail RE HUG IMAGER , now namely updated hug3 do for the ones that know graphics bits the canvas can be transparent the default canvas is the image without gdk pixel, replaced by gdk_pixbuf default draw methods are cairo implenting ALPHA PICTURE is scaled by the sizex sizey bit of code with the CLS function Showing and can get picture of what can be done with this code INCLUDE hug3.bac
HUGOPTIONS("NOSCALING") SUB CLS(unsigned int hug_col) LOCAL pix, context, ebox pix = hug_gui_properties.canvas ebox = hug_widget_ebox(STR$(pix)) context = hug_widget_context(STR$(pix)) CLSC(context,hug_col)
END SUB
win = WINDOW("text Canvas",600,450) but = BUTTON("Click",100,25) ATTACH(win,but,3,3) lab = MARK("LOOK AT THIS MARK",-1,-1) ATTACH(win,lab,130,130) FONT(lab,"msbm10 20px") can = CANVAS(600-6,400) ATTACH(win,can,3,15) CLS(0x00000000)
' keep drawing within the bound of the canvas LINE("#FF0000",0,0,600-6,400) LINE("#FFFF00",0,400,600-6,0) SQUARE("#FF00006F",100,100,200,200,1) CIRCLE("#FF00006F",100,100,100,100,1) OUT("Cairo TEXT","#FF0000","#FF0000",250,150) PICTURE ("/home/pi/toroid.png", 300, 200, 128,128) DISPLAY Now on cleanup Release will be next weekend Picky : last one in this bit Attachments:
|
|
|
Post by alexfish on Apr 11, 2023 9:39:30 GMT 1
And So To the diff between gtk2 image and the gtk3 image and the pita is it your version of gtk3::
' gtk_image_new_from_surface () ' gtk_image_set_from_surface () if not the above methods will work on gtk2 & 3 as quick test RE fractal test from main site gtk2 using pixel 1sec gtk3 using cairo above = 3 sec gtk3 goocanvas = 7.5 dec
goocanvas1 for gtk 2 Deprecated as in gone, and more. depends on the distro
if set the cs surface as the context the from memory possible 1.5 to 2 secs, not bad considering cairo render gives alpha
and typical :: test: SQUARE FUNCTION
surface = hug_widget_surface( STR$(pix))
LOCAL cr
cr = cairo_create (surface) IF LEN(hug_color$) = 7 THEN cairo_set_source_rgb(cr,DEC(MID$(hug_color$, 2, 2))/255.0 , DEC(MID$(hug_color$, 4, 2))/255.0, DEC(MID$(hug_color$, 6, 2))/255.0) END IF
IF LEN(hug_color$) = 9 THEN cairo_set_source_rgba(cr,DEC(MID$(hug_color$, 2, 2))/255.0 ,DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0, \ DEC(MID$(hug_color$, 8, 2))/255.0 ) END IF
cairo_rectangle(cr, hug_x, hug_y,hug_xsize,hug_ysize)
IF hug_fill THEN cairo_fill(cr) ELSE cairo_set_line_width (cr,1) cairo_stroke(cr) END IF cairo_destroy(cr) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) )
then all sides are covered surface render to surface :: composite pixbuf pixbuf render to pixbuf :: composite
pixbuf put pixel :: pixbuf get pixel blagh blagh
BR Alex
|
|
|
Post by alexfish on Apr 11, 2023 12:56:36 GMT 1
And So it is Done and a fractal test note : this id straight fractal no SQUARES or TEXT times 'original hug default canvas RGB = 0.732 SEC 'New default Canvas for GTK3 RGBA = 1.246 SEC
Draw Pixel by pixel = 2 Secs IF rsquared + isquared <= 4.0 THEN PIXEL(PixelCol$[ROUND((rsquared + isquared)*4)], x, y) SYNC END IF + drawing is silky smooth Gtk2 default 4.2717 Secs & a bit jerky Gtk2 goocanvas1 NA Gtk3 goocanvas 145.723 Secs Not Tested direct pixbuf but think this one is a no-brainer + Added RE gtk4 reincarnated gtk2 , where are they heading, Arh I get it , use en.wikipedia.org/wiki/Etch_A_SketchEtch A Sketchdocs.gtk.org/gtk4/method.Image.clear.htmllook at rest of the api cairo surface not named:: BR Alex Added:: PICTURE id done so update not far away Example of PICTURE in the lib , + shows how to get raw pixbuf into the cairo surface LOCAL surface,cr surface = hug_widget_surface( STR$(pix)) cr = cairo_create (surface)
buf = gdk_pixbuf_new_from_file(hug_file$, 0) buf2 = gdk_pixbuf_scale_simple(buf,hug_xsize,hug_ysize,GDK_INTERP_HYPER)
gdk_cairo_set_source_pixbuf (cr, buf2, hug_xpos, hug_ypos) cairo_paint (cr)
cairo_destroy(cr) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface)
g_object_unref(buf) g_object_unref(buf2) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) Attachments:
|
|
|
Post by alexfish on Apr 11, 2023 20:59:15 GMT 1
In the meantime Sample code with added FUNCTION :: PICSIZE image original = 1920*1024 INCLUDE "hug35.bac" HUGOPTIONS("NOSCALING") HOME$= GETENVIRON$("HOME")
win = WINDOW("picture",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) LOCAL wd,ht wd = PICSIZE(HOME$ & "/Pictures/BUNNY.png",0) ht = PICSIZE(HOME$ & "/Pictures/BUNNY.png",1) PICTURE(HOME$ & "/Pictures/BUNNY.png",50,50,wd/5,ht/5) 'check alpha and placement SQUARE("#FF000060",50,50,wd/5,ht/5,1) DISPLAY also Added canvas fontsize CAIRO_FONT_SIZE
INCLUDE "hug35.bac" HUGOPTIONS("NOSCALING") HOME$= GETENVIRON$("HOME")
win = WINDOW("picture",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) LOCAL wd,ht wd = PICSIZE(HOME$ & "/Pictures/BUNNY.png",0) ht = PICSIZE(HOME$ & "/Pictures/BUNNY.png",1) PICTURE(HOME$ & "/Pictures/BUNNY.png",3,3,wd/5,ht/5) SQUARE("#FF000060",3,3,wd/5,ht/5,1) CAIRO_FONT_SIZE = 50 ' bg is ignored use SQUARE :: OUT("Cairo TEXT","#FF00FF","#FF0000",50,300) DISPLAY So Why NO BG onTEXT OUT INCLUDE "hug35.bac" HUGOPTIONS("NOSCALING") HOME$= GETENVIRON$("HOME")
win = WINDOW("picture",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) LOCAL wd,ht wd = PICSIZE(HOME$ & "/Pictures/BUNNY.png",0) ht = PICSIZE(HOME$ & "/Pictures/BUNNY.png",1) PICTURE(HOME$ & "/Pictures/BUNNY.png",3,3,wd/5,ht/5) SQUARE("#FF000060",3,3,wd/5,ht/5,1) CAIRO_FONT_SIZE = 50 ' bg is ignored use SQUARE Or What ever:: CIRCLE("#FFFF00FF",20,285,350,100,1) OUT("Cairo TEXT","#FF00FF","#FF0000",50,300) DISPLAY Pickys
|
|
|
Post by alexfish on Apr 11, 2023 23:45:26 GMT 1
And FONTNAME INCLUDE "hug35.bac" HUGOPTIONS("NOSCALING") HOME$= GETENVIRON$("HOME")
win = WINDOW("picture",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) LOCAL wd,ht wd = PICSIZE(HOME$ & "/Pictures/BUNNY.png",0) ht = PICSIZE(HOME$ & "/Pictures/BUNNY.png",1) PICTURE(HOME$ & "/Pictures/BUNNY.png",3,3,wd/5,ht/5) SQUARE("#FF000060",3,3,wd/5,ht/5,1) CAIRO_FONT_SIZE = 50 CAIROFONT$ = "Z003" ' bg is ignored use SQUARE Or What ever:: CIRCLE("#FFFF00",20,285,350,100,1) OUT("Bunny Bugs","#FF00FF","#FF0000",80,300)
DISPLAY and that's a Wrap Attachments:
|
|
|
Post by alexfish on Apr 12, 2023 7:30:03 GMT 1
Oh how do you get cairo arc to make a circle , that is well documented how do you get get hug to draw arc/circle, main bits are are in the lib hug.bac how do you get Cairo to draw circle as an ellipse, like in the above Yellow one Here We Go LOCAL surface,cr surface = hug_widget_surface( STR$(pix)) cr = cairo_create (surface)
cairo_set_line_width (cr,1)
IF LEN(hug_color$) = 7 THEN cairo_set_source_rgb(cr,DEC(MID$(hug_color$, 2, 2))/255.0 , DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0) END IF
IF LEN(hug_color$) = 9 THEN cairo_set_source_rgba(cr,DEC(MID$(hug_color$, 2, 2))/255.0 ,DEC(MID$(hug_color$, 4, 2))/255.0, \ DEC(MID$(hug_color$, 6, 2))/255.0, \ DEC(MID$(hug_color$, 8, 2))/255.0 ) END IF
cairo_translate (cr, hug_x, hug_y) cairo_scale (cr,hug_xsize/2,hug_ysize/2) cairo_arc (cr, 1.0, 1.0, 1.0, 0.0, 2.0 * M_PI)
IF hug_fill THEN cairo_fill(cr) ELSE cairo_stroke(cr) END IF
cairo_destroy(cr) cairo_surface_flush(surface) gtk_image_set_from_surface (pix,surface) gtk_widget_queue_draw(hug_widget_image(STR$(ebox)) ) Have Fun + BR Alex as a final check for sanity :: straight download & compile of ' ' The Fifteen-puzzle: http://en.wikipedia.org/wiki/Fifteen_puzzle ' ' Created on a boring sunday afternoon - February 2012, PvE ' ' - 1.0: initial release ' - 1.1: some beautifications ' ' This HTML page generated as follows: ' # enscript --color --style=emacs --language=html --highlight=bacon 15puzzle.bac -p - | expand -t 4 > 15puzzle.bac.html ' '------------------------------------------------------------------------------------------ Second Screen shot is the gtk2 original Attachments:
|
|
|
Post by alexfish on Apr 12, 2023 9:09:45 GMT 1
Q: How Will I animate the Canvas like GooCanvas TIMEOUT TRANSLATE/ROTATE
the user space is different to original geo functions Example in the demo(ellipse bit) cairo_translate (cr, hug_x, hug_y) cairo_rotate(cr,rot) cairo_scale (cr,hug_xsize/2,hug_ysize/2) cairo_arc (cr, 0, 0, 1.0, 0.0, 2.0 * M_PI) and 'Your' code looks like CIRCLE("#FFFF00", 20,285,350,100,1) CIRCLEA("#FFFF00",350/2,350,350,100,1,45) CIRCLEA("#FFFF00",350/2,350,350,100,1,90)
INCLUDE "hug35.bac" HUGOPTIONS("NOSCALING") HOME$= GETENVIRON$("HOME")
win = WINDOW("picture",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) LOCAL wd,ht wd = PICSIZE(HOME$ & "/Pictures/BUNNY.png",0) ht = PICSIZE(HOME$ & "/Pictures/BUNNY.png",1) PICTURE(HOME$ & "/Pictures/BUNNY.png",3,3,wd/5,ht/5) 'SQUARE("#0000FF60",3,3,wd/5,ht/5,1) SQUARE("#0000FF60",0,0,600,400,1) CAIRO_FONT_SIZE = 50 CAIROFONT$ = "Z003" ' bg is ignored use SQUARE Or What ever:: CIRCLE("#FFFF00",20,285,350,100,1) OUT("Bunny Bugs","#FF00FF","#FF0000",80,300) CIRCLEA("#FFFF00",350/2,350,350,100,1,45) CIRCLEA("#FFFF00",350/2,350,350,100,1,90) DISPLAY see 2nd screenshot Hoping new hug3.5.bac ready for the weekend coming Attachments:
|
|
|
Post by alexfish on Apr 12, 2023 10:58:15 GMT 1
and the user space explained by orignal coords for existing canvas are top/left , can't do that else the object will look like a Lasso so to translate rotate the coords need to be centered the code looks like INCLUDE "hug35.bac" HUGOPTIONS("NOSCALING") HOME$= GETENVIRON$("HOME")
win = WINDOW("Elipse",600,400) can = CANVAS(600,400) ATTACH(win,can,0,0) FOR t = 1 TO 360 STEP 5 CIRCLEA("#FFFF00",600/2,400/2,350,100,0,t) NEXT DISPLAY And total total Wrap The Picky center for center then can do things like second photo Attachments:
|
|