1#import "OSXTimeBar.h" 2 3 4@implementation OSXTimeBar 5 6- (void) setText: (NSString*) aText 7{ 8 text = aText; 9} 10 11- (void) setValue: (int) aValue 12{ 13 value = aValue; 14} 15 16- (void) setColor: (ColorId) aColor 17{ 18 color = aColor; 19} 20 21- (void) setMaxValue: (int) aMaxValue 22{ 23 max_value = aMaxValue; 24} 25 26- (void) setSecondaryValue: (int) aSecondaryValue 27{ 28 secondary_value = aSecondaryValue; 29} 30 31- (void) setSecondaryMaxValue: (int) aSecondaryMaxValue 32{ 33 secondary_max_value = aSecondaryMaxValue; 34} 35 36- (void) setSecondaryColor: (ColorId) aColor 37{ 38 secondary_color = aColor; 39} 40 41- (void)drawRect:(NSRect)rect 42{ 43// [[NSColor whiteColor] set]; 44// NSRectFill(NSMakeRect(1, 1, 98, 20)); 45 46 const int border_size = 2; 47 48 int win_w = 30; 49 int win_h = 22; 50 51 // Draw background 52 [[NSColor blackColor] set]; 53 NSFrameRect(NSMakeRect(1, 1, win_w - 2, win_h - 2)); 54 [[NSColor whiteColor] set]; 55 NSRectFill(NSMakeRect(2, 2, win_w - 4, win_h - 4)); 56 57 // Bar 58 int bar_width = 0; 59 if (max_value > 0) 60 { 61 bar_width = (value * (win_w - 2 * border_size)) / max_value; 62 } 63 64 // Secondary bar 65 int sbar_width = 0; 66 if (secondary_max_value > 0) 67 { 68 sbar_width = (secondary_value * (win_w - 2 * border_size)) / secondary_max_value; 69 } 70 71 int bar_height = win_h - 2 * border_size; 72 73 if (sbar_width > 0) 74 { 75 // Overlap 76 77 // We should assert() because this is not supported 78 // but there are some weird boundary cases 79 // in which this still happens.. need to check 80 // this out some time. 81 // assert(secondary_bar_color == COLOR_ID_INACTIVE); 82 NSColor *overlap_color; 83 switch (color) 84 { 85 case COLOR_ID_ACTIVE: 86 overlap_color = [NSColor blueColor]; 87 break; 88 case COLOR_ID_OVERDUE: 89 overlap_color = [NSColor orangeColor]; 90 break; 91 default: 92 // We could abort() because this is not supported 93 // but there are some weird boundary cases 94 // in which this still happens.. need to check 95 // this out some time. 96 overlap_color = [NSColor redColor]; 97 } 98 99 if (sbar_width >= bar_width) 100 { 101 if (bar_width) 102 { 103 [[NSColor redColor] set]; 104 NSRectFill(NSMakeRect(border_size, border_size, bar_width, bar_height)); 105// window_gc->set_foreground(bar_colors[overlap_color]); 106// draw_bar(window, window_gc, true, 107// border_size, border_size, 108// bar_width, bar_height, 109// win_w, win_h); 110 } 111 if (sbar_width > bar_width) 112 { 113 [[NSColor yellowColor] set]; 114 NSRectFill(NSMakeRect(border_size + bar_width, border_size, sbar_width - bar_width, bar_height)); 115// window_gc->set_foreground(bar_colors[secondary_bar_color]); 116// draw_bar(window, window_gc, true, 117// border_size + bar_width, border_size, 118// sbar_width - bar_width, bar_height, 119// win_w, win_h); 120 } 121 } 122 else 123 { 124 if (sbar_width) 125 { 126 [[NSColor blueColor] set]; 127 NSRectFill(NSMakeRect(border_size, border_size, sbar_width, bar_height)); 128// window_gc->set_foreground(bar_colors[overlap_color]); 129// draw_bar(window, window_gc, true, 130// border_size, border_size, 131// sbar_width, bar_height, 132// win_w, win_h); 133 } 134 [[NSColor greenColor] set]; 135 NSRectFill(NSMakeRect(border_size + sbar_width, border_size, bar_width - sbar_width, bar_height)); 136 137// window_gc->set_foreground(bar_colors[bar_color]); 138// draw_bar(window, window_gc, true, 139// border_size + sbar_width, border_size, 140// bar_width - sbar_width, bar_height, 141// win_w, win_h); 142 } 143 } 144 else 145 { 146 [[NSColor grayColor] set]; 147 NSRectFill(NSMakeRect(border_size, border_size, bar_width, bar_height)); 148 // No overlap 149// window_gc->set_foreground(bar_colors[bar_color]); 150// draw_bar(window, window_gc, true, 151// border_size, border_size, 152// bar_width, bar_height, win_w, win_h); 153 } 154 155 156 // Text 157// window_gc->set_foreground(bar_text_color); 158// Glib::RefPtr<Pango::Layout> pl1 = create_pango_layout(bar_text); 159// Glib::RefPtr<Pango::Context> pc1 = pl1->get_context(); 160 161// Pango::Matrix matrix = PANGO_MATRIX_INIT; 162 163// pango_matrix_rotate(&matrix, 360 - rotation); 164// pc1->set_matrix(matrix); 165 166// int text_width, text_height; 167// pl1->get_pixel_size(text_width, text_height); 168 169// int text_x, text_y; 170 171// Gdk::Rectangle rect1, rect2; 172 173// if (rotation == 0 || rotation == 180) 174// { 175// if (win_w - text_width - MARGINX > 0) 176// { 177// if (bar_text_align > 0) 178// text_x = (win_w - text_width - MARGINX); 179// else if (bar_text_align < 0) 180// text_x = MARGINX; 181// else 182// text_x = (win_w - text_width) / 2; 183// } 184// else 185// { 186// text_x = MARGINX; 187// } 188// text_y = (win_h - text_height) / 2; 189 190// int left_width = (bar_width > sbar_width) ? bar_width : sbar_width; 191// left_width += border_size; 192 193// Gdk::Rectangle left_rect(0, 0, left_width, win_h); 194// Gdk::Rectangle right_rect(left_width, 0, win_w - left_width, win_h); 195 196// rect1 = left_rect; 197// rect2 = right_rect; 198// } 199// else 200// { 201// if (win_h - text_width - MARGINY > 0) 202// { 203// int a = bar_text_align; 204// if (rotation == 270) 205// { 206// a *= -1; 207// } 208// if (a > 0) 209// text_y = (win_h - text_width - MARGINY); 210// else if (a < 0) 211// text_y = MARGINY; 212// else 213// text_y = (win_h - text_width) / 2; 214// } 215// else 216// { 217// text_y = MARGINY; 218// } 219 220// text_x = (win_w - text_height) / 2; 221 222// int left_width = (bar_width > sbar_width) ? bar_width : sbar_width; 223// left_width += border_size; 224 225// Gdk::Rectangle up_rect(0, 0, win_w, left_width); 226// Gdk::Rectangle down_rect(0, left_width, win_w, win_h - left_width); 227 228// rect1 = up_rect; 229// rect2 = down_rect; 230// } 231 232// Gdk::Color textcolor = style->get_fg(Gtk::STATE_NORMAL); 233 234// TRACE_MSG(textcolor.get_red() << " " << 235// textcolor.get_green() << " " << 236// textcolor.get_blue()); 237 238// Glib::RefPtr<Gdk::GC> window_gc1 = Gdk::GC::create(window); 239 240// window_gc1->set_clip_origin(0,0); 241// window_gc1->set_clip_rectangle(rect1); 242// window_gc1->set_foreground(bar_text_color); 243// window->draw_layout(window_gc1, text_x, text_y, pl1); 244 245// window_gc1->set_foreground(textcolor); 246// window_gc1->set_clip_rectangle(rect2); 247// window->draw_layout(window_gc1, text_x, text_y, pl1); 248// TRACE_EXIT(); 249} 250 251 252// void 253// TimeBar::draw_bar(Glib::RefPtr<Gdk::Window> &window, 254// const Glib::RefPtr<Gdk::GC> &gc, 255// bool filled, int x, int y, int width, int height, 256// int winw, int winh) 257// { 258// (void) winh; 259 260// if (rotation == 0 || rotation == 180) 261// { 262// window->draw_rectangle(gc, filled, x, y, width, height); 263// } 264// else 265// { 266// window->draw_rectangle(gc, filled, y, winw - x - width, height, width); 267// } 268// } 269 270 271- (void)dealloc 272{ 273 [super dealloc]; 274} 275 276@end 277