Silverfrost Forums

Welcome to our forums

Problem with rotate_font@

21 May 2020 9:32 #25486

I think this example may point to a bug, or perhaps I am doing something silly?

module example_22_5_20
use clrwin
implicit none
integer, parameter :: dp=kind(1.d0), gw = 800, gh = 600
real(kind=dp) :: x_array(1:20)=0.d0 , y_array(1:20)=0.d0

contains

  integer function generate_data()
  integer i
    do i = 1, 20
      x_array(i)=random@() - 0.5d0  ; y_array(i)=random@() - 0.5d0
    end do
    generate_data = 2
  end function generate_data

  integer function plot()
  integer, save :: iw
    call winop@('%pl[independent,x_array,link=none,symbol=6,gridlines,frame,margin=(100,100,100,100)]') 
    iw = winio@('%pl&',gw,gh,20,x_array,y_array) 
    iw = winio@('%ob&')
    iw = winio@('%^tt[SP redraw]&',sp_redraw_cb)
    iw = winio@('%2nl%^tt[x_axis]&',x_axis_cb)
    iw = winio@('%2nl%ws&','1. Click on x axis button, and note position of text drawn on screen.')
    iw = winio@('%1nl%ws&','2. Click on SP redraw button.')
    iw = winio@('%1nl%ws&','3. Click on x axis button.  Text is now drawn in different position.')
    iw = winio@('%2nl%ws&','If the calls to rotate_font@ (associated with drawing y axis text)')
    iw = winio@('%1nl%ws&','are commented out this does not happen.')
    iw = winio@('%cb&')
    iw = winio@(' ')

    iw = winio@('%gr&',gw,gh) 
    iw = winio@('%ob&')
    iw = winio@('%^tt[SP redraw]&',sp_redraw_cb)
    iw = winio@('%2nl%^tt[x_axis]&',x_axis_cb)
    iw = winio@('%2nl%ws&','1. Click on x axis button, and note position of text drawn on screen.')
    iw = winio@('%1nl%ws&','2. Click on SP redraw button.')
    iw = winio@('%1nl%ws&','3. Click on x axis button.  Text is now drawn in different position.')
    iw = winio@('%2nl%ws&','If the calls to rotate_font@ (associated with drawing y axis text)')
    iw = winio@('%1nl%ws&','are commented out this does not happen.')
    iw = winio@('%cb&')
    iw = winio@(' ')
    
    plot = 2
  end function plot

  integer function sp_redraw_cb()
    call simpleplot_redraw@()
    sp_redraw_cb = 2
  end function sp_redraw_cb

  integer function x_axis_cb()
  integer tw, th
    call get_text_size@('x label', tw, th)
    call draw_characters@('x label', 400 - tw, gh-50, rgb@(0,0,0))
    call rotate_font@(90.d0)
    ! Here draw y label
    !
    call rotate_font(0.d0)  !Reset default angle for drawing text to horizontal
    x_axis_cb = 2
  end function x_axis_cb

end module example_22_5_20

program main
use example_22_5_20
implicit none
integer i
  i = generate_data() ; i = plot() ; i=i
end program main
21 May 2020 9:49 #25487

Missing the @ in my second call to rotate_font in the code above - but the problem still exists when this is corrected.

21 May 2020 10:52 #25488

Maybe rotate_font@ does not work that way and you have to rotate back again.

Try a simple %gr with just draw_characters@ and rotate_font@.

21 May 2020 11:10 #25489

Paul,

I discovered by accident that a call to rotate_font@(0.d0) immediately, before the call to draw_characters@ fixes the problem. Without this, the text is initially drawn in the incorrect place, the first time the callback runs.

Ken

  integer function x_axis_cb()
  integer tw, th
    call get_text_size@('x label', tw, th)
    call draw_line_between@(0, gh-100, gw, gh - 100, rgb@(255,0,0))
    call draw_line_between@(0, gh-50, gw, gh - 50, rgb@(255,0,0))
    call rotate_font@(0.d0)                                         !COMMENT OUT TO SEE ERROR IN Y POSITION
    call draw_characters@('x label', 400 - tw, gh-50, rgb@(0,0,0))
    call rotate_font@(90.d0)
    ! Here draw y label
    !
    call rotate_font@(0.d0)  !Reset default angle for drawing text to horizontal
    x_axis_cb = 2
  end function x_axis_cb
Please login to reply.