ms_slidex.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:12k
- /***********************************************************************/
- /* File: */
- /* Copyright (c) 2002 ZORAN Corporation, All Rights Reserved */
- /* THIS IS PROPRIETARY SOURCE CODE OF ZORAN CORPORATION */
- /* */
- /* =========== */
- /* Descripton: */
- /* =========== */
- /* */
- /* Log: */
- /* === */
- /* $Name: $
- /* $Header: /SourceCode/I64_Common/I64_Reference/UI/Menu_sys/ms_slidex.c 3 03-02-19 21:48 Rogerl $
- /* $Log: /SourceCode/I64_Common/I64_Reference/UI/Menu_sys/ms_slidex.c $
- *
- * 3 03-02-19 21:48 Rogerl
- * Add MS_SLIDER_EX_HLP support
- *
- * 2 03-02-14 17:46 Janeg
- * Change slider displaying.
- *
- * 1 03-01-17 11:54 Rogerl
- * Add New widgets: MS_COMBO_BUTTON,MS_EXT_BUTTON,MS_choice_ex,ms_slider_e
- * x
- / *
-
- /***********************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #include "DebugDbgMain.h"
- #undef IFTRACE
- #define IFTRACE if (gTraceMenu)
- #endif //_DEBUG
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "Includesysdefs.h"
- #include "UIMenu_Sysosd_drv.h"
- #include "UIMenu_Sysms_wdgt.h"
- #include "UIMenu_Sysms_lib.h"
- #include "UIMenu_Sysms_slidex.h"
- #include "menumenu_var.h"
- #include "decoderosdrendr.h"
- #define COLOR_INDEX_WHITE 0x02
- #define COLOR_INDEX_BLACK 0x0f
- #define COLOR_INDEX_BLUE_DARK 0x04
- #define COLOR_INDEX_GREY_DARK 0x08
- #define COLOR_INDEX_BLUE_LIGHT 0x05
- #define COLOR_INDEX_HALFBLUE 0x06
- #define COLOR_INDEX_YELLOW 0x0B
- #define COLOR_INDEX_GREEN 0x0C
- #define COLOR_INDEX_TURQUOISE 0x0d
- #define COLOR_INDEX_BLUE 0x0E
- #define COLOR_INDEX_RED 0x09
- #define COLOR_INDEX_BG_DIALOG 0x03
- #define COLOR_INDEX_BG_SCREEN 0x01
- #define COLOR_INDEX_TOOLBAR_BG 0x04
- #define COLOR_INDEX_TOOLBAR_FOCUS 0x05
- #define COLOR_INDEX_GREY_LIGHT 0x0F
- #define SLIDER_EX_GAP 8
- #define SLIDER_EX_SCALE 16
- #define SLIDER_EX_THICKNESS 4
- #define SLIDER_EX_MARKER 16
- #define SLIDER_EX_MAX_TEXT_LEN 6*20
- static void display_scale(MS_SLIDER_EX * slider_ex, char param);
- static void display_marker(MS_SLIDER_EX * slider_ex, char param) ;
- static void display(MS_SLIDER_EX * slider_ex, char param);
- static void on_slider_change(MS_SLIDER_EX * slider_ex, int dir);
- static void display_scale(MS_SLIDER_EX * slider_ex, char param)
- {
- int i, vertical;
- MS_SLIDER * slider = (MS_SLIDER*) slider_ex;
- MS_POS pos1,pos2, post;
- MS_WIDGET* wdgt = (MS_WIDGET*)slider_ex;
- int inter ;
- if (MS_IS_VSLIDER(slider_ex) )
- {
- inter = ( wdgt->pos.h - 2 * SLIDER_EX_GAP - MS_LINE_HEIGHT) / (slider->max_value ) ;
- }
- else
- {
- inter = ( wdgt->pos.w - 2 * SLIDER_EX_GAP - SLIDER_EX_MAX_TEXT_LEN ) / (slider->max_value) ;
- }
-
- for (i = 0; i <= slider->max_value; i++)
- {
- if (MS_IS_VSLIDER(slider_ex) )
- {
- pos1.x = wdgt->pos.x + SLIDER_EX_GAP*3 ;
- pos1.y = wdgt->pos.y + SLIDER_EX_GAP + i * inter + MS_LINE_HEIGHT /2;
- pos1.w = SLIDER_EX_SCALE;
- pos1.h = SLIDER_EX_THICKNESS;
- pos2 = pos1;
- pos2.x += (pos1.w + SLIDER_EX_GAP*2+SLIDER_EX_MARKER);
-
- post = pos2;
- post.x += (SLIDER_EX_GAP*2+pos2.w);
- post.y -= MS_LINE_HEIGHT /2;
- post.w = wdgt->pos.w + wdgt->pos.x - post.x ;
- post.h = MS_LINE_HEIGHT ;
- }
- else
- {
- pos1.x = wdgt->pos.x + SLIDER_EX_GAP + i * inter ;
- pos1.y = wdgt->pos.y + SLIDER_EX_GAP ;
- pos1.w = SLIDER_EX_THICKNESS;
- pos1.h = SLIDER_EX_SCALE;
- pos2 = pos1;
- pos2.y += (pos1.h + SLIDER_EX_GAP*2+SLIDER_EX_MARKER);
- post = pos2;
- post.y += (SLIDER_EX_GAP+pos2.h);
- post.w = SLIDER_EX_MAX_TEXT_LEN ;
- post.h = MS_LINE_HEIGHT ;
- }
- OSD_PutRect(pos1.x, pos1.y, pos1.w, pos1.h, FG_COLOR(wdgt->color)) ;
- OSD_PutRect(pos2.x, pos2.y, pos2.w, pos2.h, FG_COLOR(wdgt->color)) ;
- if (slider_ex->scale_list != NULL)
- 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);
- }
- }
- static void display_marker(MS_SLIDER_EX * slider_ex, char param)
- {
- MS_POS posbg, posbase, posmk;
- MS_WIDGET* wdgt = (MS_WIDGET*)slider_ex;
- MS_SLIDER * slider = (MS_SLIDER*) slider_ex;
- int inter ;
- int scale ;
- if (MS_SLIDER_WITH_SCALE(slider_ex) )
- scale = SLIDER_EX_SCALE;
- else
- scale = 0;
-
- if (MS_IS_VSLIDER(slider_ex) )
- {
- inter = ( wdgt->pos.h - 2 * SLIDER_EX_GAP - MS_LINE_HEIGHT) / (slider->max_value ) ;
- }
- else
- {
- inter = ( wdgt->pos.w - 2 * SLIDER_EX_GAP - SLIDER_EX_MAX_TEXT_LEN ) / (slider->max_value) ;
- }
- if (MS_IS_VSLIDER(slider_ex) )
- {
- posbase.x = wdgt->pos.x + SLIDER_EX_GAP*4 + scale + (SLIDER_EX_MARKER - SLIDER_EX_THICKNESS) / 2;
- posbase.y = wdgt->pos.y +SLIDER_EX_GAP + MS_LINE_HEIGHT /2 ;
- posbase.w = SLIDER_EX_THICKNESS;
- posbase.h = inter * slider->max_value;
- posbg.x = wdgt->pos.x + SLIDER_EX_GAP*4 + scale ;
- posbg.y = wdgt->pos.y+SLIDER_EX_THICKNESS;
- posbg.w = SLIDER_EX_MARKER;
- posbg.h = wdgt->pos.h - SLIDER_EX_THICKNESS*2;
- posmk.x = wdgt->pos.x + SLIDER_EX_GAP*4 + scale ;
- posmk.y = wdgt->pos.y + SLIDER_EX_GAP + inter * slider->cur_ratio - SLIDER_EX_MARKER /2 + MS_LINE_HEIGHT /2;
- posmk.w = SLIDER_EX_MARKER ;
- posmk.h = SLIDER_EX_MARKER ;
- }
- else
- {
- posbase.x = wdgt->pos.x +SLIDER_EX_GAP ;
- posbase.y = wdgt->pos.y + SLIDER_EX_GAP*2 + scale + (SLIDER_EX_MARKER - SLIDER_EX_THICKNESS) / 2;
- posbase.w = inter * slider->max_value;
- posbase.h = SLIDER_EX_THICKNESS;
- posbg.x = wdgt->pos.x+SLIDER_EX_THICKNESS;
- posbg.y = wdgt->pos.y + SLIDER_EX_GAP*2 + scale ;
- posbg.w = wdgt->pos.h - SLIDER_EX_THICKNESS*2;
- posbg.h = SLIDER_EX_MARKER ;
- posmk.x = wdgt->pos.x + SLIDER_EX_GAP + inter * slider->cur_ratio - SLIDER_EX_MARKER /2 ;
- posmk.y = wdgt->pos.y + SLIDER_EX_GAP * 2 + scale ;
- posmk.w = SLIDER_EX_MARKER ;
- posmk.h = SLIDER_EX_MARKER ;
- }
- OSD_PutRect(posbg.x, posbg.y, posbg.w, posbg.h, BG_COLOR(wdgt->color) );
- OSD_PutRect(posbase.x, posbase.y, posbase.w, posbase.h, FG_COLOR(wdgt->color));
-
- OSD_PutRect(posmk.x, posmk.y, posmk.w, posmk.h, FG_COLOR(wdgt->color));
- OSD_3DFrameRect(posmk.x, posmk.y, posmk.w, posmk.h,COLOR_INDEX_BLUE_LIGHT,COLOR_INDEX_BLUE, SLIDER_EX_THICKNESS);
-
- }
- static void display(MS_SLIDER_EX* slider_ex, char param)
- {
- MS_WIDGET* wdgt = (MS_WIDGET*) slider_ex;
- OSD_PutRect(wdgt->pos.x,wdgt->pos.y,wdgt->pos.w,wdgt->pos.h,BG_COLOR(wdgt->color) );
- if (MS_SLIDER_WITH_SCALE(slider_ex))
- display_scale(slider_ex, param);
- display_marker(slider_ex,param);
- OSD_FrameRect(wdgt->pos.x,wdgt->pos.y,wdgt->pos.w,wdgt->pos.h,FORE_COLOR(wdgt, param), SLIDER_EX_THICKNESS);
- }
- static void on_slider_change(MS_SLIDER_EX * slider_ex, int dir)
- {
- int cur;
- MS_SLIDER * slider = (MS_SLIDER*) slider_ex;
- cur = slider->cur_ratio + slider->step * dir;
- if ( ((dir < 0)&& (cur >= 0 )) ||
- ((dir>0)&&(cur <= slider->max_value)) )
-
- {
- slider->cur_ratio = cur ;
- if (slider->action != NULL)
- slider->action(slider->cur_ratio);
- display_marker(slider_ex, 0) ;
- }
- }
- MS_SLIDER_EX *MS_create_slider_ex(MS_POS *pos,
- MS_COLOR color,
- unsigned char max_value,
- unsigned char cur_ratio,
- unsigned char step,
- void (* action)(unsigned char cur_ratio),
- int tick_ratio,
- unsigned char attr,
- void** scale_list )
- {
- MS_SLIDER_EX *slider_ex;
- MS_SLIDER *slider;
- slider_ex = (MS_SLIDER_EX *)malloc(sizeof(MS_SLIDER_EX));
- #ifdef _DEBUG
- if (!slider_ex) {
- return 0;
- }
- #endif
- slider = (MS_SLIDER*)slider_ex;
- ((MS_WIDGET *)slider)->pos = *pos;
- ((MS_WIDGET *)slider)->parent = NO_PARENT;
- slider->action = action;
- slider->tick_ratio = tick_ratio;
- // Not allow zero step;
- if (0 == step)
- step = 1;
- slider->step = step;
- slider->cur_ratio = cur_ratio;
- slider->max_value = max_value;
- ((MS_WIDGET *)slider)->attr = attr;
- ((MS_WIDGET *)slider)->color = color;
- ((MS_WIDGET *)slider)->user_op = slider_ex_user_op;
- ((MS_WIDGET *)slider)->attrh = 0;
- slider_ex->scale_list = scale_list;
- return slider_ex;
- }
- MS_UOP slider_ex_user_op(MS_WIDGET *widget,MS_UOP uop,char param)
- {
- switch (uop) {
- case MS_UOP_DELETE:
- uop = MS_UOP_NOP;
- break;
- case MS_UOP_DISPLAY:
- display((MS_SLIDER_EX*)widget,param);
- uop = MS_UOP_NOP;
- break;
- case MS_UOP_LEFT:
- case MS_UOP_RIGHT:
- if (! MS_IS_VSLIDER(widget))
- {
- on_slider_change((MS_SLIDER_EX *)widget, ( (uop==MS_UOP_LEFT) ? -1 : 1 ));
- uop = MS_UOP_NOP;
- }
- break;
-
- case MS_UOP_UP:
- case MS_UOP_DOWN:
- if (MS_IS_VSLIDER(widget))
- {
- on_slider_change((MS_SLIDER_EX *)widget, ( (uop==MS_UOP_UP) ? -1 : 1));
- uop = MS_UOP_NOP;
- }
- break;
- default:
- break;
- }
- return uop;
- }
- MS_UOP slider_ex_hlp_user_op(MS_WIDGET *widget,MS_UOP uop,char param)
- {
- MS_SLIDER_EX_HLP *slider_ex_hlp = (MS_SLIDER_EX_HLP*)widget;
-
- switch (uop) {
- case MS_UOP_DELETE:
- uop = MS_UOP_NOP;
- break;
- case MS_UOP_DISPLAY:
- uop = slider_ex_user_op( widget, uop,param);
- // Don't show help_text when not foucused.
- if(C_FOCUSED != param)
- break;
- case MS_UOP_UP:
- case MS_UOP_DOWN:
- uop = slider_ex_user_op( widget, uop,param);
- OSD_PutRect(
- slider_ex_hlp->helptext->widget.pos.x,
- slider_ex_hlp->helptext->widget.pos.y,
- slider_ex_hlp->helptext->widget.pos.w,
- slider_ex_hlp->helptext->widget.pos.h,
- BG_COLOR(slider_ex_hlp->helptext->widget.color));
- OSD_PutText(
- slider_ex_hlp->helptext->widget.pos.x,
- slider_ex_hlp->helptext->widget.pos.y,
- slider_ex_hlp->helptext->widget.pos.w,
- slider_ex_hlp->helptext->widget.pos.h,
- FG_COLOR(slider_ex_hlp->helptext->widget.color),
- BG_COLOR(slider_ex_hlp->helptext->widget.color),
- (void *)slider_ex_hlp->help_list->head[slider_ex_hlp->slider_ex.slider.cur_ratio/slider_ex_hlp->slider_ex.slider.step],
- MS_JUST(slider_ex_hlp->helptext),
- !C_ASCII);
- break;
- default:
- uop = slider_ex_user_op(widget, uop, param);
- break;
- }
- return uop;
- }
- MS_SLIDER_EX_HLP *MS_create_slider_ex_hlp(MS_POS *pos,
- MS_COLOR color,
- unsigned char max_value,
- unsigned char cur_ratio,
- unsigned char step,
- void (* action)(unsigned char cur_ratio),
- int tick_ratio,
- unsigned char attr,
- void** scale_list ,
- MS_STATIC *helptext,
- MS_TEXT_LIST * help_list)
- {
- MS_SLIDER_EX_HLP *slider_ex_hlp;
- MS_SLIDER *slider;
- slider_ex_hlp = (MS_SLIDER_EX_HLP *)malloc(sizeof(MS_SLIDER_EX_HLP));
- #ifdef _DEBUG
- if (!slider_ex_hlp) {
- return 0;
- }
- #endif
- slider = (MS_SLIDER*)slider_ex_hlp;
- ((MS_WIDGET *)slider)->pos = *pos;
- ((MS_WIDGET *)slider)->parent = NO_PARENT;
- slider->action = action;
- slider->tick_ratio = tick_ratio;
- // Not allow zero step;
- if (0 == step)
- step = 1;
- slider->step = step;
- slider->cur_ratio = cur_ratio;
- slider->max_value = max_value;
- ((MS_WIDGET *)slider)->attr = attr;
- ((MS_WIDGET *)slider)->color = color;
- ((MS_WIDGET *)slider)->user_op = slider_ex_hlp_user_op;
- ((MS_WIDGET *)slider)->attrh = 0;
- slider_ex_hlp->slider_ex.scale_list = scale_list;
- slider_ex_hlp->helptext = helptext;
- slider_ex_hlp->help_list = help_list;
-
- return slider_ex_hlp;
- }