Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Usage of builder-made drawing area with plplot #288

Open
lllaxmatist opened this issue Jun 19, 2024 · 1 comment
Open

Usage of builder-made drawing area with plplot #288

lllaxmatist opened this issue Jun 19, 2024 · 1 comment

Comments

@lllaxmatist
Copy link

I was trying to make work with plplot, i was doing the same steps as in examples.
(I have trшed it in both gtk4 and gtk-3. it is all the same):
At first i was getting hl_gtk_pixbuf_cairo_new:: Backing surface is NULL error.

I have realised, I am getting that because drawing area is created with builder, instead of hl_gtk_drawing_area_new.
In hl_gtk_drawing_area_new there is setting of backing surface:
call g_object_set_data(plota, "backing-surface", isurface)

I was trying to made some setting function to mimic what hl_gtk_drawing_area_new doing, but to builder-made drawing area:

  subroutine drawing_area_set(area, has_alpha, cairo_status)
  
	type(c_ptr) :: area !pointer to existing drawing-area
	integer(kind=c_int), intent(in), optional :: has_alpha
	integer(kind=c_int), intent(out), optional :: cairo_status
	
	type(c_ptr) :: isurface, cstat_cstr
	integer(kind=c_int) :: mask, insert_mask
	integer(kind=c_int) :: auto_add, s_type
	integer(kind=c_int) ::szx, szy
	type(c_ptr) :: szx_cp, szy_cp	
	logical :: rgba
	integer(kind=c_int) :: cstat
	character(len=120) :: cstat_fstr
	
	!Not working, type mismatch int(4) to c_ptr:
	!call gtk_widget_get_size_request (area, szx, szy)
	
	!Makeshift workaround untilll get_size_request is working
	szx = 300
	szy = 300
	
	if (present(has_alpha)) then
       rgba = c_f_logical(has_alpha)
	else
       rgba = .false.
	end if
	
	if (rgba) then
       s_type = CAIRO_FORMAT_ARGB32
	else
       s_type = CAIRO_FORMAT_RGB24
	end if
  
	isurface = cairo_image_surface_create(s_type, szx, szy)
	isurface = cairo_surface_reference(isurface)   ! Prevent accidental deletion
	call g_object_set_data(area, "backing-surface", isurface)
	
	if (present(cairo_status)) then
       cairo_status = cairo_surface_status(isurface)
    else
       cstat = cairo_surface_status(isurface)
       if (cstat /= CAIRO_STATUS_SUCCESS) then
          cstat_cstr = cairo_status_to_string(cstat)
          call c_f_string(cstat_cstr, cstat_fstr)
          write(error_unit, "(A)") &
               & "GTK_DRAWING_AREA_SET: Error creating backing store", &
               & trim(cstat_fstr)
       end if
    end if
 endsubroutine drawing_area_set

But it gets me no result. It is hl_gtk_pixbuf_cairo_new:: Backing surface is NULL anyway.
What am i doing wrong?
What is the correct way to use plplot with builder-made drawing area?

P.s. all examples are working, so that is all on my end.

@vmagnin
Copy link
Owner

vmagnin commented Jun 19, 2024

I will have a look when I have time.

At first sight, what I can say is that the error message hl_gtk_pixbuf_cairo_new:: Backing surface is NULL comes from that file:

$ ack hl_gtk_pixbuf_cairo_new
src/gtk-draw-hl.f90
614:       write(error_unit,*) "hl_gtk_pixbuf_cairo_new:: Backing surface is NULL"

That line is in the function hl_gtk_drawing_area_cairo_new(), which contains some comments:

    ! Create a cairo context which will draw into the backing surface
    !
    ! AREA |  c_ptr |  required |  The drawing area to which we will draw.
    !
    ! After the drawing operations, you should call `gtk_widget_queue_draw`
    ! to update the plot on the screen and `hl_gtk_pixbuf_cairo_destroy`
    ! to destroy the cairo context.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants