Program T_navod1

!! K navodu pro modul Japigraf
!! Vypis promennych nastavenych procedurami StartJapi, DefViewPort
!! ukazka kresby na Viewport (PortArea, canvas)

use std_type
		! vsechny realne promenne v Japigraf jsou REAL(KIND=DP)
		! g95 umoznuje zkraceny zapis, napr. REAL(DP) misto REAL(KIND=DP)
use japi
use japigraf
use rgbcolor


implicit none

character(len=*),parameter :: CRLF = char(13)//char(10)

integer :: frame, canvas
	! pro normalni souradnice leveho horniho rohu frame
real(DP) :: NposxFR, NposyFR
	! pro velikost PortArea v normalnich souradnicich
real(DP) :: NsirkaPA, NvyskaPA
	! uzivatelske souradnice pro PlotArea
real(DP) :: uxmin,uymin,uxmax,uymax
	! pro SetAspRatio .true. zmeni rozmer osy x nebo y tak,
	! aby "ctverec byl ctverec"
logical :: SetAspRat 	! co udela s ViewPortem zmena na .true. ?
	! barvy pro canvas a PlotArea
type(rgbcol) :: canvasColor, PlotAreaColor 
type(userCO) :: coU		! pro uxmin,uxmax,uymin,uymax z infVP
Type(objCO) :: coP		! pro polx,poly,psirka,pvyska z infVP
type(Ubod) :: Umin, Umax
type(Ubod),dimension(5) :: vrcholy	!vrcholy ctverce pro UPolyLine
type(ViewPortInfo) :: infVP

! *****************  zahajeni volanim StartJapi() **********************
call StartJapi()

print *,"Promenne nastavene po provedeni CALL StartJapi()"
print "(2(a15,i5),a20,f5.3,a)","S_width = ",S_width,"S_height = ",S_height,&
								 "AspRatio = ",AspRatio,CRLF
print *,"Poloha PlotArea na canvas, mozno zmenit pred volanim DefViewPort"
print "(4(a15,i5),a)","PAleft=",PAleft,"PAright=",PAright,&
					"PAtop=",PAtop,"PAbottom=",PAbottom,CRLF


! ***************** pokracovani volanim DefViewPort ********************
!
! definice noveho ViewPortu; pozice+ rozmery frame jsou zadany ciselne
! k tomu se programove stanovi rozmery canvas a PlotArea
! uzivatelske souradnice pro PlotArea jsou opet zadany ciselne

print *,CRLF//"Provedeno CALL DefViewPort(...)"//CRLF

PAright=40     ! zmena praveho okraje pro PlotArea na canvas z 10 na 40 pixelu
NposxFR = 0.1
NposyFR = 0.1
NsirkaPA = 0.7
NvyskaPA = 0.5
uxmin = -1.1
uxmax = 1.1
uymin = -4.1
uymax = 4.1
canvasColor = AntiqueWhite
PlotAreaColor = white
SetAspRat = .true.
! zkuste zmenit na .true.

call DefViewPort(NposxFR,NposyFR,"Program T_navod1 k navodu pro Japigraf",&
				 NsirkaPA,NvyskaPA,SetAspRat,&
				 uxmin,uxmax,uymin,uymax,&
				 canvasColor,PlotAreaColor,&
				 infVP)
				 
! odkazy (handlery) pro frame a canvas ziskane z vystupni promenne infVP
frame = infVP%frame
canvas = infVP%frame
print *,CRLF//"Handlery pro frame a canvas"
print "(2(a20,i2),a)","infVP%frame = ",frame,"infVP%canvas = ",canvas,CRLF

! priklady moznosti prace s uzivatelskymi jednotkami ziskanymi z infVP
! --------- VVVVVVVV ----------- PlotArea
coU = infVP%PlotAreaUPinfo%Uinfo			! uxmin,uxmax,uymin,uymax
print *,"Ruzne zpusoby vypisu promenne TYPE(userCO) = coU pro PlotArea"//CRLF
print *,coU
print "(a,4f10.3)",crlf,coU
print *
print "(2f10.3)",coU
print *
print "(f10.3)",coU

Umin = Ubod(coU%uxmin,coU%uymin)			! uxmin, uymin
uxmax = coU%uxmax
uymax = infVP%PlotAreaUPinfo%Uinfo%uymax	! uymax primo z infVP

! ----------VVVVVV ----------- canvas
coU = infVP%canvasUPinfo%Uinfo	! uxmin,uxmax,uymin,uymax
print *,CRLF//" Uzivatelske souradnice pro canvas"
print *,"(definuji se pro PlotArea ale rozsiruji se na canvas)"
print "(4f10.3)",coU
! 
coP = infVP%canvasUPinfo%Pinfo	! uxmin,uxmax,uymin,uymax
print *,CRLF//" polx,poly,psirka,pvyska pro canvas"
print "(4i6)",coP

! Pocty pixelu na uzivatelskou jednotku ve smeru x a y
print *,CRLF//"Pocet pixelu na uzivatelskou jednotku ve smeru x a y"
print "(a20,i5)","infVP%pix2ux = ",infVP%pix2ux,&
					"infVP%pix2uy = ",infVP%pix2uy

! az n8sledujici prikaz (CALL j_show) zobrazi ViewPort (frame) na obrazovku
print *,CRLF//"Enter:  CALL j_show(infVP%frame) provede zobrazeni ViewPortu"
read *
call j_show(infVP%frame)
call Sleep(3)	! pauza 5sec, rozsireni zabudovanych procedur g95 !

! *************** Nekolik jednoduchych kreslicich prikazu ******************** 
! +++++ Kresba usecek +++++
	! kresba usecky spojujici 2 body
call Uline(infVP,Ubod(uxmin,uymin),Ubod(uxmax,uymax),SpringGreen)
	! nastaveni grafickeho kuzoru do vychoziho bodu a kresba cary do koncoveho
call Sleep(2)	
call USetGcursor(infVP,Ubod(uxmin,uymax))
call ULineTo(infVP,Ubod(uxmax,uymin),ForestGreen)
	! po provedeni ULineTo je Gcursor nastaveny do koncoveho bodu usecky
	! takze je mozne pokracovat dale
Call Sleep(2)
call UlineTo(infVP,Ubod(uxmin,uymin),black)
call UlineTo(infVP,Ubod(uxmin,uymax),black)

call Sleep(3)

! +++++ Clipping (omezeni kresby jen na canvas nebo PlotArea) +++++
	! standardne je nastaveny clipping na canvas (kresba jen na canvas)
call Uline(infVP,Ubod(1.5*uxmin,0.0),Ubod(1.5*uxmax,0.0),Goldenrod)
call Sleep(2)
	! Procedura ClipPlotArea nastavi clipping na PlotArea
call ClipPlotArea(infVP)	
call Uline(infVP,Ubod(1.5*uxmin,0.05),Ubod(1.5*uxmax,0.05),tomato)
call Sleep(2)
	! POZOR ! provedeme-li clipping zpet na canvas, nic se nestane.
	! Je to proto, ze JAPI k tomu pouziva javovskou proceduru "cliprect",
	! ktera (bohuzel) po opetovnem volani ohranici oblast, ktera
	! je PRUNIKEM puvodne nastavene oblasti (u nas nyni PlotArea) a nove
	! nastavovane oblasti (zadame canvas, prunik je ale PlotArea)	
call ClipCanvas(infVP)
call Uline(infVP,Ubod(1.5*uxmin,-0.05),Ubod(1.5*uxmax,-0.05),peru)
call Sleep(5)

! +++++ Nazorna ukazka vlivu nastaveni promenne SetAspRat +++++
	!  Nastavte SetAspRat = .true.|.false. a sledujte graf
	! nakresli kruznici s polomerem 1 a stredem v (0,0)  
	
call DrawCircle(infVP,Ubod(0.0,0.0),1.0_DP,LightCoral)

	! vrcholy ctverce opsaneho kruznici
vrcholy = (/Ubod(-1.0,-1.0),Ubod(-1.0,1.0),Ubod(1.0,1.0),&
			Ubod(1.0,-1.0),Ubod(-1.0,-1.0)/)	! UPolyLine jen spojuje po sobe
call UpolyLine(infVP,vrcholy,CornflowerBlue)	! jdouci body, proto 5	

print *,"ENTER ukonci program"
read *

call StopJapi()

end program T_navod1
