program T_navod5

!!	Modifikace T_navod4 s vyuzitim doplnujicich procedur v Japigraf ver.2.4
!!  ===========================================================================
!! K navodu pro modul Japigraf
!! Prace s vlastnimi procedurami JAPI - dve canvas na frame
!! USE Japigraf+USE rgbcolor umozni vyuzit nektere procedury Japigraf a rgbcolor
!! Start procedurou StartJapi() nastavi S_width,S_height,AspRatio
!! a umozni pouzivat normalni souradnice misto pixelu a funkce Nx2Pix, Ny2Pix
!! Castecna nebo uplna rekonstrukce promenne TYPE(ViewPortInfo) :: infVP
!! umozni vyuzivat dalsi procedury z Japigraf (1.parametr maji infVP)


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, canvas1, canvas2
	! normalni souradnice leveho horniho rohu + rozmer frame
real(DP) :: NposxFR, NposyFR, NsirkaFR, NvyskaFR
	! normalni souradnice pro polohu a rozmer canvas1
real(DP) :: NposxC1, NposyC1, NsirkaC1, NvyskaC1
	! normalni souradnice pro polohu a rozmer canvas2
real(DP) :: NposxC2, NposyC2, NsirkaC2, NvyskaC2
	! pro zadani RGB barvy
type(rgbcol) :: BGcolorFR, BGcolorC1, BGcolorC2,PAcolor
	! promenne ktere po castecnem naplneni dovoli volat 
	! nektere procedury Japigraf
type(Frameinfo) :: infFR
Type(CanvasInfo) :: infC1,infC2
type(PlotAreaInfo) :: infPA
type(ViewPortInfo) :: infVP1,infVP2
	!~ ! promenne pro ulozeni prevodu Nx2Pix,... pro canvas1,canvas2
!~ integer :: PxC1,PyC1,PsirkaC1,PvyskaC1,PxC2,PyC2,PsirkaC2,PvyskaC2	
real(DP) :: uxminC2,uyminC2,uxmaxC2,uymaxC2
	!~ ! pomocne promenne
!~ character(len=60) :: text
!~ type(Pbod) :: poloha
!~ real(DP) :: dux, duy



! *****************  zahajeni volanim StartJapi() ***********************
! Nastavi S_width,S_height,AspRatio
! umozni pouzivani normalnich souradnic s pouzitim prevodu Nx2Pix, Ny2Pix
call StartJapi()

! ****************   pokracovani ****************************************
! nastavit frame a na nem dve canvas
	! oro frame
	! Normalni souradnice se vztahuji k cele obrazovce
NposxFR = 0.2
NposyFR = 0.1
NsirkaFR = 0.7
NvyskaFR = 0.6
BGcolorFR = lavender

	! Pro canvas se normalni souradnice vztahuji k frame !!!
	! pro canvas1
NposxC1 = 0.05
NposyC1 = 0.2
NsirkaC1 = 0.3
NvyskaC1 = 0.35
BGcolorC1 = AntiqueWhite
	! pro canvas2
NposxC2 = 0.4
NposyC2 = 0.1
NsirkaC2 = 0.25
NvyskaC2 = 0.45
BGcolorC2 = MintCream
uxminC2 = 0
uxmaxC2 = 10.0
uyminC2 = 0
uymaxC2 = 10.0

	! definice frame
infFR = NastavFrame(NobjCO(NposxFR,NposyFR,NsirkaFR,NvyskaFR),&
					"Program T_navod5",BGcolorFR)
frame = infFR%frame
	! definice canvas1, pouzity default Umeze a BGbarva
	! PlotArea je cela canvas, uzivatelske jednotky: 0<=x<=100, 0<=y<=100 
infC1 = NastavCanvas(frame,NobjCO(NposxC1,NposyC1,NsirkaC1,NvyskaC1))
canvas1 = infC1%canvas

	! definice canvas2 s  PlotArea
infPA = PlotAreaInfo(35,15,35,15)	! PAleft, PAright, PAbottom, PAtop
PAcolor = white					! barva PlotArea
infC2 = NastavCanvas(frame,NobjCO(NposxC2,NposyC2,NsirkaC2,NvyskaC2),&
					userCO(uxminC2,uxmaxC2,uyminC2,uymaxC2),BGcolorC2,&
					infPA,PAcolor)
canvas2 = infC2%canvas
!======================== vse Zobrazit ========================================
call j_show(frame)

!======================== KRESLENI NA CANVAS ==================================
!=========================== Sestaveni infVP ==================================
! Sestavene promenne infVP1, infVP2 pouzijeme pro volani procedur z Japigraf
! S infVP1 pujde vystup na canvas1 a s infVP2 na canvas2

infVP1 = SestavVPinfo(infFR,infC1)	
infVP2 = SestavVPinfo(infFR,infC2)

! vystup na canvas1
call ULine(infVP1,Ubod(10.0,10.0),Ubod(90.0,90.0),red)
call PlotSymbol5(infVP1,Ubod(0.0_DP,0.0_DP),ctvr5f,red)
call PlotSymbol5(infVP1,Ubod(100.0_DP,0.0_DP),ctvr5f,red)
call PlotSymbol5(infVP1,Ubod(0.0_DP,100.0_DP),ctvr5f,red)
call PlotSymbol5(infVP1,Ubod(100.0_DP,100.0_DP),ctvr5f,red)

! vystup na canvas2
call OsaX(infVP2,uxminC2,uxmaxC2,uyminC2,2.0_DP,4,navy,.true.,gray80)
call OsaY(infVP2,uyminC2,uymaxC2,uxminC2,2.0_DP,4,navy,.true.,gray80)
call ULine(infVP2,Ubod(0.0,0.0),Ubod(10.0,10.0),blue)
call PlotSymbol5(infVP2,Ubod(0.0,0.0),ctvr5f,red)
call PlotSymbol5(infVP2,Ubod(10.0,0.0),ctvr5f,red)
call PlotSymbol5(infVP2,Ubod(0.0,10.0),ctvr5f,red)
call PlotSymbol5(infVP2,Ubod(10.0,10.0),ctvr5f,red)

! Vliv procedury ClipPlotArea
! Zatim je nastavena ClipCanvas
call ULine(infVP2,Ubod(-5,3),Ubod(11,3),MediumSeaGreen)

! nyni nastavime clipping na PlotArea
call ClipPlotArea(infVP2)
call ULine(infVP2,Ubod(-5,3.5),Ubod(11,3.5),chocolate)

! bohuzel algoritmus pracuje tak, ze se nelze vratit zpet na Canvas
! naopak, nelze uz kreslit ani do PlotArea
call ClipCanvas(infVP2)
call ULine(infVP2,Ubod(1.0,4.0),Ubod(9.0,4.0),blue)
call PlotSymbol5(infVP2,Ubod(5.0,5.0),ctvr5f,red)

! informativni vystup mezi pro canvas se zavedenym PlotArea
! uzivatelske jednotky uvedene pro canvas se pouziji pro PlotArea
Print *,"Opravene Umeze pro canvas je-li definovan PlotArea"
print *,Ubod(infC2%UmezeC%uxmin,infC2%UmezeC%uymin)
print *,Ubod(infC2%UmezeC%uxmax,infC2%UmezeC%uymax)

! pridani standardniho menu, lze pouzit infVP1 nebo infVP2 (stejne frame!)
call AddStdMenu(infVP1)

! odpoznamkovani: tisk a ukladani obrazku canvas1
!~ call StartStdMenu(infVP1)

! odpoznamkovani: tisk a ukladani obrazku canvas2
call StartStdMenu(infVP2)


end program T_navod5
