Chinaunix首页 | 论坛 | 博客
  • 博客访问: 196835
  • 博文数量: 60
  • 博客积分: 3269
  • 博客等级: 中校
  • 技术积分: 648
  • 用 户 组: 普通用户
  • 注册时间: 2005-09-21 10:48
文章存档

2012年(6)

2011年(6)

2010年(30)

2009年(8)

2007年(6)

2005年(4)

我的朋友

分类:

2007-08-09 13:39:43

以下代码在dos/turbo_C2.0编译通过,并使用良好,只是没有注释,
我也忘了,大家根据函数名猜吧。

http://leadgenius.cublog.cn/
/* gpopup.c */

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include"gpopup.h"

#include"mouse.h"

#define Max(a,b) ((a)>(b)?(a)b))

#define Min(a,b) ((a)<(b)?(a)b))

windesc *base_win = NULL;

windesc *curr_win = NULL;

int graphdriver = 0;

int graphmode = 0;

char *pathdriver = "";

wincolors defcolors = {

        {SOLID_LINE,0,NORM_WIDTH},

        {EMPTY_FILL,0},

        {DEFAULT_FONT,HORIZ_DIR,1,LEFT_TEXT,TOP_TEXT},

        {SOLID_LINE,0,THICK_WIDTH},

        {0,0,0,0,1},

        1,7,7,7,0

        };

static windesc *top_win;

static void dispose_window_node(windesc *w);

static windesc *push_window_node(void);

static windesc *make_window_node(void);

static void chg_win(windesc *this);

static void fill_win(windesc *w);



void init_win(void)

{

        initgraph(>aphdriver,>aphmode,pathdriver);

        base_win = make_window_node();

        getviewsettings(&base_win->wc.viewinfo);

        base_win->wc.text_color = getcolor();

        getfillsettings(&base_win->wc.fillinfo);

        getlinesettings(&base_win->wc.lineinfo);

        gettextsettings(&base_win->wc.textinfo);

        base_win->wc.brdinfo = base_win->wc.lineinfo;

        base_win->xsave = getx();

        base_win->ysave = gety();

        base_win->wtype = tile;

        base_win->wc.border_type = 0;

        top_win = base_win;

        curr_win = base_win;

}





windesc *draw_win(int x,int y,int wd,int ht,char *title,

                enum windowtype wt,wincolors *wc)

{

        windesc *w;

        int maxx,maxy;

        w = push_window_node();

        maxx = getmaxx();

        maxy = getmaxy();

        wd = Max(wd,3);

        wd = Min(wd,maxx);

        ht = Max(ht,3);

        ht = Min(ht,maxy);

        if(x == Ctrwin) x=(maxx - wd) / 2;

        if(y == Ctrwin) y=(maxy - ht) / 2;

        x = Max(x,0);

        y = Max(y,0);

        if((x+wd) > maxx) x = maxx - wd + 1;

        if((y+ht) > maxy) y = maxy - ht + 1;

        w->wc = *wc ;

        w->wd = wd;

        w->ht = ht;

        w->xul = x;

        w->yul = y;

        w->xlr = x+w->wd-1;

        w->ylr = y+w->ht-1;

        w->xsave = 1;

        w->ysave = 1;

        w->wtype = wt;

        w->name = strdup(title);

        if(wt == popup) {

                w->image = calloc(imagesize(w->xul,w->yul,

                                w->xlr,w->ylr),1);

                swap_image(w);

        }

        fill_win(w);

        chg_win(w);

        return w;

}



static void fill_win(windesc *w)

{

        mouse_off(1);

        chgviewport(base_win);

        setcolor(w->wc.border_color);

        setlinestyle(w->wc.brdinfo.linestyle,

                w->wc.brdinfo.upattern,

                w->wc.brdinfo.thickness);

        setfillstyle(Solid_fill,w->wc.back_color);

        if(w->wc.border_type&&w->wc.brdinfo.thinkness == Thick_width)

                bar3d(w->xul+1,w->yul+1,w->xlr-1,w->ylr-1,0,0);

        else

                bar3d(w->xul,w->yul,w->xlr,w->ylr,0,0);

        chgviewport(curr_win);

        mouse_on(1);

}



void clr_win(void )

{

        fill_win(curr_win);

}



void view_win(windesc *this,int select)

{

        windesc *p;

        if(selete && this == top_win) return ;

        mouse_off(1);

        if(thisf->wtype == popup) {

                p = top_win;

                while(p != this) {

                        swap_image(p);

                        p = p->under;

                }

                swap_image(this);

                p = this;

                while (p != top_win) {

                        p = p->over;

                        swap_image(p);

                }

        }

        if (this == top_win) {

                this->under->over = NULL;

                top_win = this->under;

        }

        else {

                this->under->over = this->over;

                this->over->under = this->under;

        }

        if (select) {

                top_win->over = this;

                this->under = top_win;

                top_win = this;

                swap_image(this);

                chg_win(this);

        }

        else {

                chg_win(top_win);

                dispose_window_node(this);

        }

        mouse_on(1);

}



static void chg_win(windesc *this)

{

        curr_win->xsave = getx();

        curr_win->ysave = gety();

        getfillsettings(&curr_win->wc.fillinfo);

        getlinesettings(&curr_win->wc.lineinfo);

        gettextsettings(&curr_win->wc.textinfo);

        chgviewport(this);

        setcolor(this->wc.text_color);

        setfillstyle  (this->wc.fillinfo.pattern,

                        this->wc.fillinfo.color);

        setlinestyle  (this->wc.lineinfo.linestyle,

                        this->wc.lineinfo.upattern,

                        this->wc.lineinfo.thickness);

        settextjustify(this->wc.textinfo.horiz,

                        this->wc.textinfo.vert);

        settextdtyle  (this->wc.textinfo.font,

                        this->wc.textinfo.dirction,

                        this->wc.textinfo.charsize);

        moveto(this->xsave,this->ysave);

        curr_win = this;

}



void chgviewport(windesc *this)

{

        int delta;

        if(this->wc.border_type)

                delta = this->wc.brdinfo.thickness;

        else delta = 0;

        setviewport(this->xul+delta,this->yul+delta,

                        this->xlr-delta,this->ylr-delta,

                        this->wc.viewinfo.clip);

}



void swap_image(windesc *w)

{

        char *temp_image;

        int nbytes;

        if (w->wtype == popup)  {

                nbytes = imagesize (w->xul,w->yul,w->xlr,w->ylr);

                temp_image = malloc(nbytes);

                chgviewport (base_win);

                mouse_off(1);

                getimage(w->xul,w->yul,w->xlr,w->ylr,temp_image);

                putimage(w->xul,w->yul,w->image,Copy_put);

                mouse_on(1);

                chgviewport(w);

                memcpy(w->image,temp_image,nbytes);

                free(temp_image);

        }

}



static windesc *make_window_node(void)

{

        /*

        Make_window_node allocates room for a new window strctyre,

        and initializes it’s link to NULL.

        */

        windesc *q;

        q = (windesc *)malloc(sizeof(windesc));

        q->image = NULL;

        q->under = NULL;

        q->over = NULL;

        return q;

}



static windesc *push_window_node(void)

{

        windesc *q;

        q = make_window_node();

        top_win->over = q;

        q->under = top_win;

        top_win = q;

        return q;

}



static void dispose_window_node(windesc *w)

{

        if(w != NULL) {

                if (w->wtype == popup) free(w->image);

                free(w->name);

                free(w);

        }

}
阅读(1292) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~