Skip to content

Commit

Permalink
issue olikraus#364, added second update function for the clip window
Browse files Browse the repository at this point in the history
  • Loading branch information
olikraus committed Oct 28, 2018
1 parent 20df2c2 commit 2f1eed2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 22 deletions.
4 changes: 3 additions & 1 deletion csrc/u8g2.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ typedef struct u8g2_struct u8g2_t;
typedef struct u8g2_cb_struct u8g2_cb_t;

typedef void (*u8g2_update_dimension_cb)(u8g2_t *u8g2);
typedef void (*u8g2_update_page_win_cb)(u8g2_t *u8g2);
typedef void (*u8g2_draw_l90_cb)(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir);
typedef void (*u8g2_draw_ll_hvline_cb)(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir);

Expand Down Expand Up @@ -269,7 +270,8 @@ typedef struct _u8g2_kerning_t u8g2_kerning_t;

struct u8g2_cb_struct
{
u8g2_update_dimension_cb update;
u8g2_update_dimension_cb update_dimension;
u8g2_update_page_win_cb update_page_win;
u8g2_draw_l90_cb draw_l90;
};

Expand Down
3 changes: 2 additions & 1 deletion csrc/u8g2_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ void u8g2_SendBuffer(u8g2_t *u8g2)
void u8g2_SetBufferCurrTileRow(u8g2_t *u8g2, uint8_t row)
{
u8g2->tile_curr_row = row;
u8g2->cb->update(u8g2);
u8g2->cb->update_dimension(u8g2);
u8g2->cb->update_page_win(u8g2);
}

void u8g2_FirstPage(u8g2_t *u8g2)
Expand Down
49 changes: 30 additions & 19 deletions csrc/u8g2_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ void u8g2_SetMaxClipWindow(u8g2_t *u8g2)
u8g2->clip_y0 = 0;
u8g2->clip_x1 = (u8g2_uint_t)~(u8g2_uint_t)0;
u8g2->clip_y1 = (u8g2_uint_t)~(u8g2_uint_t)0;
u8g2->cb->update(u8g2);

u8g2->cb->update_page_win(u8g2);
}

void u8g2_SetClipWindow(u8g2_t *u8g2, u8g2_uint_t clip_x0, u8g2_uint_t clip_y0, u8g2_uint_t clip_x1, u8g2_uint_t clip_y1 )
Expand All @@ -58,7 +59,7 @@ void u8g2_SetClipWindow(u8g2_t *u8g2, u8g2_uint_t clip_x0, u8g2_uint_t clip_y0,
u8g2->clip_y0 = clip_y0;
u8g2->clip_x1 = clip_x1;
u8g2->clip_y1 = clip_y1;
u8g2->cb->update(u8g2);
u8g2->cb->update_page_win(u8g2);
}
#endif

Expand Down Expand Up @@ -88,10 +89,11 @@ void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_
u8g2->is_auto_page_clear = 1;

u8g2->cb = u8g2_cb;
u8g2->cb->update_dimension(u8g2);
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
u8g2_SetMaxClipWindow(u8g2); /* assign a clip window and call the update() procedure */
#else
u8g2->cb->update(u8g2);
u8g2->cb->update_page_win(u8g2);
#endif

u8g2_SetFontPosBaseline(u8g2); /* issue 195 */
Expand All @@ -108,7 +110,8 @@ void u8g2_SetupBuffer(u8g2_t *u8g2, uint8_t *buf, uint8_t tile_buf_height, u8g2_
void u8g2_SetDisplayRotation(u8g2_t *u8g2, const u8g2_cb_t *u8g2_cb)
{
u8g2->cb = u8g2_cb;
u8g2->cb->update(u8g2);
u8g2->cb->update_dimension(u8g2);
u8g2->cb->update_page_win(u8g2);
}


Expand Down Expand Up @@ -198,8 +201,11 @@ static void u8g2_apply_clip_window(u8g2_t *u8g2)

void u8g2_update_dimension_r0(u8g2_t *u8g2)
{
u8g2_update_dimension_common(u8g2);
u8g2_update_dimension_common(u8g2);
}

void u8g2_update_page_win_r0(u8g2_t *u8g2)
{
u8g2->user_x0 = 0;
u8g2->user_x1 = u8g2->pixel_buf_width; /* pixel_buf_width replaced with width */

Expand All @@ -209,18 +215,20 @@ void u8g2_update_dimension_r0(u8g2_t *u8g2)
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
u8g2_apply_clip_window(u8g2);
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */

// printf("x0=%d x1=%d y0=%d y1=%d\n",
// u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1);
}


void u8g2_update_dimension_r1(u8g2_t *u8g2)
{
u8g2_update_dimension_common(u8g2);

u8g2->height = u8g2_GetU8x8(u8g2)->display_info->pixel_width;
u8g2->width = u8g2_GetU8x8(u8g2)->display_info->pixel_height;

}

void u8g2_update_page_win_r1(u8g2_t *u8g2)
{
u8g2->user_x0 = u8g2->buf_y0;
u8g2->user_x1 = u8g2->buf_y1;

Expand All @@ -230,14 +238,15 @@ void u8g2_update_dimension_r1(u8g2_t *u8g2)
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
u8g2_apply_clip_window(u8g2);
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
//printf("x0=%d x1=%d y0=%d y1=%d\n",
// u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1);
}

void u8g2_update_dimension_r2(u8g2_t *u8g2)
{
u8g2_update_dimension_common(u8g2);
}

void u8g2_update_page_win_r2(u8g2_t *u8g2)
{
u8g2->user_x0 = 0;
u8g2->user_x1 = u8g2->width; /* pixel_buf_width replaced with width */

Expand All @@ -251,17 +260,20 @@ void u8g2_update_dimension_r2(u8g2_t *u8g2)
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
u8g2_apply_clip_window(u8g2);
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
// printf("x0=%d x1=%d y0=%d y1=%d\n",
// u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1);
}


void u8g2_update_dimension_r3(u8g2_t *u8g2)
{
u8g2_update_dimension_common(u8g2);

u8g2->height = u8g2_GetU8x8(u8g2)->display_info->pixel_width;
u8g2->width = u8g2_GetU8x8(u8g2)->display_info->pixel_height;

}

void u8g2_update_page_win_r3(u8g2_t *u8g2)
{
/* there are ases where the height is not a multiple of 8. */
/* in such a case u8g2->buf_y1 might be heigher than u8g2->width */
u8g2->user_x0 = 0;
Expand All @@ -275,10 +287,9 @@ void u8g2_update_dimension_r3(u8g2_t *u8g2)
#ifdef U8G2_WITH_CLIP_WINDOW_SUPPORT
u8g2_apply_clip_window(u8g2);
#endif /* U8G2_WITH_CLIP_WINDOW_SUPPORT */
// printf("x0=%d x1=%d y0=%d y1=%d\n",
// u8g2->user_x0, u8g2->user_x1, u8g2->user_y0, u8g2->user_y1);
}


/*============================================*/
extern void u8g2_draw_hv_line_2dir(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, uint8_t dir);

Expand Down Expand Up @@ -407,12 +418,12 @@ void u8g2_draw_l90_r3(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t le


/*============================================*/
const u8g2_cb_t u8g2_cb_r0 = { u8g2_update_dimension_r0, u8g2_draw_l90_r0 };
const u8g2_cb_t u8g2_cb_r1 = { u8g2_update_dimension_r1, u8g2_draw_l90_r1 };
const u8g2_cb_t u8g2_cb_r2 = { u8g2_update_dimension_r2, u8g2_draw_l90_r2 };
const u8g2_cb_t u8g2_cb_r3 = { u8g2_update_dimension_r3, u8g2_draw_l90_r3 };
const u8g2_cb_t u8g2_cb_r0 = { u8g2_update_dimension_r0, u8g2_update_page_win_r0, u8g2_draw_l90_r0 };
const u8g2_cb_t u8g2_cb_r1 = { u8g2_update_dimension_r1, u8g2_update_page_win_r1, u8g2_draw_l90_r1 };
const u8g2_cb_t u8g2_cb_r2 = { u8g2_update_dimension_r2, u8g2_update_page_win_r2, u8g2_draw_l90_r2 };
const u8g2_cb_t u8g2_cb_r3 = { u8g2_update_dimension_r3, u8g2_update_page_win_r3, u8g2_draw_l90_r3 };

const u8g2_cb_t u8g2_cb_mirror = { u8g2_update_dimension_r0, u8g2_draw_l90_mirrorr_r0 };
const u8g2_cb_t u8g2_cb_mirror = { u8g2_update_dimension_r0, u8g2_update_page_win_r0, u8g2_draw_l90_mirrorr_r0 };

/*============================================*/
/* setup for the null device */
Expand Down
4 changes: 4 additions & 0 deletions sys/arduino/u8g2_page_buffer/FPS/FPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@
U8G2_SSD1306_128X64_NONAME_1_3W_SW_SPI Uno Clip=2.7 Box=2.9 @=1.8 Pix=2.2 issue 586, before optimization
U8G2_SSD1306_128X64_NONAME_1_3W_SW_SPI Uno Clip=23.4 Box=40.8 @=4.4 Pix=8.1 issue 586, after optimization
28 Oct 2018, Arduino 1.8.4, 8 Bit Mode
U8G2_SSD1306_128X64_NONAME_1_4W_HW_SPI Uno 8MHz Clip=34.0 Box=88.4 @=4.5 Pix=8.2 issue 364, clip window
*/


Expand Down
2 changes: 1 addition & 1 deletion sys/utf8/clip_test_picture_loop/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main(void)

u8g2_SetFontDirection(&u8g2, 0);

u8g2_SetClipWindow(&u8g2, 10, 10, 50, 60 );
//u8g2_SetClipWindow(&u8g2, 10, 10, 50, 60 );


u8g2_SetDisplayRotation(&u8g2, U8G2_R0);
Expand Down

0 comments on commit 2f1eed2

Please sign in to comment.