uint8_t m2_gh_u8g_fb(m2_gfx_arg_p arg) { switch(arg->msg) { case M2_GFX_MSG_DRAW_NORMAL_NO_FOCUS: if ( (arg->font & 4) != 0 ) { m2_u8g_current_text_color = m2_u8g_bg_text_color; m2_u8g_draw_box(arg->x+m2_gh_u8g_invisible_frame_border_x_size, arg->y, arg->w-2*m2_gh_u8g_invisible_frame_border_x_size, arg->h); } else { m2_u8g_current_text_color = m2_u8g_fg_text_color; } break; case M2_GFX_MSG_DRAW_NORMAL_FOCUS: case M2_GFX_MSG_DRAW_NORMAL_PARENT_FOCUS: if ( (arg->font & 4) != 0 ) { m2_u8g_current_text_color = m2_u8g_fg_text_color; m2_u8g_draw_frame(arg->x+m2_gh_u8g_invisible_frame_border_x_size, arg->y, arg->w-2*m2_gh_u8g_invisible_frame_border_x_size, arg->h); } else { m2_u8g_current_text_color = m2_u8g_fg_text_color; m2_u8g_draw_frame(arg->x, arg->y, arg->w, arg->h); } break; case M2_GFX_MSG_DRAW_SMALL_FOCUS: m2_u8g_current_text_color = m2_u8g_bg_text_color; m2_u8g_draw_box(arg->x, arg->y, arg->w, arg->h); break; case M2_GFX_MSG_DRAW_GO_UP: /* does not work because of missing xor... also: can not be fixed with FRAME_DRAW_AT_END m2_u8g_current_text_color = m2_u8g_bg_text_color; */ m2_u8g_draw_box(arg->x, arg->y, arg->w, arg->h/2); break; case M2_GFX_MSG_GET_NORMAL_BORDER_HEIGHT: return 2; case M2_GFX_MSG_GET_NORMAL_BORDER_WIDTH: if ( (arg->font & 4) != 0 ) return 2+2*m2_gh_u8g_invisible_frame_border_x_size+2*m2_gh_u8g_additional_text_border_x_size; return 2*m2_gh_u8g_additional_text_border_x_size; case M2_GFX_MSG_GET_NORMAL_BORDER_X_OFFSET: if ( (arg->font & 4) != 0 ) return 1+m2_gh_u8g_invisible_frame_border_x_size+m2_gh_u8g_additional_text_border_x_size; return m2_gh_u8g_additional_text_border_x_size; case M2_GFX_MSG_GET_NORMAL_BORDER_Y_OFFSET: return 1; case M2_GFX_MSG_GET_LIST_OVERLAP_HEIGHT: return 0; case M2_GFX_MSG_GET_LIST_OVERLAP_WIDTH: return 0; case M2_GFX_MSG_IS_FRAME_DRAW_AT_END: return 0; /* focus (highlight) is drawn first, then the text string */ } return m2_gh_u8g_base(arg); }
uint8_t m2_gh_u8g_base(m2_gfx_arg_p arg) { /* Do a safety check here: Abort if m2_SetU8g has not been called */ if ( m2_u8g_dev_variables.m2_u8g == NULL ) return 0; /* Proceed with normal message processing */ switch(arg->msg) { case M2_GFX_MSG_INIT: break; case M2_GFX_MSG_START: /* check for proper setup */ break; case M2_GFX_MSG_END: break; case M2_GFX_MSG_DRAW_HLINE: u8g_DrawHLine(m2_u8g_dev_variables.m2_u8g, arg->x, m2_u8g_dev_variables.m2_u8g_height_minus_one - arg->y, arg->w); break; case M2_GFX_MSG_DRAW_VLINE: u8g_DrawVLine(m2_u8g_dev_variables.m2_u8g, arg->x, m2_u8g_dev_variables.m2_u8g_height_minus_one - arg->y, arg->h); break; case M2_GFX_MSG_DRAW_BOX: m2_u8g_draw_box(arg->x, arg->y, arg->w, arg->h); break; case M2_GFX_MSG_DRAW_TEXT: { u8g_uint_t x = arg->x; u8g_uint_t y; u8g_SetColorIndex(m2_u8g_dev_variables.m2_u8g, m2_u8g_dev_variables.m2_u8g_current_text_color); u8g_SetFont(m2_u8g_dev_variables.m2_u8g, m2_u8g_get_font(arg->font)); u8g_SetFontPosBottom(m2_u8g_dev_variables.m2_u8g); if ( (arg->font & 8) != 0 ) { if ( arg->w != 0 ) { x = arg->w; x -= u8g_GetStrWidth(m2_u8g_dev_variables.m2_u8g, arg->s); x >>= 1; x += arg->x; } } y = m2_u8g_dev_variables.m2_u8g_height_minus_one; y -= arg->y; y++; /* 13 Jan 2013: Issue 95, problem 2 */ x -= u8g_GetStrX(m2_u8g_dev_variables.m2_u8g, arg->s); //x += m2_gh_u8g_additional_text_border_x_size; u8g_DrawStr(m2_u8g_dev_variables.m2_u8g, x, y, arg->s); // printf("DRAW_TEXT: x=%d y=%d s=%s\n", x, y, arg->s); } break; case M2_GFX_MSG_DRAW_TEXT_P: { u8g_uint_t x = arg->x; u8g_uint_t y; u8g_SetColorIndex(m2_u8g_dev_variables.m2_u8g, m2_u8g_dev_variables.m2_u8g_current_text_color); u8g_SetFont(m2_u8g_dev_variables.m2_u8g, m2_u8g_get_font(arg->font)); u8g_SetFontPosBottom(m2_u8g_dev_variables.m2_u8g); if ( (arg->font & 8) != 0 ) { if ( arg->w != 0 ) { x = arg->w; x -= u8g_GetStrWidthP(m2_u8g_dev_variables.m2_u8g, (const u8g_pgm_uint8_t *)arg->s); x >>= 1; x += arg->x; } } y = m2_u8g_dev_variables.m2_u8g_height_minus_one; y -= arg->y; x -= u8g_GetStrXP(m2_u8g_dev_variables.m2_u8g, (const u8g_pgm_uint8_t *)arg->s); //x += m2_gh_u8g_additional_text_border_x_size; y++; /* 13 Jan 2013: Issue 95, problem 2 */ u8g_DrawStrP(m2_u8g_dev_variables.m2_u8g, x, y, (const u8g_pgm_uint8_t *)arg->s); }
uint8_t m2_gh_u8g_ffs(m2_gfx_arg_p arg) { switch(arg->msg) { case M2_GFX_MSG_DRAW_NORMAL_NO_FOCUS: if ( (arg->font & 4) != 0 ) { /* highlight flag is set, draw frame with shadow */ m2_u8g_draw_frame_shadow(arg->x+m2_gh_u8g_invisible_frame_border_x_size, arg->y, arg->w-2*m2_gh_u8g_invisible_frame_border_x_size, arg->h); } m2_u8g_current_text_color = m2_u8g_fg_text_color; if ( m2_gh_u8g_invert_at_depth < m2_gh_u8g_current_depth ) { m2_u8g_current_text_color = m2_u8g_bg_text_color; } break; case M2_GFX_MSG_DRAW_NORMAL_PARENT_FOCUS: break; case M2_GFX_MSG_DRAW_NORMAL_FOCUS: if ( (arg->font & 4) != 0 ) { /* highlight version draw frame with shadow together with a filled box */ m2_u8g_current_text_color = m2_u8g_bg_text_color; m2_u8g_draw_box(arg->x+1, arg->y+1, arg->w-2, arg->h-2); m2_u8g_draw_frame_shadow(arg->x+m2_gh_u8g_invisible_frame_border_x_size, arg->y, arg->w-2*m2_gh_u8g_invisible_frame_border_x_size, arg->h); m2_gh_u8g_invert_at_depth = m2_gh_u8g_current_depth; } else { /* normal version draw only the frame with shadow */ m2_u8g_current_text_color = m2_u8g_fg_text_color; m2_u8g_draw_frame_shadow(arg->x+m2_gh_u8g_invisible_frame_border_x_size, arg->y, arg->w-2*m2_gh_u8g_invisible_frame_border_x_size, arg->h); } // printf("invert %d, width %d x:%d y:%d\n", m2_gh_u8g_invert_at_depth, arg->w, arg->x, arg->y); break; case M2_GFX_MSG_DRAW_SMALL_FOCUS: m2_u8g_current_text_color = m2_u8g_bg_text_color; m2_u8g_draw_box(arg->x, arg->y, arg->w, arg->h); break; case M2_GFX_MSG_DRAW_NORMAL_DATA_ENTRY: m2_u8g_current_text_color = m2_u8g_fg_text_color; u8g_DrawHLine(m2_u8g, arg->x, m2_u8g_height_minus_one - arg->y, arg->w); break; case M2_GFX_MSG_DRAW_SMALL_DATA_ENTRY: m2_u8g_current_text_color = m2_u8g_fg_text_color; u8g_DrawHLine(m2_u8g, arg->x, m2_u8g_height_minus_one - arg->y, arg->w); break; case M2_GFX_MSG_DRAW_GO_UP: /* does not work because of missing xor... also: can not be fixed with FRAME_DRAW_AT_END m2_u8g_current_text_color = m2_u8g_bg_text_color; */ m2_u8g_draw_box(arg->x, arg->y, arg->w, arg->h/2); break; case M2_GFX_MSG_GET_NORMAL_BORDER_HEIGHT: return 3; case M2_GFX_MSG_GET_NORMAL_BORDER_WIDTH: return 3+2*m2_gh_u8g_invisible_frame_border_x_size+2*m2_gh_u8g_additional_text_border_x_size; case M2_GFX_MSG_GET_NORMAL_BORDER_X_OFFSET: return 1+m2_gh_u8g_invisible_frame_border_x_size+m2_gh_u8g_additional_text_border_x_size; case M2_GFX_MSG_GET_NORMAL_BORDER_Y_OFFSET: return 2; case M2_GFX_MSG_GET_LIST_OVERLAP_HEIGHT: return 0; case M2_GFX_MSG_GET_LIST_OVERLAP_WIDTH: return 0; case M2_GFX_MSG_IS_FRAME_DRAW_AT_END: return 0; /* focus (highlight) is drawn first, then the text string */ } return m2_gh_u8g_base(arg); }