|
Post by alexfish on Jan 27, 2014 21:03:25 GMT 1
Hi @ all
in preparation for Demo's have prepared a lookup array for the ExEvents names . but can test in any of the demos posted
Typical usage at the WHILE events snippets
At the INCLUDE's or PRAGMA
'@ the file should be placed in the working directory INCLUDE X11_event_names.bac
WHILE (1) XNextEvent(display, &e) PRINT "Event Name : " ,event_names$[e.type] '@ get the select window prior to SELECT CASE IF event_names$[e.type]="ButtonPress" THEN Win_Event_id =e.xbutton.window PRINT "Win id : " ,Win_Event_id END IF
'@ rest of code here
WEND
BR Alex
The Include X11_event_names.bac
'@ FILE 'X11_event_names.bac' DECLARE event_names$[] = { \ "", \ "", \ "KeyPress", \ "KeyRelease", \ "ButtonPress", \ "ButtonRelease", \ "MotionNotify", \ "EnterNotify", \ "LeaveNotify", \ "FocusIn", \ "FocusOut", \ "KeymapNotify", \ "Expose", \ "GraphicsExpose", \ "NoExpose", \ "VisibilityNotify", \ "CreateNotify", \ "DestroyNotify", \ "UnmapNotify", \ "MapNotify", \ "MapRequest", \ "ReparentNotify", \ "ConfigureNotify", \ "ConfigureRequest", \ "GravityNotify", \ "ResizeRequest", \ "CirculateNotify", \ "CirculateRequest", \ "PropertyNotify", \ "SelectionClear", \ "SelectionRequest", \ "SelectionNotify", \ "ColormapNotify", \ "ClientMessage", \ "MappingNotify" \ }
|
|
|
Post by alexfish on Jan 28, 2014 3:16:26 GMT 1
Hi @ all + Vovchik just done some blit testing using cairo direct with the x lib doing 500 filled rectangles 300x300 pixels , Time = 2 to 3 mSec. Thinks this is an amazing result , have not tested gl , but think it can not be far behind it in the 2d arena. LINE move to and draw is slower since there secondary stage to render line as STROKE but the line length range from 300px to 1000px, Time avrg 780 mSec to 1 Sec, but suppose could use rectangle as a line. wonder if Vovchik can improve on some of goo canvas render speeds in the MandleBrot dem's using cairo/xlib . BR Alex
|
|
|
Post by bigbass on Jan 28, 2014 18:15:37 GMT 1
Hey guys great news! just as everything in linux is a file everything in Xlib is a window so making a child window unlocks making widgets now we have events and child windows (Alex added cairo and gl demos) so now we can have some real fun mixing the goodies together Xlibchild.bacJoe
|
|
|
Post by alexfish on Jan 29, 2014 18:58:53 GMT 1
Hi All
here have use Joe's child window and rendered as a Widget with Callback + identify if correct BUTTON as in widget is pressed
The SUB BUTTON is Bacon Hug name convention , U may also find this a useful Routine , since getting a Button Type Render IE rounded corners ,is not easy task in Cairo .
have kept the render as a plain fill , later may see linear grads , but lets get to grips with some Basics of rendering Widgets with Cairo..
No text in this one ,butt if see previous demo's the is similar with Cairo Text .. Your Task is to render the Text into the BUTTON
That will entail adapting the sub to accept the TEXT ... + also note Have left all the full bits of cairo..can strip if want ..
Have Fun
Alex
'--- xlibbtton.bac Demo simple add child window + render a SIMPLE BUTTON with text + callback + identify the widget
PRAGMA LDFLAGS `pkg-config --cflags --libs x11 --libs cairo` PRAGMA INCLUDE X11/Xlib.h PRAGMA INCLUDE X11/Xutil.h PRAGMA INCLUDE X11/cursorfont.h PRAGMA INCLUDE string.h PRAGMA INCLUDE cairo.h PRAGMA INCLUDE cairo-pdf.h PRAGMA INCLUDE cairo-ps.h PRAGMA INCLUDE cairo-xlib.h '@ for delete event PROTO XInternAtom PROTO XSetWMProtocols PROTO Atom PROTO DefaultScreen PROTO XCreateSimpleWindow PROTO RootWindow PROTO XSelectInput PROTO XMapWindow PROTO XNextEvent PROTO XFillRectangle PROTO XDrawString PROTO XCloseDisplay PROTO XFlush PROTO XSelectInput 'PROTO cairo_set_user_data PROTO cairo_xlib_surface_create PROTO cairo_xlib_surface_create_for_bitmap PROTO cairo_xlib_surface_set_size PROTO cairo_xlib_surface_get_display PROTO cairo_xlib_surface_get_screen PROTO cairo_xlib_surface_set_drawable PROTO cairo_xlib_surface_get_drawable PROTO cairo_xlib_surface_get_visual PROTO cairo_xlib_surface_get_width PROTO cairo_xlib_surface_get_heigh PROTO cairo_xlib_surface_get_depth
PROTO cairo_surface_get_device PROTO cairo_create PROTO cairo_rectangle PROTO cairo_set_source_rgb PROTO cairo_fill PROTO cairo_move_to PROTO cairo_set_source_rgb PROTO cairo_show_text PROTO cairo_show_page PROTO cairo_destroy PROTO cairo_surface_destroy PROTO cairo_set_font_size PROTO cairo_line_to PROTO cairo_save PROTO cairo_set_line_width PROTO cairo_stroke PROTO cairo_surface_write_to_png PROTO cairo_rel_line_to PROTO cairo_arc PROTO cairo_arc_negative PROTO cairo_rel_curve_to PROTO cairo_close_path PROTO cairo_new_path PROTO cairo_translate PROTO cairo_scale PROTO cairo_restore '@ compositing bits PROTO cairo_surface_create_similar PROTO cairo_operator_t PROTO cairo_set_operator PROTO cairo_set_source_surface PROTO cairo_paint
'@ cairo suface
DECLARE *cs TYPE cairo_surface_t '---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 '========child declare '--- this variable will store the handle of the newly created child window. DECLARE child_win_button_1 TYPE Window SUB BUTTON(cairo_surface_t *cs,double x ,double y,double width , double height) LOCAL *c TYPE cairo_t 'LOCAL *cr TYPE cairo_new_path LOCAL rx,ry TYPE double rx=10.0 ry=10.0
c=cairo_create(cs) cairo_new_path(c) /* Draw the top-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 1.5 * PI, 2.0 * PI) cairo_restore (c) cairo_line_to (c, x + width,y + height - ry) /* Draw the bottom-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 0.0, 0.5 * PI) cairo_restore (c) /* Draw the line left across the bottom. */ cairo_line_to (c, x + rx, y + height) /* Draw the bottom-left arc. */ cairo_save (c) cairo_translate (c,x + rx,y +height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 0.5 * PI, PI) cairo_restore (c) /* Draw the line up the left side. */ cairo_line_to (c,x, y + ry) /* Draw the top-left arc. */ cairo_save (c) cairo_translate (c,x + rx, y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, PI, 1.5 * PI) cairo_restore (c) cairo_close_path (c) cairo_set_source_rgb(c,0.705, 0.196, 0.18) cairo_fill(c) cairo_show_page(c) cairo_destroy(c)
END SUB '--- these variables will store the window's width and height. '@ window for BUTTON Widget child_win_width = 150 child_win_height = 50 child_win_border_width = 0 '--- 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 = 50 child_win_y = 50 '===================== d = XOpenDisplay(NULL) msg = "Hello, BaCon child!" s = DefaultScreen(d) w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 300, 1, \ BlackPixel(d, s), WhitePixel(d, s)) XSelectInput(d, w, ExposureMask | KeyPressMask) XMapWindow(d, w) '-----------Add child code '--- create the window, as specified earlier. child_win = XCreateSimpleWindow(d, w, child_win_x, child_win_y, \ child_win_width, child_win_height, \ 0, \ BlackPixel(d, s), \ WhitePixel(d, s)) XSelectInput(d, child_win,ButtonPressMask) cs=cairo_xlib_surface_create(d, child_win, DefaultVisual(d, s),child_win_width, child_win_height) '--- show main root win XMapWindow(d, w); '-------------------------- '--- show child win XMapWindow(d, child_win)
'@ set up client for WM delete event exit = this stops the ERR messages in Terminal DECLARE wm_delete_window TYPE Atom DECLARE wm_click_widget TYPE Atom wm_delete_window = XInternAtom (d, "WM_DELETE_WINDOW", False) XSetWMProtocols (d,w, &wm_delete_window, 1) WHILE (1) XNextEvent(d, &e) IF (e.type == Expose) THEN '@ Draw a BUTTON in the child window BUTTON(cs,0,0,(double)child_win_width,(double)child_win_height)
END IF IF (e.type == ClientMessage) THEN PRINT "Closing Down" IF ((Atom)e.xclient.data.l[0] == wm_delete_window) THEN PRINT "EXIT" cairo_surface_destroy(cs) XCloseDisplay(d) XFlush(d) BREAK END IF END IF '@ check button press / chick if our button IF (e.type == ButtonPress) THEN Win_Event_id =e.xbutton.window IF child_win = Win_Event_id THEN PRINT "Button Press Event :: Widget ID : " , child_win END IF ENDIF WEND
|
|
|
Post by bigbass on Jan 29, 2014 19:14:45 GMT 1
Hey Alex we were on the same thought I was going to post when I just saw you post I was going about it differently as you can see I got the the child or the main window detected with event handling of the mouse click this will allow for any widget to be made Joe '--- xlibchild.bac the simple add child window demo with text 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 PROTO DefaultScreen PROTO XCreateSimpleWindow PROTO RootWindow PROTO XSelectInput PROTO XMapWindow PROTO XNextEvent PROTO XFillRectangle PROTO XDrawString PROTO XCloseDisplay PROTO XFlush
PROTO printf
'---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
'========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 = 150 child_win_height = 150 child_win_border_width = 10
'--- 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 '=====================
d = XOpenDisplay(NULL) msg = "Hello, BaCon child!" s = DefaultScreen(d) w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 300, 1, \ BlackPixel(d, s), WhitePixel(d, s)) XSelectInput(d, w, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask)
XMapWindow(d, w)
'-----------Add child code '--- create the window, as specified earlier. child_win = XCreateSimpleWindow(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 child window too XSelectInput(d, child_win, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask)
'--- show main root win XMapWindow(d, w); '--------------------------
DECLARE fc TYPE XFocusChangeEvent*
'--- show child win XMapWindow(d, child_win);
WHILE (1) XNextEvent(d, &e) IF (e.type == Expose) THEN XMapWindow(d, child_win); XFillRectangle(d, w, DefaultGC(d, s), 200, 200, 10, 10) XDrawString(d, child_win, DefaultGC(d, s), 20, 50, msg, strlen(msg)) END IF
IF (e.type == FocusIn) THEN PRINT "FocusIn" PRINT "The parent window = " ,(long)w PRINT "child_win = ",child_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 END IF
IF (e.type == KeyPress) THEN BREAK ENDIF WEND XFlush(d) XCloseDisplay(d)
|
|
|
Post by bigbass on Jan 29, 2014 19:40:09 GMT 1
Hey Alex I just tried your demo great stuff! that was going to be my question to you could you do this in cairo take a look at my snippet it does a few checks for the main window child window focus in and out would be easy to add these looks like cairo widgets are in the making Joe
|
|
|
Post by alexfish on Jan 30, 2014 1:30:39 GMT 1
Hi joe ..
looks like the bits are coming together , thought about some type of container / but then decided may start this with a Scrolled window
Here using same code as the cairo Button Widget , but Added height to the child window + a boarder
then Identify the Scroll button up and down , not much separation of the code for the window ID , but this is just to get a feel of what can be done directly with X11
: just as an expansion on this one , IE homework , try adding a 2nd child to the first child then make a Widget in the 2nd child
Possible . method of adding Scroll bars ? ..
then also thinking about some method of keep track of the bits , Bacon has easy to use RECORD + ASSOC Arrays >> ..
BR Alex
Here We go
'--- xlibchild.bac Demo simple add child window + render a SIMPLE BUTTON with text + callback + identify the widget ,added scrollable window
PRAGMA LDFLAGS `pkg-config --cflags --libs x11 --libs cairo` PRAGMA INCLUDE X11/Xlib.h PRAGMA INCLUDE X11/Xutil.h PRAGMA INCLUDE X11/cursorfont.h PRAGMA INCLUDE string.h PRAGMA INCLUDE cairo.h PRAGMA INCLUDE cairo-pdf.h PRAGMA INCLUDE cairo-ps.h PRAGMA INCLUDE cairo-xlib.h '@ for delete event PROTO XInternAtom PROTO XSetWMProtocols PROTO Atom PROTO XMoveWindow PROTO DefaultScreen PROTO XCreateSimpleWindow PROTO RootWindow PROTO XSelectInput PROTO XMapWindow PROTO XNextEvent PROTO XFillRectangle PROTO XDrawString PROTO XCloseDisplay PROTO XFlush PROTO XSelectInput 'PROTO cairo_set_user_data PROTO cairo_xlib_surface_create PROTO cairo_xlib_surface_create_for_bitmap PROTO cairo_xlib_surface_set_size PROTO cairo_xlib_surface_get_display PROTO cairo_xlib_surface_get_screen PROTO cairo_xlib_surface_set_drawable PROTO cairo_xlib_surface_get_drawable PROTO cairo_xlib_surface_get_visual PROTO cairo_xlib_surface_get_width PROTO cairo_xlib_surface_get_heigh PROTO cairo_xlib_surface_get_depth
PROTO cairo_surface_get_device PROTO cairo_create PROTO cairo_rectangle PROTO cairo_set_source_rgb PROTO cairo_fill PROTO cairo_move_to PROTO cairo_set_source_rgb PROTO cairo_show_text PROTO cairo_show_page PROTO cairo_destroy PROTO cairo_surface_destroy PROTO cairo_set_font_size PROTO cairo_line_to PROTO cairo_save PROTO cairo_set_line_width PROTO cairo_stroke PROTO cairo_surface_write_to_png PROTO cairo_rel_line_to PROTO cairo_arc PROTO cairo_arc_negative PROTO cairo_rel_curve_to PROTO cairo_close_path PROTO cairo_new_path PROTO cairo_translate PROTO cairo_scale PROTO cairo_restore '@ compositing bits PROTO cairo_surface_create_similar PROTO cairo_operator_t PROTO cairo_set_operator PROTO cairo_set_source_surface PROTO cairo_paint
'@ cairo suface
DECLARE *cs TYPE cairo_surface_t '---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 '========child declare '--- this variable will store the handle of the newly created child window. DECLARE child_win_button_1 TYPE Window SUB BUTTON(cairo_surface_t *cs,double x ,double y,double width , double height) LOCAL *c TYPE cairo_t 'LOCAL *cr TYPE cairo_new_path LOCAL rx,ry TYPE double rx=10.0 ry=10.0
c=cairo_create(cs) cairo_new_path(c) /* Draw the top-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 1.5 * PI, 2.0 * PI) cairo_restore (c) cairo_line_to (c, x + width,y + height - ry) /* Draw the bottom-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 0.0, 0.5 * PI) cairo_restore (c) /* Draw the line left across the bottom. */ cairo_line_to (c, x + rx, y + height) /* Draw the bottom-left arc. */ cairo_save (c) cairo_translate (c,x + rx,y +height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 0.5 * PI, PI) cairo_restore (c) /* Draw the line up the left side. */ cairo_line_to (c,x, y + ry) /* Draw the top-left arc. */ cairo_save (c) cairo_translate (c,x + rx, y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, PI, 1.5 * PI) cairo_restore (c) cairo_close_path (c) cairo_set_source_rgb(c,0.705, 0.196, 0.18) cairo_fill(c) cairo_show_page(c) cairo_destroy(c)
END SUB '--- these variables will store the window's width and height. '@ window for BUTTON Widget child_win_width = 150 child_win_height = 50 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 '===================== d = XOpenDisplay(NULL) msg = "Hello, BaCon child!" s = DefaultScreen(d) w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 300, 1, \ BlackPixel(d, s), WhitePixel(d, s)) XSelectInput(d, w, ExposureMask | KeyPressMask) XMapWindow(d, w) '-----------Add child code '--- create the window, as specified earlier. child_win = XCreateSimpleWindow(d, w, child_win_x, child_win_y, \ child_win_width, child_win_height+600, \ child_win_border_width, \ BlackPixel(d, s), \ WhitePixel(d, s)) XSelectInput(d, child_win,ButtonPressMask) cs=cairo_xlib_surface_create(d, child_win, DefaultVisual(d, s),child_win_width, child_win_height) '--- show main root win XMapWindow(d, w); '-------------------------- SCRPOS = 0 '--- show child win XMapWindow(d, child_win)
'@ set up client for WM delete event exit = this stops the ERR messages in Terminal DECLARE wm_delete_window TYPE Atom DECLARE wm_click_widget TYPE Atom wm_delete_window = XInternAtom (d, "WM_DELETE_WINDOW", False) XSetWMProtocols (d,w, &wm_delete_window, 1) WHILE (1) XNextEvent(d, &e) IF (e.type == Expose) THEN '@ Draw a BUTTON in the child window BUTTON(cs,0,0,(double)child_win_width,(double)child_win_height)
END IF IF (e.type == ClientMessage) THEN PRINT "Closing Down" IF ((Atom)e.xclient.data.l[0] == wm_delete_window) THEN PRINT "EXIT" cairo_surface_destroy(cs) XCloseDisplay(d) XFlush(d) BREAK END IF END IF '@ check button press / chick if our button IF (e.type == ButtonPress) THEN PRINT e.xbutton.button IF e.xbutton.button = 4 THEN PRINT "Sc UP" DECR SCRPOS ,5 XMoveWindow(d,child_win,child_win_x,SCRPOS) END IF IF e.xbutton.button = 5 THEN PRINT "Sc Down" INCR SCRPOS ,5 XMoveWindow(d,child_win,child_win_x,SCRPOS) END IF Win_Event_id =e.xbutton.window IF child_win = Win_Event_id THEN PRINT "Button Press Event :: Widget ID : " , child_win END IF ENDIF WEND
|
|
|
Post by bigbass on Jan 30, 2014 5:24:42 GMT 1
Hey Alex I am enjoying the progress with cairo! using your example with quick minor adjustments as you can see its just a matter of preferences it can be made many ways will work on it Joe '--- xlibchild.bac Demo simple add child window + render a SIMPLE BUTTON with text + callback + identify the widget ,added scrollable window
PRAGMA LDFLAGS `pkg-config --cflags --libs x11 --libs cairo` PRAGMA INCLUDE X11/Xlib.h PRAGMA INCLUDE X11/Xutil.h PRAGMA INCLUDE X11/cursorfont.h PRAGMA INCLUDE string.h PRAGMA INCLUDE cairo.h PRAGMA INCLUDE cairo-pdf.h PRAGMA INCLUDE cairo-ps.h PRAGMA INCLUDE cairo-xlib.h '@ for delete event PROTO XInternAtom PROTO XSetWMProtocols PROTO Atom PROTO XMoveWindow PROTO DefaultScreen PROTO XCreateSimpleWindow PROTO RootWindow PROTO XSelectInput PROTO XMapWindow PROTO XNextEvent PROTO XFillRectangle PROTO XDrawString PROTO XCloseDisplay PROTO XFlush PROTO XSelectInput 'PROTO cairo_set_user_data PROTO cairo_xlib_surface_create PROTO cairo_xlib_surface_create_for_bitmap PROTO cairo_xlib_surface_set_size PROTO cairo_xlib_surface_get_display PROTO cairo_xlib_surface_get_screen PROTO cairo_xlib_surface_set_drawable PROTO cairo_xlib_surface_get_drawable PROTO cairo_xlib_surface_get_visual PROTO cairo_xlib_surface_get_width PROTO cairo_xlib_surface_get_heigh PROTO cairo_xlib_surface_get_depth
PROTO cairo_surface_get_device PROTO cairo_create PROTO cairo_rectangle PROTO cairo_set_source_rgb PROTO cairo_fill PROTO cairo_move_to PROTO cairo_set_source_rgb PROTO cairo_show_text PROTO cairo_show_page PROTO cairo_destroy PROTO cairo_surface_destroy PROTO cairo_set_font_size PROTO cairo_line_to PROTO cairo_save PROTO cairo_set_line_width PROTO cairo_stroke PROTO cairo_surface_write_to_png PROTO cairo_rel_line_to PROTO cairo_arc PROTO cairo_arc_negative PROTO cairo_rel_curve_to PROTO cairo_close_path PROTO cairo_new_path PROTO cairo_translate PROTO cairo_scale PROTO cairo_restore '@ compositing bits PROTO cairo_surface_create_similar PROTO cairo_operator_t PROTO cairo_set_operator PROTO cairo_set_source_surface PROTO cairo_paint
'@ cairo suface
DECLARE *cs TYPE cairo_surface_t '---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
'========child declare '--- this variable will store the handle of the newly created child window. DECLARE child_win_button_1 TYPE Window
SUB BUTTON(cairo_surface_t *cs,double x ,double y,double width , double height) LOCAL *c TYPE cairo_t 'LOCAL *cr TYPE cairo_new_path LOCAL rx,ry TYPE double rx=10.0 ry=10.0
c=cairo_create(cs) cairo_new_path(c) /* Draw the top-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 1.5 * PI, 2.0 * PI) cairo_restore (c) cairo_line_to (c, x + width,y + height - ry) /* Draw the bottom-right arc. */ cairo_save (c) cairo_translate (c, x + width - rx,y + height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 0.0, 0.5 * PI) cairo_restore (c) /* Draw the line left across the bottom. */ cairo_line_to (c, x + rx, y + height) /* Draw the bottom-left arc. */ cairo_save (c) cairo_translate (c,x + rx,y +height - ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, 0.5 * PI, PI) cairo_restore (c) /* Draw the line up the left side. */ cairo_line_to (c,x, y + ry) /* Draw the top-left arc. */ cairo_save (c) cairo_translate (c,x + rx, y + ry) cairo_scale (c, rx, ry) cairo_arc (c, 0.0, 0.0, 1.0, PI, 1.5 * PI) cairo_restore (c) cairo_close_path (c) 'cairo_set_source_rgb(c,0.205, 0.196, 0.18) cairo_set_source_rgb(c, 0.8, 0.8, 0.8)
cairo_fill(c) cairo_restore (c) cairo_show_page(c) cairo_destroy(c)
END SUB '--- these variables will store the window's width and height. '@ window for BUTTON Widget child_win_width = 20 child_win_height = 380 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 '=====================
d = XOpenDisplay(NULL) msg = "Hello, BaCon child!"
s = DefaultScreen(d) w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 400, 1, \ BlackPixel(d, s), WhitePixel(d, s)) XSelectInput(d, w, ExposureMask | KeyPressMask) XMapWindow(d, w)
'-----------Add child code '--- create the window, as specified earlier. child_win = XCreateSimpleWindow(d, w, child_win_x, child_win_y, \ child_win_width, child_win_height, \ child_win_border_width, \ BlackPixel(d, s), \ WhitePixel(d, s)) XSelectInput(d, child_win,ButtonPressMask) cs=cairo_xlib_surface_create(d, child_win, DefaultVisual(d, s),child_win_width, 400) '--- show main root win XMapWindow(d, w); '-------------------------- SCRPOS = 0 '--- show child win XMapWindow(d, child_win)
'@ set up client for WM delete event exit = this stops the ERR messages in Terminal DECLARE wm_delete_window TYPE Atom DECLARE wm_click_widget TYPE Atom wm_delete_window = XInternAtom (d, "WM_DELETE_WINDOW", False) XSetWMProtocols (d,w, &wm_delete_window, 1)
'@ Draw a BUTTON in the child window
WHILE (1) XNextEvent(d, &e) IF (e.type == Expose) THEN BUTTON(cs,0,0,(double)child_win_width,(double)child_win_height) END IF
IF (e.type == ClientMessage) THEN PRINT "Closing Down" IF ((Atom)e.xclient.data.l[0] == wm_delete_window) THEN PRINT "EXIT" cairo_surface_destroy(cs) XCloseDisplay(d) XFlush(d) BREAK END IF END IF
'@ check button press / chick if our button IF (e.type == ButtonPress) THEN PRINT e.xbutton.button IF e.xbutton.button = 4 THEN PRINT "Sc UP" DECR SCRPOS ,5 XMoveWindow(d,child_win,child_win_x,SCRPOS)
'@ Draw a BUTTON in the child window BUTTON(cs,0,0,(double)child_win_width,(double)child_win_height) END IF
IF e.xbutton.button = 5 THEN PRINT "Sc Down" INCR SCRPOS ,5 XMoveWindow(d,child_win,child_win_x,SCRPOS)
'@ Draw a BUTTON in the child window BUTTON(cs,0,0,(double)child_win_width,(double)child_win_height) END IF
Win_Event_id =e.xbutton.window IF child_win = Win_Event_id THEN PRINT "Button Press Event :: Widget ID : " , child_win END IF ENDIF WEND
|
|
|
Post by alexfish on Jan 31, 2014 21:48:49 GMT 1
Hi Joe + all
Joe > I looked for your child windows demos . now looks like on Wiki site
have done a take on the Win, Child win & Grandchild win using Cairo + left inpart using Default GC/rendering
Have also Added Method of getting Window Attributes, this can be called from the SUB ,, but the attributes are stored in the RECORD
maybe handy for setting win as widget so can render to size of the window Attributes..
can also define colour of TEXT and SQUARE
BR Alex
Here we go
'--- xlibgrandchild.bac the simple add child and grandchild window demo with text + use cairo '--- add events to get the mouse click PRAGMA LDFLAGS `pkg-config --cflags --libs x11 --libs cairo` PRAGMA INCLUDE X11/Xlib.h PRAGMA INCLUDE X11/Xutil.h PRAGMA INCLUDE X11/cursorfont.h PRAGMA INCLUDE string.h PRAGMA INCLUDE cairo.h PRAGMA INCLUDE cairo-pdf.h PRAGMA INCLUDE cairo-ps.h PRAGMA INCLUDE cairo-xlib.h
PROTO DefaultScreen PROTO XCreateSimpleWindow PROTO RootWindow PROTO XSelectInput PROTO XMapWindow PROTO XNextEvent PROTO XFillRectangle PROTO XDrawString PROTO XCloseDisplay PROTO XFlush PROTO XClearWindow '@ ADDED PROTO XGetGeometry PROTO Display PROTO printf PROTO cairo_surface_get_device PROTO cairo_create PROTO cairo_rectangle PROTO cairo_set_source_rgb PROTO cairo_fill PROTO cairo_move_to PROTO cairo_set_source_rgb PROTO cairo_show_text PROTO cairo_show_page PROTO cairo_destroy PROTO cairo_surface_destroy PROTO cairo_set_font_size PROTO cairo_line_to PROTO cairo_save PROTO cairo_set_line_width PROTO cairo_stroke PROTO cairo_surface_write_to_png PROTO cairo_rel_line_to PROTO cairo_arc PROTO cairo_arc_negative PROTO cairo_rel_curve_to PROTO cairo_close_path PROTO cairo_new_path PROTO cairo_translate PROTO cairo_scale PROTO cairo_restore '@ compositing bits PROTO cairo_surface_create_similar PROTO cairo_operator_t PROTO cairo_set_operator PROTO cairo_set_source_surface PROTO cairo_paint PROTO Drawable '---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* 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 '=====================
SUB SQUARE(cairo_surface_t *cs,STRING color$,double xpos,double ypos ,double width , double height)
LOCAL *c TYPE cairo_t
c=cairo_create(cs) cairo_set_source_rgb(c,DEC(MID$(color$, 2, 2)), DEC(MID$(color$, 4, 2)), DEC(MID$(color$, 6, 2)) ) cairo_set_line_width(c,2.0) cairo_rectangle(c, xpos, ypos,width,height) cairo_fill(c) cairo_show_page(c) cairo_destroy(c)
END SUB SUB TEXT(cairo_surface_t *cs,STRING txt$,STRING color$,double xpos,double ypos) LOCAL *c TYPE cairo_t
c=cairo_create(cs) cairo_set_source_rgb(c,DEC(MID$(color$, 2, 2)), DEC(MID$(color$, 4, 2)), DEC(MID$(color$, 6, 2)) ) cairo_move_to(c,xpos,ypos) cairo_show_text(c,txt$) cairo_show_page(c) cairo_destroy(c)
END SUB
d = XOpenDisplay(NULL) msg = "Child window" msg2 = "Grand child window" msg3 = "Main window" s = DefaultScreen(d) w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 300, 1, \ BlackPixel(d, s), WhitePixel(d, s)) XSelectInput(d, w, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) XMapWindow(d, w) DECLARE *cs TYPE cairo_surface_t DECLARE *cs_child_win TYPE cairo_surface_t DECLARE *cs_grand_child_win TYPE cairo_surface_t cs=cairo_xlib_surface_create(d, w, DefaultVisual(d, s),300, 300) '-----------Add child code '--- create the window, as specified earlier. child_win = XCreateSimpleWindow(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 XSelectInput(d, child_win, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) '-----------Add gran child code '--- create the window, as specified earlier. grandchild_win = XCreateSimpleWindow(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 XSelectInput(d, grandchild_win, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) '--- show main root win XMapWindow(d, w); '-------------------------- DECLARE fc TYPE XFocusChangeEvent* '--- show child win XMapWindow(d, child_win); '--- show grandchild win XMapWindow(d, grandchild_win);
'@ RECORD for storing window Geometry RECORD geometry LOCAL x , y ,width,height ,border,depth TYPE int LOCAL root END RECORD ' @ getting Geometry SUB Geometry(NUMBER window)
XGetGeometry(d,window,&geometry.root,&geometry.x,&geometry.y,&geometry.width,&geometry.height,&geometry.border,&geometry.depth) WITH geometry PRINT geometry.x PRINT geometry.y PRINT geometry.width PRINT geometry.height PRINT geometry.border PRINT geometry.depth END WITH
END SUB
WHILE (1) XNextEvent(d, &e) IF (e.type == Expose) THEN PRINT "xepose Window", e.xexpose.window IF (e.xexpose.window == w) THEN PRINT "Main Geometry------------------" Geometry(w) PRINT " : ---------------------------------------" PRINT "" END IF XMapWindow(d, child_win) cs_child_win=cairo_xlib_surface_create(d, child_win, DefaultVisual(d, s),300, 300) cs_grand_child_win=cairo_xlib_surface_create(d, grandchild_win, DefaultVisual(d, s),300, 300)
SQUARE(cs_grand_child_win,"#79FF00",10,10,20,20) TEXT(cs_grand_child_win,msg2,"#7C00FF",50,50) SQUARE(cs,"#7C00FF",150,200,125,90) TEXT(cs,msg3,"#7C00FF",50,280) '@ do X11 way XDrawString(d, child_win, DefaultGC(d, s), 20, 170, msg, strlen(msg)) END IF IF (e.type == FocusIn) THEN PRINT "FocusIn" PRINT "The parent window = " ,(long)w PRINT "child_win = ",child_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 cairo_surface_destroy(cs) cairo_surface_destroy(cs_child_win) cairo_surface_destroy(cs_grand_child_win) XFlush(d) XCloseDisplay(d)
|
|
|
Post by alexfish on Feb 1, 2014 0:23:40 GMT 1
Here , same again but scroll child window added
Note to scroll the grandchild the scroll is applied the the grand , best is to look visually what is happen ,
then can decided how to apply the scolled as in Move Window .. discerning if a scrollable window with widgets or perhaps something else
note from previous example one of the Squares is Strategically placed ,
also play around with scrolling the other windows one at a time..
Have fun Alex
'--- xlibgrandchild.bac the simple add child and grandchild window demo with text + use cairo '--- add events to get the mouse click +scroll PRAGMA LDFLAGS `pkg-config --cflags --libs x11 --libs cairo` PRAGMA INCLUDE X11/Xlib.h PRAGMA INCLUDE X11/Xutil.h PRAGMA INCLUDE X11/cursorfont.h PRAGMA INCLUDE string.h PRAGMA INCLUDE cairo.h PRAGMA INCLUDE cairo-pdf.h PRAGMA INCLUDE cairo-ps.h PRAGMA INCLUDE cairo-xlib.h
PROTO DefaultScreen PROTO XCreateSimpleWindow PROTO RootWindow PROTO XSelectInput PROTO XMapWindow PROTO XNextEvent PROTO XFillRectangle PROTO XDrawString PROTO XCloseDisplay PROTO XFlush PROTO XClearWindow '@ ADDED PROTO XMoveWindow PROTO XGetGeometry PROTO XStoreName PROTO Display PROTO printf PROTO cairo_surface_get_device PROTO cairo_create PROTO cairo_rectangle PROTO cairo_set_source_rgb PROTO cairo_fill PROTO cairo_move_to PROTO cairo_set_source_rgb PROTO cairo_show_text PROTO cairo_show_page PROTO cairo_destroy PROTO cairo_surface_destroy PROTO cairo_set_font_size PROTO cairo_line_to PROTO cairo_save PROTO cairo_set_line_width PROTO cairo_stroke PROTO cairo_surface_write_to_png PROTO cairo_rel_line_to PROTO cairo_arc PROTO cairo_arc_negative PROTO cairo_rel_curve_to PROTO cairo_close_path PROTO cairo_new_path PROTO cairo_translate PROTO cairo_scale PROTO cairo_restore '@ compositing bits PROTO cairo_surface_create_similar PROTO cairo_operator_t PROTO cairo_set_operator PROTO cairo_set_source_surface PROTO cairo_paint PROTO Drawable '---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* 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 '=====================
SUB SQUARE(cairo_surface_t *cs,STRING color$,double xpos,double ypos ,double width , double height)
LOCAL *c TYPE cairo_t
c=cairo_create(cs) cairo_set_source_rgb(c,DEC(MID$(color$, 2, 2)), DEC(MID$(color$, 4, 2)), DEC(MID$(color$, 6, 2)) ) cairo_set_line_width(c,2.0) cairo_rectangle(c, xpos, ypos,width,height) cairo_fill(c) cairo_show_page(c) cairo_destroy(c)
END SUB SUB TEXT(cairo_surface_t *cs,STRING txt$,STRING color$,double xpos,double ypos) LOCAL *c TYPE cairo_t
c=cairo_create(cs) cairo_set_source_rgb(c,DEC(MID$(color$, 2, 2)), DEC(MID$(color$, 4, 2)), DEC(MID$(color$, 6, 2)) ) cairo_move_to(c,xpos,ypos) cairo_show_text(c,txt$) cairo_show_page(c) cairo_destroy(c)
END SUB
d = XOpenDisplay(NULL) msg = "Child window" msg2 = "Grand child window" msg3 = "Main window" s = DefaultScreen(d) w = XCreateSimpleWindow(d, RootWindow(d, s), 10, 10, 300, 300, 1, \ BlackPixel(d, s), WhitePixel(d, s)) XSelectInput(d, w, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) XStoreName(d, w, "X11childs+ Cairo") XMapWindow(d, w) DECLARE *cs TYPE cairo_surface_t DECLARE *cs_child_win TYPE cairo_surface_t DECLARE *cs_grand_child_win TYPE cairo_surface_t cs=cairo_xlib_surface_create(d, w, DefaultVisual(d, s),300, 300) '-----------Add child code '--- create the window, as specified earlier. child_win = XCreateSimpleWindow(d, w, child_win_x, child_win_y, \ child_win_width, child_win_height, \ 0, \ BlackPixel(d, s), \ WhitePixel(d, s)) '--- add event handling for the gran child window too XSelectInput(d, child_win, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) '-----------Add gran child code '--- create the window, as specified earlier. grandchild_win = XCreateSimpleWindow(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 XSelectInput(d, grandchild_win, ExposureMask | KeyPressMask|FocusChangeMask | ButtonPressMask | ButtonReleaseMask) '--- show main root win XMapWindow(d, w); '-------------------------- DECLARE fc TYPE XFocusChangeEvent* '--- show child win XMapWindow(d, child_win); '--- show grandchild win XMapWindow(d, grandchild_win);
'@ RECORD for storing window Geometry RECORD geometry LOCAL x , y ,width,height ,border,depth TYPE int LOCAL root END RECORD ' @ getting Geometry SUB Geometry(NUMBER window)
XGetGeometry(d,window,&geometry.root,&geometry.x,&geometry.y,&geometry.width,&geometry.height,&geometry.border,&geometry.depth) WITH geometry PRINT geometry.x PRINT geometry.y PRINT geometry.width PRINT geometry.height PRINT geometry.border PRINT geometry.depth END WITH
END SUB SCRPOS = 0 WHILE (1) XNextEvent(d, &e) IF (e.type == Expose) THEN PRINT "xepose Window", e.xexpose.window IF (e.xexpose.window == w) THEN PRINT "Main Geometry------------------" Geometry(w) PRINT " : ---------------------------------------" PRINT "" END IF XMapWindow(d, child_win) cs_child_win=cairo_xlib_surface_create(d, child_win, DefaultVisual(d, s),300, 300) cs_grand_child_win=cairo_xlib_surface_create(d, grandchild_win, DefaultVisual(d, s),300, 300)
SQUARE(cs_grand_child_win,"#79FF00",10,10,20,20) TEXT(cs_grand_child_win,msg2,"#7C00FF",50,50) SQUARE(cs,"#7C00FF",150,200,125,90) TEXT(cs,msg3,"#7C00FF",50,280) '@ do X11 way XDrawString(d, child_win, DefaultGC(d, s), 20, 170, msg, strlen(msg)) END IF IF (e.type == FocusIn) THEN PRINT "FocusIn" PRINT "The parent window = " ,(long)w PRINT "child_win = ",child_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" IF e.xbutton.button = 5 THEN PRINT "Sc Down" INCR SCRPOS ,5 XMoveWindow(d,child_win,child_win_x,SCRPOS) XMoveWindow(d,grandchild_win,grandchild_win_x,SCRPOS) END IF IF e.xbutton.button = 4 THEN PRINT "Sc UP" DECR SCRPOS ,5 XMoveWindow(d,child_win,child_win_x,SCRPOS) XMoveWindow(d,grandchild_win,grandchild_win_x,SCRPOS) END IF 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 cairo_surface_destroy(cs) cairo_surface_destroy(cs_child_win) cairo_surface_destroy(cs_grand_child_win) XFlush(d) XCloseDisplay(d)
Here is a code snippet with font select , if got bacon gui or a font selector the can just copy the STRING of the font also include the enums can use as is in the code above or adapted the text function or sub to pass the bits
ENUM CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_SLANT_ITALIC, CAIRO_FONT_SLANT_OBLIQUE END ENUM
ENUM CAIRO_FONT_WEIGHT_NORMAL, CAIRO_FONT_WEIGHT_BOLD END ENUM
SUB TEXT(cairo_surface_t *cs,STRING txt$,STRING color$,double xpos,double ypos) LOCAL *c TYPE cairo_t
c=cairo_create(cs) '@ set the font and size of font cairo_select_font_face(c,"Comic Sans MS",CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL) cairo_set_font_size(c,13)
cairo_set_source_rgb(c,DEC(MID$(color$, 2, 2)), DEC(MID$(color$, 4, 2)), DEC(MID$(color$, 6, 2)) ) cairo_move_to(c,xpos,ypos) cairo_show_text(c,txt$) cairo_show_page(c) cairo_destroy(c)
END SUB
|
|
|
Post by bigbass on Feb 2, 2014 3:39:23 GMT 1
Hey Alex (and all) I should hope that it obvious to everyone using Xlib to code in is not what we expect for BASIC (or bacon) for general use as is we can however clean up the code and make it look more like BASIC later but this is experimental showing what is really under the hood of widgets how they were created and getting down under the gtk layer to get direct access to the low level signals and embedding external libraries and use their structures ( an area not well documented in BASIC) For example to see how Alex added cairo without gtk (that's pretty cool) and I like how you added the RECORD inside the code this ongoing experiment has opened many new ways of using BaCon and remember we are doing this just because its fun Hey Alex here is your code just added some color and cleaned up my typos Grandcairo.bacJoe
|
|
|
Post by vovchik on Feb 3, 2014 12:31:41 GMT 1
Dear Joe and Alex,
Nice work. I tried Joes Grandchild.bac with the latest beta and it did not compile. Tried an older bacon version (2.4) and it worked fine (Mint 16, 32-bit).
With kind regards, vovchik
|
|
|
Post by bigbass on Feb 3, 2014 17:19:27 GMT 1
Hey friend Thanks for the notice I dug into it and found out why if you look at the log the cairo.h wasn't getting detected so its an easy fix (the depth level of some search routine I guess)? PRAGMA INCLUDE cairo/cairo.h PRAGMA INCLUDE cairo/cairo-pdf.h PRAGMA INCLUDE cairo/cairo-ps.h PRAGMA INCLUDE cairo/cairo-xlib.h
I will adjust the code so it compiles on all versions but this should get Peter's attention anyway Joe
|
|
|
Post by Pjot on Feb 3, 2014 20:32:46 GMT 1
Alex, bigbass, You guys rock! Very interesting stuff, indeed we now can see how all this stuff works 'under the hood' of X. For PRAGMA INCLUDE, I noticed this issue earlier with some sample code of mr. Spikowski. The problem is caused by the 'pkg-config' construct, which, by the way, contains an error also - a bare "--cflags" doesn't do anything. So instead of this: PRAGMA LDFLAGS `pkg-config --cflags --libs x11 --libs cairo`
...we have to specify for which library we want to add compiler flags, namely Cairo: PRAGMA LDFLAGS `pkg-config --cflags cairo --libs x11 --libs cairo`
Now, we have added the include path to the compiler, where it can actually find the Cairo header files. But this is only step one of the solution. Step two is a problem in the Makefile generated by BaCon. It assumes that the PRAGMA LDFLAGS is only needed at linking time. However, if we use the "--cflags" parameter in LDFLAGS, this must be provided to the compile line also. For now, this works with the new beta: PRAGMA LDFLAGS `pkg-config --libs x11 --libs cairo` PRAGMA OPTIONS `pkg-config --cflags cairo`
Here, the libs are provided during linking, and the path to search the include files is provided during compilation. This setup would be recommended as it is more clean, nevertheless, it is not backward compatible as vovchik mentions. So I will add the LDFLAGS also to the compile line to be more compatible. Again thanks all testing and patience! BR, Peter
|
|
|
Post by bigbass on Feb 3, 2014 21:40:46 GMT 1
I will test what you posted thanks for taking a look and acting on it We were on the same thought about finding the headers this is messy for you but you will see the expressed idea implied (not all systems have locate) but it is fast and BTW it complies with simple names now since it auto completes notice the first if is now positive the >>111 and the >> zzz is just so we can test and see it gets removed the idea is if it is one deep we use /usr/include/$EXP if we cant find it we go two deep /usr/include/*/${EXP} and take the first hit starting at line 5621 of your new beta bacon.bash (before your new edits) if [[ -f "/usr/include/$EXP" ]] then #echo "#include \"${EXP}\"" >> $g_HFILE echo "#include \"`locate /usr/include/$EXP`"\" > 111 echo "#include \"`locate /usr/include/$EXP`"\" >> $g_HFILE else # echo "#include <${EXP}>" >> $g_HFILE echo "#include \"`locate /usr/include/*/${EXP}`"\" >> $g_HFILE echo "#include \"`locate /usr/include/*/${EXP}`"\" | head -n 1 > zzz fi done
we can now use simple names here Joe
|
|