diff --git a/lv_objx/lv_bar.c b/lv_objx/lv_bar.c index 454aba4bb..46ca9bd1a 100644 --- a/lv_objx/lv_bar.c +++ b/lv_objx/lv_bar.c @@ -317,11 +317,11 @@ static bool lv_bar_design(lv_obj_t * bar, const lv_area_t * mask, lv_design_mode lv_coord_t h = lv_area_get_height(&indic_area); if(w >= h) { - indic_area.x2 = (int32_t)((int32_t)w * (ext->cur_value - ext->min_value - 1)) / (ext->max_value - ext->min_value); - indic_area.x2 = indic_area.x1 + indic_area.x2; + indic_area.x2 = (int32_t)((int32_t)w * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value); + indic_area.x2 = indic_area.x1 + indic_area.x2 - 1; } else { - indic_area.y1 = (int32_t)((int32_t)h * (ext->cur_value - ext->min_value - 1)) / (ext->max_value - ext->min_value); - indic_area.y1 = indic_area.y2 - indic_area.y1; + indic_area.y1 = (int32_t)((int32_t)h * (ext->cur_value - ext->min_value)) / (ext->max_value - ext->min_value); + indic_area.y1 = indic_area.y2 - indic_area.y1 + 1; } /*Draw the indicator*/ diff --git a/lv_objx/lv_btnm.c b/lv_objx/lv_btnm.c index c5f609213..38f011091 100644 --- a/lv_objx/lv_btnm.c +++ b/lv_objx/lv_btnm.c @@ -547,45 +547,42 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param) } } else if(sign == LV_SIGNAL_RELEASED) { if(ext->btn_id_pr != LV_BTNM_PR_NONE) { - if(ext->action) { - uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr); - if(txt_i != LV_BTNM_PR_NONE && button_is_inactive(ext->map_p[txt_i]) == false) { - ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); - } - } + uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr); + if(button_is_inactive(ext->map_p[txt_i]) == false && txt_i != LV_BTNM_PR_NONE) { /*Ignore the inactive buttons anf click between the buttons*/ + if(ext->action)ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); - /*Invalidate to old pressed area*/; - lv_obj_get_coords(btnm, &btnm_area); - lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]); - btn_area.x1 += btnm_area.x1; - btn_area.y1 += btnm_area.y1; - btn_area.x2 += btnm_area.x1; - btn_area.y2 += btnm_area.y1; - lv_inv_area(&btn_area); - - if(ext->toggle != 0) { - /*Invalidate to old toggled area*/; - lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]); + /*Invalidate to old pressed area*/; + lv_obj_get_coords(btnm, &btnm_area); + lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]); btn_area.x1 += btnm_area.x1; btn_area.y1 += btnm_area.y1; btn_area.x2 += btnm_area.x1; btn_area.y2 += btnm_area.y1; lv_inv_area(&btn_area); - ext->btn_id_tgl = ext->btn_id_pr; - } + if(ext->toggle != 0) { + /*Invalidate to old toggled area*/; + lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]); + btn_area.x1 += btnm_area.x1; + btn_area.y1 += btnm_area.y1; + btn_area.x2 += btnm_area.x1; + btn_area.y2 += btnm_area.y1; + lv_inv_area(&btn_area); + ext->btn_id_tgl = ext->btn_id_pr; + } - -#if USE_LV_GROUP - /*Leave the clicked button as pressed if this the focused object in a group*/ - lv_group_t * g = lv_obj_get_group(btnm); - if(lv_group_get_focused(g) != btnm) { + #if USE_LV_GROUP + /*Leave the clicked button as pressed if this the focused object in a group*/ + lv_group_t * g = lv_obj_get_group(btnm); + if(lv_group_get_focused(g) != btnm) { + ext->btn_id_pr = LV_BTNM_PR_NONE; + } + #else ext->btn_id_pr = LV_BTNM_PR_NONE; + #endif + } -#else - ext->btn_id_pr = LV_BTNM_PR_NONE; -#endif } } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) { ext->btn_id_pr = LV_BTNM_PR_NONE; diff --git a/lv_objx/lv_slider.c b/lv_objx/lv_slider.c index 857bb61bd..71e4b4162 100644 --- a/lv_objx/lv_slider.c +++ b/lv_objx/lv_slider.c @@ -349,12 +349,12 @@ static bool lv_slider_design(lv_obj_t * slider, const lv_area_t * mask, lv_desig if(ext->drag_value != LV_SLIDER_NOT_PRESSED) cur_value = ext->drag_value; if(slider_w >= slider_h) { - area_indic.x2 = (int32_t)((int32_t)(lv_area_get_width(&area_indic) - 1) * (cur_value - min_value)) / (max_value - min_value); - area_indic.x2 = area_indic.x1 + area_indic.x2; + area_indic.x2 = (int32_t)((int32_t)(lv_area_get_width(&area_indic)) * (cur_value - min_value)) / (max_value - min_value); + area_indic.x2 = area_indic.x1 + area_indic.x2 - 1; } else { - area_indic.y1 = (int32_t)((int32_t)(lv_area_get_height(&area_indic) - 1) * (cur_value - min_value)) / (max_value - min_value); - area_indic.y1 = area_indic.y2 - area_indic.y1; + area_indic.y1 = (int32_t)((int32_t)(lv_area_get_height(&area_indic)) * (cur_value - min_value)) / (max_value - min_value); + area_indic.y1 = area_indic.y2 - area_indic.y1 + 1; } if(cur_value != min_value) lv_draw_rect(&area_indic, mask, style_indic, opa_scale); diff --git a/utils/bdf_font_converter.py b/utils/bdf_font_converter.py new file mode 100644 index 000000000..16935822e --- /dev/null +++ b/utils/bdf_font_converter.py @@ -0,0 +1,201 @@ +#!/user/bin/env python + +''' +Small utility that converts 1bpp BDF fonts to a font compatible with littlevgl +''' + +# General imports +import argparse +import math + + +class Glyph: + def __init__(self, props ): + for k, v in props.items(): + setattr(self, k, v) + + def __lt__(self, other): + return self.encoding < other.encoding + + def get_width(self): + return self.dwidth[0] + + def get_byte_width(self): + # Compute how many bytes wide the glyph will be + return math.ceil(self.dwidth[0] / 8.0) + + def get_height(self): + return len(self.bitmap) + + def get_encoding(self): + return self.encoding + + def write_bitmap(self, f): + f.write('''/*Unicode: U+%04x ( %s ) , Width: %d */\n''' % + (self.encoding, self.name, self.dwidth[0]) ) + for line in self.bitmap: + for i in range(0, len(line), 2): + f.write("0x%s," % line[i:i+2]) + if(i > 0): + f.write(" ") + f.write("\n") + f.write("\n\n") + +def parse_bdf(fn): + # Converts bdf file to a list of Glyphs + # Read in BDF File + with open(fn, "r") as f: + bdf = f.readlines() + bdf = [x.rstrip("\n") for x in bdf] + + # Iterate through BDF Glyphs + glyphs = [] + i = -1 + while i < len(bdf): + props = {} + + i += 1 + tokens = bdf[i].split(' ') + if tokens[0] == 'ENDFONT': + break; + if tokens[0] != "STARTCHAR": + continue + props['name'] = tokens[1] + + i += 1 + tokens = bdf[i].split(' ') + if tokens[0] != "ENCODING": + continue + encoding = int(tokens[-1]) + if encoding < 0: # skip glyphs with a negative encoding value + continue + props['encoding'] = encoding + + i += 1 + tokens = bdf[i].split(' ') + if tokens[0] != "SWIDTH": + continue + props['swidth'] = (int(tokens[1]), int(tokens[2])) + + i += 1 + tokens = bdf[i].split(' ') + if tokens[0] != "DWIDTH": + continue + props['dwidth'] = (int(tokens[1]), int(tokens[2])) + + i += 1 + tokens = bdf[i].split(' ') + if tokens[0] != "BBX": + continue + props['dwidth'] = (int(tokens[1]), int(tokens[2]), + int(tokens[3]), int(tokens[4])) + + i += 1 + tokens = bdf[i].split(' ') + if tokens[0] != "BITMAP": + continue + + props['bitmap'] = [] + while True: + i += 1 + tokens = bdf[i].split(' ') + if tokens[0] == 'ENDCHAR': + break + props['bitmap'].append(tokens[0]) + glyphs.append(Glyph(props)) + return glyphs + +def parse_args(): + ''' Parse CLI arguments into an object and a dictionary ''' + parser = argparse.ArgumentParser() + parser.add_argument('bdf_fn', type=str, default='imgs', + help='BDF Filename') + parser.add_argument('font_name', type=str, default='font_name', + help='Name of the font to be generated') + args = parser.parse_args() + dargs = vars(args) + return (args, dargs) + +def main(): + args, dargs = parse_args() + + glyphs = parse_bdf(args.bdf_fn) + glyphs.sort() # Sorts by encoding (utf8) value + + ################ + # WRITE HEADER # + ################ + out = open(args.font_name + '.c', "w") + out.write(''' +#include "../lv_misc/lv_font.h" +''') + + ################# + # WRITE BITMAPS # + ################# + out.write( +''' +static const uint8_t %s_glyph_bitmap[] = +{ +''' % args.font_name) + + for glyph in glyphs: + glyph.write_bitmap(out) + + out.write(''' +}; +''') + + ###################### + # WRITE DESCRIPTIONS # + ###################### + out.write( +''' +/*Store the glyph descriptions*/ +static const lv_font_glyph_dsc_t %s_glyph_dsc[] = +{ +''' % args.font_name) + glyph_index = 0 + for glyph in glyphs: + out.write(''' +{.w_px = %d, .glyph_index = %d}, /*Unicode: U+%04x ( )*/ +''' % (glyph.get_width(), glyph_index, glyph.get_encoding()) ) + glyph_index += glyph.get_byte_width() * glyph.get_height() + + out.write(''' +}; +''') + + ##################### + # WRITE FONT STRUCT # + ##################### + out.write( +''' +lv_font_t %s = +{ + .unicode_first = %d, /*First Unicode letter in this font*/ + .unicode_last = %d, /*Last Unicode letter in this font*/ + .h_px = %d, /*Font height in pixels*/ + .glyph_bitmap = %s_glyph_bitmap, /*Bitmap of glyphs*/ + .glyph_dsc = %s_glyph_dsc, /*Description of glyphs*/ + .glyph_cnt = %d, /*Number of glyphs in the font*/ + .unicode_list = NULL, /*Every character in the font from 'unicode_first' to 'unicode_last'*/ + .get_bitmap = lv_font_get_bitmap_continuous, /*Function pointer to get glyph's bitmap*/ + .get_width = lv_font_get_width_continuous, /*Function pointer to get glyph's width*/ + .bpp = 1, /*Bit per pixel*/ + .monospace = 0, /*Fix width (0: if not used)*/ + .next_page = NULL, /*Pointer to a font extension*/ +}; +''' % (args.font_name, + glyphs[0].get_encoding(), + glyphs[-1].get_encoding(), + glyphs[0].get_height(), + args.font_name, + args.font_name, + len(glyphs), + ) ) + + out.close() + +if __name__=='__main__': + main()