void ViewObject::draw() { auto& gfxMgr = GraphicsManager::getInstance(); std::stringstream temp_str; // Display view string + value. if (border) { temp_str << "|" << getViewString() << " " << value << "|"; } else { temp_str << getViewString() << " " << value; } // Draw centered at position. Position pos = viewToWorld(getPosition()); gfxMgr.drawString(pos, temp_str.str(), CENTER_JUSTIFIED, getColor()); if (border) { int x = pos.getX(); int y = pos.getY(); int length = temp_str.str().length(); std::stringstream frameStr; for (int i = 0; i < length; i++) { frameStr << "="; } // Draw box around display. gfxMgr.drawString(Position(x, y - 1), frameStr.str(), CENTER_JUSTIFIED, getColor()); gfxMgr.drawString(Position(x, y + 1), frameStr.str(), CENTER_JUSTIFIED, getColor()); } }
void ViewObject::draw(){ GraphicsManager &graphics_manager = GraphicsManager::getInstance(); string temp_str; if(getBorder() == true){ temp_str = " " + getViewString() + " " + intToString(value) + " "; } else { temp_str = getViewString() + " " + intToString(value); } //Draw centered at position Position pos = viewToWorld(getPosition()); graphics_manager.drawString(pos, temp_str, CENTER_JUSTIFIED, getColor()); //Draw box around display if (getBorder() == true){ int boxLength = strlen(getViewString().c_str()) + 4; int boxHeight = 3; int boxOffset = boxLength/2; bool odd = false; if (boxLength % 2){ odd = true; } for (int i = 0; i < boxLength; i++){ Position new_pos(pos.getX() + i - boxOffset, pos.getY()-1); graphics_manager.drawCh(new_pos, '-', getColor()); } //Bottom for (int i = 0; i < boxLength; i++){ Position new_pos(pos.getX() + i - boxOffset, pos.getY()+1); graphics_manager.drawCh(new_pos, '-', getColor()); } //Left Position left_pos(pos.getX()-boxOffset-1, pos.getY()); graphics_manager.drawCh(left_pos, '|', getColor()); //Right if (!odd){ Position right_pos(pos.getX()+boxOffset, pos.getY()); graphics_manager.drawCh(right_pos, '|', getColor()); } else { Position right_pos(pos.getX()+boxOffset+1, pos.getY()); graphics_manager.drawCh(right_pos, '|', getColor()); } } }
//event handler int Reticle::eventHandler(const df::Event *p_e) { if (p_e->getType() == df::A_MOUSE_EVENT) { const df::EventMouse *p_mouse_event = static_cast <const df::EventMouse *> (p_e); if (p_mouse_event->getMouseAction() == df::MOVED) { // Change location to new mouse position setPosition(viewToWorld(p_mouse_event->getMousePosition())); return 1; } } //ignore event return 0; }