|
Post by vovchik on Aug 17, 2020 22:04:56 GMT 1
Dear Alex,
It looks good. I like cairo - and pango-cairo. And the syntax is not ugly...
With kind regards, vovchik
|
|
|
Post by alexfish on Aug 18, 2020 8:25:58 GMT 1
Hi Vovchik & All a XCB example cairo can be found here can omit the #include <xcb/xcb_aux.h> #include <xcb/xcb_image.h> HEREin bacon can use FLAGS values = XCB_EVENT_MASK_BUTTON_PRESS |XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_STRUCTURE_NOTIFY;
I adapted the original make window to xcb_create_window(window.connection, XCB_COPY_FROM_PARENT, window.win, window.scr->root, 0, 0, 800, 600, 5, XCB_WINDOW_CLASS_INPUT_OUTPUT, window.scr->root_visual, XCB_CW_EVENT_MASK,&values);
and in the main loop redraw the surface at CASE XCB_CONFIGURE_NOTIFY ' to re draw window ... to cairo redraw(); xcb_flush(window.connection)
you will need the original Delete event to point the clean up // hence part of this thread in the redraw routine delete the CR 'window.cr' before redraw 'elese in future may get 'mem leaky' images use the surface = cairo_image_surface_create_from_png("*.png") and render at the renderer cairo_destroy (window.cr)
window.cr = cairo_create (window.surface) 'cairo_set_source_surface(cr,surface,xpos,ypos) cairo_set_source_surface (window.cr,img,0,0) cairo_paint (window.cr)
away 'Ye Go' for best performance , can put the imagages into an array IE cairo_surface_t * img[6]; in main load the images; BR Alex and I am getting tired of this messageAGREE I must of click that thing 20 times to get into this post , updated it and the leave post : go to home page and exit Attachments:
|
|
|
Post by vovchik on Aug 18, 2020 10:53:10 GMT 1
Dear Alex,
As somebody pointed out in the comments, that example needs a "#include <unistd.h>", and the "-l" can be eliminted, so the compile line can be:
[g]cc xcr.c -o xcr $(pkg-config --cflags --libs cairo xcb xcb-icccm)
It works nicely and will be simple to port. The struc can be done as a RECORD for window creation, I should think.
With kind regards, vovchik
|
|
|
Post by alexfish on Aug 18, 2020 15:10:56 GMT 1
Hi Vovchik
the 'lxcb-icccm' can be as well also delete the
#include <xcb/xcb_icccm.h>
IE window title at
xcb_icccm_set_wm_name change to example in c using strlen
xcb_change_property(window.connection, XCB_PROP_MODE_REPLACE, window.win, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen("Cairo Example"), "Cairo Example")
there are many postings about cairo been unusable + getting flickering
at this level yes may see it on the cairo_paint the 'cr' xcb surface : there is a way to stop this and will be posted on the cairo2 thread, as soon as can get the cairo bits back to where it was before the wipe out
BR Alex
|
|
|
Post by alexfish on Aug 18, 2020 22:53:25 GMT 1
Hi Vovchik & All Got the bits in place C wise:: Now a what some call a slippy surface + from XCB cairo is now Flicker Free:: Will start posting the bits on the cairo2 thread tomorrow .. + pointers where I be stuck BaCon Wise Picky of map demo similar to what I was working on BR Alex Attachments:
|
|
|
Post by rikky on Aug 19, 2020 14:44:29 GMT 1
Hallo Alexfish. There are a few Raspi users working in the same direction here. Rik.
|
|
|
Post by alexfish on Aug 19, 2020 20:34:53 GMT 1
Hi Rick Interesting , not sure but that looks like an embedded device a little bit to go yet + a bit of tweaking , and tweaking ' it will not be as good as this one, nor as versatile esp the layers. BR Alex Attachments:
|
|
|
Post by alexfish on Aug 20, 2020 1:45:53 GMT 1
Hi All
staying on the nautical aspect
as part of looking for a emended AIS best sit i found to date in terms of speed
save this to a html file
<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <script type="text/javascript"> // Map appearance var width="100%"; // width in pixels or percentage var height="900"; // height in pixels var latitude="56.00"; // center latitude (decimal degrees) var longitude="-1.40"; // center longitude (decimal degrees) var zoom="8"; // initial zoom (between 3 and 18) </script> <script type="text/javascript" src="https://www.vesselfinder.com/aismap.js"></script>
</body> </html>
for testing click on the saved file
Have Fun + BR Alex
|
|
|
Post by rikky on Aug 20, 2020 6:33:28 GMT 1
Impressive Especially the speed. Much much faster then marine-traffic. In fact marine-traffic crashes if you shuff the chart to a different place say like three times. And quickly search for a vessel just by the imo number. vesselfinderWhile for marinetraffic you have to have a shipid and a mmsi and an imo and a vessels name. And then you aren't even to the chart yet. Let alone that your Raspi3 crashes if you try to zoom in.
|
|
|
Post by alexfish on Aug 20, 2020 13:01:22 GMT 1
Hi Rik and All For future reference :: openstreet Nautical sybols etc can be found HEREBR Alex
|
|
|
Post by alexfish on Aug 21, 2020 17:19:06 GMT 1
Hi All
Now a bit out of time
had to back track on the get image from openstreetmap where using geo lat and long + zoom to find the map
will not go into the algo's as of yet but now think : works as it should down load looks like
https://b.tile.openstreetmap.org/Zoom/Xpos/Ypos.png from converted cords // zoom 10 & longitude 1.* and latitude 55.* 'blyth harbour port area ' 10.507.323 can find the file exmple below
"https://b.tile.openstreetmap.org/10/507/323.png"
next problem connecting to the tile server and get the png file using bacon Example
INCLUDE "curl.bac" CONST loader$ = "10/507/323.png" CONST filename$ = "323.png"
' File where we store the download OPEN filename$ FOR WRITING AS download
' Create the handle easyhandle = curl_easy_init() curl_global_init(CURL_GLOBAL_ALL) curl_easy_setopt(easyhandle, CURLOPT_SSL_VERIFYHOST, 0L); curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, "libosmgpsmap"); curl_easy_setopt(easyhandle , CURLOPT_SSL_VERIFYHOST, 2L) ' https://b.tile.openstreetmap.org/10/507/323.png ' Set the options curl_easy_setopt(easyhandle, CURLOPT_URL, CONCAT$("https://b.tile.openstreetmap.org/", loader$)) curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, NULL); curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, download) 'curl_easy_setopt(easyhandle, CURLOPT_WRITEFUNCTION, NULL); 'curl_easy_setopt(image, CURLOPT_WRITEDATA, fp); ' Perform the GET success = curl_easy_perform(easyhandle)
' Cleanup curl_easy_cleanup(easyhandle)
' Close filehandle CLOSE FILE download
' Print Curl version PRINT NL$, "Downloaded '", filename$, "' using CURL version: ", curl_version$(), NL$
hope it works
next update , hopfull next week for the cairo2 thread BR Alex
|
|
|
Post by alexfish on Aug 24, 2020 20:32:39 GMT 1
HI All Final demo compiling XCB _ Cairo think most of the basics are in the code + Slippy Surface , click button 1 and Drag the mouse Screen should update on resize & reconfigure events , some will know this is tricky + the drag on Cairo surfaces again the bits are in the code (sequences). If require the actual monitor screen sizes in pixels & mm there in the WINDOW.scr PRINT "Screen pixels >", WINDOW.scr->width_in_pixels, "*", WINDOW.scr->height_in_pixels PRINT "Screen millimeters >", WINDOW.scr->width_in_millimeters, "*", WINDOW.scr->height_in_millimeters Have Fun BR Alex also in archive at foot of Post OPTION PARSE FALSE
PRAGMA LDFLAGS `pkg-config --libs xcb cairo pango` PRAGMA OPTIONS `pkg-config --cflags xcb cairo pango`
PRAGMA INCLUDE <xcb/xcb.h> PRAGMA INCLUDE <stdint.h> PRAGMA INCLUDE <pango/pangocairo.h> PRAGMA INCLUDE <cairo/cairo-xcb.h> PRAGMA INCLUDE <cairo/cairo.h>
DECLARE values TYPE uint32_t DECLARE c TYPE xcb_connection_t* DECLARE s TYPE xcb_screen_t* DECLARE w TYPE xcb_window_t DECLARE cookie, cookie2, cookie3, cookie4 TYPE xcb_intern_atom_cookie_t DECLARE reply, reply2 ,reply3,reply4 TYPE xcb_intern_atom_reply_t* DECLARE event TYPE xcb_generic_event_t* DECLARE rt TYPE uint8_t DECLARE mev TYPE xcb_motion_notify_event_t * DECLARE b_press TYPE xcb_button_press_event_t * DECLARE motion TYPE xcb_enter_notify_event_t * DECLARE config TYPE xcb_configure_notify_event_t * DECLARE but_press TYPE xcb_button_press_event_t * DECLARE expose TYPE xcb_expose_event_t * RECORD WINDOW LOCAL mouse_seq TYPE int LOCAL sequence TYPE int LOCAL width, height TYPE int LOCAL scrno TYPE int LOCAL scr TYPE xcb_screen_t * LOCAL connection TYPE xcb_connection_t * LOCAL win TYPE xcb_drawable_t LOCAL white TYPE unsigned int LOCAL visual_type TYPE xcb_visualtype_t * LOCAL surface TYPE cairo_surface_t * LOCAL CANVAS TYPE cairo_surface_t * LOCAL CANVAS_CR TYPE cairo_t * LOCAL cr TYPE cairo_t * LOCAL ticks TYPE int LOCAL canX, canY TYPE int LOCAL can_relX, can_relY TYPE int LOCAL offset[2] TYPE uint32_t LOCAL origin[2] TYPE uint32_t END RECORD
SUB cairo_set_rgba(cairo_t *cr,char r,char g,char b,char a) cairo_set_source_rgba(cr,(float)r/255,(float)g/255,(float)b/255,(float)a/255) END SUB
SUB REDRAW() cairo_surface_destroy (WINDOW.surface)
WINDOW.surface = cairo_xcb_surface_create (WINDOW.connection, WINDOW.win, WINDOW.visual_type, WINDOW.width, WINDOW.height)
cairo_destroy(WINDOW.CANVAS_CR)
WINDOW.CANVAS_CR = cairo_create (WINDOW.CANVAS)
cairo_set_rgba(WINDOW.CANVAS_CR,0,27,51,255) cairo_paint(WINDOW.CANVAS_CR)
cairo_save(WINDOW.CANVAS_CR) cairo_restore(WINDOW.CANVAS_CR)
cairo_select_font_face (WINDOW.CANVAS_CR, "dejavu sans mono book", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD) cairo_set_font_size (WINDOW.CANVAS_CR, 16.0) cairo_set_rgba(WINDOW.CANVAS_CR, 255,0, 255,255)
cairo_move_to (WINDOW.CANVAS_CR, 0,16) cairo_show_text (WINDOW.CANVAS_CR, "Hello Cruel World") cairo_stroke (WINDOW.CANVAS_CR)
cairo_move_to (WINDOW.CANVAS_CR, WINDOW.width -155,16) cairo_show_text (WINDOW.CANVAS_CR, "Hello Cruel World") cairo_stroke (WINDOW.CANVAS_CR)
cairo_move_to (WINDOW.CANVAS_CR, (WINDOW.width/2)-75,(WINDOW.height/2)+4) cairo_show_text (WINDOW.CANVAS_CR, "Hello Cruel World") cairo_stroke (WINDOW.CANVAS_CR)
cairo_move_to (WINDOW.CANVAS_CR,0,WINDOW.height -8) cairo_show_text (WINDOW.CANVAS_CR, "Hello Cruel World") cairo_stroke (WINDOW.CANVAS_CR)
cairo_move_to (WINDOW.CANVAS_CR,WINDOW.width -155,WINDOW.height -8) cairo_show_text (WINDOW.CANVAS_CR, "Hello Cruel World") cairo_stroke (WINDOW.CANVAS_CR)
cairo_destroy (WINDOW.cr) WINDOW.cr = cairo_create (WINDOW.surface)
cairo_set_source_surface (WINDOW.cr,WINDOW.CANVAS,0,0) cairo_paint(WINDOW.cr) xcb_flush(WINDOW.connection)
END SUB
SUB DRAW()
cairo_destroy (WINDOW.cr) WINDOW.cr = cairo_create (WINDOW.surface) cairo_set_source_surface (WINDOW.cr,WINDOW.CANVAS,0,0) cairo_paint(WINDOW.cr) xcb_flush(WINDOW.connection)
END SUB
SUB MOVE_SLIPPY_DRAW(double x, double y) 'paint ready drawn surface to cairo xcb surface cairo_destroy (WINDOW.cr) WINDOW.cr = cairo_create (WINDOW.surface) cairo_set_rgba(WINDOW.cr,0,27,51,255) cairo_paint(WINDOW.cr) cairo_set_source_surface (WINDOW.cr,WINDOW.CANVAS,x, y) cairo_paint(WINDOW.cr) xcb_flush(WINDOW.connection)
END SUB
FUNCTION INIT() TYPE int LOCAL iter TYPE xcb_screen_iterator_t LOCAL depth_iter TYPE xcb_depth_iterator_t LOCAL Mvalues TYPE uint32_t Mvalues = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_STRUCTURE_NOTIFY | \ XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_KEY_PRESS | XCB_EVENT_MASK_BUTTON_1_MOTION | XCB_EVENT_MASK_ENTER_WINDOW WINDOW.ticks = 0 WINDOW.width = 800 WINDOW.height = 600 WINDOW.canX=0 WINDOW.canY=0 WINDOW.sequence=0 WINDOW.mouse_seq=0 WINDOW.connection = xcb_connect(NULL,& WINDOW .scrno) iter = xcb_setup_roots_iterator(xcb_get_setup(WINDOW.connection)) ' CAN THIS BE BACONISED USEC for (; iter.rem; --WINDOW.scrno, xcb_screen_next(&iter)) if (WINDOW.scrno == 0) { WINDOW.scr = iter.data; break; }
END USEC 'XCB_EVENT_MASK_ENTER_WINDOW // notify us when the mouse pointer enters any of our controlled windows. 'XCB_EVENT_MASK_LEAVE_WINDOW // notify us when the mouse pointer leaves any of our controlled windows. 'XCB_EVENT_MASK_POINTER_MOTION // motion with no mouse button held 'XCB_EVENT_MASK_BUTTON_MOTION // motion with one or more mouse buttons held 'XCB_EVENT_MASK_BUTTON_1_MOTION // motion while only 1st mouse button is held 'XCB_EVENT_MASK_BUTTON_2_MOTION // and so on... 'XCB_EVENT_MASK_BUTTON_3_MOTION 'XCB_EVENT_MASK_BUTTON_4_MOTION 'XCB_EVENT_MASK_BUTTON_5_MOTION WINDOW.win = xcb_generate_id(WINDOW.connection) WINDOW.white = XCB_CW_BACK_PIXEL xcb_create_window(WINDOW.connection, XCB_COPY_FROM_PARENT, \ WINDOW.win, WINDOW.scr->root, \ 0, 0, \ WINDOW.width, WINDOW.height, \ 5, \ XCB_WINDOW_CLASS_INPUT_OUTPUT, \ WINDOW.scr->root_visual, \ XCB_CW_EVENT_MASK ,&Mvalues) xcb_change_property(WINDOW.connection, XCB_PROP_MODE_REPLACE, \ WINDOW.win, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, strlen("XCB Cairo Example"), \ "XCB Cairo Example"); cookie3 = xcb_intern_atom(WINDOW.connection, 1, 12,"WM_PROTOCOLS") reply3 = xcb_intern_atom_reply(WINDOW.connection, cookie3, 0) cookie4 = xcb_intern_atom(WINDOW.connection, 0, 16,"WM_DELETE_WINDOW") reply4 = xcb_intern_atom_reply(WINDOW.connection, cookie4, 0) xcb_change_property(WINDOW.connection, XCB_PROP_MODE_REPLACE, WINDOW.win, (*reply3).atom, 4, 32, 1, &(*reply4).atom)
xcb_map_window(WINDOW.connection, WINDOW.win); xcb_flush(WINDOW.connection);
depth_iter = xcb_screen_allowed_depths_iterator(WINDOW.scr) ' CAN THIS BE BACONISED USEC for (; depth_iter.rem; xcb_depth_next(&depth_iter)) { xcb_visualtype_iterator_t visual_iter;
visual_iter = xcb_depth_visuals_iterator(depth_iter.data); for (; visual_iter.rem; xcb_visualtype_next(&visual_iter)) { if (WINDOW.scr->root_visual == visual_iter.data->visual_id) { WINDOW.visual_type = visual_iter.data; goto visual_found; } } } END USEC
LABEL visual_found WINDOW.surface = cairo_xcb_surface_create (WINDOW.connection, WINDOW.win, WINDOW.visual_type, WINDOW.width, WINDOW.height) ' draw smaller size canvas WINDOW.CANVAS =cairo_image_surface_create (CAIRO_FORMAT_ARGB32,1920,1080)
REDRAW() RETURN 1 END FUNCTION
FUNCTION DESTROY() TYPE int cairo_destroy (WINDOW.cr) cairo_surface_destroy (WINDOW.surface) cairo_surface_destroy (WINDOW.CANVAS) cairo_destroy (WINDOW.CANVAS_CR) xcb_disconnect(WINDOW.connection) PRINT "Destroy" RETURN 1 END FUNCTION
INIT()
WHILE TRUE DO event = xcb_wait_for_event(WINDOW.connection) rt = (*event).response_type & ~0x80 SELECT rt CASE XCB_EXPOSE
expose= (xcb_expose_event_t *)event 'PRINT "Exp :sequence" ,expose->sequence 'PRINT "Exp count :" ,expose->count IF (expose->sequence = WINDOW.sequence ) THEN
ELSE WINDOW.sequence = expose->sequence REDRAW()
END IF
CASE XCB_CONFIGURE_NOTIFY 'width' height config = (xcb_configure_notify_event_t *)event WINDOW.width = config->width WINDOW.height = config->height 'PRINT "W/H >" ,config->width, ":" , config->height REDRAW()
CASE XCB_CLIENT_MESSAGE IF ((*(xcb_client_message_event_t*)event).data.data32[0] == (*reply4).atom) THEN
DESTROY() BREAK END IF
CASE XCB_MOTION_NOTIFY INCR WINDOW.ticks
WINDOW.ticks = MOD(WINDOW.ticks,1)
IF (WINDOW.ticks = 0) THEN
mev = (xcb_motion_notify_event_t *)event 'PRINT "Mouse :sequence" ,mev->sequence 'PRINT "Mouse count :" ,expose->count IF (mev->sequence = WINDOW.mouse_seq ) THEN
ELSE WINDOW.mouse_seq = mev->sequence MOVE_SLIPPY_DRAW (mev->event_x,mev->event_y)
END IF 'WINDOW->origin[0] += mev->event_x - WINDOW->offset[0] ' WINDOW->origin[1] += mev->event_y - WINDOW->offset[1]
END IF
CASE XCB_BUTTON_PRESS but_press = (xcb_button_press_event_t *)event WINDOW.offset[0] = but_press->event_x WINDOW.offset[1] = but_press->event_y 'b_press = (xcb_button_press_event_t *)event 'MOVEDRAW (b_press->event_x,b_press->event_y)
CASE XCB_ENTER_NOTIFY 'motion = (xcb_enter_notify_event_t *)event 'MOVEDRAW (motion->event_x,motion->event_y)
END SELECT free(event) SLEEP 1 WEND Attachments:XCB.bac.bz2 (2.6 KB)
|
|
|
Post by vovchik on Aug 24, 2020 22:09:05 GMT 1
Dear Alex, Thanks. Looks very good. Now examining the code... With kind regards, vovchik Attachments:
|
|
|
Post by alexfish on Aug 24, 2020 23:13:02 GMT 1
Hi Vovchik screen shoot has been wiped best way is to only have the xcb window on DE then select screenshot grab current window only BR Alex Picky but with black surface Attachments:
|
|
|
Post by alexfish on Aug 31, 2020 10:45:21 GMT 1
Hi All Latest XCB cairo demo; Have cleaned up the redraw functions : rather tedious task find the bits working well but think possible improve the redraw : on window resize less than Have Added Drag :: click in the window & drag the mouse :: cords are shown in top left of window BR Alex Attachments:XCB.bac.bz2 (4.06 KB)
|
|