Files
Upsilon/apps/graph/list/function_name_view.cpp
Émilie Feral e5ff8f65c3 [apps/graph] Handle undefined function
Change-Id: Id26e0f81ba5c1446655f33b2c63f97ab5b684e41
2016-10-24 15:24:01 +02:00

45 lines
1.8 KiB
C++

#include "function_name_view.h"
#include "../function_store.h"
namespace Graph {
constexpr KDColor FunctionNameView::k_separatorColor;
FunctionNameView::FunctionNameView() :
FunctionCell()
{
}
void FunctionNameView::drawRect(KDContext * ctx, KDRect rect) const {
EvenOddCell::drawRect(ctx, rect);
KDCoordinate height = bounds().height();
KDCoordinate width = bounds().width();
// Color the color indicator
KDColor functionColor = m_function->color();
ctx->fillRect(KDRect(0, 0, k_colorIndicatorThickness, height), functionColor);
// Color the separator
ctx->fillRect(KDRect(width - k_separatorThickness, 0, k_separatorThickness, height), k_separatorColor);
// Select function name color and the text color according to the state of the function
bool active = m_function->isActive();
KDColor textColor = active ? KDColorBlack : FunctionCell::k_desactiveTextColor;
KDColor functionNameColor = active ? functionColor : FunctionCell::k_desactiveTextColor;
// Select the background color according to the even line and the cursor selection
KDColor background = backgroundColor();
// Position the name of the function
const char * functionName = m_function->name();
KDSize textSize = KDText::stringSize(functionName);
KDCoordinate baseline = textSize.height();
KDSize expressionSize = textSize;
if (m_function->layout()) {
baseline = m_function->layout()->baseline();
expressionSize = m_function->layout()->size();
}
KDPoint origin(0.5f*(k_colorIndicatorThickness + m_frame.width() - 4*textSize.width()),
baseline-textSize.height()+0.5f*(m_frame.height() - expressionSize.height()));
ctx->drawString(functionName, origin, functionNameColor, background);
ctx->drawString(Function::Parameter, origin.translatedBy(KDPoint(textSize.width(), 0)), textColor, background);
}
}