Exemplo n.º 1
0
/*
 * Battery icon callback handler (called via icon bar update now)
 */
static void battery_layer_update_callback(Layer *layer, GContext *ctx, int *running_horizontal) {

  #ifdef PBL_COLOR
    graphics_context_set_compositing_mode(ctx, GCompOpSet);
  #else
    graphics_context_set_compositing_mode(ctx, GCompOpAssign);
  #endif

  if (!ui.battery_plugged) {
    paint_icon(ctx, running_horizontal, 24, RESOURCE_ID_BATTERY_ICON, BMP_CACHE_BATTERY_ICON);
    graphics_context_set_stroke_color(ctx, BACKGROUND_COLOR);
    #ifdef PBL_COLOR
      GColor b_color = BATTERY_BAR_COLOR;
      if (ui.battery_level <= 20) {
        b_color = BATTERY_BAR_COLOR_CRITICAL;
      } else if (ui.battery_level <= 40) {
        b_color = BATTERY_BAR_COLOR_WARN;
      }
      graphics_context_set_fill_color(ctx, b_color);
    #else
      graphics_context_set_fill_color(ctx, BATTERY_BAR_COLOR);
    #endif
    graphics_fill_rect(ctx, GRect(*running_horizontal + 7, 4, ui.battery_level / 9, 4), 0, GCornerNone);
  } else {
    paint_icon(ctx, running_horizontal, 24, RESOURCE_ID_BATTERY_CHARGE, BMP_CACHE_BATTERY_CHARGE);
  }
}
Exemplo n.º 2
0
/*
 * Icon bar update handler
 */
EXTFN void icon_bar_update_callback(Layer *layer, GContext *ctx) {

  int running_horizontal = ICON_BAR_WIDTH;

  graphics_context_set_fill_color(ctx, BACKGROUND_COLOR);
  graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone);

  graphics_context_set_fill_color(ctx, GColorWhite);
  graphics_context_set_stroke_color(ctx, GColorBlack);

#ifdef PBL_COLOR
  graphics_context_set_compositing_mode(ctx, GCompOpSet);
#endif

  // Don't draw if we're currently doing
  if (!is_animation_complete())
    return;

  // Battery icon (always showing)
  battery_layer_update_callback(layer, ctx, &running_horizontal);
  running_horizontal += ICON_PAD_BATTERY;

  // Comms icon / Bluetooth icon
  if (icon_state[IS_COMMS] || icon_state[IS_BLUETOOTH]) {
    paint_icon(ctx, &running_horizontal, 9, icon_state[IS_COMMS] ? RESOURCE_ID_COMMS_ICON : RESOURCE_ID_BLUETOOTH_ICON,
               icon_state[IS_COMMS] ? BMP_CACHE_COMMS_ICON : BMP_CACHE_BLUETOOTH_ICON);
  }
  
  // Record icon
  if (icon_state[IS_RECORD]) {
    paint_icon(ctx, &running_horizontal, 10, RESOURCE_ID_ICON_RECORD, BMP_CACHE_ICON_RECORD);
  }

  // Alarm icon
  if (icon_state[IS_ALARM_RING] || icon_state[IS_ALARM]) {
    paint_icon(ctx, &running_horizontal, 12, icon_state[IS_ALARM_RING] ? RESOURCE_ID_ALARM_RING_ICON : RESOURCE_ID_ALARM_ICON,
              icon_state[IS_ALARM_RING] ? BMP_CACHE_ALARM_RING_ICON : BMP_CACHE_ALARM_ICON);
  }

  // Ignore icon
  if (icon_state[IS_IGNORE]) {
    paint_icon(ctx, &running_horizontal, 9, RESOURCE_ID_IGNORE, BMP_CACHE_IGNORE );
  }

  // Export icon
  if (icon_state[IS_EXPORT]) {
    paint_icon(ctx, &running_horizontal, 9, RESOURCE_ID_EXPORT, BMP_CACHE_EXPORT);
  }

}
Exemplo n.º 3
0
void UberDelegate::paint_cell(QPainter *p, const QStyleOptionViewItem &opt, const QModelIndex &idx, const bool drawing_aggregate) const {
    QModelIndex model_idx = idx;
    if (m_proxy)
        model_idx = m_proxy->mapToSource(idx);

    COLUMN_TYPE type = static_cast<COLUMN_TYPE>(model_idx.data(DwarfModel::DR_COL_TYPE).toInt());
    QRect adjusted = opt.rect.adjusted(cell_padding, cell_padding, -cell_padding, -cell_padding);

    float rating = model_idx.data(DwarfModel::DR_RATING).toFloat();
    QString text_rating = model_idx.data(DwarfModel::DR_DISPLAY_RATING).toString();
    float limit = 100.0;

    switch (type) {
    case CT_SKILL:
    {
        QColor bg = paint_bg(adjusted, p, opt, idx);
        limit = 15.0;
        if(rating >= 0)
            paint_values(adjusted, rating, text_rating, bg, p, opt, idx, 0, 0, limit, 0, 0);

        paint_mood_cell(adjusted,p,opt,idx,model_idx.data(DwarfModel::DR_SKILL_ID).toInt(),false);
    }
        break;
    case CT_LABOR:
    {
        if (!drawing_aggregate) {
            Dwarf *d = m_model->get_dwarf_by_id(idx.data(DwarfModel::DR_ID).toInt());
            if (!d) {
                return QStyledItemDelegate::paint(p, opt, idx);
            }
            int labor_id = idx.data(DwarfModel::DR_LABOR_ID).toInt();
            bool enabled = d->labor_enabled(labor_id);
            bool dirty = d->is_labor_state_dirty(labor_id);

            QColor bg = paint_bg_active(adjusted, enabled, p, opt, idx);
            limit = 15.0;
            if(rating >= 0)
                paint_values(adjusted, rating, text_rating, bg, p, opt, idx, 0, 0, limit, 0, 0);

            paint_mood_cell(adjusted,p,opt,idx,GameDataReader::ptr()->get_labor(labor_id)->skill_id, dirty);
        }else {
            paint_labor_aggregate(adjusted, p, opt, idx);
        }
    }
        break;
    case CT_HAPPINESS:
    {
        paint_bg(adjusted, p, opt, idx, true, model_idx.data(Qt::BackgroundColorRole).value<QColor>());
        if(draw_happiness_icons){
            paint_icon(adjusted,p,opt,idx);
        }else{
            p->save();
            paint_grid(adjusted, false, p, opt, idx);
            p->restore();
        }
    }
        break;
    case CT_EQUIPMENT:
    {
        int wear_level = idx.data(DwarfModel::DR_SPECIAL_FLAG).toInt();
        paint_bg(adjusted, p, opt, idx, true, model_idx.data(Qt::BackgroundColorRole).value<QColor>());
        paint_wear_cell(adjusted,p,opt,idx,wear_level);
    }
        break;
    case CT_ITEMTYPE:
    {
        QColor bg = paint_bg(adjusted, p, opt, idx, true, model_idx.data(Qt::BackgroundColorRole).value<QColor>());
        //if we're drawing numbers, we only want to draw counts for squads
        //this is a special case because we're drawing different information if it's text mode
        if(m_skill_drawing_method == SDM_NUMERIC && rating == 100)
            rating = -1;
        paint_values(adjusted, rating, text_rating, bg, p, opt, idx,90.0f,5.0f,95.0f,99.99f,102.0f,false);
        int wear_level = idx.data(DwarfModel::DR_SPECIAL_FLAG).toInt();
        paint_wear_cell(adjusted,p,opt,idx,wear_level);
    }
        break;
    case CT_ROLE:
    {
        bool active_labors = false;
        int dirty_alpha = 255;
        int active_alpha = 255;
        bool dirty = false;
        Dwarf *d = m_model->get_dwarf_by_id(idx.data(DwarfModel::DR_ID).toInt());
        if(d){
            if(idx.data(DwarfModel::DR_SPECIAL_FLAG).canConvert<QVariantList>()){
                QVariantList labors = idx.data(DwarfModel::DR_SPECIAL_FLAG).toList();
                int active_count = 0;
                int dirty_count = 0;
                foreach(QVariant id, labors){
                    if(d->labor_enabled(id.toInt())){
                        active_labors = true;
                        active_count++;
                    }
                    if(d->is_labor_state_dirty(id.toInt())){
                        dirty = true;
                        dirty_count++;
                    }
                }
                if(active_labors)
                    active_alpha = (255 * ((float)active_count / labors.count()));
                if(dirty)
                    dirty_alpha = (255 * ((float)dirty_count / labors.count()));                                
            }
        }
        QColor bg;
        QColor color_active_adjusted = color_active_labor;
        if(active_labors){
            color_active_adjusted.setAlpha(active_alpha);
            bg = paint_bg_active(adjusted, active_labors, p, opt, idx, color_active_adjusted);
        }else{
            bg = paint_bg(adjusted, p, opt, idx);
        }
        double limit_range = (DwarfStats::get_role_max() - DwarfStats::get_role_min()) * 0.05;
        paint_values(adjusted, rating, text_rating, bg, p, opt, idx,50.0f, DwarfStats::get_role_min() + limit_range,DwarfStats::get_role_max() - limit_range,45.0f,55.0f);
        if(dirty){
            QColor color_dirty_adjusted = color_dirty_border;
            color_dirty_adjusted.setAlpha(dirty_alpha);
            paint_border(adjusted,p,color_dirty_adjusted);
            paint_grid(adjusted,false,p,opt,idx,false);
        }else{
            paint_grid(adjusted, dirty, p, opt, idx);
        }
    }
        break;
    case CT_IDLE:
    {
        paint_bg(adjusted, p, opt, idx, true, model_idx.data(Qt::BackgroundColorRole).value<QColor>());
        paint_icon(adjusted,p,opt,idx);
    }
        break;
    case CT_PROFESSION:
    {
        paint_bg(adjusted, p, opt, idx, true, model_idx.data(Qt::BackgroundColorRole).value<QColor>());
        paint_icon(adjusted,p,opt,idx);
    }
        break;
    case CT_HIGHEST_MOOD:
    {
        paint_bg(adjusted, p, opt, idx, true, model_idx.data(Qt::BackgroundColorRole).value<QColor>());
        paint_icon(adjusted,p,opt,idx);

        bool had_mood = idx.data(DwarfModel::DR_SPECIAL_FLAG).toBool();
        if(had_mood){
            p->save();
            QRect moodr = adjusted;
            moodr.adjust(2,2,-2,-2);
            p->setPen(QPen(Qt::darkRed,2));
            p->drawLine(moodr.bottomLeft(), moodr.topRight());
            p->restore();
        }
    }
        break;
    case CT_TRAIT:
    {
        QColor bg = paint_bg(adjusted, p, opt, idx);
        paint_values(adjusted, rating, text_rating, bg, p, opt, idx, 50, 10, 90);
        paint_grid(adjusted, false, p, opt, idx);
    }
        break;
    case CT_ATTRIBUTE:
    {
        QColor bg = paint_bg(adjusted, p, opt, idx);
        paint_values(adjusted, rating, text_rating, bg, p, opt, idx, 50.0f, 2.0f, 98.0f);

        if(color_attribute_syns && idx.data(DwarfModel::DR_SPECIAL_FLAG).toInt() > 0){
            paint_border(adjusted,p,Attribute::color_affected_by_syns());
            paint_grid(adjusted, false, p, opt, idx, false);
        }else{
            paint_grid(adjusted, false, p, opt, idx);
        }
    }
        break;
    case CT_WEAPON:
    {
        QColor bg = paint_bg(adjusted, p, opt, idx);
        paint_values(adjusted, rating, text_rating, bg, p, opt, idx, 50.0f, 1, 99, 49, 51, true);
        paint_grid(adjusted, false, p, opt, idx);

    }
        break;
    case CT_FLAGS:
    {
        paint_flags(adjusted, p, opt, idx);
    }
        break;
    case CT_TRAINED:
    {
        QColor bg = paint_bg(adjusted, p, opt, idx, false, model_idx.data(Qt::BackgroundColorRole).value<QColor>());
        //arbitrary ignore range is used just to hide tame animals
        paint_values(adjusted, rating, text_rating, bg, p, opt, idx, 50.0f, 1.0f, 95.0f, 49.9f, 50.1f, true);
        paint_grid(adjusted, false, p, opt, idx);
    }
        break;
    case CT_HEALTH:
    {
        QColor bg = paint_bg(adjusted, p, opt, idx, false, model_idx.data(Qt::BackgroundColorRole).value<QColor>());

        //draw the symbol text in bold
        p->save();
        if (rating != 0) {
            if(color_health_cells){
                p->setPen(model_idx.data(Qt::TextColorRole).value<QColor>());
            }else{
                if(auto_contrast){
                    p->setPen(compliment(bg));
                }else{
                    p->setPen(Qt::black);
                }
            }

            QFont tmp = m_fnt;
            tmp.setBold(true);
            p->setFont(tmp);
            p->drawText(opt.rect, Qt::AlignCenter, text_rating);
        }
        p->restore();

        paint_grid(adjusted, false, p, opt, idx);
    }
        break;
    case CT_SPACER:
    case CT_DEFAULT:
    default:
    {
        if(adjusted.width() > 0)
            paint_bg(adjusted, p, opt, idx, true, model_idx.data(Qt::BackgroundColorRole).value<QColor>());
        break;
    }
    }