gui_color_slider.c
上传用户:lqx1163
上传日期:2014-08-13
资源大小:9183k
文件大小:17k
源码类别:

MTK

开发平台:

C/C++

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   gui_color_slider.c
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui_Software
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  UI component - Color picker
  48.  *
  49.  * Author:
  50.  * -------
  51.  * -------
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * removed!
  58.  *
  59.  * removed!
  60.  * removed!
  61.  * removed!
  62.  *
  63.  * removed!
  64.  * removed!
  65.  * removed!
  66.  *
  67.  * removed!
  68.  * removed!
  69.  * removed!
  70.  *
  71.  * removed!
  72.  * removed!
  73.  * removed!
  74.  *
  75.  *------------------------------------------------------------------------------
  76.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  77.  *============================================================================
  78.  ****************************************************************************/
  79. #include "MMI_features.h"
  80. #include "stdC.h"
  81. #include "L4Dr1.h"
  82. #include "PixtelDataTypes.h"
  83. #include "GlobalDefs.h"
  84. #include "gui_data_types.h"
  85. #include "gui_color_slider.h"
  86. #include "DebugInitDef.h"
  87. const U8 color_slider_arrow_image[] = 
  88. {
  89.     0x04, 0x00, 0x3D, 0x00, 0x00, 0x00,
  90.     0x06, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x0C, 0x0C, 0x00, 0x00, 0x00,
  91.     0x34, 0x12, 0x34, 0x12, 0x00, 0x00, 0x00, 0x00, 0x34, 0x12, 0x34, 0x12, 0x34, 0x12, 0x00, 0x00,
  92.     0xF8, 0x00, 0xF8, 0x00, 0x00, 0x00, 0x34, 0x12, 0x00, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0xF8, 0x00,
  93.     0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  94. };
  95. /*****************************************************************************
  96.  * FUNCTION
  97.  *  gui_color_slider_create
  98.  * DESCRIPTION
  99.  *  
  100.  * PARAMETERS
  101.  *  s           [IN/OUT]         
  102.  *  x           [IN]        
  103.  *  y           [IN]        
  104.  *  width       [IN]        
  105.  *  height      [IN]        
  106.  * RETURNS
  107.  *  void
  108.  *****************************************************************************/
  109. void gui_color_slider_create(color_slider *s, S32 x, S32 y, S32 width, S32 height)
  110. {
  111.     /*----------------------------------------------------------------*/
  112.     /* Local Variables                                                */
  113.     /*----------------------------------------------------------------*/
  114.     /*----------------------------------------------------------------*/
  115.     /* Code Body                                                      */
  116.     /*----------------------------------------------------------------*/
  117.     s->x = x;
  118.     s->y = y;
  119.     s->width = width;
  120.     s->height = height;
  121.     s->range = 0;
  122.     s->value = 0;
  123.     s->filler = NULL;
  124.     s->flags = 0;
  125.     s->simage = (PU8) color_slider_arrow_image;
  126.     gui_measure_image(s->simage, &s->swidth, &s->sheight);
  127.     s->shide = NULL;
  128. }
  129. /*****************************************************************************
  130.  * FUNCTION
  131.  *  gui_color_slider_set_range
  132.  * DESCRIPTION
  133.  *  
  134.  * PARAMETERS
  135.  *  s           [IN/OUT]         
  136.  *  range       [IN]        
  137.  * RETURNS
  138.  *  void
  139.  *****************************************************************************/
  140. void gui_color_slider_set_range(color_slider *s, S32 range)
  141. {
  142.     /*----------------------------------------------------------------*/
  143.     /* Local Variables                                                */
  144.     /*----------------------------------------------------------------*/
  145.     /*----------------------------------------------------------------*/
  146.     /* Code Body                                                      */
  147.     /*----------------------------------------------------------------*/
  148.     s->range = range;
  149. }
  150. /*****************************************************************************
  151.  * FUNCTION
  152.  *  gui_color_slider_set_value
  153.  * DESCRIPTION
  154.  *  
  155.  * PARAMETERS
  156.  *  s           [IN/OUT]         
  157.  *  value       [IN]        
  158.  * RETURNS
  159.  *  void
  160.  *****************************************************************************/
  161. void gui_color_slider_set_value(color_slider *s, S32 value)
  162. {
  163.     /*----------------------------------------------------------------*/
  164.     /* Local Variables                                                */
  165.     /*----------------------------------------------------------------*/
  166.     /*----------------------------------------------------------------*/
  167.     /* Code Body                                                      */
  168.     /*----------------------------------------------------------------*/
  169.     if (value < 0)
  170.     {
  171.         value = 0;
  172.     }
  173.     if (value >= s->range)
  174.     {
  175.         value = s->range - 1;
  176.     }
  177.     s->value = value;
  178. }
  179. /*****************************************************************************
  180.  * FUNCTION
  181.  *  gui_color_slider_set_filler
  182.  * DESCRIPTION
  183.  *  
  184.  * PARAMETERS
  185.  *  s       [IN/OUT]     
  186.  *  f       [IN]     
  187.  * RETURNS
  188.  *  void
  189.  *****************************************************************************/
  190. void gui_color_slider_set_filler(color_slider *s, UI_filled_area *f)
  191. {
  192.     /*----------------------------------------------------------------*/
  193.     /* Local Variables                                                */
  194.     /*----------------------------------------------------------------*/
  195.     /*----------------------------------------------------------------*/
  196.     /* Code Body                                                      */
  197.     /*----------------------------------------------------------------*/
  198.     s->filler = f;
  199. }
  200. /*****************************************************************************
  201.  * FUNCTION
  202.  *  gui_color_slider_set_hide_function
  203.  * DESCRIPTION
  204.  *  
  205.  * PARAMETERS
  206.  *  s       [IN/OUT]         
  207.  *  f       [IN]        
  208.  * RETURNS
  209.  *  void
  210.  *****************************************************************************/
  211. void gui_color_slider_set_hide_function(color_slider *s, void (*f) (S32 x1, S32 y1, S32 x2, S32 y2))
  212. {
  213.     /*----------------------------------------------------------------*/
  214.     /* Local Variables                                                */
  215.     /*----------------------------------------------------------------*/
  216.     /*----------------------------------------------------------------*/
  217.     /* Code Body                                                      */
  218.     /*----------------------------------------------------------------*/
  219.     s->shide = f;
  220. }
  221. /*****************************************************************************
  222.  * FUNCTION
  223.  *  gui_color_slider_show
  224.  * DESCRIPTION
  225.  *  
  226.  * PARAMETERS
  227.  *  s       [IN/OUT]     
  228.  * RETURNS
  229.  *  void
  230.  *****************************************************************************/
  231. void gui_color_slider_show(color_slider *s)
  232. {
  233.     /*----------------------------------------------------------------*/
  234.     /* Local Variables                                                */
  235.     /*----------------------------------------------------------------*/
  236.     S32 x1, y1, x2, y2, width, sx;
  237.     /*----------------------------------------------------------------*/
  238.     /* Code Body                                                      */
  239.     /*----------------------------------------------------------------*/
  240.     x1 = s->x;
  241.     y1 = s->y;
  242.     x2 = x1 + s->width - 1;
  243.     y2 = y1 + s->height - 1;
  244.     if (s->filler != NULL)
  245.     {
  246.         gui_draw_filled_area(x1, y1, x2, y2, s->filler);
  247.     }
  248.     width = x2 - x1 - 1;
  249.     if (s->range > 0)
  250.     {
  251.         sx = width * s->value / s->range;
  252.     }
  253.     else
  254.     {
  255.         sx = 0;
  256.     }
  257.     s->sx1 = x1 + sx + 2 - (s->swidth >> 1);
  258.     s->sy1 = y2 + 1;
  259.     s->sx2 = s->sx1 + s->swidth - 1;
  260.     s->sy2 = s->sy1 + s->sheight - 1;
  261.     gdi_image_draw(s->sx1, s->sy1, (U8*) s->simage);
  262. }
  263. /*****************************************************************************
  264.  * FUNCTION
  265.  *  gui_color_slider_hide
  266.  * DESCRIPTION
  267.  *  
  268.  * PARAMETERS
  269.  *  s       [IN/OUT]     
  270.  * RETURNS
  271.  *  void
  272.  *****************************************************************************/
  273. void gui_color_slider_hide(color_slider *s)
  274. {
  275.     /*----------------------------------------------------------------*/
  276.     /* Local Variables                                                */
  277.     /*----------------------------------------------------------------*/
  278.     S32 sx1, sy1, sx2, sy2;
  279.     S32 x1, y1, x2, y2;
  280.     /*----------------------------------------------------------------*/
  281.     /* Code Body                                                      */
  282.     /*----------------------------------------------------------------*/
  283.     if (s->shide == NULL)
  284.     {
  285.         return;
  286.     }
  287.     sx1 = s->sx1;
  288.     sy1 = s->sy1;
  289.     sx2 = s->sx2;
  290.     sy2 = s->sy2;
  291.     x1 = s->x;
  292.     y1 = s->y;
  293.     x2 = x1 + s->width - 1;
  294.     y2 = y1 + s->height - 1;
  295.     if (x1 < sx1)
  296.     {
  297.         sx1 = x1;
  298.     }
  299.     if (y1 < sy1)
  300.     {
  301.         sy1 = y1;
  302.     }
  303.     if (x2 > sx2)
  304.     {
  305.         sx2 = x2;
  306.     }
  307.     if (y2 > sy2)
  308.     {
  309.         sy2 = y2;
  310.     }
  311.     s->shide(sx1, sy1, sx2, sy2);
  312. }
  313. #ifdef __MMI_TOUCH_SCREEN__
  314. /*****************************************************************************
  315.  * FUNCTION
  316.  *  wgui_color_slider_translate_pen_position
  317.  * DESCRIPTION
  318.  *  
  319.  * PARAMETERS
  320.  *  s           [IN/OUT]         
  321.  *  x           [IN]        
  322.  *  value       [OUT]         
  323.  *  state       [OUT]         
  324.  * RETURNS
  325.  *  void
  326.  *****************************************************************************/
  327. void wgui_color_slider_translate_pen_position(
  328.         color_slider *s,
  329.         S16 x,
  330.         S32 *value,
  331.         gui_slide_control_pen_state_enum *state)
  332. {
  333.     /*----------------------------------------------------------------*/
  334.     /* Local Variables                                                */
  335.     /*----------------------------------------------------------------*/
  336.     /*----------------------------------------------------------------*/
  337.     /* Code Body                                                      */
  338.     /*----------------------------------------------------------------*/
  339.     *state = GUI_SLIDE_CONTROL_PEN_STATE_SLIDE;
  340.     *value = s->value;
  341.     if (x < s->sx1 && s->value > 0)
  342.     {
  343.         x -= s->x - (s->swidth >> 1);
  344.         if (x < 0)
  345.         {
  346.             x = 0;
  347.         }
  348.         *state = GUI_SLIDE_CONTROL_PEN_STATE_AREA1;
  349.         *value = x * s->range / (s->width + s->swidth);
  350.     }
  351.     else if (x > s->sx2 && s->value < s->range - 1)
  352.     {
  353.         x -= s->x - (s->swidth >> 1);
  354.         if (x > s->width + s->swidth - 1)
  355.         {
  356.             x = s->width + s->swidth - 1;
  357.         }
  358.         *state = GUI_SLIDE_CONTROL_PEN_STATE_AREA2;
  359.         *value = x * s->range / (s->width + s->swidth);
  360.     }
  361.     MMI_DBG_ASSERT(*value >= 0 && *value <= s->range - 1);
  362. }
  363. /*****************************************************************************
  364.  * FUNCTION
  365.  *  wgui_color_slider_translate_pen_event
  366.  * DESCRIPTION
  367.  *  
  368.  * PARAMETERS
  369.  *  s               [IN/OUT]         
  370.  *  pen_event       [IN]        
  371.  *  x               [IN]        
  372.  *  y               [IN]        
  373.  *  slide_event     [OUT]         
  374.  *  slide_param     [OUT]         
  375.  * RETURNS
  376.  *  
  377.  *****************************************************************************/
  378. BOOL wgui_color_slider_translate_pen_event(
  379.         color_slider *s,
  380.         mmi_pen_event_type_enum pen_event,
  381.         S16 x,
  382.         S16 y,
  383.         gui_slide_control_pen_event_enum *slide_event,
  384.         gui_pen_event_param_struct *slide_param)
  385. {
  386.     /*----------------------------------------------------------------*/
  387.     /* Local Variables                                                */
  388.     /*----------------------------------------------------------------*/
  389.     MMI_BOOL ret = MMI_TRUE;
  390.     S32 new_value;
  391.     gui_slide_control_pen_state_enum new_state;
  392.     /*----------------------------------------------------------------*/
  393.     /* Code Body                                                      */
  394.     /*----------------------------------------------------------------*/
  395.     *slide_event = GUI_SLIDE_CONTROL_PEN_NONE;
  396.     GUI_PEN_EVENT_PARAM_SET_VOID(slide_param);
  397.     switch (pen_event)
  398.     {
  399.         case MMI_PEN_EVENT_DOWN:
  400.             if (PEN_CHECK_BOUND(x, y, s->x, s->y, s->width, s->height + s->sheight))
  401.             {
  402.                 wgui_color_slider_translate_pen_position(s, x, &new_value, &new_state);
  403.                 s->pen_state = new_state;
  404.                 if (new_state == GUI_SLIDE_CONTROL_PEN_STATE_AREA1)
  405.                 {
  406.                     *slide_event = GUI_SLIDE_CONTROL_PEN_JUMP_TO_I;
  407.                     GUI_PEN_EVENT_PARAM_SET_INTEGER(slide_param, s->value - 1);
  408.                 }
  409.                 else if (new_state == GUI_SLIDE_CONTROL_PEN_STATE_AREA2)
  410.                 {
  411.                     *slide_event = GUI_SLIDE_CONTROL_PEN_JUMP_TO_I;
  412.                     GUI_PEN_EVENT_PARAM_SET_INTEGER(slide_param, s->value + 1);
  413.                 }
  414.             }
  415.             else
  416.             {
  417.                 ret = MMI_FALSE;
  418.                 s->pen_state = GUI_SLIDE_CONTROL_PEN_STATE_INVALID;
  419.             }
  420.             break;
  421.         case MMI_PEN_EVENT_LONG_TAP:
  422.             /* FALLTHROUGH no break */
  423.         case MMI_PEN_EVENT_REPEAT:
  424.             /* FALLTHROUGH no break */
  425.         case MMI_PEN_EVENT_MOVE:
  426.             if (s->pen_state == GUI_SLIDE_CONTROL_PEN_STATE_AREA1)
  427.             {
  428.                 wgui_color_slider_translate_pen_position(s, x, &new_value, &new_state);
  429.                 if (new_state == GUI_SLIDE_CONTROL_PEN_STATE_AREA1)
  430.                 {
  431.                     *slide_event = GUI_SLIDE_CONTROL_PEN_JUMP_TO_I;
  432.                     GUI_PEN_EVENT_PARAM_SET_INTEGER(slide_param, s->value - 1);
  433.                 }
  434.             }
  435.             else if (s->pen_state == GUI_SLIDE_CONTROL_PEN_STATE_AREA2)
  436.             {
  437.                 wgui_color_slider_translate_pen_position(s, x, &new_value, &new_state);
  438.                 if (new_state == GUI_SLIDE_CONTROL_PEN_STATE_AREA2)
  439.                 {
  440.                     *slide_event = GUI_SLIDE_CONTROL_PEN_JUMP_TO_I;
  441.                     GUI_PEN_EVENT_PARAM_SET_INTEGER(slide_param, s->value + 1);
  442.                 }
  443.             }
  444.             else if (s->pen_state == GUI_SLIDE_CONTROL_PEN_STATE_SLIDE)
  445.             {
  446.                 wgui_color_slider_translate_pen_position(s, x, &new_value, &new_state);
  447.                 if (new_value != s->value)
  448.                 {
  449.                     *slide_event = GUI_SLIDE_CONTROL_PEN_JUMP_TO_I;
  450.                     GUI_PEN_EVENT_PARAM_SET_INTEGER(slide_param, new_value);
  451.                 }
  452.             }
  453.             else
  454.             {
  455.                 /* Ignore the event */
  456.             }
  457.             break;
  458.         case MMI_PEN_EVENT_UP:
  459.             /* FALLTHROUGH no break */
  460.         case MMI_PEN_EVENT_ABORT:
  461.             /* Do nothing */
  462.             break;
  463.     }
  464.     return ret;
  465. }
  466. #endif /* __MMI_TOUCH_SCREEN__ */