void create_widget(const dictionary_t& parameters, size_enum_t size, progress_bar_t*& widget) { name_t orientation(key_horizontal); int length(100); int width(14); GG::Clr color(GG::CLR_BLACK); GG::Clr bar_color(GG::CLR_BLUE); GG::Clr interior_color(GG::CLR_ZERO); dictionary_t::const_iterator it(parameters.find(key_format)); value_range_format_t format; if (it != parameters.end()) format.set(it->second.cast<dictionary_t>()); get_value(parameters, key_orientation, orientation); get_value(parameters, static_name_t("length"), length); get_value(parameters, static_name_t("width"), width); implementation::get_color(parameters, static_name_t("color"), color); implementation::get_color(parameters, static_name_t("bar_color"), bar_color); implementation::get_color(parameters, static_name_t("interior_color"), interior_color); widget = new progress_bar_t(orientation == key_vertical, format, length, width, color, bar_color, interior_color); }
/* * Progress line */ EXTFN void progress_layer_update_callback(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, BACKGROUND_COLOR); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); graphics_context_set_fill_color(ctx, BAR_CHART_MARKS); graphics_context_set_stroke_color(ctx, BAR_CHART_MARKS); graphics_context_set_stroke_width(ctx, 2); for (uint8_t i = 0; i <= 120; i += 12) { graphics_draw_pixel(ctx, GPoint(i, 8)); graphics_draw_pixel(ctx, GPoint(i, 7)); } for (uint8_t i = 0; i <= get_internal_data()->highest_entry; i++) { if (!get_internal_data()->ignore[i]) { uint16_t height = get_internal_data()->points[i] / 500; uint8_t i2 = i * 2; #ifdef PBL_COLOR graphics_context_set_stroke_color(ctx, bar_color(height)); #endif graphics_draw_line(ctx, GPoint(i2, 8 - height), GPoint(i2, 8)); } } }
void LLVelocityBar::draw() { const S32 BAR_TOP = 24; const S32 BAR_BOTTOM = 20; const S32 TICK_BOTTOM = 15; const S32 TICK_WIDTH = 2; const S32 MAGIC_CHAR_WIDTH = 6; S32 left, top, right, bottom; // const F32 MS_TO_SECONDS = 0.001f; // const S32 WIDTH_IN_MS = 66; // const F32 WIDGET_TIME_FOR_WIDTH = WIDTH_IN_MS * MS_TO_SECONDS; F32 velocity = gAgent.getVelocity().magVec(); LLColor4 bar_color(0.0f, 1.0f, 0.0f, 1.f); // // Set bar color // gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE); // draw background box // gGL.color4f(0.f, 0.f, 0.f, 0.3f); // gl_rect_2d(0, getRect().getHeight(), getRect().getWidth(), 0); // draw white lines for special times // (60 hz = 16 ms, 30 hz = 33 ms, 15 hz = 66 ms) LLColor4 color(1.f, 1.f, 1.f, 1.f); top = BAR_BOTTOM - 1; bottom = TICK_BOTTOM; left = 0; right = left + TICK_WIDTH; gl_rect_2d(left, top, right, bottom, color); left = (S32) (getRect().getWidth() * 1 / 6); right = left + TICK_WIDTH; gl_rect_2d(left, top, right, bottom, color); left = (S32) (getRect().getWidth() * 2 / 6); right = left + TICK_WIDTH; gl_rect_2d(left, top, right, bottom, color); left = (S32) (getRect().getWidth() * 3 / 6); right = left + TICK_WIDTH; gl_rect_2d(left, top, right, bottom, color); left = (S32) (getRect().getWidth() * 4 / 6); right = left + TICK_WIDTH; gl_rect_2d(left, top, right, bottom, color); left = (S32) (getRect().getWidth() * 5 / 6); right = left + TICK_WIDTH; gl_rect_2d(left, top, right, bottom, color); left = (S32) (getRect().getWidth() * 6 / 6); right = left + TICK_WIDTH; gl_rect_2d(left, top, right, bottom, color); // draw labels for the bar top = BAR_TOP + 15; left = 0; std::string str; str = llformat( "Velocity %.3fm/s", velocity); LLFontGL::sMonospace->renderUTF8(str, 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); top = TICK_BOTTOM; left = - MAGIC_CHAR_WIDTH/2; LLFontGL::sMonospace->renderUTF8(std::string("0"), 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); left = (getRect().getWidth()*1 / 6) - MAGIC_CHAR_WIDTH * 2; LLFontGL::sMonospace->renderUTF8(std::string("1"), 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); left = (getRect().getWidth()*2 / 6) - MAGIC_CHAR_WIDTH; LLFontGL::sMonospace->renderUTF8(std::string("2"), 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); left = (getRect().getWidth()*3 / 6) - MAGIC_CHAR_WIDTH * 2; LLFontGL::sMonospace->renderUTF8(std::string("3"), 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); left = (getRect().getWidth()*4 / 6) - MAGIC_CHAR_WIDTH; LLFontGL::sMonospace->renderUTF8(std::string("4"), 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); left = (getRect().getWidth()*5 / 6) - MAGIC_CHAR_WIDTH * 2; LLFontGL::sMonospace->renderUTF8(std::string("5"), 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); left = (getRect().getWidth()*6 / 6) - MAGIC_CHAR_WIDTH * 3; LLFontGL::sMonospace->renderUTF8(std::string("6 m/s"), 0, left, top, color, LLFontGL::LEFT, LLFontGL::TOP); // draw idle time top = BAR_TOP; bottom = BAR_BOTTOM; // Draw energy level left = 0; right = (S32) (left + velocity * 0.33333f * getRect().getWidth() / 2.f); gl_rect_2d(left, top, right, bottom, bar_color); }
//////////////////////////////////////////////////////////////////////////////// // Project Remaining Avg Age Complete 0% 100% // A 12 13d 55% XXXXXXXXXXXXX----------- // B 109 3d 12h 10% XXX--------------------- int CmdSummary::execute (std::string& output) { int rc = 0; // Scan the pending tasks. handleRecurrence (); // Apply filter. std::vector <Task> filtered; filter (filtered); context.tdb2.commit (); // Generate unique list of project names from all pending tasks. std::map <std::string, bool> allProjects; std::vector <Task>::iterator task; for (task = filtered.begin (); task != filtered.end (); ++task) if (task->getStatus () == Task::pending) allProjects[task->get ("project")] = false; // Initialize counts, sum. std::map <std::string, int> countPending; std::map <std::string, int> countCompleted; std::map <std::string, double> sumEntry; std::map <std::string, int> counter; time_t now = time (NULL); // Initialize counters. std::map <std::string, bool>::iterator project; for (project = allProjects.begin (); project != allProjects.end (); ++project) { countPending [project->first] = 0; countCompleted [project->first] = 0; sumEntry [project->first] = 0.0; counter [project->first] = 0; } // Count the various tasks. for (task = filtered.begin (); task != filtered.end (); ++task) { std::string project = task->get ("project"); ++counter[project]; if (task->getStatus () == Task::pending || task->getStatus () == Task::waiting) { ++countPending[project]; time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); if (entry) sumEntry[project] = sumEntry[project] + (double) (now - entry); } else if (task->getStatus () == Task::completed) { ++countCompleted[project]; time_t entry = strtol (task->get ("entry").c_str (), NULL, 10); time_t end = strtol (task->get ("end").c_str (), NULL, 10); if (entry && end) sumEntry[project] = sumEntry[project] + (double) (end - entry); } } // Create a table for output. ViewText view; view.width (context.getWidth ()); view.add (Column::factory ("string", STRING_CMD_SUMMARY_PROJECT)); view.add (Column::factory ("string.right", STRING_CMD_SUMMARY_REMAINING)); view.add (Column::factory ("string.right", STRING_CMD_SUMMARY_AVG_AGE)); view.add (Column::factory ("string.right", STRING_CMD_SUMMARY_COMPLETE)); view.add (Column::factory ("string.left_fixed", "0% 100%")); Color bar_color (context.config.get ("color.summary.bar")); Color bg_color (context.config.get ("color.summary.background")); int barWidth = 30; std::vector <std::string> processed; std::map <std::string, bool>::iterator i; for (i = allProjects.begin (); i != allProjects.end (); ++i) { if (countPending[i->first] > 0) { const std::vector <std::string> parents = extractParents (i->first); std::vector <std::string>::const_iterator parent; for (parent = parents.begin (); parent != parents.end (); parent++) { if (std::find (processed.begin (), processed.end (), *parent) == processed.end ()) { int row = view.addRow (); view.set (row, 0, indentProject (*parent)); processed.push_back (*parent); } } int row = view.addRow (); view.set (row, 0, (i->first == "" ? STRING_CMD_SUMMARY_NONE : indentProject (i->first, " ", '.'))); view.set (row, 1, countPending[i->first]); if (counter[i->first]) view.set (row, 2, Duration ((int) (sumEntry[i->first] / (double)counter[i->first])).format ()); int c = countCompleted[i->first]; int p = countPending[i->first]; int completedBar = (c * barWidth) / (c + p); std::string bar; std::string subbar; if (context.color ()) { bar += bar_color.colorize (std::string ( completedBar, ' ')); bar += bg_color.colorize (std::string (barWidth - completedBar, ' ')); } else { bar += std::string ( completedBar, '=') + std::string (barWidth - completedBar, ' '); } view.set (row, 4, bar); char percent[12]; sprintf (percent, "%d%%", 100 * c / (c + p)); view.set (row, 3, percent); processed.push_back (i->first); } } std::stringstream out; if (view.rows ()) { out << optionalBlankLine () << view.render () << optionalBlankLine (); if (view.rows ()) out << format (STRING_CMD_PROJECTS_SUMMARY2, view.rows ()); else out << STRING_CMD_PROJECTS_SUMMARY; out << "\n"; } else { out << STRING_CMD_PROJECTS_NO << "\n"; rc = 1; } output = out.str (); return rc; }