bool Listbox::drawScrollButton(GL2DProgram * shaders,bool isTop) { Rect drawPos; Shape * triangleShape; vec4 drawColor; bool retValue = false; //First select values based off of button if (isTop) { triangleShape = &upShape; drawPos = Rect(position.Width-3-scrollButtonWidth,3,scrollButtonWidth,scrollButtonWidth); } else { triangleShape = &downShape; drawPos = Rect(position.Width-3-scrollButtonWidth,position.Height-3-scrollButtonWidth,scrollButtonWidth,scrollButtonWidth); } //Now select color based off of cursor status if (drawPos.InRect(lastMousePos)) { if (lastScrollUpdate != 0) { retValue = true; drawColor = highlightColor; } else drawColor = (highlightColor+barColor)/2.0; } else drawColor = barColor; //Calculate the triangle position Rect tPos = Rect(drawPos.Width*.25f,drawPos.Height*.25f,drawPos.Width*.5f,drawPos.Height*.5f); //Now draw the shape shaders->Model.PushMatrix(); shaders->Model.Translate(drawPos.X,drawPos.Y,0); scrollPosShape.color = drawColor; scrollPosShape.OverrideCalculatedSize(drawPos); scrollPosShape.Draw(shaders); //Draw the triangle too shaders->Model.Translate(tPos.X,tPos.Y,0); triangleShape->color = shapeColor; triangleShape->OverrideCalculatedSize(tPos); triangleShape->Draw(shaders); shaders->Model.PopMatrix(); return retValue; }
void Listbox::drawScrollBar(GL2DProgram * shaders) { vec4 drawColor; Rect scrollBarLoc = calcScrollBarRect(); //Is the user dragging the bar? if ((lastScrollUpdate != 0) && (lastScrollPos.x >= 0)) { //The bar is being dragged now drawColor = highlightColor; //Determine the new scrollPosition scrollPosition = float scrollBarMovement = (lastScrollPos.y-lastMousePos.y)/scrollBarRange(); scrollPosition += scrollBarMovement*scrollRange(); lastScrollPos.y = lastMousePos.y; //Limit scroll position SafeScrollPosition(); //Since the scroll position moved, recalculate the bars position scrollBarLoc = calcScrollBarRect(); } else if (scrollBarLoc.InRect(lastMousePos)) { if (lastScrollUpdate != 0) { //Just started dragging drawColor = highlightColor; lastScrollPos = lastMousePos; } else drawColor = (highlightColor+barColor)/2.0; } else drawColor = barColor; //Finally draw the bar shaders->Model.PushMatrix(); shaders->Model.Translate(scrollBarLoc.X,scrollBarLoc.Y,0); scrollPosShape.color = drawColor; scrollPosShape.OverrideCalculatedSize(scrollBarLoc); scrollPosShape.Draw(shaders); shaders->Model.PopMatrix(); }