📄 editpal.c
字号:
MoveBox__Draw(this);
}
}
static BOOLEAN MoveBox_Process(MoveBox *this)
{
int key;
int orig_x = this->x,
orig_y = this->y,
orig_csize = this->csize;
MoveBox__Draw(this);
#ifdef XFRACT
Cursor_StartMouseTracking();
#endif
while (1)
{
Cursor_WaitKey();
key = getakey();
if (key==ENTER || key==ENTER_2 || key==ESC || key=='H' || key=='h')
{
if (this->x != orig_x || this->y != orig_y || this->csize != orig_csize)
this->moved = TRUE;
else
this->moved = FALSE;
break;
}
switch(key)
{
case UP_ARROW:
case DOWN_ARROW:
case LEFT_ARROW:
case RIGHT_ARROW:
case UP_ARROW_2:
case DOWN_ARROW_2:
case LEFT_ARROW_2:
case RIGHT_ARROW_2:
MoveBox__Move(this, key);
break;
case PAGE_UP: /* shrink */
if (this->csize > CSIZE_MIN)
{
int t = this->csize - CSIZE_INC;
int change;
if (t < CSIZE_MIN)
t = CSIZE_MIN;
MoveBox__Erase(this);
change = this->csize - t;
this->csize = t;
this->x += (change*16) / 2;
this->y += (change*16) / 2;
MoveBox__Draw(this);
}
break;
case PAGE_DOWN: /* grow */
{
int max_width = min(sxdots, MAX_WIDTH);
if (this->base_depth+(this->csize+CSIZE_INC)*16+1 < sydots &&
this->base_width+(this->csize+CSIZE_INC)*16+1 < max_width )
{
MoveBox__Erase(this);
this->x -= (CSIZE_INC*16) / 2;
this->y -= (CSIZE_INC*16) / 2;
this->csize += CSIZE_INC;
if (this->y+this->base_depth+this->csize*16+1 > sydots)
this->y = sydots - (this->base_depth+this->csize*16+1);
if (this->x+this->base_width+this->csize*16+1 > max_width)
this->x = max_width - (this->base_width+this->csize*16+1);
if (this->y < 0)
this->y = 0;
if (this->x < 0)
this->x = 0;
MoveBox__Draw(this);
}
}
break;
}
}
#ifdef XFRACT
Cursor_EndMouseTracking();
#endif
MoveBox__Erase(this);
this->should_hide = (key == 'H' || key == 'h') ? TRUE : FALSE;
return( (key==ESC) ? FALSE : TRUE );
}
/*
* Class: CEditor
*
* Purpose: Edits a single color component (R, G or B)
*
* Note: Calls the "other_key" function to process keys it doesn't use.
* The "change" function is called whenever the value is changed
* by the CEditor.
*/
struct _CEditor
{
int x, y;
char letter;
int val;
BOOLEAN done;
BOOLEAN hidden;
#ifndef XFRACT
void (*other_key)(int key, struct _CEditor *ce, VOIDPTR info);
void (*change)(struct _CEditor *ce, VOIDPTR info);
#else
void (*other_key)();
void (*change)();
#endif
void *info;
} ;
#define CEditor struct _CEditor
/* public: */
#ifndef XFRACT
static CEditor *CEditor_Construct( int x, int y, char letter,
void (*other_key)(int,CEditor*,void*),
void (*change)(CEditor*,void*), VOIDPTR info);
static void CEditor_Destroy (CEditor *this);
static void CEditor_Draw (CEditor *this);
static void CEditor_SetPos (CEditor *this, int x, int y);
static void CEditor_SetVal (CEditor *this, int val);
static int CEditor_GetVal (CEditor *this);
static void CEditor_SetDone (CEditor *this, BOOLEAN done);
static void CEditor_SetHidden (CEditor *this, BOOLEAN hidden);
static int CEditor_Edit (CEditor *this);
#else
static CEditor *CEditor_Construct( int , int , char ,
void (*other_key)(),
void (*change)(), VOIDPTR );
static void CEditor_Destroy (CEditor *);
static void CEditor_Draw (CEditor *);
static void CEditor_SetPos (CEditor *, int , int );
static void CEditor_SetVal (CEditor *, int );
static int CEditor_GetVal (CEditor *);
static void CEditor_SetDone (CEditor *, BOOLEAN );
static void CEditor_SetHidden (CEditor *, BOOLEAN );
static int CEditor_Edit (CEditor *);
#endif
#define CEditor_WIDTH (8*3+4)
#define CEditor_DEPTH (8+4)
#ifndef XFRACT
static CEditor *CEditor_Construct( int x, int y, char letter,
void (*other_key)(int,CEditor*,VOIDPTR),
void (*change)(CEditor*, VOIDPTR), VOIDPTR info)
#else
static CEditor *CEditor_Construct( int x, int y, char letter,
void (*other_key)(),
void (*change)(), VOIDPTR info)
#endif
{
CEditor *this = new(CEditor);
this->x = x;
this->y = y;
this->letter = letter;
this->val = 0;
this->other_key = other_key;
this->hidden = FALSE;
this->change = change;
this->info = info;
return(this);
}
static void CEditor_Destroy(CEditor *this)
{
delete(this);
}
static void CEditor_Draw(CEditor *this)
{
if (this->hidden)
return;
Cursor_Hide();
displayf(this->x+2, this->y+2, fg_color, bg_color, "%c%02d", this->letter, this->val);
Cursor_Show();
}
static void CEditor_SetPos(CEditor *this, int x, int y)
{
this->x = x;
this->y = y;
}
static void CEditor_SetVal(CEditor *this, int val)
{
this->val = val;
}
static int CEditor_GetVal(CEditor *this)
{
return(this->val);
}
static void CEditor_SetDone(CEditor *this, BOOLEAN done)
{
this->done = done;
}
static void CEditor_SetHidden(CEditor *this, BOOLEAN hidden)
{
this->hidden = hidden;
}
static int CEditor_Edit(CEditor *this)
{
int key;
int diff;
this->done = FALSE;
if (!this->hidden)
{
Cursor_Hide();
rect(this->x, this->y, CEditor_WIDTH, CEditor_DEPTH, fg_color);
Cursor_Show();
}
#ifdef XFRACT
Cursor_StartMouseTracking();
#endif
while ( !this->done )
{
Cursor_WaitKey();
key = getakey();
switch( key )
{
case PAGE_UP:
if (this->val < 63)
{
this->val += 5;
if (this->val > 63)
this->val = 63;
CEditor_Draw(this);
this->change(this, this->info);
}
break;
case '+':
diff = 1;
while ( keypressed() == key )
{
getakey();
++diff;
}
if (this->val < 63)
{
this->val += diff;
if (this->val > 63)
this->val = 63;
CEditor_Draw(this);
this->change(this, this->info);
}
break;
case PAGE_DOWN:
if (this->val > 0)
{
this->val -= 5;
if (this->val < 0)
this->val = 0;
CEditor_Draw(this);
this->change(this, this->info);
} break;
case '-':
diff = 1;
while ( keypressed() == key )
{
getakey();
++diff;
}
if (this->val > 0)
{
this->val -= diff;
if (this->val < 0)
this->val = 0;
CEditor_Draw(this);
this->change(this, this->info);
}
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
this->val = (key - '0') * 10;
if (this->val > 63)
this->val = 63;
CEditor_Draw(this);
this->change(this, this->info);
break;
default:
this->other_key(key, this, this->info);
break;
} /* switch */
} /* while */
#ifdef XFRACT
Cursor_EndMouseTracking();
#endif
if (!this->hidden)
{
Cursor_Hide();
rect(this->x, this->y, CEditor_WIDTH, CEditor_DEPTH, bg_color);
Cursor_Show();
}
return(key);
}
/*
* Class: RGBEditor
*
* Purpose: Edits a complete color using three CEditors for R, G and B
*/
struct _RGBEditor
{
int x, y; /* position */
int curr; /* 0=r, 1=g, 2=b */
int pal; /* palette number */
BOOLEAN done;
BOOLEAN hidden;
CEditor *color[3]; /* color editors 0=r, 1=g, 2=b */
#ifndef XFRACT
void (*other_key)(int key, struct _RGBEditor *e, VOIDPTR info);
void (*change)(struct _RGBEditor *e, VOIDPTR info);
#else
void (*other_key)();
void (*change)();
#endif
void *info;
} ;
#define RGBEditor struct _RGBEditor
/* private: */
static void RGBEditor__other_key (int key, CEditor *ceditor, VOIDPTR info);
static void RGBEditor__change (CEditor *ceditor, VOIDPTR info);
/* public: */
#ifndef XFRACT
static RGBEditor *RGBEditor_Construct(int x, int y,
void (*other_key)(int,RGBEditor*,void*),
void (*change)(RGBEditor*,void*), VOIDPTR info);
#else
static RGBEditor *RGBEditor_Construct(int x, int y,
void (*other_key)(),
void (*change)(), VOIDPTR info);
#endif
static void RGBEditor_Destroy (RGBEditor *this);
static void RGBEditor_SetPos (RGBEditor *this, int x, int y);
static void RGBEditor_SetDone (RGBEditor *this, BOOLEAN done);
static void RGBEditor_SetHidden(RGBEditor *this, BOOLEAN hidden);
static void RGBEditor_BlankSampleBox(RGBEditor *this);
static void RGBEditor_Update (RGBEditor *this);
static void RGBEditor_Draw (RGBEditor *this);
static int RGBEditor_Edit (RGBEditor *this);
static void RGBEditor_SetRGB (RGBEditor *this, int pal, PALENTRY *rgb);
static PALENTRY RGBEditor_GetRGB (RGBEditor *this);
#define RGBEditor_WIDTH 62
#define RGBEditor_DEPTH (1+1+CEditor_DEPTH*3-2+2)
#define RGBEditor_BWIDTH ( RGBEditor_WIDTH - (2+CEditor_WIDTH+1 + 2) )
#define RGBEditor_BDEPTH ( RGBEditor_DEPTH - 4 )
#ifndef XFRACT
static RGBEditor *RGBEditor_Construct(int x, int y, void (*other_key)(int,RGBEditor*,void*),
void (*change)(RGBEditor*,void*), VOIDPTR info)
#else
static RGBEditor *RGBEditor_Construct(int x, int y, void (*other_key)(),
void (*change)(), VOIDPTR info)
#endif
{
RGBEditor *this = new(RGBEditor);
static char far letter[] = "RGB";
int ctr;
for (ctr=0; ctr<3; ctr++)
this->color[ctr] = CEditor_Construct(0, 0, letter[ctr], RGBEditor__other_key,
RGBEditor__change, this);
RGBEditor_SetPos(this, x, y);
this->curr = 0;
this->pal = 1;
this->hidden = FALSE;
this->other_key = other_key;
this->change = change;
this->info = info;
return(this);
}
static void RGBEditor_Destroy(RGBEditor *this)
{
CEditor_Destroy(this->color[0]);
CEditor_Destroy(this->color[1]);
CEditor_Destroy(this->color[2]);
delete(this);
}
static void RGBEditor_SetDone(RGBEditor *this, BOOLEAN done)
{
this->done = done;
}
static void RGBEditor_SetHidden(RGBEditor *this, BOOLEAN hidden)
{
this->hidden = hidden;
CEditor_SetHidden(this->color[0], hidden);
CEditor_SetHidden(this->color[1], hidden);
CEditor_SetHidden(this->color[2], hidden);
}
static void RGBEditor__other_key(int key, CEditor *ceditor, VOIDPTR info) /* private */
{
RGBEditor *this = (RGBEditor *)info;
switch( key )
{
case 'R':
case 'r':
if (this->curr != 0)
{
this->curr = 0;
CEditor_SetDone(ceditor, TRUE);
}
break;
case 'G':
case 'g':
if (this->curr != 1)
{
this->curr = 1;
CEditor_SetDone(ceditor, TRUE);
}
break;
case 'B':
case 'b':
if (this->curr != 2)
{
this->curr = 2;
CEditor_SetDone(ceditor, TRUE);
}
break;
case DELETE: /* move to next CEditor */
if ( ++this->curr > 2)
this->curr = 0;
CEditor_SetDone(ceditor, TRUE);
break;
case INSERT: /* move to prev CEditor */
if ( --this->curr < 0)
this->curr = 2;
CEditor_SetDone(ceditor, TRUE);
break;
default:
this->other_key(key, this, this->info);
if (this->done)
CEditor_SetDone(ceditor, TRUE);
break;
}
}
#ifdef __TURBOC__
# pragma argsused /* kills "arg not used" warning */
#endif
static void RGBEditor__change(CEditor *ceditor, VOIDPTR info) /* private */
{
RGBEditor *this = (RGBEditor *)info;
if ( this->pal < colors && !is_reserved(this->pal) )
setpal(this->pal, CEditor_GetVal(this->color[0]),
CEditor_GetVal(this->color[1]), CEditor_GetVal(this->color[2]));
this->change(this, this->info);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -