#include "shellscrollbar.h" #include "sparrowshell.h" #include "mesh.h" #include "phongmaterial.h" #include "scene/meshnode.h" #include "tools/utils.h" #include ShellScrollBar::ShellScrollBar(SparrowShell *shell): MeshNode(nullptr,false), m_shell(shell) { m_position = glm::vec2(m_shell->getDimension().x-SparrowShell::SCROLLBAR_PIXEL_WIDTH,0); m_max_height = SparrowShell::DEFAULT_FONT_SIZE*SparrowShell::BUFFER_DISPLAYED_LINES; m_dimension = glm::vec2(SparrowShell::SCROLLBAR_PIXEL_WIDTH, m_max_height); moveTo2D(m_position); Mesh* mesh = new Mesh(); mesh->addRectangle2D(glm::vec2(0),m_dimension); PhongMaterial* mat = new PhongMaterial(); mat->diffuse = glm::vec3(0,0,0.5); mat->m_opacity = 0.8; mesh->setMaterial(mat); mesh->setDepth(SparrowShell::SHELL_DEPTH+1); mesh->initGL(); m_geometry.mesh = mesh; } void ShellScrollBar::update(){ MeshNode::update(); int size = m_shell->getBuffer()->size(); float cran = (m_max_height/(float)size); int indexCursor = size - (m_shell->getIndex()+SparrowShell::BUFFER_DISPLAYED_LINES); if (m_shell->isBufferResized()){ // std::cout << size << std::endl; // std::cout << cran * SparrowShell::BUFFER_DISPLAYED_LINES << std::endl; glm::ivec2 new_dim(m_dimension.x,(int)(cran * SparrowShell::BUFFER_DISPLAYED_LINES)); resize2D(m_dimension,new_dim); m_dimension = new_dim; } if (m_shell->isBufferResized() || m_shell->indexMoved()) { // std::cout << m_position.x << " " << cran*indexCursor << std::endl; glm::ivec2 new_pos((int)m_position.x, (int) cran * indexCursor); moveTo2D(new_pos); } }