<commit_before>#include <stdio.h>
#include "allocore/io/al_App.hpp"

namespace al{
//______________________________________________________________________________

Viewpoint::Viewpoint(const Pose& transform)
:	mViewport(0,0,0,0),
	mParentTransform(NULL), mTransform(transform),
	mAnchorX(0), mAnchorY(0), mStretchX(1), mStretchY(1),
	mLens(NULL), mClearColor(NULL)
{}

Viewpoint& Viewpoint::anchor(float ax, float ay){
	mAnchorX=ax; mAnchorY=ay; return *this;
}

Viewpoint& Viewpoint::stretch(float sx, float sy){
	mStretchX=sx; mStretchY=sy; return *this;
}

Frustumd Viewpoint::frustum() const {
	Frustumd fr;
	lens().frustum(fr, worldTransform(), viewport().aspect());
	return fr;
}

void Viewpoint::onParentResize(int w, int h){
	mViewport.l = w * anchorX();
	mViewport.b = h * anchorY();
	mViewport.w = w * stretchX();
	mViewport.h = h * stretchY();
}

//______________________________________________________________________________

ViewpointWindow::ViewpointWindow(){
	append(mStandardKeyControls);
}

ViewpointWindow::ViewpointWindow(
	const Dim& dims,
	const std::string title,
	double fps,
	DisplayMode mode
)
:	ViewpointWindow()
{
	create(dims, title, fps, mode);
}

bool ViewpointWindow::onResize(int w, int h){
	//printf("ViewpointWindow onResize: %d %d\n", w, h);
	for(auto * vp : mViewpoints){
		vp->onParentResize(w, h);
		//printf("%g %g %g %g\n", vp->viewport().l, vp->viewport().b, vp->viewport().w, vp->viewport().h);
	}

	mResized = true;

	return true;
}

ViewpointWindow& ViewpointWindow::add(Viewpoint& v){
	mViewpoints.push_back(&v);

	// If the window is already created, then we need to manually update the
	// Viewpoint. Otherwise, this happens through ViewpointWindow::onResize().
	if(created()){
		v.onParentResize(width(), height());
	}
	return *this;
}

//______________________________________________________________________________

struct SceneInputHandler : public InputEventHandler{
	ViewpointWindow& win;
	App& app;

	SceneInputHandler(ViewpointWindow& w, App& a): win(w), app(a){}

	bool onKeyDown(const Keyboard& k){
		app.onKeyDown(win, k);
		switch(k.key()){
			case Keyboard::TAB:
				app.stereo().stereo(!app.stereo().stereo());
				return false;
			default:;
		}
		return true;
	}
	bool onKeyUp(const Keyboard& k){ app.onKeyUp(win,k); return true;}
	bool onMouseDown(const Mouse& m){ app.onMouseDown(win,m); return true;}
	bool onMouseUp(const Mouse& m){ app.onMouseUp(win,m); return true;}
	bool onMouseDrag(const Mouse& m){ app.onMouseDrag(win,m); return true;}
	bool onMouseMove(const Mouse& m){ app.onMouseMove(win,m); return true;}
};

// attached to each ViewpointWindow
struct SceneWindowHandler : public WindowEventHandler{
	ViewpointWindow& win;
	App& app;

	SceneWindowHandler(ViewpointWindow& w, App& a): win(w), app(a){}

	bool onCreate(){
/*
		#ifdef AL_GRAPHICS_SUPPORTS_FIXED_PIPELINE
		// Enable color material to simplify cases where materials are not used 
		// explicitly (e.g., only mesh colors are used).
		glEnable(GL_COLOR_MATERIAL);
			#ifdef AL_GRAPHICS_SUPPORTS_COLOR_MATERIAL_SPEC
			glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
			#endif
		#endif
*/
		app.onCreate(win);
		return true;
	}
	bool onDestroy(){ app.onDestroy(win); return true; }
	bool onResize(int dw, int dh){ app.onResize(win, dw,dh); return true; }

	virtual bool onFrame();
};

bool SceneWindowHandler::onFrame(){<commit_msg>App: undo commented out code<commit_after>#include <stdio.h>
#include "allocore/io/al_App.hpp"

namespace al{
//______________________________________________________________________________

Viewpoint::Viewpoint(const Pose& transform)
:	mViewport(0,0,0,0),
	mParentTransform(NULL), mTransform(transform),
	mAnchorX(0), mAnchorY(0), mStretchX(1), mStretchY(1),
	mLens(NULL), mClearColor(NULL)
{}

Viewpoint& Viewpoint::anchor(float ax, float ay){
	mAnchorX=ax; mAnchorY=ay; return *this;
}

Viewpoint& Viewpoint::stretch(float sx, float sy){
	mStretchX=sx; mStretchY=sy; return *this;
}

Frustumd Viewpoint::frustum() const {
	Frustumd fr;
	lens().frustum(fr, worldTransform(), viewport().aspect());
	return fr;
}

void Viewpoint::onParentResize(int w, int h){
	mViewport.l = w * anchorX();
	mViewport.b = h * anchorY();
	mViewport.w = w * stretchX();
	mViewport.h = h * stretchY();
}

//______________________________________________________________________________

ViewpointWindow::ViewpointWindow(){
	append(mStandardKeyControls);
}

ViewpointWindow::ViewpointWindow(
	const Dim& dims,
	const std::string title,
	double fps,
	DisplayMode mode
)
:	ViewpointWindow()
{
	create(dims, title, fps, mode);
}

bool ViewpointWindow::onResize(int w, int h){
	//printf("ViewpointWindow onResize: %d %d\n", w, h);
	for(auto * vp : mViewpoints){
		vp->onParentResize(w, h);
		//printf("%g %g %g %g\n", vp->viewport().l, vp->viewport().b, vp->viewport().w, vp->viewport().h);
	}

	mResized = true;

	return true;
}

ViewpointWindow& ViewpointWindow::add(Viewpoint& v){
	mViewpoints.push_back(&v);

	// If the window is already created, then we need to manually update the
	// Viewpoint. Otherwise, this happens through ViewpointWindow::onResize().
	if(created()){
		v.onParentResize(width(), height());
	}
	return *this;
}

//______________________________________________________________________________

struct SceneInputHandler : public InputEventHandler{
	ViewpointWindow& win;
	App& app;

	SceneInputHandler(ViewpointWindow& w, App& a): win(w), app(a){}

	bool onKeyDown(const Keyboard& k){
		app.onKeyDown(win, k);
		switch(k.key()){
			case Keyboard::TAB:
				app.stereo().stereo(!app.stereo().stereo());
				return false;
			default:;
		}
		return true;
	}
	bool onKeyUp(const Keyboard& k){ app.onKeyUp(win,k); return true;}
	bool onMouseDown(const Mouse& m){ app.onMouseDown(win,m); return true;}
	bool onMouseUp(const Mouse& m){ app.onMouseUp(win,m); return true;}
	bool onMouseDrag(const Mouse& m){ app.onMouseDrag(win,m); return true;}
	bool onMouseMove(const Mouse& m){ app.onMouseMove(win,m); return true;}
};

// attached to each ViewpointWindow
struct SceneWindowHandler : public WindowEventHandler{
	ViewpointWindow& win;
	App& app;

	SceneWindowHandler(ViewpointWindow& w, App& a): win(w), app(a){}

	bool onCreate(){

		// FIXME: only do this if actually using fixed pipeline
		#ifdef AL_GRAPHICS_SUPPORTS_FIXED_PIPELINE
		// Enable color material to simplify cases where materials are not used 
		// explicitly (e.g., only mesh colors are used).
		glEnable(GL_COLOR_MATERIAL);
			#ifdef AL_GRAPHICS_SUPPORTS_COLOR_MATERIAL_SPEC
			glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
			#endif
		#endif

		app.onCreate(win);
		return true;
	}
	bool onDestroy(){ app.onDestroy(win); return true; }
	bool onResize(int dw, int dh){ app.onResize(win, dw,dh); return true; }

	virtual bool onFrame();
};

bool SceneWindowHandler::onFrame(){
{'fraction_non_alphanumeric': 0.14099751352932574, 'fraction_numerical': 0.002340207693432792, 'mean_word_length': 5.710500490677134, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2819808', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2351, 'n_words': 552}