📄 badctrls.c
字号:
/******************************************************************
* SEAL 2.0 *
* Copyright (c) 1999-2002 SEAL Developers. All Rights Reserved. *
* *
* Web site: http://sealsystem.sourceforge.net/ *
* E-mail (current maintainer): orudge@users.sourceforge.net *
******************************************************************/
/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/****************************************************************/
/* */
/* badctrls.c */
/* Bad Controls for SEAL */
/* v0.4.2 */
/* */
/* (c) 2000, 2001 Kostas Michalopoulos aka Bad Sector */
/* first version for Bad Seal | www.badseal.org */
/* */
/* ============================================================ */
/* Controls included: */
/* t_bad_checkbox Checkbox control */
/* t_bad_button t_button replacement */
/* t_bad_vtrackbar vertical trackbar */
/* t_bad_tabbook tab book */
/* t_bad_iconbox box with icons :-) */
/* t_bad_vscrollbar vertical scrollbar */
/* ============================================================ */
/* */
/* Seal - free desktop environment */
/* */
/* Copyright (c) 1999,2000 */
/* Michal Stencl */
/* All Rights Reserved */
/* */
/* mail : stenclpmd@ba.telecom.sk */
/* web : http://www.home.sk/public/seal/ */
/* */
/* This file is part of Seal. */
/* */
/* Seal is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU General Public License */
/* as published by the Free Software Foundation; either version */
/* 2, or (at your option) any later version. */
/* */
/* Seal is distributed in the hope that it will be useful, but */
/* WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See */
/* the GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public */
/* License along with Seal; see the file COPYING. If not, */
/* write to the Free Software Foundation, 675 Mass Ave, */
/* Cambridge, MA 02139, USA. */
/* */
/****************************************************************/
#include <allegro.h>
#include <seal.h>
#include <badctrls.h>
//#include <beditor.h>
SetInfoAppName("Bad Controls 0.4.2");
SetInfoDesciption("Bad Controls 0.4.2");
SetInfoCopyright("Copyright (c) Kostas Michalopoulos aka Bad Sector 2000-2001");
SetInfoManufacturer("Kostas Michalopoulos");
//#include "beditor.c"
/* common palette for Bad Controls
0 3d face
1 3d light
2 3d shadow
3 3d dark
4 3d border
5 text color
6 flat color
7 flat border
8 highlight
9 highlight text
10 iconbox text
11 filebox background
12 filebox text
*/
l_color pal_bad_common[] = {CO_LIGHTGRAY,
CO_WHITE,
CO_DARKGRAY,
CO_BLACK,
CO_BLACK,
CO_BLACK,
CO_WHITE,
CO_BLACK,
CO_BLUE,
CO_WHITE,
CO_BLACK,
CO_WHITE,
CO_BLACK,
CO_NOCOLOR};
p_bad_checkbox (*bad_checkbox_init)(p_bad_checkbox o, t_rect r, l_text cap, l_dword msg, l_int st)=&_bad_checkbox_init;
p_bad_button (*bad_button_init)(p_bad_button o, t_rect r, l_text cap, l_int style, l_dword msg)=&_bad_button_init;
p_bad_vtrackbar (*bad_vtrackbar_init)(p_bad_vtrackbar o, t_rect r, l_dword msg)=&_bad_vtrackbar_init;
p_bad_tabbook (*bad_tabbook_init)(p_bad_tabbook o, t_rect r, l_text ftitle)=&_bad_tabbook_init;
p_bad_iconbox (*bad_iconbox_init)(p_bad_iconbox o, t_rect r, l_big flags)=&_bad_iconbox_init;
p_bad_vscrollbar (*bad_vscrollbar_init)(p_bad_vscrollbar o, t_rect r, l_int flags)=&_bad_vscrollbar_init;
static DATAFILE *dat = NULL;
#define Get_Bitmap(n) (BITMAP*)GET_DATA(dat, n)
void light_image ( BITMAP *bmp, int x1, int y1, int x2, int y2, int dr, int dg, int db )
{
int x = x1;
int y = y1;
int r, g, b;
int col;
if (x1 > x2) {
int tmp = x1;
x1 = x2;
x2 = x1;
};
if (y1 > y2) {
int tmp = y1;
y1 = y2;
y2 = y1;
};
for (;;) {
for (;;) {
col = getpixel(bmp, x, y);
r = getr(col);
g = getg(col);
b = getb(col);
r += dr;
g += dg;
b += db;
if (r < 0) r = 0; else if (r > 255) r = 255;
if (g < 0) g = 0; else if (g > 255) g = 255;
if (b < 0) b = 0; else if (b > 255) b = 255;
col = makecol(r, g, b);
putpixel(bmp, x, y, col);
x++;
if (x > x2) break;
};
y++;
if (y > y2) break;
x = x1;
};
};
void draw_bevel(BITMAP *out, int x1, int y1, int x2, int y2, int c1, int c2)
{
if (out) {
line(out, x1, y1, x2, y1, c1);
line(out, x1, y1, x1, y2, c1);
line(out, x2, y1, x2, y2, c2);
line(out, x1, y2, x2, y2, c2);
}
}
/* t_bad_checkbox */
l_bool bad_checkbox_done(p_object o)
{
if (!view_done(o)) return false;
afree(&(BAD_CHECKBOX(o)->caption));
return true;
};
void bad_checkbox_set_state(p_object o, l_dword st, l_bool set)
{
view_set_state(o, st, set);
if ( st & OB_SF_FOCUSED ) {
VIEW(o)->draw_view(VIEW(o));
};
};
void bad_checkbox_translate_event(p_object o, t_event *event)
{
RETVIEW(o, event);
view_translate_event(o, event);
/* check if we're clicked by the mouse */
if (event->type & EV_MOUSE && OBJECT(mouse)->state & MO_SF_MOUSELDOWN)
{
l_bool in_view = false;
if (VIEW(o)->is_mouse_in_view(VIEW(o))) {
BAD_CHECKBOX(o)->grayed = true;
BAD_CHECKBOX(o)->draw_state(BAD_CHECKBOX(o), in_view);
};
while (OBJECT(mouse)->state & MO_SF_MOUSELPRESS)
{
l_bool safe_in_view = in_view;
in_view = VIEW(o)->is_mouse_in_view(VIEW(o));
if (in_view != safe_in_view) {
BAD_CHECKBOX(o)->grayed = in_view;
BAD_CHECKBOX(o)->draw_state(BAD_CHECKBOX(o), in_view);
};
o->get_event(o, event);
};
if (in_view) {
if (BAD_CHECKBOX(o)->state < 2) {
BAD_CHECKBOX(o)->state = 1-BAD_CHECKBOX(o)->state;
BAD_CHECKBOX(o)->grayed = false;
BAD_CHECKBOX(o)->draw_state(BAD_CHECKBOX(o), false);
set_event(event, EV_MESSAGE, BAD_CHECKBOX(o)->message, o);
o->put_event(o, event);
clear_event(event);
} else {
BAD_CHECKBOX(o)->grayed = false;
BAD_CHECKBOX(o)->draw_state(BAD_CHECKBOX(o), false);
};
};
};
};
void bad_checkbox_draw_state(p_bad_checkbox o, l_int astate)
{
t_rect r = VIEW(o)->get_local_extent(VIEW(o));
t_point p;
BITMAP *out = VIEW(o)->begin_paint(VIEW(o), &p, r);
if ( out ) {
rectfill(out, r.a.x+p.x, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, VIEW(o)->get_color(VIEW(o), 0));
if ((o->state != 2) && (o->grayed == false)) rectfill(out, r.a.x+p.x, r.a.y+p.y, r.a.x+p.x+14, r.a.y+p.y+14, VIEW(o)->get_color(VIEW(o), 6));
line(out, r.a.x+p.x, r.a.y+p.y, r.a.x+p.x, r.a.y+p.y+14, VIEW(o)->get_color(VIEW(o), 2));
line(out, r.a.x+p.x, r.a.y+p.y, r.a.x+p.x+14, r.a.y+p.y, VIEW(o)->get_color(VIEW(o), 2));
line(out, r.a.x+p.x+14, r.a.y+p.y, r.a.x+p.x+14, r.a.y+p.y+14, VIEW(o)->get_color(VIEW(o), 1));
line(out, r.a.x+p.x, r.a.y+p.y+14, r.a.x+p.x+14, r.a.y+p.y+14, VIEW(o)->get_color(VIEW(o), 1));
line(out, r.a.x+p.x+1, r.a.y+p.y+1, r.a.x+p.x+1, r.a.y+p.y+13, VIEW(o)->get_color(VIEW(o), 3));
line(out, r.a.x+p.x+1, r.a.y+p.y+1, r.a.x+p.x+13, r.a.y+p.y+1, VIEW(o)->get_color(VIEW(o), 3));
line(out, r.a.x+p.x+13, r.a.y+p.y+1, r.a.x+p.x+13, r.a.y+p.y+13, VIEW(o)->get_color(VIEW(o), 0));
line(out, r.a.x+p.x+1, r.a.y+p.y+13, r.a.x+p.x+13, r.a.y+p.y+13, VIEW(o)->get_color(VIEW(o), 0));
textout_draw_rect(out, VIEW(o)->font, o->caption, -1, r.a.x+p.x+17, r.a.y+p.y+1,
r.b.x+p.x-1, r.b.y+p.y-1, TX_ALIGN_LEFT, VIEW(o)->get_color(VIEW(o), 5), TX_NOCOLOR, 0);
if ( OBJECT(o)->is_state(OBJECT(o), OB_SF_FOCUSED) ) {
rect(out, r.a.x+p.x+16, r.a.y+p.y, r.b.x+p.x, r.b.y+p.y, VIEW(o)->get_color(VIEW(o), 4));
};
if (o->state == 1) {
line(out, r.a.x+p.x+3, r.a.y+p.y+3, r.a.x+p.x+11, r.a.y+p.y+11, COLOR(0));
line(out, r.a.x+p.x+11, r.a.y+p.y+3, r.a.x+p.x+3, r.a.y+p.y+11, COLOR(0));
line(out, r.a.x+p.x+4, r.a.y+p.y+3, r.a.x+p.x+11, r.a.y+p.y+10, COLOR(0));
line(out, r.a.x+p.x+10, r.a.y+p.y+3, r.a.x+p.x+3, r.a.y+p.y+10, COLOR(0));
line(out, r.a.x+p.x+3, r.a.y+p.y+4, r.a.x+p.x+10, r.a.y+p.y+11, COLOR(0));
line(out, r.a.x+p.x+11, r.a.y+p.y+4, r.a.x+p.x+4, r.a.y+p.y+11, COLOR(0));
}
};
VIEW(o)->end_of_paint(VIEW(o), r);
};
void bad_checkbox_change_state(p_bad_checkbox o, l_int newstate)
{
o->state = newstate;
VIEW(o)->draw_view(VIEW(o));
};
void bad_checkbox_change_caption(p_bad_checkbox o, l_text newcap)
{
afree(&(BAD_CHECKBOX(o)->caption));
o->caption = (l_text)_strdup((char*)newcap);
VIEW(o)->draw_view(VIEW(o));
}
void bad_checkbox_draw(p_view o)
{
BAD_CHECKBOX(o)->draw_state(BAD_CHECKBOX(o), false);
};
p_bad_checkbox _bad_checkbox_init(p_bad_checkbox o, t_rect r, l_text cap, l_dword msg, l_int st)
{
if (!o) return NULL;
clear_type(o, sizeof(t_bad_checkbox));
view_init(&o->obclass, r);
o->caption = (l_text)_strdup((char*)cap);
o->message = msg;
o->state = st;
OBJECT(o)->translate_event = &bad_checkbox_translate_event;
OBJECT(o)->set_state = &bad_checkbox_set_state;
OBJECT(o)->done = &bad_checkbox_done;
VIEW(o)->draw = &bad_checkbox_draw;
VIEW(o)->set_palette(VIEW(o), pal_bad_common);
o->draw_state = &bad_checkbox_draw_state;
o->change_state = &bad_checkbox_change_state;
o->change_caption = &bad_checkbox_change_caption;
return o;
};
/* t_bad_button */
l_bool bad_button_done(p_object o)
{
if (!view_done(o)) return false;
afree(&(BAD_BUTTON(o)->caption));
return true;
};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -