📄 touchscreen.c
字号:
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
mmi_pen_handwriting_area_struct *block;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (*x < 0)
{
*x = 0;
}
else if (*x >= UI_device_width)
{
*x = UI_device_width - 1;
}
if (*y < 0)
{
*y = 0;
}
else if (*y >= UI_device_height)
{
*y = UI_device_height - 1;
}
if (check_multi_block)
{
MMI_ASSERT(g_pen_cntx.stroke_down_block_index >= 0 &&
g_pen_cntx.stroke_down_block_index < g_pen_num_stroke_area);
block = &g_pen_stroke_areas[g_pen_cntx.stroke_down_block_index];
if (*x < block->x1)
{
*x = block->x1;
}
else if (*x > block->x2)
{
*x = block->x2;
}
if (*y < block->y1)
{
*y = block->y1;
}
else if (*y > block->y2)
{
*y = block->y2;
}
}
}
/*****************************************************************************
* FUNCTION
* mmi_pen_simulator_pixel_diff
* DESCRIPTION
*
* PARAMETERS
* pos1 [IN]
* pos2 [IN]
* RETURNS
*
*****************************************************************************/
static S16 mmi_pen_simulator_pixel_diff(mmi_pen_point_struct pos1, mmi_pen_point_struct pos2)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
S16 diff_x = pos1.x - pos2.x;
S16 diff_y = pos1.y - pos2.y;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (diff_x < 0)
{
diff_x = -diff_x;
}
if (diff_y < 0)
{
diff_y = -diff_y;
}
return diff_x + diff_y;
}
/*****************************************************************************
* FUNCTION
* mmi_pen_simulator_in_stroke_area
* DESCRIPTION
*
* PARAMETERS
* x [IN]
* y [IN]
* RETURNS
* The index of block. 0 for block-0 or extended area, -1 if not found.
*****************************************************************************/
static S32 mmi_pen_simulator_in_stroke_area(S16 x, S16 y)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
int i;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_pen_cntx.is_stroke_created &&
(g_pen_ext_stroke_area.x2 >= 0) && /* Test if the extended handwriting area is enabled */
x >= g_pen_ext_stroke_area.x1 && x <= g_pen_ext_stroke_area.x2 &&
y >= g_pen_ext_stroke_area.y1 && y <= g_pen_ext_stroke_area.y2)
{
return 0;
}
for (i = 0; i < g_pen_num_stroke_area; i++)
{
if (x >= g_pen_stroke_areas[i].x1 && x <= g_pen_stroke_areas[i].x2 &&
y >= g_pen_stroke_areas[i].y1 && y <= g_pen_stroke_areas[i].y2)
{
return i;
}
}
return -1;
}
/*****************************************************************************
* FUNCTION
* mmi_pen_simulator_push_stroke_point
* DESCRIPTION
*
* PARAMETERS
* x [IN]
* y [IN]
* RETURNS
* void
*****************************************************************************/
static void mmi_pen_simulator_push_stroke_point(S16 x, S16 y)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_pen_cntx.num_points_queued >= g_pen_stroke_max_points - 2)
{
return;
}
g_pen_stroke_points[g_pen_cntx.num_points_queued].x = x;
g_pen_stroke_points[g_pen_cntx.num_points_queued].y = y;
g_pen_cntx.num_points_queued++;
}
/*****************************************************************************
* FUNCTION
* mmi_pen_simulator_push_stroke_end
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
static void mmi_pen_simulator_push_stroke_end(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_pen_cntx.num_points_queued >= g_pen_stroke_max_points - 1)
{
MMI_ASSERT(0); /* queue full */
return;
}
#if defined(__MMI_HANWANG__)
g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
g_pen_stroke_points[g_pen_cntx.num_points_queued].y = 0;
#elif defined(__MMI_PENPOWER__)
g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
g_pen_stroke_points[g_pen_cntx.num_points_queued].y = -1;
#else
g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
g_pen_stroke_points[g_pen_cntx.num_points_queued].y = 0;
#endif
g_pen_cntx.num_points_queued++;
}
/*****************************************************************************
* FUNCTION
* mmi_pen_simulator_push_char_end
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
static void mmi_pen_simulator_push_char_end(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (g_pen_cntx.num_points_queued >= g_pen_stroke_max_points)
{
MMI_ASSERT(0); /* queue full */
return;
}
#if defined(__MMI_HANWANG__)
g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
g_pen_stroke_points[g_pen_cntx.num_points_queued].y = -1;
#elif defined(__MMI_PENPOWER__)
g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
g_pen_stroke_points[g_pen_cntx.num_points_queued].y = 0;
#else
g_pen_stroke_points[g_pen_cntx.num_points_queued].x = -1;
g_pen_stroke_points[g_pen_cntx.num_points_queued].y = -1;
#endif
g_pen_cntx.num_points_queued++;
}
/*****************************************************************************
* FUNCTION
* mmi_pen_simulator_repeat_hdlr
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
static void mmi_pen_simulator_repeat_hdlr(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
MMI_ASSERT(g_pen_cntx.is_enabled && g_pen_cntx.is_pen_down);
if (g_pen_cntx.is_waiting_long_tap_event)
{
if (g_pen_event_table[MMI_PEN_EVENT_LONG_TAP])
{
(g_pen_event_table[MMI_PEN_EVENT_LONG_TAP]) (g_pen_cntx.pen_down_pos);
}
g_pen_cntx.is_waiting_long_tap_event = 0;
}
else
{
if (g_pen_event_table[MMI_PEN_EVENT_REPEAT])
{
(g_pen_event_table[MMI_PEN_EVENT_REPEAT]) (g_pen_cntx.pen_repeat_origin_pos);
}
}
/* touch screen might be disabled/reset inside pen handler */
if (g_pen_cntx.is_enabled && g_pen_cntx.is_pen_down)
{
gui_start_timer(MMI_PEN_REPEAT_TIME * 10, mmi_pen_simulator_repeat_hdlr);
}
}
/*****************************************************************************
* FUNCTION
* mmi_pen_simulator_stroke_longtap_hdlr
* DESCRIPTION
*
* PARAMETERS
* void
* RETURNS
* void
*****************************************************************************/
static void mmi_pen_simulator_stroke_longtap_hdlr(void)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
MMI_ASSERT(g_pen_cntx.is_enabled && g_pen_cntx.is_pen_down && g_pen_cntx.is_stroke_event);
g_pen_cntx.is_stroke_longtap_event_generated = 1;
if (g_pen_stroke_table[MMI_PEN_STROKE_LONGTAP])
{
(g_pen_stroke_table[MMI_PEN_STROKE_LONGTAP]) (g_pen_cntx.pen_current_pos);
}
}
/*****************************************************************************
* FUNCTION
* mmi_pen_simulator_button_down_hdlr
* DESCRIPTION
*
* PARAMETERS
* x [IN]
* y [IN]
* RETURNS
* void
*****************************************************************************/
void mmi_pen_simulator_button_down_hdlr(S16 x, S16 y)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
mmi_pen_point_struct pos;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (!g_pen_cntx.is_enabled || g_pen_cntx.is_all_stroke_finished)
{
return;
}
MMI_DBG_ASSERT(!g_pen_cntx.is_pen_down);
mmi_pen_simulator_fix_point_bound(&x, &y, MMI_FALSE);
pos.x = x;
pos.y = y;
g_pen_cntx.pen_down_pos = g_pen_cntx.pen_current_pos = g_pen_cntx.pen_repeat_origin_pos = pos;
g_pen_cntx.is_pen_down = 1;
g_pen_cntx.is_stroke_event = 0;
g_pen_cntx.is_pending_stroke_event = 0;
g_pen_cntx.is_stroke_longtap_event_generated = 0;
/* Not reset is_stroke_created */
g_pen_cntx.is_waiting_long_tap_event = 0;
if ((g_pen_cntx.stroke_down_block_index = mmi_pen_simulator_in_stroke_area(x, y)) >= 0)
{
if (!g_pen_cntx.is_stroke_created && g_pen_stroke_min_offset > 0)
{
g_pen_cntx.is_pending_stroke_event = 1;
/* Fire pen down event. For example, it will display key down on virtual keyboard */
if (g_pen_event_table[MMI_PEN_EVENT_DOWN])
{
(g_pen_event_table[MMI_PEN_EVENT_DOWN]) (pos);
}
}
else
{
if (!g_pen_cntx.is_stroke_created) /* StrokeLongTap is used in the first stroke only */
{
gui_start_timer(MMI_PEN_STROKE_LONGTAP_TIME * 10, mmi_pen_simulator_stroke_longtap_hdlr);
}
g_pen_cntx.is_stroke_event = 1;
g_pen_cntx.is_stroke_created = 1;
if (g_pen_stroke_table[MMI_PEN_STROKE_DOWN])
{
(g_pen_stroke_table[MMI_PEN_STROKE_DOWN]) (pos);
}
/* Put stroke point after stroke down handler because multi-block handwriting may invoke
* mmi_pen_begin_strokes_of_character() and mmi_pen_end_strokes_of_character() in
* Stroke Down handler.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -