Newer
Older
ubixos / src / lib / views / sunlight / vTitleTab.cpp
#include <string>
#include <vContext.h>
#include <vTitleTab.h>
#include <sTypes.h>

vTitleTab::vTitleTab(vContext * parent) : vContext(parent) {
  // Allocate a new font
  font = new ogBitFont();

  // Set the title to nothing
  title = "";

  // Retrieve the default font filename out of the style tree
  sString * fontFileName = dynamic_cast<sString *>(GetStyle("default font"));

  // Attempt to load the font
  if (NULL != fontFileName) {
    // I should check for failure here, although everything fails quietly...
    // so even if it does fail it won't matter much
    font->Load(fontFileName->name.c_str(), 0);
  }
  return;
} // vTitleTab::vTitleTab

void
vTitleTab::Draw(void) {
  ogPoint2d points[4];
  sBGColor * BGColor = NULL;
  BGColor = dynamic_cast<sBGColor *>(GetStyle("passive title color"));
  if (NULL == BGColor) return;
 
  points[0].x = points[0].y = points[1].y = points[3].x = 0;
  points[1].x = points[2].x = GetMaxX()+1;
  points[2].y = points[3].y = GetMaxY();

  FillGouraudPolygon(4, points, BGColor->colors);
  font->JustifyText(*this, centerText, centerText, title.c_str());
  return;
} // vTitleTab::Draw()

void
vTitleTab::SetTitle(const std::string newTitle) {
  title = newTitle;
  return;
} // vTitleTab::SetTitle

vTitleTab::~vTitleTab(void) {
  delete font;
  font = NULL;
  return;
} // vTitleTab::~vTitleTab