@ -2,8 +2,6 @@
@@ -2,8 +2,6 @@
# include "DocumentComponent.h"
# include <iostream>
# include "../graphical/font/TextRasterizerCache.h"
# include "../../scheduler.h"
# include "../graphical/renderers/glfw/Shader.h"
extern TextRasterizerCache * rasterizerCache ;
@ -14,10 +12,10 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
@@ -14,10 +12,10 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
//std::cout << "InputComponent::InputComponent - create, boundToPage" << boundToPage << std::endl;
//std::cout << "InputComponent::InputComponent - window: " << windowWidth << "x" << windowHeight << " passed " << passedWindowWidth << "x" << passedWindowHeight << std::endl;
//boundToPage = true;
useBoxShader = true ;
// set up state
windowWidth = passedWindowWidth ;
windowHeight = passedWindowHeight ;
@ -29,7 +27,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
@@ -29,7 +27,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
x = rawX ;
y = rawY ;
lastRenderedWindowHeight = windowHeight ;
// const float rawX, const float rawY, const float rawWidth, const float rawHeight, const unsigned int hexColor, const int passedWindowWidth, const int passedWindowHeight
// we only want it one line high (esp for text area)
this - > cursorBox = new BoxComponent ( x , y , 2 , 13 , 0x000000FF , windowWidth , windowHeight ) ;
@ -42,7 +40,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
@@ -42,7 +40,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
}
this - > cursorBox - > resize ( this - > windowWidth , this - > windowHeight ) ;
this - > updateText ( ) ;
onFocus = [ this ] ( ) {
this - > focused = true ;
//std::cout << "focus input" << std::endl;
@ -67,7 +65,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
@@ -67,7 +65,7 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
} ;
//std::cout << "InputComponent::InputComponent - placing box at " << (int)x << "," << (int)y << " size: " << (int)width << "x" << (int)height << std::endl;
// copy initial state
initialX = x ;
initialY = y ;
@ -75,26 +73,26 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
@@ -75,26 +73,26 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
initialHeight = height ;
initialWindowWidth = windowWidth ;
initialWindowHeight = windowHeight ;
data [ 0 ] [ 0 ] [ 0 ] = 0xf0 ; // set R color
data [ 0 ] [ 0 ] [ 1 ] = 0xf0 ; // set G color
data [ 0 ] [ 0 ] [ 2 ] = 0xf0 ; // set B color
data [ 0 ] [ 0 ] [ 3 ] = 0xff ; // set alpha
float vx = rawX ;
float vy = rawY ;
//std::cout << "placing box at " << (int)vx << "x" << (int)vy << " size: " << (int)rawWidth << "x" << (int)rawHeight << std::endl;
float vWidth = rawWidth ;
float vHeight = rawHeight ;
pointToViewport ( vx , vy ) ;
// converts 512 to 1 and 1 to 2
//std::cout << "vWidth before: " << (int)vWidth << std::endl;
distanceToViewport ( vWidth , vHeight ) ;
//std::cout << "vWidth after: " << (int)vWidth << std::endl;
//std::cout << "InputComponent::InputComponent - placing box at GL " << vx << "," << vy << " to " << vx+vWidth << "," << vy+vHeight << " size: " << vWidth << "x" << vHeight << std::endl;
vertices [ ( 0 * 5 ) + 0 ] = vx ;
vertices [ ( 0 * 5 ) + 1 ] = vy + vHeight ;
vertices [ ( 1 * 5 ) + 0 ] = vx + vWidth ;
@ -103,31 +101,31 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
@@ -103,31 +101,31 @@ InputComponent::InputComponent(const float rawX, const float rawY, const float r
vertices [ ( 2 * 5 ) + 1 ] = vy ;
vertices [ ( 3 * 5 ) + 0 ] = vx ;
vertices [ ( 3 * 5 ) + 1 ] = vy ;
glGenVertexArrays ( 1 , & vertexArrayObject ) ;
glGenBuffers ( 1 , & vertexBufferObject ) ;
glGenBuffers ( 1 , & elementBufferObject ) ;
glBindVertexArray ( vertexArrayObject ) ;
glBindBuffer ( GL_ARRAY_BUFFER , vertexBufferObject ) ;
glBufferData ( GL_ARRAY_BUFFER , sizeof ( vertices ) , vertices , GL_STATIC_DRAW ) ;
glBindBuffer ( GL_ELEMENT_ARRAY_BUFFER , elementBufferObject ) ;
glBufferData ( GL_ELEMENT_ARRAY_BUFFER , sizeof ( indices ) , indices , GL_STATIC_DRAW ) ;
glVertexAttribPointer ( 0 , 3 , GL_FLOAT , GL_FALSE , 5 * sizeof ( float ) , nullptr ) ;
glEnableVertexAttribArray ( 0 ) ;
glVertexAttribPointer ( 1 , 2 , GL_FLOAT , GL_FALSE , 5 * sizeof ( float ) , reinterpret_cast < void * > ( 3 * sizeof ( float ) ) ) ;
glEnableVertexAttribArray ( 1 ) ;
glGenTextures ( 1 , & texture ) ;
glBindTexture ( GL_TEXTURE_2D , texture ) ;
glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RGBA , 1 , 1 , 0 , GL_RGBA , GL_UNSIGNED_BYTE , data ) ;
glGenerateMipmap ( GL_TEXTURE_2D ) ;
glBindVertexArray ( 0 ) ; // protect what we created against any further modification
}
@ -152,7 +150,7 @@ void InputComponent::render() {
@@ -152,7 +150,7 @@ void InputComponent::render() {
}
verticesDirty = false ;
}
glBindVertexArray ( vertexArrayObject ) ;
glErr = glGetError ( ) ;
if ( glErr ! = GL_NO_ERROR ) {
@ -196,7 +194,7 @@ void InputComponent::render() {
@@ -196,7 +194,7 @@ void InputComponent::render() {
}
if ( focused ) {
//std::cout << "Rendering cursor" << std::endl;
// render it if we need to
if ( showCursor ) {
cursorBox - > render ( ) ;
@ -207,14 +205,14 @@ void InputComponent::render() {
@@ -207,14 +205,14 @@ void InputComponent::render() {
void InputComponent : : resize ( const int passedWindowWidth , const int passedWindowHeight ) {
//std::cout << "InputComponent::resize" << std::endl;
//std::cout << "InputComponent::resize - rasterizing at " << (int)x << "x" << (int)y << " size: " << (int)width << "x" << (int)height << std::endl;
// maybe already done at component::resize
// set up state
windowWidth = passedWindowWidth ;
windowHeight = passedWindowHeight ;
//std::cout << "InputComponent::resize - boxShader: " << useBoxShader << " boundToPage: " << boundToPage << std::endl;
/*
if ( ! boundToPage ) {
// ok because box shader is anchored to the bottom of the screen
@ -225,20 +223,20 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH
@@ -225,20 +223,20 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH
lastRenderedWindowHeight = windowHeight ;
}
*/
// turning this off breaks coordinates
//boundToPage = true;
/*
useBoxShader = true ;
for ( int i = 0 ; i < 3 ; i + + ) {
data [ 0 ] [ 0 ] [ i ] = 0xf0 ; // set RGB color
}
data [ 0 ] [ 0 ] [ 3 ] = 0xff ; // set alpha
*/
//std::cout << "InputComponent::resize - placing box at " << (int)x << "," << (int)y << " size: " << (int)width << "x" << (int)height << std::endl;
float vx = x ;
float vy = y ;
if ( this - > boundToPage ) {
@ -246,37 +244,37 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH
@@ -246,37 +244,37 @@ void InputComponent::resize(const int passedWindowWidth, const int passedWindowH
//std::cout << "InputComponent::resize - Adjust y to " << vy << " from " << y << " h: " << (int)height << std::endl;
}
pointToViewport ( vx , vy ) ;
float vWidth = width ;
float vHeight = height ;
distanceToViewport ( vWidth , vHeight ) ;
float vx1 = vx + vWidth ;
float vy1 = vy + vHeight ;
//std::cout << "InputComponent::resize - placing box at GL " << vx << "," << vy << " to " << vx1 << "," << vy1 << " size: " << vWidth << "x" << vHeight << std::endl;
vertices [ ( 0 * 5 ) + 0 ] = vx ;
vertices [ ( 0 * 5 ) + 1 ] = vy1 ;
vertices [ ( 1 * 5 ) + 0 ] = vx1 ;
vertices [ ( 1 * 5 ) + 1 ] = vy1 ;
vertices [ ( 2 * 5 ) + 0 ] = vx1 ;
vertices [ ( 2 * 5 ) + 1 ] = vy ;
vertices [ ( 3 * 5 ) + 0 ] = vx ;
vertices [ ( 3 * 5 ) + 1 ] = vy ;
glBindVertexArray ( vertexArrayObject ) ;
glBindBuffer ( GL_ARRAY_BUFFER , vertexBufferObject ) ;
glBufferData ( GL_ARRAY_BUFFER , sizeof ( vertices ) , vertices , GL_STATIC_DRAW ) ;
glBindVertexArray ( 0 ) ; // protect what we created against any further modification
//updateText();
if ( userInputText ) {
// do we need updateText here?
userInputText - > resize ( passedWindowWidth , passedWindowHeight ) ;
}
}
@ -418,7 +416,7 @@ void InputComponent::updateCursor(int mX, int mY) {
@@ -418,7 +416,7 @@ void InputComponent::updateCursor(int mX, int mY) {
//if (pos < this->text.getValue().size()) {
//std::cout << "InputComponent::updateCursor - Cursor at " << this->cursorCharX << "," << this->cursorCharY << " " << this->value.at(pos) << std::endl;
//}
const std : : shared_ptr < TextRasterizer > textRasterizer = rasterizerCache - > loadFont ( 12 , false ) ; // fontSize, bold
rasterizationRequest request ;
//request.text = text.getValue().substr(0, pos);
@ -437,7 +435,7 @@ void InputComponent::updateCursor(int mX, int mY) {
@@ -437,7 +435,7 @@ void InputComponent::updateCursor(int mX, int mY) {
//std::cout << "InputComponent::updateCursor - response at [" << textInfo->endingX << "," << textInfo->endingY << "]" << std::endl;
int textEndingX = textInfo - > endingX ;
int textEndingY = textInfo - > endingY ;
// adjust text crop
//std::cout << "c.endingY: " << textInfo->endingY << " c.y:" << endingY << "" << std::endl;
this - > textCropX = std : : max ( textInfo - > endingX , static_cast < int > ( this - > width ) ) ;
@ -445,7 +443,7 @@ void InputComponent::updateCursor(int mX, int mY) {
@@ -445,7 +443,7 @@ void InputComponent::updateCursor(int mX, int mY) {
this - > textScrollY = 0 ; // reset scroll
//this->cursorStartAtX = textInfo->endingX;
//this->cursorStartAtY = textInfo->endingY;
// adjust our scroll
//std::cout << "cursor height" << (int)textInfo->height << " > " << (int)this->height << " (" << this->textScrollY << ")" << std::endl;
if ( textInfo - > height > this - > height ) {
@ -463,7 +461,7 @@ void InputComponent::updateCursor(int mX, int mY) {
@@ -463,7 +461,7 @@ void InputComponent::updateCursor(int mX, int mY) {
}
//std::cout << "placing cursor at " << (int)cursorBox->x << "," << (int)cursorBox->y << std::endl;
cursorBox - > resize ( this - > windowWidth , this - > windowHeight ) ;
// ok placement of the cursor may trigger the text to scroll and need to be re-rasterized
if ( moved ) {
/*
@ -482,7 +480,7 @@ void InputComponent::updateCursor(int mX, int mY) {
@@ -482,7 +480,7 @@ void InputComponent::updateCursor(int mX, int mY) {
this - > cursorLastX = this - > cursorCharX ;
this - > cursorLastY = this - > cursorCharY ;
}
// if we move the cursor, redraw immediately
this - > showCursor = true ;
if ( this - > win ) {
@ -492,7 +490,7 @@ void InputComponent::updateCursor(int mX, int mY) {
@@ -492,7 +490,7 @@ void InputComponent::updateCursor(int mX, int mY) {
void InputComponent : : updateText ( ) {
//std::cout << "InputComponent::updateText - input value is now: " << this->text.getValue() << std::endl;
if ( this - > node ) {
std : : map < std : : string , std : : string > : : iterator it = this - > node - > properties . find ( " value " ) ;
if ( it = = this - > node - > properties . end ( ) ) {
@ -501,7 +499,7 @@ void InputComponent::updateText() {
@@ -501,7 +499,7 @@ void InputComponent::updateText() {
it - > second = this - > text . getValue ( ) ;
}
}
//std::cout << "placed userInputText at " << static_cast<int>(x) << "," << static_cast<int>(y - windowHeight) << std::endl;
// 125 pixels width
// but first we need to know how wide the text is
@ -528,7 +526,7 @@ void InputComponent::updateText() {
@@ -528,7 +526,7 @@ void InputComponent::updateText() {
//int estHeight = textInfo->height;
//this->cursorStartAtX = textInfo->endingX;
//this->cursorStartAtY = textInfo->endingY;
// if textHeight is bigger than window, adjust cursor too
/*
if ( estHeight > this - > height ) {
@ -537,7 +535,7 @@ void InputComponent::updateText() {
@@ -537,7 +535,7 @@ void InputComponent::updateText() {
}
*/
//this->updateCursor(0, 0);
// why does changing the width mess shit up?
//std::cout << "InputComponent::updateText - our width: " << static_cast<int>(width) << " windowWidth: " << windowWidth << std::endl;
if ( this - > win ) {
@ -559,7 +557,7 @@ void InputComponent::updateText() {
@@ -559,7 +557,7 @@ void InputComponent::updateText() {
userInputText - > y = this - > y - this - > windowHeight + 16 ;
}
userInputText - > boundToPage = this - > boundToPage ;
userInputText - > rasterStartX = this - > textScrollX ;
userInputText - > rasterStartY = this - > textScrollY ;
userInputText - > rasterCropX = this - > textCropX ;
@ -594,8 +592,8 @@ void InputComponent::updateText() {
@@ -594,8 +592,8 @@ void InputComponent::updateText() {
//std::cout << "InputComponent::updateText - textHeight: " << estHeight << " inputHeight: " << static_cast<int>(height) << " eY: " << textInfo->endingY << " y0max:" << textInfo->y0max << " rasterStartY: " << userInputText->rasterStartY << " lines: " << textInfo->lines << std::endl;
// don't wrap if multiLine, otherwise wrap
userInputText - > noWrap = ! this - > multiLine ;
userInputText - > resize ( this - > windowWidth , this - > windowHeight , this - > width ) ; // need to make sure there's a texture
this - > win - > renderDirty = true ;
} // else it was called from cstr, and window isn't set up yet but no worrites, render will be dirty
}
}