ms_slid.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:13k
- /* **************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: ms_slid.c $
- *
- * Description:
- * ============
- * menu system slider handling
- *
- * Log:
- * ====
- * $Revision: 4 $
- * Last Modified by $Author: Leonm $ at $Modtime: 03-07-14 14:53 $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /SourceCode/I64_Common/I64_Reference/UI/Menu_sys/ms_slid.c $
- *
- * 4 03-07-14 14:54 Leonm
- *
- * 3 3/27/03 4:01p Clifflv
- * Enable slide to move more steps once by param
- *
- * 2 03-01-09 4:43 Leslie
- * Unicode support
- *
- * 11 23/04/02 9:39 Nirm
- * - Added dependency in "Config.h".
- *
- * 10 11/03/02 13:01 Nirm
- * Debug message in case of memory allocation failure.
- *
- * 9 2/27/02 7:02a Tomasp
- * Changed get_blk/rel_blk to malloc,free.
- *
- * 8 2/07/02 11:55 Rinata
- * fix slide when changed
- *
- * 7 2/06/02 17:37 Rinata
- * fix kar menu by change the display slid eto print teh value of current
- * closer to teh slide then it was
- *
- * 5 16/01/02 8:57 Nirm
- * Fixed debug-messages.
- *
- * 4 9/01/02 18:23 Nirm
- * Corrected Include-Paths.
- *
- * 3 30/12/01 10:04 Atai
- * Add explicit casting
- *
- * 2 25/12/01 10:54 Atai
- * Code cleaning
- **************************************************************************************** */
- #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 "Includesysdefs.h"
- #include "UIMenu_Sysosd_drv.h"
- #include "UIMenu_Sysms_wdgt.h"
- #include "UIMenu_Sysms_lib.h"
- #if defined(USE_JOG) && defined(D_SHOW_VOLUME_MENU)
- #include "Decoderosdrendr.h"
- #endif
- #define SLIDER_BASE_LINE 4
- #if defined(USE_JOG) && defined(D_SHOW_VOLUME_MENU)
- #define SLIDER_ONTIC_HEIGHT 4
- #define VOL_MIDDLE_VALUE 10
- extern BOOL b_vol_move_right, b_vol_move_left;
- #else
- #define SLIDER_ONTIC_HEIGHT 7
- #define KEYSHIFT_MIDDLE_VALUE 7
- #endif
- static void display (MS_WIDGET *widget, char focus)
- {
- // REMINDER Y increases downward
- MS_SLIDER *slider = (MS_SLIDER *) widget;
-
- // Top of slider base
- WORD y = widget->pos.y + ((widget->pos.h - SLIDER_BASE_LINE) / 2);
- // Marker position
- WORD p = (WORD)(widget->pos.x + (((DWORD)(slider->cur_ratio * widget->pos.w /slider->max_value)) & 0xfff8));
- BOOL bIsAtMax = (slider->cur_ratio == slider->max_value);
-
- {
- #if defined(USE_JOG) && defined(D_SHOW_VOLUME_MENU)
- wchar_t str[5] ;
-
- if (MS_IS_SLIDER_POINT(widget))
- {
- if (slider->cur_ratio == VOL_MIDDLE_VALUE)
- {
- str[0]=' ';
- str[1]='0';
- str[2] = 0;
- }
- else if (slider->cur_ratio > VOL_MIDDLE_VALUE)
- {
- str[0]='+';
- if (slider->cur_ratio >= 20)
- {
- str[1] = '1';
- str[2] = '0';
- str[3] = 0;
- }
- else
- {
- str[1]=(slider->cur_ratio-VOL_MIDDLE_VALUE)%10+'0';
- str[2] = 0;
- }
- }
- else
- {
- str[0]= '-';
- if (0 == slider->cur_ratio)
- {
- str[1] = '1';
- str[2] = '0';
- str[3] = 0;
- }
- else
- {
- str[1]=(VOL_MIDDLE_VALUE-slider->cur_ratio)%10+'0';
- str[2] = 0;
- }
- }
- OSD_PutText(widget->pos.x+widget->pos.w+24,widget->pos.y - SLIDER_ONTIC_HEIGHT,72,MS_LINE_HEIGHT,FG_COLOR(widget->color),BG_COLOR(widget->color),str,1,1);
- }
- else
- {
- str[0]=(slider->cur_ratio)/10+'0';
- str[1]=(slider->cur_ratio)%10+'0';
- str[2]=0;
- OSD_PutText(widget->pos.x+widget->pos.w+8,widget->pos.y - SLIDER_ONTIC_HEIGHT,72,MS_LINE_HEIGHT,FG_COLOR(widget->color),BG_COLOR(widget->color),str,1,1);
- }
- #else
- wchar_t str[4] = {0,0,0,0} ;
- if (MS_IS_SLIDER_POINT(widget))
- {
- if (slider->cur_ratio == KEYSHIFT_MIDDLE_VALUE)
- {
- str[0]=' ';
- str[1]='0';
- str[2] = 0;
- }
- else if (slider->cur_ratio > KEYSHIFT_MIDDLE_VALUE)
- {
- str[0]='+';
- str[1]=(slider->cur_ratio - KEYSHIFT_MIDDLE_VALUE)%10+'0';
- str[2] = 0;
- }
- else
- {
- str[0]= '-';
- str[1]=(KEYSHIFT_MIDDLE_VALUE - slider->cur_ratio)%10+'0';
- str[2] = 0;
- }
- OSD_PutText(widget->pos.x+widget->pos.w+8,widget->pos.y - 4,72,MS_LINE_HEIGHT,FG_COLOR(widget->color),BG_COLOR(widget->color),str,1,1);
- }
- else
- {
- str[0]=(slider->cur_ratio)/10+'0';
- str[1]=(slider->cur_ratio)%10+'0';
- str[2]=0;
- OSD_PutText(widget->pos.x+widget->pos.w+24,widget->pos.y,72,MS_LINE_HEIGHT,FG_COLOR(widget->color),BG_COLOR(widget->color),str,1,1);
- }
- #endif
- }
- OSD_PutRect(widget->pos.x, widget->pos.y, widget->pos.w, widget->pos.h, BACK_COLOR(widget, focus));
- if (MS_IS_SLIDER_POINT(widget))
- {
- // This is the single position style
- if ( bIsAtMax )
- {
- p -= 8;
- }
- // Slider base
- OSD_PutRect(
- widget->pos.x, y,
- widget->pos.w, SLIDER_BASE_LINE,
- FG_COLOR(widget->color));
- // Marker
- OSD_PutRect(
- p, widget->pos.y+4,
- 8, widget->pos.h-8,
- FG_COLOR(widget->color));
- if ( slider->tick_ratio >= 0 )
- {
- p = (WORD)(widget->pos.x +
- (((DWORD)(slider->tick_ratio * widget->pos.w / slider->max_value)) & 0xfff8));
-
- // Ticks for zero position
- // ( needs to be parametrized )
- OSD_PutRect(
- p, widget->pos.y,
- 8, 2,
- FG_COLOR(widget->color));
- OSD_PutRect(
- p, widget->pos.y + widget->pos.h - 2,
- 8, 2,
- FG_COLOR(widget->color));
- }
- }
- else
- {
- // This is the cumulative style
- if ( p == widget->pos.x )
- {
- p += 4;
- }
-
- if ( bIsAtMax )
- {
- p = widget->pos.x + widget->pos.w;
- }
- // Accumulated (left) part
- OSD_PutRect(
- widget->pos.x, widget->pos.y + SLIDER_ONTIC_HEIGHT,
- p - widget->pos.x, widget->pos.h - 2*SLIDER_ONTIC_HEIGHT,
- FG_COLOR(widget->color));
- if ( !bIsAtMax )
- {
- // Non-accumulated (right) part
- OSD_PutRect(
- p, y,
- widget->pos.x + widget->pos.w - p, SLIDER_BASE_LINE,
- FG_COLOR(widget->color));
- }
- }
- }
- static void on_slider_change(MS_SLIDER *slider,char dir, char param)
- {
- unsigned short new_ratio, step_back;
- unsigned short y = slider->widget.pos.y+SLIDER_ONTIC_HEIGHT;
- unsigned short p = (unsigned short)(slider->widget.pos.x+
- (((DWORD)(slider->cur_ratio * slider->widget.pos.w / slider->max_value )) & 0xfff8));
- unsigned short a; // adjustment rect left coordinate
- unsigned short b; // adjustment rect right coordinate
- unsigned char color;
- step_back = slider->step;
- slider->step = param?param:1;
- if (slider->cur_ratio == slider->max_value) {
- p = slider->widget.pos.x + slider->widget.pos.w ;//- 8;
- }
- if (dir ){
- // right
- #if defined(USE_JOG) && defined(D_SHOW_VOLUME_MENU)
- if (!b_vol_move_right)
- return;
- #endif
- if ( slider->cur_ratio == slider->max_value )
- return;
-
- new_ratio = slider->cur_ratio + slider->step;
- if (new_ratio > slider->max_value)
- {
- new_ratio = slider->max_value;
- }
- a = p;
- b = (unsigned short)(slider->widget.pos.x +
- (((DWORD)(new_ratio * slider->widget.pos.w / slider->max_value)) & 0xfff8));
- //b &= 0xfff8;
- color = FG_COLOR(slider->widget.color);
- }
- else {
- // left
- #if defined(USE_JOG) && defined(D_SHOW_VOLUME_MENU)
- if (!b_vol_move_left)
- return;
- #endif
- if ( slider->cur_ratio == 0 )
- return;
- if (slider->cur_ratio > slider->step)
- {
- new_ratio = slider->cur_ratio - slider->step;
- }
- else
- {
- new_ratio = 0;
- }
- b = p;
- if ( new_ratio == 0 )
- a = slider->widget.pos.x + 4;
- else
- {
- a = (unsigned short)(slider->widget.pos.x +
- (((DWORD)(new_ratio * slider->widget.pos.w / slider->max_value)) & 0xfff8));
- //a &= 0xFFF8;
- }
- color = FOCUS_COLOR(slider->widget.color);
- }
- if (MS_IS_SLIDER_POINT(slider))
- {
- if (slider->cur_ratio == slider->max_value) {
- p -= 8;
- }
- // Remove the previous marker:
- // Top part
- OSD_PutRect(p, slider->widget.pos.y + 4,
- 8, (slider->widget.pos.h-SLIDER_BASE_LINE)/2 - 4,
- FOCUS_COLOR(slider->widget.color));
- // Bottom part
- OSD_PutRect(p, slider->widget.pos.y+slider->widget.pos.h-(slider->widget.pos.h-SLIDER_BASE_LINE)/2,
- 8, (slider->widget.pos.h-SLIDER_BASE_LINE)/2 - 4,
- FOCUS_COLOR(slider->widget.color));
- if (new_ratio == slider->max_value) {
- p = slider->widget.pos.w + slider->widget.pos.x - 8;
- }
- else {
- p = (unsigned short)(slider->widget.pos.x+
- (((DWORD)(new_ratio * slider->widget.pos.w / slider->max_value )) & 0xfff8));
- }
- // Put the new marker
- OSD_PutRect(
- p, slider->widget.pos.y+4,
- 8, slider->widget.pos.h-8,FG_COLOR(slider->widget.color));
- }
- else
- {
- if ( b > a )
- {
- // type == MS_SLIDER_RELATIVE
- // top part
- OSD_PutRect(
- a, y,
- b - a, (slider->widget.pos.h - SLIDER_BASE_LINE) /2 - SLIDER_ONTIC_HEIGHT,
- color);
- y += (slider->widget.pos.h - SLIDER_BASE_LINE)/2 + SLIDER_BASE_LINE - SLIDER_ONTIC_HEIGHT;
- // bottom part
- OSD_PutRect(
- a, y,
- b - a, slider->widget.pos.h - SLIDER_ONTIC_HEIGHT - ( y - slider->widget.pos.y),
- color);
- }
- }
- slider->cur_ratio = new_ratio;
- #ifndef NO_NUMBER_ON_SLIDER
- {
- #if defined(USE_JOG) && defined(D_SHOW_VOLUME_MENU)
- wchar_t str[5] ;
- if (MS_IS_SLIDER_POINT(slider))
- {
- if (slider->cur_ratio == VOL_MIDDLE_VALUE)
- {
- str[0]=' ';
- str[1]='0';
- str[2] = 0;
- }
- else if (slider->cur_ratio > VOL_MIDDLE_VALUE)
- {
- str[0]='+';
- if (slider->cur_ratio >= (VOL_MIDDLE_VALUE*2))
- {
- str[1] = '1';
- str[2] = '0';
- str[3] = 0;
- }
- else
- {
- str[1]=(slider->cur_ratio-VOL_MIDDLE_VALUE)%10+'0';
- str[2] = 0;
- }
- }
- else
- {
- str[0]= '-';
- if (0 == slider->cur_ratio)
- {
- str[1] = '1';
- str[2] = '0';
- str[3] = 0;
- }
- else
- {
- str[1]=(VOL_MIDDLE_VALUE-slider->cur_ratio)%10+'0';
- str[2] = 0;
- }
- }
- OSD_PutText(slider->widget.pos.x+slider->widget.pos.w+24,slider->widget.pos.y - SLIDER_ONTIC_HEIGHT,72,MS_LINE_HEIGHT,FG_COLOR(slider->widget.color),BG_COLOR(slider->widget.color),str,1,1);
- }
- else
- {
- str[0]=(slider->cur_ratio)/10+'0';
- str[1]=(slider->cur_ratio)%10+'0';
- str[2]=0;
- OSD_PutText(slider->widget.pos.x+slider->widget.pos.w+8,slider->widget.pos.y - SLIDER_ONTIC_HEIGHT,72,MS_LINE_HEIGHT,FG_COLOR(slider->widget.color),BG_COLOR(slider->widget.color),str,1,1);
- }
- #else
- wchar_t str[4] = {0,0,0,0} ;
- if (MS_IS_SLIDER_POINT(slider))
- {
- if (slider->cur_ratio == KEYSHIFT_MIDDLE_VALUE)
- {
- str[0]=' ';
- str[1]='0';
- str[2] = 0;
- }
- else if (slider->cur_ratio > KEYSHIFT_MIDDLE_VALUE)
- {
- str[0]='+';
- str[1]=(slider->cur_ratio - KEYSHIFT_MIDDLE_VALUE )%10+'0';
- str[2] = 0;
- }
- else
- {
- str[0]= '-';
- str[1]=(KEYSHIFT_MIDDLE_VALUE - slider->cur_ratio)%10+'0';
- str[2] = 0;
- }
- OSD_PutText(slider->widget.pos.x+slider->widget.pos.w+8,slider->widget.pos.y - 4,72,MS_LINE_HEIGHT,FG_COLOR(slider->widget.color),BG_COLOR(slider->widget.color),str,1,1);
- }
- else
- {
- str[0]=(slider->cur_ratio)/10+'0';
- str[1]=(slider->cur_ratio)%10+'0';
- str[2]=0;
- OSD_PutText(slider->widget.pos.x+slider->widget.pos.w+24,slider->widget.pos.y,72,MS_LINE_HEIGHT,FG_COLOR(slider->widget.color),BG_COLOR(slider->widget.color),str,1,1);
- }
- #endif
- }
- #endif
- slider->action(new_ratio);
- slider->step = step_back;
- }
- MS_UOP slider_user_op(MS_WIDGET *widget,MS_UOP uop,char param)
- {
- switch (uop) {
- case MS_UOP_DELETE:
- return 0;
- case MS_UOP_DISPLAY:
- display(widget,param);
- return 0;
- case MS_UOP_LEFT:
- case MS_UOP_RIGHT:
- on_slider_change((MS_SLIDER *)widget,uop==MS_UOP_RIGHT, param);
- break;
- default:
- return uop;
- }
- return MS_UOP_NOP;
- }
- MS_SLIDER *MS_create_slider(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)
- {
- MS_SLIDER *slider;
- dbg_printf(("MS_create_slidern"));
- slider = (MS_SLIDER *)malloc(sizeof(MS_SLIDER));
- #ifdef _DEBUG
- if (NULL == slider) {
- tr_printf(("FATAL: MS_create_slider() Failed: Low system resources.n"));
- return NULL;
- }
- #endif //_DEBUG
- ((MS_WIDGET *)slider)->pos = *pos;
- ((MS_WIDGET *)slider)->parent = NO_PARENT;
- slider->action = action;
- slider->tick_ratio = tick_ratio;
- 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_user_op;
- ((MS_WIDGET *)slider)->attrh = 0;
- return slider;
- }