from pandac.PandaModules import loadPrcFileData
loadPrcFileData('', 'load-display pandagl')
loadPrcFileData('', 'framebuffer-software #t')
loadPrcFileData('', 'framebuffer-depth #t')
loadPrcFileData('', 'depth-bits 24')
loadPrcFileData('', 'color-bits 24')
loadPrcFileData('', 'back-buffers 1')
loadPrcFileData('', 'sync-video 1')
loadPrcFileData('', 'show-frame-rate-meter  #t')
loadPrcFileData('', 'basic-shaders-only #t')
loadPrcFileData('', 'preload-textures 0')
loadPrcFileData('', 'compressed-textures 1')
loadPrcFileData('', 'allow-incomplete-render 1')
from direct.showbase.ShowBase import ShowBase
from pandac.PandaModules import *
from direct.gui.OnscreenText import OnscreenText
from direct.gui.DirectGui import *
from direct.task import Task
from direct.showbase.DirectObject import DirectObject
import sys
class Game(DirectObject):
    def __init__(self):
        base = ShowBase()
        base.setBackgroundColor(1,1,1)
        self.currentbibleimage = 1;
        self.PsalmsFrame = DirectScrolledFrame()
        self.LoadPsalmsFrame()
        for x in range(148):
            if x != 0:
                self.image = self.loadImageAsPlane('psalms/PsalmsJohn' + str(x) + '.jpg')
                self.image.reparentTo(aspect2d)
                self.image.reparentTo(self.PsalmsFrame.getCanvas())    
                offset = 722.5
                self.image.setPos(1.3,0,offset + (-5 * x))
                self.image.setScale(1)
        self.b9 = DirectButton(text=("Image Gallery"),pos=(1.1,0.85,0.85), scale=.06, command=self.ShowBibleImageGallery)  
    def ShowBibleImageGallery(self):        
        self.PsalmsFrame.hide() 
        self.b9.hide()
        self.b10 = DirectButton(text=("<--"),pos=(-1.12,-0.95,-0.95), scale=.15, command=self.PreviousBibleImage)
        self.b11 = DirectButton(text=("-->"),pos=(1.12,-0.95,-0.95), scale=.15, command=self.NextBibleImage) 
        self.currentbibleimage = 1;
        self.image = self.loadBibleImageAsPlane('psalms/BibleImages/' + str(self.currentbibleimage) + '.jpg')
        self.image.reparentTo(render)    
        self.image.setPos(0,12,0)   
        base.camera.setPos(0,0,0)
        base.camera.setHpr(0,0,0)
    def PreviousBibleImage(self):
        self.currentbibleimage = self.currentbibleimage - 1;
        if self.currentbibleimage <= 0:
            self.currentbibleimage = 1
        self.image.removeNode()
        self.image = self.loadBibleImageAsPlane('psalms/BibleImages/' + str(self.currentbibleimage) + '.jpg')
        self.image.reparentTo(render) 
        self.image.setPos(0,12,0)   
        base.camera.setPos(0,0,0)
        base.camera.setHpr(0,0,0) 
    def NextBibleImage(self):
        self.currentbibleimage = self.currentbibleimage + 1;
        if self.currentbibleimage >= 12:
            self.currentbibleimage = 11
        self.image.removeNode()
        self.image = self.loadBibleImageAsPlane('psalms/BibleImages/' + str(self.currentbibleimage) + '.jpg')
        self.image.reparentTo(render)
        self.image.setPos(0,12,0)   
        base.camera.setPos(0,0,0)
        base.camera.setHpr(0,0,0)      
    def LoadPsalmsFrame(self):
        self.PsalmsFrame.removeNode()
        self.PsalmsFrame = DirectScrolledFrame(canvasSize=(0, 0, -20, 720), frameSize=(-1.35, 1.35, -1.5, 1.5),verticalScroll_resizeThumb=(False))
        #self.PsalmsFrame.setPos(-1.2, 0, -0)
        self.PsalmsFrame.setScale(0.6) 
    def loadImageAsPlane(self, filepath, yresolution = 600):
        tex = loader.loadTexture(filepath)
        tex.setBorderColor(Vec4(0,0,0,0))
        tex.setWrapU(Texture.WMBorderColor)
        tex.setWrapV(Texture.WMBorderColor)
        cm = CardMaker(filepath + ' card')
        cm.setFrame(-700, 700, -1200, 1200) 
        card = NodePath(cm.generate())
        card.setTexture(tex)
        card.setScale(card.getScale()/ yresolution)
        card.flattenLight()
        return card
    def loadBibleImageAsPlane(self, filepath, yresolution = 600):
        tex = loader.loadTexture(filepath)
        tex.setBorderColor(Vec4(0,0,0,0))
        tex.setWrapU(Texture.WMBorderColor)
        tex.setWrapV(Texture.WMBorderColor)
        cm = CardMaker(filepath + ' card')
        cm.setFrame(-1920, 1920, -1300, 1300) 
        card = NodePath(cm.generate())
        card.setTexture(tex)
        card.setScale(card.getScale()/ yresolution)
        card.flattenLight()
        return card
fgame = Game()
base.run()