<commit_before>#include "SlideShowConstructor.h"

#include <osg/Geometry>
#include <osg/PolygonOffset>
#include <osg/Geode>
#include <osg/Texture2D>
#include <osg/MatrixTransform>

#include <osgDB/ReadFile>

#include <osgText/Text>


SlideShowConstructor::SlideShowConstructor()
{
    _slideOrigin.set(0.0f,0.0f,0.0f);
    _slideWidth = 1280.0f;
    _slideHeight = 1024.0f;

    _backgroundColor.set(0.0f,0.0f,0.0f,1.0f);
    _textColor.set(1.0f,1.0f,1.0f,1.0f);
    _textFont = "fonts/arial.ttf";

}

void SlideShowConstructor::createPresentation()
{
    _titleHeight = _slideHeight*0.08f;
    _titleWidth = _slideWidth*0.8f;
    _titleOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.5f,0.0f,_slideHeight*0.98f-_titleHeight);

    _textHeight = _slideHeight*0.05f;
    _textWidth = _slideWidth*0.8f;
    
    _textOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.1f,0.0f,_titleOrigin.z()-2*_textHeight);
    _imageOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.7f,0.0f,_titleOrigin.z()*0.5f);
    _modelLeft = _slideOrigin + osg::Vec3(_slideWidth*0.0f,0.0f,_titleOrigin.z()*0.5f);
    _modelRight = _slideOrigin + osg::Vec3(_slideWidth*1.0f,0.0f,_titleOrigin.z()*0.5f);
    
    _root = new osg::ClearNode;
    _root->setClearColor(_backgroundColor);
    
    _presentationSwitch = new osg::Switch;
    _presentationSwitch->setName(std::string("Presentation_")+_presentationName);
    
    _root->addChild(_presentationSwitch.get());
    
}

void SlideShowConstructor::setBackgroundColor(const osg::Vec4& color)
{
    _backgroundColor = color;
    if (_root.valid()) _root->setClearColor(_backgroundColor);
}

void SlideShowConstructor::setTextColor(const osg::Vec4& color)
{
    _textColor = color;
}

void SlideShowConstructor::setPresentationName(const std::string& name)
{
    _presentationName = name;
    if (_presentationSwitch.valid()) _presentationSwitch->setName(std::string("Presentation_")+_presentationName);
}


void SlideShowConstructor::addSlide()
{
    if (!_presentationSwitch) createPresentation();

    // reset cursors
    _textCursor = _textOrigin;
    _imageCursor = _imageOrigin;
    _modelCursor = _modelLeft*0.5f + _modelRight*0.5f;
    
    _slide = new osg::Switch;
    _slide->setName(std::string("Slide_")+_slideTitle);
    
    _presentationSwitch->addChild(_slide.get());

    _previousLayer = 0;
    _currentLayer = 0;    
}

void SlideShowConstructor::addLayer()
{
    if (!_slide) addSlide();

    _previousLayer = _currentLayer;
    
    _currentLayer = new osg::Group;
    
    _slide->addChild(_currentLayer.get());
    
    if (!_previousLayer)
    {
        // create the background and title..
        if (!_slideBackgroundImageFileName.empty())
        {
            osg::Geometry* backgroundQuad = osg::createTexturedQuadGeometry(_slideOrigin,
                                                            osg::Vec3(_slideWidth,0.0f,0.0f),
                                                            osg::Vec3(0.0f,0.0f,_slideHeight));

            osg::Geode* background = new osg::Geode;

            osg::StateSet* backgroundStateSet = background->getOrCreateStateSet();
            backgroundStateSet->setAttributeAndModes(
                        new osg::PolygonOffset(1.0f,1.0f),
                        osg::StateAttribute::ON);

            backgroundStateSet->setTextureAttributeAndModes(0,
                        new osg::Texture2D(osgDB::readImageFile(_slideBackgroundImageFileName)),
                        osg::StateAttribute::ON);

            background->addDrawable(backgroundQuad);

            _currentLayer->addChild(background);
        }
        
        if (!_slideTitle.empty())
        {
            osg::Geode* geode = new osg::Geode;

            osgText::Text* text = new osgText::Text;
            text->setFont(_textFont);
            text->setColor(_textColor);
            text->setCharacterSize(_titleHeight);
            text->setMaximumWidth(_titleWidth);
            text->setAxisAlignment(osgText::Text::XZ_PLANE);
            text->setAlignment(osgText::Text::CENTER_BASE_LINE);
            text->setPosition(_titleOrigin);

            text->setText(_slideTitle);

            geode->addDrawable(text);

            _currentLayer->addChild(geode);
        }
        <commit_msg>From Gideon, update to the PolygonOffset for the background quad.<commit_after>#include "SlideShowConstructor.h"

#include <osg/Geometry>
#include <osg/PolygonOffset>
#include <osg/Geode>
#include <osg/Texture2D>
#include <osg/MatrixTransform>

#include <osgDB/ReadFile>

#include <osgText/Text>


SlideShowConstructor::SlideShowConstructor()
{
    _slideOrigin.set(0.0f,0.0f,0.0f);
    _slideWidth = 1280.0f;
    _slideHeight = 1024.0f;

    _backgroundColor.set(0.0f,0.0f,0.0f,1.0f);
    _textColor.set(1.0f,1.0f,1.0f,1.0f);
    _textFont = "fonts/arial.ttf";

}

void SlideShowConstructor::createPresentation()
{
    _titleHeight = _slideHeight*0.08f;
    _titleWidth = _slideWidth*0.8f;
    _titleOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.5f,0.0f,_slideHeight*0.98f-_titleHeight);

    _textHeight = _slideHeight*0.05f;
    _textWidth = _slideWidth*0.8f;
    
    _textOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.1f,0.0f,_titleOrigin.z()-2*_textHeight);
    _imageOrigin = _slideOrigin + osg::Vec3(_slideWidth*0.7f,0.0f,_titleOrigin.z()*0.5f);
    _modelLeft = _slideOrigin + osg::Vec3(_slideWidth*0.0f,0.0f,_titleOrigin.z()*0.5f);
    _modelRight = _slideOrigin + osg::Vec3(_slideWidth*1.0f,0.0f,_titleOrigin.z()*0.5f);
    
    _root = new osg::ClearNode;
    _root->setClearColor(_backgroundColor);
    
    _presentationSwitch = new osg::Switch;
    _presentationSwitch->setName(std::string("Presentation_")+_presentationName);
    
    _root->addChild(_presentationSwitch.get());
    
}

void SlideShowConstructor::setBackgroundColor(const osg::Vec4& color)
{
    _backgroundColor = color;
    if (_root.valid()) _root->setClearColor(_backgroundColor);
}

void SlideShowConstructor::setTextColor(const osg::Vec4& color)
{
    _textColor = color;
}

void SlideShowConstructor::setPresentationName(const std::string& name)
{
    _presentationName = name;
    if (_presentationSwitch.valid()) _presentationSwitch->setName(std::string("Presentation_")+_presentationName);
}


void SlideShowConstructor::addSlide()
{
    if (!_presentationSwitch) createPresentation();

    // reset cursors
    _textCursor = _textOrigin;
    _imageCursor = _imageOrigin;
    _modelCursor = _modelLeft*0.5f + _modelRight*0.5f;
    
    _slide = new osg::Switch;
    _slide->setName(std::string("Slide_")+_slideTitle);
    
    _presentationSwitch->addChild(_slide.get());

    _previousLayer = 0;
    _currentLayer = 0;    
}

void SlideShowConstructor::addLayer()
{
    if (!_slide) addSlide();

    _previousLayer = _currentLayer;
    
    _currentLayer = new osg::Group;
    
    _slide->addChild(_currentLayer.get());
    
    if (!_previousLayer)
    {
        // create the background and title..
        if (!_slideBackgroundImageFileName.empty())
        {
            osg::Geometry* backgroundQuad = osg::createTexturedQuadGeometry(_slideOrigin,
                                                            osg::Vec3(_slideWidth,0.0f,0.0f),
                                                            osg::Vec3(0.0f,0.0f,_slideHeight));

            osg::Geode* background = new osg::Geode;

            osg::StateSet* backgroundStateSet = background->getOrCreateStateSet();
            backgroundStateSet->setAttributeAndModes(
                        new osg::PolygonOffset(1.0f,2.0f),
                        osg::StateAttribute::ON);

            backgroundStateSet->setTextureAttributeAndModes(0,
                        new osg::Texture2D(osgDB::readImageFile(_slideBackgroundImageFileName)),
                        osg::StateAttribute::ON);

            background->addDrawable(backgroundQuad);

            _currentLayer->addChild(background);
        }
        
        if (!_slideTitle.empty())
        {
            osg::Geode* geode = new osg::Geode;

            osgText::Text* text = new osgText::Text;
            text->setFont(_textFont);
            text->setColor(_textColor);
            text->setCharacterSize(_titleHeight);
            text->setMaximumWidth(_titleWidth);
            text->setAxisAlignment(osgText::Text::XZ_PLANE);
            text->setAlignment(osgText::Text::CENTER_BASE_LINE);
            text->setPosition(_titleOrigin);

            text->setText(_slideTitle);

            geode->addDrawable(text);

            _currentLayer->addChild(geode);
        }
        
{'fraction_non_alphanumeric': 0.12736179146256124, 'fraction_numerical': 0.023792862141357594, 'mean_word_length': 2.946157386102163, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7141113', 'n_tokens_mistral': 2841, 'n_tokens_neox': 2750, 'n_words': 347}