box.cpp (1262B)
1 // Copyright (c) 2003 - 2009 Anselm R Garbe <anselm@garbe.us> 2 // See LICENSE for license details. 3 4 #include "box.h" 5 6 #include "draw.h" 7 #include "label.h" 8 #include "monitor.h" 9 #include "theme.h" 10 #include "xcore.h" 11 12 Box::Box(Monitor *monitor, Rectangle *rect, string text) : 13 Widget(monitor, rect) 14 { 15 theme_ = this->monitor()->theme(); 16 label_ = new Label(this->monitor(), window(), Label::CENTER, gc()); 17 label_->setX(1); 18 label_->setY(1); 19 label_->setHeight(height() - 2); 20 setText(text); 21 } 22 23 Box::~Box() { 24 delete label_; 25 } 26 27 void Box::setText(string text) { 28 label_->setText(text); 29 label_->adjustWidth(); 30 setX(monitor()->width() / 2 - label_->width() / 2 - 1); 31 setWidth(label_->width() + 2); 32 resize(); 33 } 34 35 void Box::illuminate() { 36 if (!isVisible()) { 37 return; 38 } 39 Rectangle borderRect(0, 0, width(), height()); 40 label_->update(theme_->TAB_BACKGROUND_ACTIVE_FOCUSSED, 41 theme_->TAB_TEXT_ACTIVE_FOCUSSED, 42 theme_->TAB_SHINE_ACTIVE_FOCUSSED, 43 theme_->TAB_SHADOW_ACTIVE_FOCUSSED, 44 true, true); 45 Draw::drawRectBorder(window(), gc(), &borderRect, 46 theme_->BAR_SHINE, theme_->BAR_SHADOW); 47 XCORE->sync(); 48 }