void CComponentsFrmClock::initCCLockItems() { //prepare and set current time string initTimeString(); string s_time = cl_timestr; /* create label objects and add to container, ensure that count of items = count of chars (one char = one segment) * this is required for the case, if any time string format was changed */ if (v_cc_items.empty() || (v_cc_items.size() != s_time.size())){ //exit on empty time string if (s_time.empty()){ clear(); return; } //clean up possible old items before add new items clear(); //create new empty label objects, set some general properties and add to container for (size_t i = 0; i < s_time.size(); i++){ CComponentsLabel * lbl = new CComponentsLabel(); addCCItem(lbl); //background paint of item is not required lbl->doPaintBg(false); //preset corner properties of label item lbl->setCorner(max(0, corner_rad-fr_thickness), corner_type); //set text border to 0 lbl->setTextBorderWidth(0,0); } } /*calculate minimal separator width, we use char size of some possible chars * TODO: it's not really generic at the moment */ int minSepWidth = 0; string sep[] ={" ", ".", ":"}; for (size_t i = 0; i < sizeof(sep)/sizeof(sep[0]); i++) minSepWidth = max(cl_font->getRenderWidth(sep[i]), minSepWidth); //get minimal required dimensions for segements from current format string int w_text_min = max(cl_font->getRenderWidth(s_time), width); int h_text_min = max(cl_font->getHeight(), height); //init some temporary variables int x_tmp = x; int h_tmp = h_text_min; int y_tmp = y; //summary of all segments (labels) int w_segments = 0; /* modify available label items with current segment chars * we are using segments with only one char per segment, * these chars are predefined via format string */ for (size_t i = 0; i < v_cc_items.size(); i++) { //v_cc_items are only available as CComponent-items here, so we must cast them before CComponentsLabel *lbl = static_cast <CComponentsLabel*> (v_cc_items[i]); //add rounded corners only to 1st and last segment if (corner_type) { if (i == 0) lbl->setCornerType(corner_type & CORNER_LEFT);// 1st label item else if (i == v_cc_items.size()-1) lbl->setCornerType(corner_type & CORNER_RIGHT);// last label item else lbl->setCorner(0,CORNER_NONE);// inner items don't need round corners } //extract timestring segment (char) string stmp = s_time.substr(i, 1); int w_tmp = minSepWidth; //get width of current segment if (isdigit(stmp.at(0)) ) //check for digits, if true, we use digit width w_tmp = cl_font->getMaxDigitWidth(); else //not digit found, we use render width or minimal width w_tmp = max(cl_font->getRenderWidth(stmp), minSepWidth); //lbl->enablePaintCache(); //set size, text, color of current item lbl->setDimensionsAll(x_tmp, y_tmp, w_tmp, h_tmp); lbl->setColorAll(col_frame, col_body, col_shadow); lbl->forceTextPaint(cl_force_repaint); lbl->setText(stmp, CTextBox::CENTER, cl_font, cl_col_text, cl_font_style); //init background behavior of segment //printf("[CComponentsFrmClock] [%s - %d] paint_bg: [%d] gradient_mode = [%d], text save screen mode = [%d]\n", __func__, __LINE__, paint_bg, cc_body_gradient_enable, cc_txt_save_screen); lbl->doPaintBg(false); lbl->doPaintTextBoxBg(paint_bg); bool save_txt_screen = cc_txt_save_screen || (!paint_bg || cc_body_gradient_enable); lbl->enableTboxSaveScreen(save_txt_screen); #if 0 //use matching height for digits for better vertical centerring into form CTextBox* ctb = lbl->getCTextBoxObject(); if (ctb) ctb->setFontUseDigitHeight(); //ensure paint of text and label bg on changed text or painted form background bool force_txt_and_bg = (lbl->textChanged() || this->paint_bg); lbl->forceTextPaint(force_txt_and_bg); #endif //set xpos and width of item (segment) lbl->setWidth(w_tmp); x_tmp += w_tmp; //sum required width for clock (this) w_segments += w_tmp; h_text_min = max(lbl->getHeight(), height); height = max(lbl->getHeight(), height); } //set required width for clock (this) width = max(w_text_min, w_segments); //use first item as reference and set x and y position to the 1st segement item with definied alignment int x_lbl = width/2-w_segments/2; v_cc_items[0]->setXPos(x_lbl); int y_lbl = height/2-h_text_min/2; v_cc_items[0]->setYPos(y_lbl); //set all evaluated position values to all other segement items for (size_t i = 1; i < v_cc_items.size(); i++){ x_lbl += v_cc_items[i-1]->getWidth(); v_cc_items[i]->setPos(x_lbl, y_lbl); } }
void CComponentsFrmClock::initCCLockItems() { initTimeString(); string s_time = cl_timestr; //get minimal required height, width from raw text int min_text_w = (*getClockFont())->getRenderWidth(s_time, true);; int min_text_h = (*getClockFont())->getHeight(); height = max(height, min_text_h); width = max(width, min_text_w); int cl_x = 0; int cl_h = min_text_h; int cl_y = 0; int w_lbl_tmp = 0; //create label objects and add to container, ensure count of items = count of chars (one char = one segment) if (v_cc_items.size() != s_time.size()){ //clean up possible old items before add new items clear(); //create new empty label objects, set some general properties and add to container for (size_t i = 0; i < s_time.size(); i++){ CComponentsLabel * lbl = new CComponentsLabel(); addCCItem(lbl); //background paint of item is not required lbl->doPaintBg(false); //set corner properties of label item lbl->setCorner(corner_rad-fr_thickness, corner_type); //set text border to 0 lbl->setTextBorderWidth(0,0); } } //calculate minimal separator width, we use char size of some possible chars int minSepWidth = 0; string sep[] ={" ", ".", ":"}; for (size_t i = 0; i < sizeof(sep)/sizeof(sep[0]); i++) minSepWidth = max((*getClockFont())->getRenderWidth(sep[i], true), minSepWidth); //modify available label items with current segment chars for (size_t i = 0; i < v_cc_items.size(); i++) { //v_cc_items are only available as CComponent-items here, so we must cast them before CComponentsLabel *lbl = static_cast <CComponentsLabel*> (v_cc_items[i]); //add rounded corners only to 1st and last segment if (corner_type) { if (i == 0) lbl->setCornerType(corner_type & CORNER_LEFT);// 1st label item else if (i == v_cc_items.size()-1) lbl->setCornerType(corner_type & CORNER_RIGHT);// last label item else lbl->setCornerType(0);// inner items } //extract timestring segment (char) string stmp = s_time.substr(i, 1); //get width of current segment int wtmp = 0; if (isdigit(stmp.at(0)) ) //check for digits, if true, we use digit width wtmp = (*getClockFont())->getMaxDigitWidth(); else //not digit found, we use render width or minimal width wtmp = max((*getClockFont())->getRenderWidth(stmp, true), minSepWidth); //set size, text, color of current item lbl->setDimensionsAll(cl_x, cl_y, wtmp, cl_h); lbl->setTextColor(cl_col_text); lbl->setColorAll(col_frame, col_body, col_shadow); lbl->setText(stmp, CTextBox::CENTER, *getClockFont()); //use matching height for digits for better vertical centerring into form CTextBox* ctb = lbl->getCTextBoxObject(); if (ctb) ctb->setFontUseDigitHeight(); #if 0 //ensure paint of text and label bg on changed text or painted form background bool force_txt_and_bg = (lbl->textChanged() || this->paint_bg); lbl->forceTextPaint(force_txt_and_bg); #endif //set xpos of item cl_x += wtmp; lbl->setWidth(wtmp); //set current width for form w_lbl_tmp += wtmp; } //set required width width = max(width, w_lbl_tmp); initSegmentAlign(&w_lbl_tmp, &min_text_h); }