|
Post by vovchik on Feb 17, 2014 17:04:47 GMT 1
Dear Joe and Alex, And here another ufo, but with a gratuitous bit of radial gradient thrown in... With kind regards, vovchik
|
|
|
Post by bigbass on Feb 17, 2014 17:18:04 GMT 1
Hey vovchik I wouldn't doubt that you could fly one of those too Joe
|
|
|
Post by bigbass on Apr 20, 2020 1:57:32 GMT 1
most of my code was lost on the old wiki when it crashed I will rewrite a few of them again from scratch (still looking for one to change default fonts) I added this to the rosetta page (we need more demos there) rosettacode.org/wiki/Window_creation/X11#BaConXLIB hello '---ported to bacon by bigbass from '---http://rosettacode.org/wiki/Window_creation/X11#Xlib '--- added a flush to exit cleanly PRAGMA LDFLAGS `pkg-config --cflags --libs x11` PRAGMA INCLUDE <X11/Xlib.h> PRAGMA INCLUDE <X11/Xutil.h> PRAGMA INCLUDE <string.h> OPTION PARSE FALSE
'---XLIB is so ugly ALIAS XNextEvent TO EVENT ALIAS XOpenDisplay TO DISPLAY ALIAS DefaultScreen TO SCREEN ALIAS XCreateSimpleWindow TO CREATE ALIAS XCloseDisplay TO CLOSE_DISPLAY ALIAS XSelectInput TO EVENT_TYPE ALIAS XMapWindow TO MAP_EVENT ALIAS XFillRectangle TO FILL_RECTANGLE ALIAS XDrawString TO DRAW_STRING ALIAS XFlush TO FLUSH
'---pointer to X Display structure DECLARE d TYPE Display* '---pointer to the newly created window DECLARE w TYPE Window '---pointer to the XEvent DECLARE e TYPE XEvent DECLARE msg TYPE char* '--- number of screen to place the window on DECLARE s TYPE int
msg = "Hello, World!" d = DISPLAY(NULL) IF d == NULL THEN EPRINT "Cannot open display" FORMAT "%s%s\n" END END IF s = SCREEN(d) w = CREATE(d, RootWindow(d, s), 10, 10, 100, 100, 1,BlackPixel(d, s), WhitePixel(d, s)) EVENT_TYPE(d, w, ExposureMask | KeyPressMask) MAP_EVENT(d, w) WHILE (1) EVENT(d, &e) IF e.type == Expose THEN FILL_RECTANGLE(d, w, DefaultGC(d, s), 20, 20, 10, 10) DRAW_STRING(d, w, DefaultGC(d, s), 10, 50, msg, strlen(msg)) END IF IF e.type == KeyPress THEN BREAK END IF WEND FLUSH(d) CLOSE_DISPLAY(d)
|
|
|
Post by bigbass on Apr 21, 2020 15:24:33 GMT 1
some steps get skipped along the way we are using Athena widgets and the first step
is doing a system check if all the dependencies are there and it compiles and runs
Joe
'--- dependency check -ported by bigbass '--- A very simple X program that uses the Athena widgets
PRAGMA INCLUDE <X11/StringDefs.h> PRAGMA INCLUDE <X11/Intrinsic.h> PRAGMA INCLUDE <X11/Xaw/Command.h> PRAGMA LDFLAGS Xaw PRAGMA LDFLAGS X11 PRAGMA LDFLAGS Xt DECLARE toplevel TYPE Widget DECLARE command TYPE Widget OPTION PARSE FALSE ALIAS XtInitialize TO XINIT ALIAS XtCreateManagedWidget TO XCREATE ALIAS XtAddCallback TO XCALLBACK ALIAS XtRealizeWidget TO XSHOW ALIAS XtMainLoop TO XDISPLAY '----------------------- SUB leave(w,client) '----------------------- PRINT "that's all folks" END ENDSUB
toplevel = XINIT(argv[0],"simple",NULL, 0, &argc, argv)
command = XCREATE("press and close", commandWidgetClass, toplevel, NULL, 0)
XCALLBACK(command,XtNcallback,(void *)leave,NULL)
XSHOW(toplevel)
XDISPLAY()
|
|
|
Post by bigbass on Apr 22, 2020 18:45:51 GMT 1
Now that we have a built in GUI for Athena widgets having some stand alone widgets will help understand how the library works its all very low level code and demos are hard to come by much less code was ported and modified for bacon but this should help Joe
'---ported then modified for bacon and get the callbacks working '---by bigbass 4-22-2020 PRAGMA INCLUDE <X11/StringDefs.h> PRAGMA INCLUDE <X11/Intrinsic.h> PRAGMA INCLUDE <X11/Xaw/Command.h> PRAGMA INCLUDE <X11/Xaw/Box.h> PRAGMA INCLUDE <X11/Xaw/Text.h>
PRAGMA LDFLAGS Xaw PRAGMA LDFLAGS X11 PRAGMA LDFLAGS Xt DECLARE toplevel TYPE Widget DECLARE command TYPE Widget DECLARE box TYPE Widget DECLARE nbuttons TYPE int DECLARE buttons[20] TYPE Widget
OPTION PARSE FALSE ALIAS XtInitialize TO XINIT ALIAS XtCreateManagedWidget TO XCREATE ALIAS XtAddCallback TO XCALLBACK ALIAS XtRealizeWidget TO XSHOW ALIAS XtMainLoop TO XDISPLAY ALIAS XtManageChildren TO XWIDGETS ALIAS XtSetArg TO XSETARG ALIAS XtSetValues TO XSETVALUES
DECLARE names[] = {"button1","button2","button3","button4","button5",0} TYPE STRING
DECLARE values[] = {1,2,3,4,5} TYPE int DECLARE wargs[10] TYPE Arg DECLARE n TYPE int
DECLARE client_data TYPE XtPointer DECLARE wxid TYPE Widget DECLARE call_data TYPE XtPointer
toplevel = XINIT(argv[0],"simple",NULL, 0, &argc, argv)
box = XCREATE("box",boxWidgetClass,toplevel, NULL, 0)
n = 0 XSETARG(wargs[n],XtNorientation,XtorientVertical) INCR n XSETARG(wargs[n],XtNvSpace,10) INCR n XSETVALUES(box,wargs,n)
command = XCREATE("quit",commandWidgetClass, box, NULL, 0)
XCALLBACK(command,XtNcallback,(void*)leave, NULL)
nbuttons = 0 WHILE names[nbuttons] != 0 buttons[nbuttons] = XtCreateWidget(names[nbuttons], commandWidgetClass, box, NULL, 0) '---fixed values callbacks with (void *) (int *) XtAddCallback(buttons[nbuttons],XtNcallback,(void*)value_print,(int *) values[nbuttons]) '---added names callback to the demo was very tricky with strings XtAddCallback(buttons[nbuttons],XtNcallback,(void*)name_print,(int *)names[nbuttons]) INCR nbuttons WEND
XWIDGETS(buttons,nbuttons)
XSHOW(toplevel)
XDISPLAY()
'---------------------------------------- SUB name_print(wxid,xclient_data,xcall_data) '----------------------------------------
PRINT "name = ",xclient_data FORMAT "%s%s\n" END SUB
'---------------------------------------- SUB value_print(wxid,xclient_data,xcall_data) '---------------------------------------- PRINT "value = ",xclient_data FORMAT "%s%d\n" END SUB
'----------------------- SUB leave(w,client) '----------------------- PRINT "that's all folks" END ENDSUB
TERMINAL OUTPUT value = 1 name = button1 value = 2 name = button2 value = 3 name = button3 value = 4 name = button4 value = 5 name = button5
|
|
|
Post by bigbass on Apr 23, 2020 4:41:52 GMT 1
We don't want to skip the first steps Here is using Motif
as a stand alone widget before jumping into the other more complex demos
this works on the RPI3 ++ and no extra (void *) (int *)casting needed like in Athena examples making it easier to get callbacks going Joe
'---Setting Resources During Widget Creation '---ported to bacon '---by bigbass 4-22-2020 PRAGMA INCLUDE <Xm/PushB.h>
PRAGMA LDFLAGS Xm PRAGMA LDFLAGS Xt PRAGMA LDFLAGS X11 OPTION PARSE FALSE DECLARE toplevel TYPE Widget DECLARE button TYPE Widget DECLARE app TYPE XtAppContext DECLARE label TYPE XmString DECLARE args[2] TYPE Arg DECLARE client_data TYPE XtPointer DECLARE widget TYPE Widget DECLARE call_data TYPE XtPointer
XtSetLanguageProc (NULL, NULL, NULL) toplevel = XtVaOpenApplication (&app, "Hello", NULL, 0, &argc, argv, \ NULL,sessionShellWidgetClass, NULL) label = XmStringCreateLocalized ("Push here to say hello") XtSetArg(args[0], XmNlabelString, label) button = XmCreatePushButton (toplevel, "pushme", args, 1) XmStringFree (label) XtAddCallback (button, XmNactivateCallback, button_pushed, NULL) XtManageChild (button) XtRealizeWidget (toplevel) XtAppMainLoop (app)
'---------------------------------------- SUB button_pushed (Widget widget, XtPointer client_data, XtPointer call_data) '---------------------------------------- PRINT "Hello Yourself!" END SUB
|
|
|
Post by rikky on Apr 23, 2020 7:17:41 GMT 1
The last Motif example gives me an unknown type name 'Widget' in line 6. But the Athena Buttons work nicely. Rik.
|
|
|
Post by bigbass on Apr 23, 2020 8:01:49 GMT 1
Hello Rikky its fixed now above copied and pasted again
here is one more with color very small just one button
(shows up in the top left corner of the screen )
I will ALIAS the next examples so its easier to read
'---Setting Resources During Widget Creation '---ported to bacon '---by bigbass 4-22-2020 PRAGMA INCLUDE <Xm/PushB.h>
PRAGMA LDFLAGS Xm PRAGMA LDFLAGS Xt PRAGMA LDFLAGS X11 OPTION PARSE FALSE DECLARE toplevel TYPE Widget DECLARE button TYPE Widget DECLARE app TYPE XtAppContext DECLARE label TYPE XmString DECLARE args[2] TYPE Arg DECLARE client_data TYPE XtPointer DECLARE widget TYPE Widget DECLARE call_data TYPE XtPointer
XtSetLanguageProc (NULL, NULL, NULL) toplevel = XtVaOpenApplication (&app, "Hello", NULL, 0, &argc, argv, NULL,sessionShellWidgetClass, NULL) XtSetArg(args[0], XmNlabelString, label) button = XtVaCreateManagedWidget ("pushme", xmPushButtonWidgetClass, toplevel, \ XmNlabelString, label,XtVaTypedArg, XmNbackground, \ XmRString, "red", strlen ("red") + 1, NULL) XmStringFree (label) XtAddCallback (button, XmNactivateCallback, button_pushed, NULL) XtManageChild (button) XtRealizeWidget (toplevel) XtAppMainLoop (app)
'---------------------------------------- SUB button_pushed (Widget widget, XtPointer client_data, XtPointer call_data) '---------------------------------------- PRINT "Hello Yourself!" END SUB
|
|
|
Post by alexfish on Apr 27, 2020 19:29:01 GMT 1
Hi Hoe It be just passed my birthday , one tradition here is I have to buy the cream-cakes simple , make right click window BR Alex from HEREAttachments:xtut14.tgz (10.78 KB)
|
|
|
Post by alexfish on Apr 27, 2020 19:35:57 GMT 1
Think some one here likes gradients Attachments:xtut15.tgz (10.4 KB)
|
|
|
Post by bigbass on Apr 27, 2020 21:18:29 GMT 1
Thanks Alex A lot of excellent info there And as you see the typedef and the -> are at the heart of all code have time tonight to dig in and come up with another try I understand how it works (after fighting with it for several years) the porting is where it chokes looking for the magical key to baconize it but I see you are after the same key so we have a better chance of finding it Joe
|
|
|
Post by alexfish on Apr 28, 2020 4:38:46 GMT 1
Hi Joe noted from your notes
think you will hit the same conundrum in c++ as parent and child widget & friend of as make button , blagh ,blagh declare window comes before the widget and other bits.
here are some bits from my toolkit
//------------------------------------------------------------------------------ // forward declare to get widgets in
NGLAPI class Buffer; NGLAPI class Widget; // Window Default Scrolled the are NO scrolled windows // not a X11 this is the actual screen NGLAPI class NaitiveWindow {
public:
// GL BITS // State Screen dimentions & bits required at the init egl int CORE_APP; int screen_width; int screen_height; int screen_xpos; int screen_ypos; int window_x; int window_y; int window_width; int window_height; DISPMANX_ELEMENT_HANDLE_T element; EGLDisplay display; EGLSurface surface; EGLContext context;
// store widget types in a vector for rendering // = widget main and friends of vector<Widget *> child;
anyway : if examine the tutorial you will find how the swich is done
now here the need to get these passed bacon
and thinking here leave them in c land and make a wrapper ?? but what kind of wrapper for me leave as is and see if bacon accepts the incude *.c
BR Alex
|
|
|
Post by alexfish on Apr 28, 2020 5:11:23 GMT 1
forgot to mention
one important bit for scroll , widgets do much Vision unless you have method of
I posted that one earlier on , an left a clue left , I posted that somewhere else recently
BR Alex
|
|
|
Post by bigbass on May 1, 2020 17:03:33 GMT 1
rebuilding some code demos that were lost on the bacon wiki crash xlibgrandchild.bac I say that because if you click on the old links they are dead so here is the fix this is pure Xlib the lowest level we can go all other toolkits are on top of Xlib Objective of demo to show how inside a window you can create other windows which were called grandchild and child of the parent window '--- xlibgrandchild.bac the simple add child and grandchild window demo '--- add events to get the mouse click '--- rebuilt again to compile in April 2020 original was on bacon's wiki page '--- by bigbass PRAGMA LDFLAGS `pkg-config --cflags --libs x11` PRAGMA INCLUDE <X11/Xlib.h> PRAGMA INCLUDE <X11/Xutil.h> PRAGMA INCLUDE <X11/cursorfont.h> PRAGMA INCLUDE <string.h> OPTION PARSE FALSE
'---XLIB is so ugly ALIAS XNextEvent TO EVENT ALIAS XOpenDisplay TO DISPLAY ALIAS DefaultScreen TO SCREEN ALIAS XCreateSimpleWindow TO CREATE ALIAS XCloseDisplay TO CLOSE_DISPLAY ALIAS XSelectInput TO EVENT_TYPE ALIAS XMapWindow TO MAP_EVENT ALIAS XFillRectangle TO FILL_RECTANGLE ALIAS XDrawString TO DRAW_STRING ALIAS XFlush TO FLUSH
ALIAS DefaultGC TO GRAPHICS '---pointer to X Display structure DECLARE d TYPE Display*
'---pointer to the newly created window DECLARE w TYPE Window DECLARE window_name TYPE char* window_name =" Xlib grandchild demo"
'---pointer to the XEvent DECLARE e TYPE XEvent DECLARE msg TYPE char* DECLARE msg2 TYPE char* DECLARE msg3 TYPE char*
'--- number of screen to place the window on DECLARE s TYPE int '========child declare '--- this variable will store the handle of the newly created child window. DECLARE child_win TYPE Window '--- these variables will store the window's width and height. child_win_width = 250 child_win_height = 250 child_win_border_width = 1 '--- these variables will store the window's location. '--- position of the child window is top-left corner of the '--- parent window. - 0,0. child_win_x = 0 child_win_y = 0 '===================== '========gran child declare '--- this variable will store the handle of the newly created gran child window. DECLARE grandchild_win TYPE Window '--- these variables will store the window's width and height. grandchild_win_width = 150 grandchild_win_height = 150 grandchild_win_border_width = 1 '--- these variables will store the window's location. '--- position of the gran child window is top-left corner of the '--- parent window. - 0,0. grandchild_win_x = 0 grandchild_win_y = 0 '=====================
d = DISPLAY(NULL) msg = "Child window" msg2 = "Grand child window" msg3 = "Main window"
s = SCREEN(d) w = CREATE(d, RootWindow(d, s), 10, 10, 300, 300, 1, \ BlackPixel(d, s), WhitePixel(d, s)) EVENT_TYPE(d, w, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) MAP_EVENT(d, w) '-----------Add child code '--- create the window, as specified earlier. child_win = CREATE(d, w, child_win_x, child_win_y, \ child_win_width, child_win_height, \ child_win_border_width, \ BlackPixel(d, s), \ WhitePixel(d, s)) '--- add event handling for the gran child window too EVENT_TYPE(d, child_win, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) '-----------Add gran child code '--- create the window, as specified earlier. grandchild_win = CREATE(d, w, grandchild_win_x, grandchild_win_y, \ grandchild_win_width, grandchild_win_height, \ grandchild_win_border_width, \ BlackPixel(d, s), \ WhitePixel(d, s)) '--- add event handling for the grandchild window too EVENT_TYPE(d, grandchild_win, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) '--- show main root win MAP_EVENT(d, w); '-------------------------- '--- show child win MAP_EVENT(d, child_win) '--- show grandchild win MAP_EVENT(d, grandchild_win)
WHILE (1) EVENT(d, &e) IF (e.xexpose.window == w) THEN MAP_EVENT(d, w) DRAW_STRING(d, grandchild_win, GRAPHICS(d, s), 20, 50, msg2, strlen(msg)) DRAW_STRING(d, child_win, GRAPHICS(d, s), 20, 170, msg, strlen(msg)) DRAW_STRING(d, w, GRAPHICS(d, s), 20, 270, msg3, strlen(msg)) END IF IF (e.type == FocusIn) THEN PRINT "FocusIn" PRINT "The parent window = " ,(long)w PRINT "child_win = ",child_win PRINT "grandchild window = ",grandchild_win ENDIF IF (e.type == FocusOut) THEN PRINT "FocusOut " ENDIF IF (e.type == ButtonPress) THEN IF (e.xexpose.window == w) THEN PRINT "You are in the main window" END IF IF (e.xexpose.window == child_win) THEN PRINT "You are in the child window" END IF IF (e.xexpose.window == grandchild_win) THEN PRINT "You are in the grandchild window" END IF END IF IF (e.type == KeyPress) THEN BREAK ENDIF WEND
FLUSH(d) CLOSE_DISPLAY(d)
|
|