?? rguiproc.c
字號:
/******************************************************************************//* *//* R-GUI: RAINE GUI *//* *//******************************************************************************/#include "raine.h"#include "rgui.h"#include "rguiproc.h"#include "gui.h" // color conversion for the gui#include "palette.h" // GET_PEN.../*Todo:- Anything/everything/something... some day maybe... boring...*/#define SLOW_DRAG // Don't buffer window when moving it, slow// typedef for the listbox callback functionstypedef char *(*getfuncptr)(int, int *);static int translate_color(int x) { int Cx=0; // Translated color SET_PAL(x); return Cx;}static DEF_INLINE void trans_3d_box(int x1, int y1, int x2, int y2){ putpixel(screen, x2, y1, CGUI_BOX_COL_MIDDLE); putpixel(screen, x1, y2, CGUI_BOX_COL_MIDDLE); hline(screen, x1, y1, x2-1, CGUI_BOX_COL_HIGH_2); hline(screen, x1+1, y2, x2, CGUI_BOX_COL_LOW_2 ); vline(screen, x1, y1, y2-1, CGUI_BOX_COL_HIGH_2); vline(screen, x2, y1+1, y2, CGUI_BOX_COL_LOW_2 );}static DEF_INLINE void trans_3d_box_invert(int x1, int y1, int x2, int y2){ putpixel(screen, x2, y1, CGUI_BOX_COL_MIDDLE); putpixel(screen, x1, y2, CGUI_BOX_COL_MIDDLE); hline(screen, x1, y1, x2-1, CGUI_BOX_COL_LOW_2 ); hline(screen, x1+1, y2, x2, CGUI_BOX_COL_HIGH_2); vline(screen, x1, y1, y2-1, CGUI_BOX_COL_LOW_2 ); vline(screen, x2, y1+1, y2, CGUI_BOX_COL_HIGH_2);}static DEF_INLINE void solid_3d_box(int x1, int y1, int x2, int y2){ rectfill(screen, x1, y1, x2-1, y2-1, CGUI_BOX_COL_MIDDLE); hline(screen, x1+0, y1+0, x2-2, CGUI_BOX_COL_HIGH_2); hline(screen, x1+1, y2-1, x2-1, CGUI_BOX_COL_LOW_2 ); vline(screen, x1+0, y1+0, y2-2, CGUI_BOX_COL_HIGH_2); vline(screen, x2-1, y1+1, y2-1, CGUI_BOX_COL_LOW_2 ); hline(screen, x1+1, y1+1, x2-3, CGUI_BOX_COL_HIGH_1); hline(screen, x1+2, y2-2, x2-2, CGUI_BOX_COL_LOW_1 ); vline(screen, x1+1, y1+1, y2-3, CGUI_BOX_COL_HIGH_1); vline(screen, x2-2, y1+2, y2-2, CGUI_BOX_COL_LOW_1 );}static DEF_INLINE void solid_3d_box_invert(int x1, int y1, int x2, int y2){ rectfill(screen, x1, y1, x2-1, y2-1, CGUI_BOX_COL_MIDDLE); hline(screen, x1+0, y1+0, x2-2, CGUI_BOX_COL_LOW_2 ); hline(screen, x1+1, y2-1, x2-1, CGUI_BOX_COL_HIGH_2); vline(screen, x1+0, y1+0, y2-2, CGUI_BOX_COL_LOW_2 ); vline(screen, x2-1, y1+1, y2-1, CGUI_BOX_COL_HIGH_2); hline(screen, x1+1, y1+1, x2-3, CGUI_BOX_COL_LOW_1 ); hline(screen, x1+2, y2-2, x2-2, CGUI_BOX_COL_HIGH_1); vline(screen, x1+1, y1+1, y2-3, CGUI_BOX_COL_LOW_1 ); vline(screen, x2-2, y1+2, y2-2, CGUI_BOX_COL_HIGH_1);}static DEF_INLINE void dotted_rect(int x1, int y1, int x2, int y2){ rect(screen, x1, y1, x2, y2, CGUI_COL_SELECT);}// d_raine_box_proc:// Simple dialog procedure: just draws a 3D box.int d_raine_box_proc(int msg, DIALOG *d, int c){ if(msg==MSG_DRAW) solid_3d_box(d->x, d->y, d->x+d->w, d->y+d->h); return D_O_K;}typedef struct WINDOW_DATA{ BITMAP *back_cache; BITMAP *window; UINT32 back_x; UINT32 back_y; UINT32 back_w; UINT32 back_h;} WINDOW_DATA;void _handle_drag_window(DIALOG *dialog){ int x_ofs, y_ofs; int xx , yy; int gx , gy; int count; WINDOW_DATA *wdat; // Init gx = rgui_mouse_x(); gy = rgui_mouse_y(); x_ofs = gx - dialog[0].x; y_ofs = gy - dialog[0].y; wdat = (WINDOW_DATA *) dialog[0].dp2; while (gui_mouse_b()) { // Check if mouse has moved gx = rgui_mouse_x(); gy = rgui_mouse_y(); xx = dialog[0].x - (gx - x_ofs); yy = dialog[0].y - (gy - y_ofs); // Update dialog if it moved if((xx != 0)||(yy != 0)){ for (count=0; dialog[count].proc; count++) { dialog[count].x -= xx; dialog[count].y -= yy; } x_ofs = gx - dialog[0].x; y_ofs = gy - dialog[0].y;#ifdef SLOW_DRAG broadcast_dialog_message(MSG_DRAW, 0);#else scare_mouse(); if(wdat){ if(wdat->window){ // Copy Window blit(screen, wdat->window, wdat->back_x, wdat->back_y, 0, 0, dialog[0].w+1, dialog[0].h+1); } if(wdat->back_cache){ // Restore Back blit(wdat->back_cache, screen, 0, 0, wdat->back_x, wdat->back_y, dialog[0].w+1, dialog[0].h+1); } } if(wdat){ if(wdat->back_cache){ // Store Back wdat->back_x = dialog[0].x; wdat->back_y = dialog[0].y; blit(screen, wdat->back_cache, wdat->back_x, wdat->back_y, 0, 0, dialog[0].w+1, dialog[0].h+1); } if(wdat->window){ // Paste Window blit(wdat->window, screen, 0, 0, wdat->back_x, wdat->back_y, dialog[0].w+1, dialog[0].h+1); } } unscare_mouse();#endif } // Don't suffocate the rest of the dialog broadcast_dialog_message(MSG_IDLE, 0); }}int d_raine_window_proc(int msg, DIALOG *dialog, int c){ WINDOW_DATA *wdat; switch(msg){ case MSG_START: wdat = (WINDOW_DATA *) malloc(sizeof(WINDOW_DATA)); if(wdat){ wdat->back_x = dialog->x; wdat->back_y = dialog->y; wdat->back_w = dialog->w; wdat->back_h = dialog->h; wdat->back_cache = create_bitmap( wdat->back_w, wdat->back_h); wdat->window = create_bitmap( wdat->back_w, wdat->back_h); if(wdat->back_cache){ scare_mouse(); blit(screen, wdat->back_cache, wdat->back_x, wdat->back_y, 0, 0, wdat->back_w, wdat->back_h); unscare_mouse(); } } dialog->dp2 = (void *) wdat; return D_O_K; break; case MSG_END: wdat = (WINDOW_DATA *) dialog->dp2; if(wdat){ if(wdat->back_cache){ scare_mouse(); blit(wdat->back_cache, screen, 0, 0, wdat->back_x, wdat->back_y, wdat->back_w, wdat->back_h); unscare_mouse(); destroy_bitmap(wdat->back_cache); } free(wdat); } return D_O_K; break; case MSG_DRAW: wdat = (WINDOW_DATA *) dialog->dp2; if(wdat){ if(wdat->back_cache){ blit(wdat->back_cache, screen, 0, 0, wdat->back_x, wdat->back_y, wdat->back_w, wdat->back_h); wdat->back_x = dialog->x; wdat->back_y = dialog->y; blit(screen, wdat->back_cache, wdat->back_x, wdat->back_y, 0, 0, wdat->back_w, wdat->back_h); } } solid_3d_box(dialog->x, dialog->y, dialog->x+dialog->w, dialog->y+dialog->h); rectfill(screen, dialog->x+3, dialog->y+3+1, dialog->x+dialog->w-4, dialog->y+3+text_height(gui_main_font), CGUI_BOX_COL_LOW_2 ); hline(screen, dialog->x+3, dialog->y+3, dialog->x+dialog->w-4, CGUI_BOX_COL_LOW_1 ); hline(screen, dialog->x+3, dialog->y+4+text_height(gui_main_font), dialog->x+dialog->w-4, CGUI_BOX_COL_LOW_1 ); text_mode(-1); if (dialog->dp) textout(screen, gui_main_font, raine_translate_text(dialog->dp), dialog->x+4+6, dialog->y+4, CGUI_COL_TEXT_1 ); return D_O_K; break; case MSG_CLICK: { int gx = rgui_mouse_x(); int gy = rgui_mouse_y(); if((gx >= dialog->x+3)&&(gy >= dialog->y+3)&&(gx <= dialog->x+dialog->w-4)&&(gy <= dialog->y+4+text_height(gui_main_font))) _handle_drag_window( dialog ); else broadcast_dialog_message(MSG_IDLE, 0); }; return D_O_K; break; case MSG_IDLE: dialog_oxygen(); return D_O_K; break; default: return D_O_K; break; }}int d_null_proc(int msg, DIALOG *d, int c){ return D_O_K;}int d_raine_oxygen_proc(int msg, DIALOG *d, int c){ if(msg==MSG_IDLE) dialog_oxygen(); return D_O_K;}int raine_slider_proc(int msg, DIALOG *d, int c){ BITMAP *slhan = NULL; int sfg; /* slider foreground color */ int vert = TRUE; /* flag: is slider vertical? */ int hh = 7; /* handle height (width for horizontal sliders) */ int hmar; /* handle margin */ int slp; /* slider position */ int irange; int slx, sly, slh, slw; int retval = D_O_K; fixed slratio, slmax, slpos; int dbg; /* check for slider direction */ if (d->h < d->w) vert = FALSE; /* set up the metrics for the control */ if (d->dp != NULL) { slhan = (BITMAP *)d->dp; if (vert) hh = slhan->h; else hh = slhan->w; } hmar = hh/2; irange = (vert) ? d->h : d->w; slmax = itofix(irange-hh); slratio = slmax / (d->d1); slpos = slratio * d->d2; slp = fixtoi(slpos); switch (msg) { case MSG_DRAW: sfg = (d->flags & D_DISABLED) ? gui_mg_color : d->fg; sfg = translate_color(sfg); dbg = translate_color(d->bg); if (vert) { rectfill(screen, d->x, d->y, d->x+d->w/2-2, d->y+d->h-1, dbg); rectfill(screen, d->x+d->w/2-1, d->y, d->x+d->w/2+1, d->y+d->h-1, sfg); rectfill(screen, d->x+d->w/2+2, d->y, d->x+d->w-1, d->y+d->h-1, dbg); } else { rectfill(screen, d->x, d->y, d->x+d->w-1, d->y+d->h/2-2, dbg); rectfill(screen, d->x, d->y+d->h/2-1, d->x+d->w-1, d->y+d->h/2+1, sfg); rectfill(screen, d->x, d->y+d->h/2+2, d->x+d->w-1, d->y+d->h-1, dbg); } /* okay, background and slot are drawn, now draw the handle */ if (slhan) { if (vert) { slx = d->x+(d->w/2)-(slhan->w/2); sly = d->y+(d->h-1)-(hh+slp); } else { slx = d->x+slp; sly = d->y+(d->h/2)-(slhan->h/2); } draw_sprite(screen, slhan, slx, sly); } else { /* draw default handle */ if (vert) { slx = d->x; sly = d->y+(d->h)-(hh+slp); slw = d->w-1; slh = hh-1; } else { slx = d->x+slp; sly = d->y; slw = hh-1; slh = d->h-1; } /* draw body */ rectfill(screen, slx+2, sly, slx+(slw-2), sly+slh, sfg); vline(screen, slx+1, sly+1, sly+slh-1, sfg); vline(screen, slx+slw-1, sly+1, sly+slh-1, sfg); vline(screen, slx, sly+2, sly+slh-2, sfg); vline(screen, slx+slw, sly+2, sly+slh-2, sfg); vline(screen, slx+1, sly+2, sly+slh-2, dbg); hline(screen, slx+2, sly+1, slx+slw-2, dbg); putpixel(screen, slx+2, sly+2, d->bg); } if (d->flags & D_GOTFOCUS) dotted_rect(d->x, d->y, d->x+d->w-1, d->y+d->h-1); break; default: return d_slider_proc(msg,d,c); } return retval;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -