HUG editable canvas
Sept 28, 2023 21:38:45 GMT 1
Post by alexfish on Sept 28, 2023 21:38:45 GMT 1
Simple canvas
Text and pictures
type text in the entry press enter position x y are the two small entry box
for PICTURE : "PICTURE myimage.png" position same as above . formats .svg .png .jpg
happy with the results
Take a Screen Shot
BR
Alex
Text and pictures
type text in the entry press enter position x y are the two small entry box
for PICTURE : "PICTURE myimage.png" position same as above . formats .svg .png .jpg
happy with the results
Take a Screen Shot
BR
Alex
'part of Bacon Gcoder ..cnc controll(View).raspberry PI4 in development
'alexfish@basic-converter.proboards.com
'
'
INCLUDE "hug.bac"
HUGOPTIONS("NOSCALING")
lib$ = HUGLIB$("gtk")
Gdk$ = HUGLIB$("gdk")
pang$ = HUGLIB$("pango")
' Import the GTK functions for file filters
IMPORT "gtk_widget_modify_fg(long,int,long)" FROM lib$ TYPE void
IMPORT "gtk_widget_modify_bg(long,int,long)" FROM lib$ TYPE void
IMPORT "gtk_file_chooser_add_filter(long,long)" FROM lib$ TYPE long
IMPORT "gtk_file_filter_add_pattern(long,char*)" FROM lib$ TYPE long
IMPORT "gtk_file_filter_new" FROM lib$ TYPE long
IMPORT "gtk_file_filter_set_name(long,char*)" FROM lib$ TYPE void
IMPORT "gdk_pixbuf_get_width(int)" FROM Gdk$ TYPE int
IMPORT "gdk_pixbuf_get_height(int)" FROM Gdk$ TYPE int
IMPORT "gdk_pixbuf_flip(long,int)" FROM Gdk$ TYPE long
/*
GdkPixbuf*
gdk_pixbuf_flip (
const GdkPixbuf* src,
gboolean horizontal
)
*/
IMPORT "gtk_viewport_new (void)" FROM lib$ TYPE long
IMPORT "gtk_scrolled_window_add_with_viewport(long,long)" FROM lib$ TYPE void
IMPORT "pango_layout_set_text(long,char*,int)" FROM pang$ TYPE void
SUB execute()
LOCAL cmd$,res$
LOCAL buf,width,height
cmd$ = GRAB$(ent)
IF INSTR(cmd$,"PICTURE") AND (INSTR(cmd$,".png")) OR INSTR(cmd$,".jpg") OR INSTR(cmd$,".svg") THEN
cmd$ = CHOP$(MID$(cmd$,INSTR(cmd$," ")))
IF FILEEXISTS(cmd$) THEN
buf = gdk_pixbuf_new_from_file(cmd$, 0)
IF buf THEN
'SQUARE("#FFFFFF",0,0,2000,5000,1)
width = gdk_pixbuf_get_width(buf)
height = gdk_pixbuf_get_height(buf)
g_object_unref(buf)
PICTURE(cmd$, VAL(GRAB$(xpos)),VAL(GRAB$(ypos)),width,height)
SYNC
END IF
END IF
ELSE
IF LEN(cmd$) THEN
OUT(cmd$,"#FFFFFF","#000000",VAL(GRAB$(xpos)),VAL(GRAB$(ypos)))
END IF
END IF
END SUB
SUB clear
SQUARE("#000000",0,0,2000,5000,1)
TEXT(ent,"")
FOCUS(ent)
SYNC
END SUB
win = WINDOW("hugterm",806,639)
'Scrolable Canvas ===============================================
scrolled = gtk_scrolled_window_new(0, 0)
gtk_scrolled_window_set_policy(scrolled, GTK_POLICY_AUTOMATIC, \
GTK_POLICY_AUTOMATIC)
gtk_scrolled_window_set_shadow_type(scrolled, GTK_SHADOW_ETCHED_IN)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(scrolled)
hug_widget_xsize(STR$(scrolled)) = 800
hug_widget_ysize(STR$(scrolled)) = 600
ATTACH(win,scrolled,0,0)
'==================================================================
can = CANVAS(2000,5000)
gtk_scrolled_window_add_with_viewport(scrolled, can)
'----------------------------------------------------
'Fill base
SQUARE("#000000",0,0,2000,5000,1)
ent=ENTRY("",500,30)
ATTACH(win,ent,3,606)
CALLBACK(ent,execute)
xpos = ENTRY("0",50,30)
ATTACH(win,xpos,503,606)
ypos=ENTRY("0",50,30)
ATTACH(win,ypos,566,606)
but = BUTTON("CLEAR",100,30)
ATTACH(win,but,806-103,606)
CALLBACK(but , clear)