?? button.c
字號:
/*-----------------------------------------------------------
程序模塊 button_menu.c : 多功能按鈕式菜單
-----------------------------------------------------------*/
#include <hanenv.h>
#include <fcntl.h>
#include <alloc.h>
/*---- 內部函數 _DrawButtonMenu : 在指定坐標處顯示菜單 ----*/
static void _Cdecl _DrawButtonMenu(b)
BUTTON_MENU *b; /* 菜單參數 */
{
int i;
/*-- 顯示菜單 -----------------------------------------*/
delight_mouse();
if(b->saveimage)
b->block = getblock(b->col,b->line,b->width,b->high);
if(b->disp_fun)
(*(b->disp_fun))(b);
for(i=0;i<b->button_count;i++)
_DrawButton(b->buttons[i],b->col,b->line,NO,0);
if(b->arrow_ctrl)
_DrawButton(b->buttons[b->current],b->col,b->line,YES,0);
light_mouse();
}
/*-----------------------------------------------------------
函數 button_menu : 多功能按鍵式菜單
-----------------------------------------------------------*/
unsigned _Cdecl button_menu(b,key)
BUTTON_MENU *b; /* 指向菜單參數表的指針 */
unsigned key; /* 進入菜單處理過程時的鍵碼 */
{
int i;
char **block; /* 菜單背景存放地址 */
/*
long memo_size = b->width*b->high*4+16;
*/
/*-- 如果菜單已經彈出,處理鍵盤碼 ----------------------*/
if(b->pop_up)
{
/*-- 如果是鼠標左鍵且鼠標光標在菜單內 -------------*/
if(key==LEFT_BUTTON && mouse_enter(b->col*8,b->line,(b->col+b->width)*8,b->line+b->high))
{
/*-- 檢查鼠標光標是否指向菜單中的某個按鍵 -----*/
for(i=0;i<b->button_count;i++)
if(mouse_enter(b->col*8+b->buttons[i].x,
b-> line+b->buttons[i].y,
b->col*8+b->buttons[i].x+b->buttons[i].w,
b-> line+b->buttons[i].y+b->buttons[i].h)
&& !(b->buttons[i].lock))
{
/*-- 如果菜單可用鍵盤控制,修改當前按鍵 */
if(b->arrow_ctrl)
{
delight_mouse();
_DrawButton(b->buttons[b->current],b->col,b->line,NO,0);
light_mouse();
}
b->current = i;
delight_mouse();
_DrawButton(b->buttons[i],b->col,b->line,YES,1);
light_mouse();
till_mouse_pop(LEFT_BUTTON);
/*-- 如果選擇退出項,取消菜單顯示,退出 -*/
if(b->buttons[i].key==b->quit_key1 || b->buttons[i].key==b->quit_key2)
{
b->pop_up = NO;
delight_mouse();
if(b->saveimage && b->block)
putblock(b->col,b->line,b->width,b->high,b->block);
light_mouse();
return b->quit_key1;
}
/*-- 如果選中項有可執行函數,執行之 ----*/
if(b->buttons[i].fun)
key = (*(b->buttons[i].fun))();
/*-- 否則取出該選擇項對應的鍵盤碼 -----*/
else
key = b->buttons[i].key;
/*-- 彈起該按鍵 -----------------------*/
delight_mouse();
_DrawButton(b->buttons[i],b->col,b->line,b->arrow_ctrl,0);
light_mouse();
/*-- 退出菜單處理 ---------------------*/
return key;
}
/*-- 如果菜單可移動,且鼠標未指向任何按鍵 ------*/
if(!b->fixed && coreleft()>(long)(b->width)*b->high*4+16)
{
int x; /* 菜單的列坐標(單位為象素) */
int y; /* 菜單的行坐標(單位為象素) */
int dx; /* 移動菜單的列增量 */
int dy; /* 移動菜單的行增量 */
int oldml,oldmt,oldmr,oldmb; /* 原鼠標范圍 */
unsigned mouse_button;
/*-- 計算菜單的位置 -----------------------*/
x = b->col*8;
y = b->line;
/*-- 保存菜單的屏幕圖象 -------------------*/
delight_mouse();
block = getblock(b->col,b->line,b->width,b->high);
light_mouse();
/*-- 設置菜單的移動范圍 -------------------*/
get_mouse_range(&oldml,&oldmt,&oldmr,&oldmb);
set_mouse_range(b->left,b->top,b->right-b->width*8+1,b->bottom-b->high+1);
/*-- 用鼠標控制一個虛線框選定菜單的新位置 -*/
do
{
/*-- 讀取鼠標光標的位置 ---------------*/
mouse_button = get_mouse_status(&dx,&dy);
/*-- 計算矩形虛線框的移動位置 ---------*/
dy -= y;
dx -= x;
/*-- 如果需要移動虛線框 ---------------*/
if(dx || dy)
{
delight_mouse();
/*-- 消除舊框 ---------------------*/
_SetWriteMode(XOR_MODE);
draw_rectangle(x,y,b->width*8,b->high,LIGHTGRAY,0xf0);
/*-- 計算新框位置 -----------------*/
x += dx;
y += dy;
/*-- 重畫新框 ---------------------*/
draw_rectangle(x,y,b->width*8,b->high,LIGHTGRAY,0xf0);
_SetWriteMode(PUT_MODE);
light_mouse();
}
}while(mouse_button == LEFT_BUTTON);
/*-- 恢復原來的鼠標移動范圍 ---------------*/
set_mouse_range(oldml,oldmt,oldmr,oldmb);
/*-- 取消最后一次所畫的框 -----------------*/
delight_mouse();
_SetWriteMode(XOR_MODE);
draw_rectangle(x,y,b->width*8,b->high,LIGHTGRAY,0xf0);
_SetWriteMode(PUT_MODE);
/*-- 恢復菜單下的背景(抹去原來的菜單) -----*/
putblock(b->col,b->line,b->width,b->high,b->block);
/*-- 修改菜單參數表中的菜單位置 -----------*/
b->col = x/8;
b->line = y;
/*-- 保存新菜單位置上的屏幕背景 -----------*/
b->block = getblock(b->col,b->line,b->width,b->high);
/*-- 在新位置上恢復菜單的圖象 -------------*/
putblock(b->col,b->line,b->width,b->high,block);
light_mouse();
}
/*-- 菜單移動處理結束 -------------------------*/
}
/*-- 如果輸入鍵盤碼為菜單退出鍵,取消菜單顯示,退出 -*/
else if(key==b->quit_key1 || key==b->quit_key2 || key==KEY_ESC)
{
b->pop_up = NO;
delight_mouse();
if(b->saveimage && b->block)
putblock(b->col,b->line,b->width,b->high,b->block);
light_mouse();
return key;
}
/*-- 如果菜單可用鍵盤控制,處理鍵盤鍵 --------------*/
else if(b->arrow_ctrl)
{
/*-- 如果輸入鍵盤碼是選擇鍵,執行當前選項 ------*/
if(key==b->press_key1 || key==b->press_key2)
{
/*-- 繪出按下狀態的按鍵 -------------------*/
delight_mouse();
_DrawButton(b->buttons[b->current],b->col,b->line,YES,1);
light_mouse();
/*-- 如果選中項有可執行函數,執行之 --------*/
if(b->buttons[b->current].fun)
key = (*(b->buttons[b->current].fun))();
/*-- 否則取出該選擇項對應的鍵盤碼 ---------*/
else
{
key = b->buttons[b->current].key;
delay(_MouseSpeed);
}
/*-- 繪出彈起狀態的按鍵 -------------------*/
delight_mouse();
_DrawButton(b->buttons[b->current],b->col,b->line,YES,0);
light_mouse();
/*-- 退出菜單處理 -------------------------*/
return key;
}
/*-- 如果是移動選擇項鍵,移動當前選擇項 --------*/
else if(key==b->forward1 || key==b->forward2 || key==b->backward1 || key==b->backward2)
{
/*-- 用正常色繪制當前鍵 -------------------*/
delight_mouse();
_DrawButton(b->buttons[b->current],b->col,b->line,NO,0);
light_mouse();
/*-- 處理向前移動鍵 -----------------------*/
if(key==b->forward1 || key==b->forward2)
{
b->current = (b->current==b->button_count-1?0:b->current+1);
if(b->buttons[b->current].lock)
ungeth(b->forward1);
}
/*-- 處理向后移動鍵 -----------------------*/
else if(key==b->backward1 || key==b->backward2)
{
b->current=(b->current==0?b->button_count-1:b->current-1);
if(b->buttons[b->current].lock)
ungeth(b->backward1);
}
/*-- 以選中鍵色繪制當前鍵 -----------------*/
delight_mouse();
_DrawButton(b->buttons[b->current],b->col,b->line,YES,0);
light_mouse();
/*-- 退出菜單處理 -------------------------*/
return key;
}
/*-- 檢查輸入鍵盤碼是否和某選擇項對應碼相同 ---*/
for(i=0;i<b->button_count;i++)
if(key==b->buttons[i].pressed)
{
delight_mouse();
/*-- 將與輸入碼對應的鍵變為當前鍵 -----*/
_DrawButton(b->buttons[b->current],b->col,b->line,NO,0);
_DrawButton(b->buttons[i],b->col,b->line,YES,1);
light_mouse();
delay(_MouseSpeed);
delight_mouse();
_DrawButton(b->buttons[i],b->col,b->line,b->arrow_ctrl,0);
light_mouse();
b->current = i;
/*-- 退出菜單處理 ---------------------*/
return b->buttons[i].key;
}
}
/*-- 使用鍵盤控制菜單的處理結束 -------------------*/
}
/*-- 如果菜單尚未彈出,設置標記,在屏幕上畫菜單 ---------*/
else
{
b->pop_up = YES;
_DrawButtonMenu(b);
}
/*-- 返回鍵盤碼 ---------------------------------------*/
return key;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -