ms_slidex.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:12k
源码类别:

DVD

开发平台:

Others

  1. /***********************************************************************/
  2. /* File:    */
  3. /*   Copyright (c) 2002 ZORAN Corporation, All Rights Reserved    */
  4. /*   THIS IS PROPRIETARY SOURCE CODE OF ZORAN CORPORATION             */
  5. /*    */
  6. /* ===========                                                         */
  7. /* Descripton:                                                         */
  8. /* ===========                                                         */
  9. /*                                                                     */
  10. /* Log:                                                                */
  11. /* ===                                                                 */
  12. /* $Name: $                                                            
  13. /* $Header: /SourceCode/I64_Common/I64_Reference/UI/Menu_sys/ms_slidex.c 3     03-02-19 21:48 Rogerl $                                                          
  14. /* $Log: /SourceCode/I64_Common/I64_Reference/UI/Menu_sys/ms_slidex.c $                        
  15.  * 
  16.  * 3     03-02-19 21:48 Rogerl
  17.  * Add MS_SLIDER_EX_HLP support
  18.  * 
  19.  * 2     03-02-14 17:46 Janeg
  20.  * Change slider displaying.
  21.  * 
  22.  * 1     03-01-17 11:54 Rogerl
  23.  * Add New widgets: MS_COMBO_BUTTON,MS_EXT_BUTTON,MS_choice_ex,ms_slider_e
  24.  * x
  25. / * 
  26.                        
  27. /***********************************************************************/
  28. #include "Config.h" // Global Configuration - do not remove!
  29. #ifdef _DEBUG
  30. #include "DebugDbgMain.h"
  31. #undef IFTRACE
  32. #define IFTRACE if (gTraceMenu)
  33. #endif //_DEBUG
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include "Includesysdefs.h"
  38. #include "UIMenu_Sysosd_drv.h"
  39. #include "UIMenu_Sysms_wdgt.h"
  40. #include "UIMenu_Sysms_lib.h"
  41. #include "UIMenu_Sysms_slidex.h"
  42. #include "menumenu_var.h"
  43. #include "decoderosdrendr.h"
  44. #define COLOR_INDEX_WHITE 0x02
  45. #define COLOR_INDEX_BLACK 0x0f
  46. #define COLOR_INDEX_BLUE_DARK 0x04
  47. #define COLOR_INDEX_GREY_DARK 0x08
  48. #define COLOR_INDEX_BLUE_LIGHT 0x05
  49. #define COLOR_INDEX_HALFBLUE 0x06
  50. #define COLOR_INDEX_YELLOW 0x0B
  51. #define COLOR_INDEX_GREEN 0x0C
  52. #define COLOR_INDEX_TURQUOISE 0x0d
  53. #define COLOR_INDEX_BLUE 0x0E
  54. #define COLOR_INDEX_RED 0x09
  55. #define COLOR_INDEX_BG_DIALOG 0x03
  56. #define COLOR_INDEX_BG_SCREEN 0x01
  57. #define COLOR_INDEX_TOOLBAR_BG 0x04
  58. #define COLOR_INDEX_TOOLBAR_FOCUS 0x05
  59. #define COLOR_INDEX_GREY_LIGHT 0x0F
  60. #define SLIDER_EX_GAP 8 
  61. #define SLIDER_EX_SCALE 16 
  62. #define SLIDER_EX_THICKNESS 4
  63. #define SLIDER_EX_MARKER 16
  64. #define SLIDER_EX_MAX_TEXT_LEN 6*20
  65. static void display_scale(MS_SLIDER_EX * slider_ex, char param); 
  66. static void display_marker(MS_SLIDER_EX  * slider_ex, char param) ;
  67. static void display(MS_SLIDER_EX * slider_ex, char param);
  68. static void on_slider_change(MS_SLIDER_EX * slider_ex, int dir);
  69. static void display_scale(MS_SLIDER_EX * slider_ex, char param)
  70. {
  71. int i, vertical;
  72. MS_SLIDER * slider = (MS_SLIDER*) slider_ex;
  73. MS_POS  pos1,pos2, post;
  74. MS_WIDGET* wdgt = (MS_WIDGET*)slider_ex;
  75. int inter ;
  76. if (MS_IS_VSLIDER(slider_ex) )
  77. {
  78. inter  = ( wdgt->pos.h - 2 * SLIDER_EX_GAP  - MS_LINE_HEIGHT) / (slider->max_value ) ;
  79. }
  80. else 
  81. {
  82. inter  = ( wdgt->pos.w - 2 * SLIDER_EX_GAP - SLIDER_EX_MAX_TEXT_LEN ) / (slider->max_value) ;
  83. }
  84. for (i = 0; i <= slider->max_value; i++) 
  85. {
  86. if (MS_IS_VSLIDER(slider_ex) )
  87. {
  88. pos1.x =  wdgt->pos.x + SLIDER_EX_GAP*3 ; 
  89. pos1.y =  wdgt->pos.y + SLIDER_EX_GAP + i *  inter + MS_LINE_HEIGHT /2;
  90. pos1.w = SLIDER_EX_SCALE;
  91. pos1.h =  SLIDER_EX_THICKNESS;
  92. pos2 = pos1;
  93. pos2.x += (pos1.w + SLIDER_EX_GAP*2+SLIDER_EX_MARKER);
  94. post = pos2;
  95. post.x +=  (SLIDER_EX_GAP*2+pos2.w);
  96. post.y -= MS_LINE_HEIGHT /2;
  97. post.w = wdgt->pos.w + wdgt->pos.x - post.x ;
  98. post.h = MS_LINE_HEIGHT ;
  99. }
  100. else
  101. {
  102. pos1.x =  wdgt->pos.x + SLIDER_EX_GAP + i *  inter ;
  103. pos1.y =  wdgt->pos.y + SLIDER_EX_GAP ; 
  104. pos1.w =  SLIDER_EX_THICKNESS;
  105. pos1.h = SLIDER_EX_SCALE;
  106. pos2 = pos1;
  107. pos2.y += (pos1.h + SLIDER_EX_GAP*2+SLIDER_EX_MARKER);
  108. post = pos2;
  109. post.y += (SLIDER_EX_GAP+pos2.h);
  110. post.w = SLIDER_EX_MAX_TEXT_LEN ;
  111. post.h = MS_LINE_HEIGHT ;
  112. }
  113. OSD_PutRect(pos1.x, pos1.y, pos1.w, pos1.h, FG_COLOR(wdgt->color)) ;
  114. OSD_PutRect(pos2.x, pos2.y, pos2.w, pos2.h, FG_COLOR(wdgt->color)) ;
  115. if (slider_ex->scale_list != NULL) 
  116. OSD_PutText(post.x, post.y, post.w, post.h, FG_COLOR(wdgt->color), BG_COLOR(wdgt->color), (void*)slider_ex->scale_list[i] , MS_JUST(wdgt), !C_ASCII); 
  117. }
  118. }
  119. static void display_marker(MS_SLIDER_EX * slider_ex, char param)
  120. {
  121. MS_POS posbg, posbase, posmk;
  122. MS_WIDGET* wdgt = (MS_WIDGET*)slider_ex;
  123. MS_SLIDER * slider = (MS_SLIDER*) slider_ex;
  124. int inter ;
  125. int scale ;
  126. if (MS_SLIDER_WITH_SCALE(slider_ex) )
  127. scale = SLIDER_EX_SCALE;
  128. else
  129. scale = 0;
  130. if (MS_IS_VSLIDER(slider_ex) )
  131. {
  132. inter  = ( wdgt->pos.h - 2 * SLIDER_EX_GAP  - MS_LINE_HEIGHT) / (slider->max_value ) ;
  133. }
  134. else 
  135. {
  136. inter  = ( wdgt->pos.w - 2 * SLIDER_EX_GAP - SLIDER_EX_MAX_TEXT_LEN ) / (slider->max_value) ;
  137. }
  138. if (MS_IS_VSLIDER(slider_ex) )
  139. {
  140. posbase.x = wdgt->pos.x +  SLIDER_EX_GAP*4 + scale + (SLIDER_EX_MARKER - SLIDER_EX_THICKNESS) / 2;
  141. posbase.y = wdgt->pos.y +SLIDER_EX_GAP  + MS_LINE_HEIGHT /2 ;
  142. posbase.w = SLIDER_EX_THICKNESS;
  143. posbase.h = inter * slider->max_value;
  144. posbg.x = wdgt->pos.x +  SLIDER_EX_GAP*4 + scale ;
  145. posbg.y = wdgt->pos.y+SLIDER_EX_THICKNESS;
  146. posbg.w = SLIDER_EX_MARKER;
  147. posbg.h = wdgt->pos.h - SLIDER_EX_THICKNESS*2;
  148. posmk.x = wdgt->pos.x + SLIDER_EX_GAP*4  + scale ;
  149. posmk.y = wdgt->pos.y + SLIDER_EX_GAP + inter *  slider->cur_ratio   - SLIDER_EX_MARKER /2 +  MS_LINE_HEIGHT /2;
  150. posmk.w = SLIDER_EX_MARKER ;
  151. posmk.h = SLIDER_EX_MARKER ;
  152. }
  153. else
  154. {
  155. posbase.x = wdgt->pos.x +SLIDER_EX_GAP ;
  156. posbase.y = wdgt->pos.y +  SLIDER_EX_GAP*2 + scale + (SLIDER_EX_MARKER - SLIDER_EX_THICKNESS) / 2;
  157. posbase.w = inter * slider->max_value;
  158. posbase.h = SLIDER_EX_THICKNESS;
  159. posbg.x = wdgt->pos.x+SLIDER_EX_THICKNESS;
  160. posbg.y = wdgt->pos.y + SLIDER_EX_GAP*2 + scale ;
  161. posbg.w = wdgt->pos.h - SLIDER_EX_THICKNESS*2;
  162. posbg.h = SLIDER_EX_MARKER ;
  163. posmk.x = wdgt->pos.x + SLIDER_EX_GAP + inter *  slider->cur_ratio - SLIDER_EX_MARKER /2 ;
  164. posmk.y = wdgt->pos.y + SLIDER_EX_GAP * 2 + scale ;
  165. posmk.w = SLIDER_EX_MARKER ;
  166. posmk.h = SLIDER_EX_MARKER ;
  167. }
  168. OSD_PutRect(posbg.x, posbg.y, posbg.w, posbg.h, BG_COLOR(wdgt->color) );
  169. OSD_PutRect(posbase.x, posbase.y, posbase.w, posbase.h, FG_COLOR(wdgt->color));
  170. OSD_PutRect(posmk.x, posmk.y, posmk.w, posmk.h, FG_COLOR(wdgt->color));
  171. OSD_3DFrameRect(posmk.x, posmk.y, posmk.w, posmk.h,COLOR_INDEX_BLUE_LIGHT,COLOR_INDEX_BLUE,  SLIDER_EX_THICKNESS); 
  172. }
  173. static void display(MS_SLIDER_EX* slider_ex, char param)
  174. {
  175. MS_WIDGET* wdgt  = (MS_WIDGET*) slider_ex;
  176. OSD_PutRect(wdgt->pos.x,wdgt->pos.y,wdgt->pos.w,wdgt->pos.h,BG_COLOR(wdgt->color) );
  177. if (MS_SLIDER_WITH_SCALE(slider_ex))
  178. display_scale(slider_ex, param);
  179. display_marker(slider_ex,param);
  180. OSD_FrameRect(wdgt->pos.x,wdgt->pos.y,wdgt->pos.w,wdgt->pos.h,FORE_COLOR(wdgt, param), SLIDER_EX_THICKNESS);
  181. }
  182. static void on_slider_change(MS_SLIDER_EX * slider_ex, int dir)
  183. {
  184. int cur;
  185. MS_SLIDER * slider = (MS_SLIDER*) slider_ex;
  186. cur = slider->cur_ratio + slider->step * dir;
  187. if ( ((dir < 0)&& (cur >= 0 ))  ||
  188. ((dir>0)&&(cur <= slider->max_value)) )
  189. {
  190.  slider->cur_ratio = cur ;
  191.  if (slider->action != NULL)
  192.   slider->action(slider->cur_ratio);
  193.  display_marker(slider_ex, 0) ;
  194. }
  195. }
  196. MS_SLIDER_EX *MS_create_slider_ex(MS_POS *pos,
  197. MS_COLOR color,
  198. unsigned char max_value,
  199. unsigned char cur_ratio,
  200. unsigned char step,
  201. void (* action)(unsigned char cur_ratio),
  202. int tick_ratio,
  203. unsigned char attr,
  204. void** scale_list )
  205. {
  206. MS_SLIDER_EX *slider_ex;
  207. MS_SLIDER *slider;
  208. slider_ex = (MS_SLIDER_EX *)malloc(sizeof(MS_SLIDER_EX));
  209. #ifdef _DEBUG
  210. if (!slider_ex) {
  211. return 0;
  212. }
  213. #endif
  214. slider = (MS_SLIDER*)slider_ex;
  215. ((MS_WIDGET *)slider)->pos = *pos;
  216. ((MS_WIDGET *)slider)->parent = NO_PARENT;
  217. slider->action = action;
  218. slider->tick_ratio = tick_ratio;
  219. // Not allow zero step;
  220. if (0 == step) 
  221. step = 1;
  222. slider->step = step;
  223. slider->cur_ratio = cur_ratio;
  224. slider->max_value = max_value;
  225. ((MS_WIDGET *)slider)->attr = attr;
  226. ((MS_WIDGET *)slider)->color = color;
  227. ((MS_WIDGET *)slider)->user_op = slider_ex_user_op;
  228. ((MS_WIDGET *)slider)->attrh = 0;
  229. slider_ex->scale_list = scale_list;
  230. return slider_ex;
  231. }
  232. MS_UOP slider_ex_user_op(MS_WIDGET *widget,MS_UOP uop,char param) 
  233. {
  234. switch (uop) {
  235. case MS_UOP_DELETE:
  236. uop =  MS_UOP_NOP;
  237. break;
  238. case MS_UOP_DISPLAY:
  239. display((MS_SLIDER_EX*)widget,param);
  240. uop =  MS_UOP_NOP;
  241. break;
  242. case MS_UOP_LEFT:
  243. case MS_UOP_RIGHT:
  244. if (! MS_IS_VSLIDER(widget))
  245. {
  246. on_slider_change((MS_SLIDER_EX *)widget, ( (uop==MS_UOP_LEFT) ? -1 : 1 ));
  247. uop =  MS_UOP_NOP;
  248. }
  249. break;
  250. case MS_UOP_UP:
  251. case MS_UOP_DOWN:
  252. if (MS_IS_VSLIDER(widget))
  253. {
  254. on_slider_change((MS_SLIDER_EX *)widget, ( (uop==MS_UOP_UP) ? -1 : 1));
  255. uop =  MS_UOP_NOP;
  256. }
  257. break;
  258. default:
  259. break;
  260. }
  261. return uop;
  262. }
  263. MS_UOP slider_ex_hlp_user_op(MS_WIDGET *widget,MS_UOP uop,char param) 
  264. {
  265. MS_SLIDER_EX_HLP *slider_ex_hlp = (MS_SLIDER_EX_HLP*)widget;
  266. switch (uop) {
  267. case MS_UOP_DELETE:
  268. uop =  MS_UOP_NOP;
  269. break;
  270. case MS_UOP_DISPLAY:
  271. uop = slider_ex_user_op( widget, uop,param);
  272. // Don't show help_text when not foucused.
  273. if(C_FOCUSED != param)
  274. break;
  275. case MS_UOP_UP:
  276. case MS_UOP_DOWN:
  277. uop = slider_ex_user_op( widget, uop,param);
  278. OSD_PutRect(
  279. slider_ex_hlp->helptext->widget.pos.x,
  280. slider_ex_hlp->helptext->widget.pos.y,
  281. slider_ex_hlp->helptext->widget.pos.w,
  282. slider_ex_hlp->helptext->widget.pos.h,
  283. BG_COLOR(slider_ex_hlp->helptext->widget.color));
  284. OSD_PutText(
  285. slider_ex_hlp->helptext->widget.pos.x,
  286. slider_ex_hlp->helptext->widget.pos.y,
  287. slider_ex_hlp->helptext->widget.pos.w,
  288. slider_ex_hlp->helptext->widget.pos.h,
  289. FG_COLOR(slider_ex_hlp->helptext->widget.color),
  290. BG_COLOR(slider_ex_hlp->helptext->widget.color),
  291. (void *)slider_ex_hlp->help_list->head[slider_ex_hlp->slider_ex.slider.cur_ratio/slider_ex_hlp->slider_ex.slider.step],
  292. MS_JUST(slider_ex_hlp->helptext),
  293. !C_ASCII);
  294. break;
  295. default:
  296. uop = slider_ex_user_op(widget, uop, param);
  297. break;
  298. }
  299. return uop;
  300. }
  301. MS_SLIDER_EX_HLP *MS_create_slider_ex_hlp(MS_POS *pos,
  302. MS_COLOR color,
  303. unsigned char max_value,
  304. unsigned char cur_ratio,
  305. unsigned char step,
  306. void (* action)(unsigned char cur_ratio),
  307. int tick_ratio,
  308. unsigned char attr,
  309. void** scale_list ,
  310. MS_STATIC *helptext,
  311. MS_TEXT_LIST * help_list)
  312. {
  313. MS_SLIDER_EX_HLP *slider_ex_hlp;
  314. MS_SLIDER *slider;
  315. slider_ex_hlp = (MS_SLIDER_EX_HLP *)malloc(sizeof(MS_SLIDER_EX_HLP));
  316. #ifdef _DEBUG
  317. if (!slider_ex_hlp) {
  318. return 0;
  319. }
  320. #endif
  321. slider = (MS_SLIDER*)slider_ex_hlp;
  322. ((MS_WIDGET *)slider)->pos = *pos;
  323. ((MS_WIDGET *)slider)->parent = NO_PARENT;
  324. slider->action = action;
  325. slider->tick_ratio = tick_ratio;
  326. // Not allow zero step;
  327. if (0 == step) 
  328. step = 1;
  329. slider->step = step;
  330. slider->cur_ratio = cur_ratio;
  331. slider->max_value = max_value;
  332. ((MS_WIDGET *)slider)->attr = attr;
  333. ((MS_WIDGET *)slider)->color = color;
  334. ((MS_WIDGET *)slider)->user_op = slider_ex_hlp_user_op;
  335. ((MS_WIDGET *)slider)->attrh = 0;
  336. slider_ex_hlp->slider_ex.scale_list = scale_list;
  337. slider_ex_hlp->helptext = helptext;
  338. slider_ex_hlp->help_list = help_list;
  339. return slider_ex_hlp;
  340. }