📄 ui_be.cpp
字号:
static menudialog *be_screen_resizedialog(uih_context *c){ if(gpDirectScreen!=NULL) { switch(gpDirectScreen->fBytesPerPixel) { case 1:be_screen_resdialog[1].defint=0; break; case 2:be_screen_resdialog[1].defint=1; break; case 4:be_screen_resdialog[1].defint=2; break; } switch(gpDirectScreen->fWidth) { case 640:be_screen_resdialog[0].defint=0; break; case 800:be_screen_resdialog[0].defint=1; break; case 1024:be_screen_resdialog[0].defint=2; break; case 1151:be_screen_resdialog[0].defint=3; break; case 1280:be_screen_resdialog[0].defint=4; break; case 1600:be_screen_resdialog[0].defint=5; break; } } return be_screen_resdialog;}static voidbe_screen_resize(struct uih_context *c, dialogparam *p){ int w,h,d; CONST char * CONST depths[]={ "8", "16", "32", }; static char mode[10]; sprintf(mode,"%sx%s",resolution[p[0].dint],depths[p[1].dint]); screen_mode=mode; sscanf(screen_mode, "%ix%ix%i",&w,&h,&d); gpDirectScreen->SetMode(w,h,d);}static menuitem screenmenuitems[]={ MENUCDIALOG ("ui", "=", "Resize", "resize", MENUFLAG_INTERRUPT, (void(*)())be_screen_resize, be_screen_resizedialog), MENUSEPARATOR("edit"), MENUNOP ("edit",NULL,"Copy","copy",MENUFLAG_INCALC,(void (*)())be_copy), MENUNOP ("edit",NULL,"Paste","paste",MENUFLAG_INTERRUPT,(void (*)())be_paste), //MENUSEPARATOR("file"), //MENUNOP ("file",NULL,"About XaoS","about",MENUFLAG_INCALC,be_about),};static int be_init(){ direct=0; menu_add (winmenuitems, NITEMS (winmenuitems)); return do_be_init();}static int be_direct_init(){ if(!BDirectWindow::SupportsWindowMode()) return 0; direct=DIRECTWINDOW; menu_add (directmenuitems, NITEMS (directmenuitems)); return do_be_init();}// Deallocate any stuff we allocated at startup.static void be_do_uninit(){ // Tell the window that it may quit, and to do so. if (direct!=DIRECTSCREEN) gpWindow->Hide(), gpWindow->Sync(), gpMenu->cleanMenu(), delete gpMenu; if (!direct) gpNormalWindow->AllowQuit(); else if (direct==DIRECTWINDOW) gpDirectWindow->AllowQuit(); else gpDirectScreen->AllowQuit(); gpWindow->PostMessage(B_QUIT_REQUESTED); ignorequit=1; XaoSDialog::cleanup(); /*destroy_port(mEventPort);*/}static void be_uninit(){ be_do_uninit(); menu_delete (winmenuitems, NITEMS (winmenuitems));}static void be_direct_uninit(){ be_do_uninit(); menu_delete (directmenuitems, NITEMS (directmenuitems));}static int be_screen_init(void){ status_t error = B_OK; BRect mainRect(0,0,65536,65536); direct=DIRECTSCREEN; // Evaluate parameters. visible=1; isfullscreen=0; mEventPort = create_port(100, "XaoS "XaoS_VERSION); mainView = new XaoSScreenView(mainRect, mEventPort); mainView->SetViewColor(215,215,215); gpDirectScreen = new XaoSDirectScreen(mEventPort, mainView, &error); gpWindow = gpDirectScreen; if (error!=B_OK) { //delete (gpDirectScreen); gpDirectScreen->AllowQuit(); gpDirectScreen->QuitRequested(); gpWindow = NULL; delete(mainView); return 0; } int w=640,h=480,d=8; sscanf(screen_mode, "%ix%ix%i",&w,&h,&d); gpDirectScreen->SetMode(w,h,d); gpDirectScreen->SetPointer((const char *)mouse_pointer_data); menu_add (screenmenuitems, NITEMS (screenmenuitems)); be_noalert=1; return 1;}static void be_screen_uninit(){ be_do_uninit(); be_noalert=0; menu_delete (screenmenuitems, NITEMS (screenmenuitems));}static void be_screen_get_size(int *x, int *y){ gpDirectScreen->locker->Lock(); gpDirectScreen->UpdateParams(); gpDirectScreen->locker->Unlock(); view_width=*x=gpDirectScreen->fWidth; view_height=*y=gpDirectScreen->fHeight; switch(gpDirectScreen->fBytesPerPixel) { case 1: be_screen_driver.imagetype = UI_C256; break; case 2: be_screen_driver.imagetype = UI_TRUECOLOR16; be_screen_driver.rmask = 31 * 64 * 32; be_screen_driver.gmask = 63 * 32; be_screen_driver.bmask = 31; break; case 3: be_screen_driver.imagetype = UI_TRUECOLOR24; be_screen_driver.bmask = 0x000000ff; be_screen_driver.gmask = 0x0000ff00; be_screen_driver.rmask = 0x00ff0000; break; case 4: be_screen_driver.bmask = 0x000000ff; be_screen_driver.gmask = 0x0000ff00; be_screen_driver.rmask = 0x00ff0000; be_screen_driver.imagetype = UI_TRUECOLOR; break; } }static void be_screen_set_range(ui_palette palette, int start, int end){ rgb_color c[256]; int i; for(i=start;i<end;i++) { c[i].red=palette[i-start][0]; c[i].green=palette[i-start][1]; c[i].blue=palette[i-start][2]; } gpDirectScreen->SetColor(c+start,start,end-1);/* // Tell XaoS about our fixed color map. BScreen screen; const color_map *pColorMap = screen.ColorMap(); for (int i = start; i < end; ++i) { palette[i-start][0] = pColorMap->color_list[i].red; palette[i-start][1] = pColorMap->color_list[i].green; palette[i-start][2] = pColorMap->color_list[i].blue; }*/}static void be_screen_print(int x, int y,CONST char *text){}static void be_screen_mousetype(int t){ switch (t) { default: case 0: gpDirectScreen->SetPointer((const char *)mouse_pointer_data); break; case 1: gpDirectScreen->SetPointer((const char *)wait_pointer_data); break; case 2: gpDirectScreen->SetPointer((const char *)replay_pointer_data); break; }}static int bytes_per_pixel;static void be_screen_display(void){ gpDirectScreen->Blit(gpFractalBuffers[gCurrentBuffer], view_width, view_height, bytes_per_pixel);}static int be_screen_alloc_buffers(char **b1, char **b2){ int linesize=gpDirectScreen->fWidth*gpDirectScreen->fBytesPerPixel; linesize=(linesize+15)&~15; gCurrentBuffer = 0; *b1=gpFractalBuffers[0] = new char[linesize*view_height]; *b2=gpFractalBuffers[1] = new char[linesize*view_height]; bytes_per_pixel=gpDirectScreen->fBytesPerPixel; return linesize;}static void be_screen_free_buffers(char *b1, char *b2){ delete gpFractalBuffers[0]; delete gpFractalBuffers[1];}CONST static struct params params[] ={ {"", P_HELP, NULL,"BeOS driver options:"}, { "-async", P_SWITCH, &async, "Asynchronous bitmap drawing" }, { "-bitmap", P_SWITCH, &bitmap, "1-bit grayscale mode" }, { "-grayscale", P_SWITCH, &grayscale, "8-bit grayscale mode" }, { "-8bit", P_SWITCH, &color8bit, "8-bit palette mode" }, { "-15bit", P_SWITCH, &realcolor, "15-bit true color mode" }, { "-16bit", P_SWITCH, &hicolor, "16-bit true color mode" }, { "-32bit", P_SWITCH, &truecolor, "32-bit true color mode" }, { "-size", P_STRING, &window_size, "set window size (WIDTHxHEIGHT)" }, { "-fullscreen", P_SWITCH, &fullscreen, "set fullscreen mode" }, { NULL, 0, NULL, NULL }};CONST static struct params directparams[] ={ {"", P_HELP, NULL,"BeOS DirectWindow driver options:"}, { "-size", P_STRING, &window_size, "set window size (WIDTHxHEIGHT)" }, { "-fullscreen", P_SWITCH, &fullscreen, "set fullscreen mode" }, { NULL, 0, NULL, NULL }};CONST static struct params screenparams[] ={ {"", P_HELP, NULL,"BeOS DirectWindow driver options:"}, { "-mode", P_STRING, &screen_mode, "set window size (WIDTHxHEIGHTxMODE)" }, { NULL, 0, NULL, NULL }};static voidbe_dorootmenu(struct uih_context *c, CONST char *name){ BAutolock locker(gpWindow); gpMenu->setMenu(c,name); if (!visible) gpWindow->Show(), visible=0;}static voidbe_enabledisable(struct uih_context *c, CONST char *name){ BAutolock locker(gpWindow); CONST menuitem *i=menu_findcommand(name); gpMenu->EnableDisable(i);}static voidbe_menu(struct uih_context *c, CONST char *name){ BPoint p; int x,y,b; BAutolock locker(gpWindow); be_getmouse(&x, &y, &b); p.x=x-5; p.y=y-5; p=gpView->ConvertToScreen(p); XaoSMenu *m=new XaoSMenu(mEventPort, name, p, gpWindow); gpMenu->AddToList(m); m->setMenu(c, name);}static voidbe_dialog(struct uih_context *c, CONST char *name){ BAutolock locker(gpWindow); new XaoSDialog(gpWindow->Frame(), name, mEventPort, c);}voidbe_help(struct uih_context *c, CONST char *name){ char s[256]; char *s1; xio_file f; sprintf(s,"\01/help/%s.html",name); if((f=xio_ropen(s))) { xio_close(f); } else { sprintf(s,"\01/../help/%s.html",name); if((f=xio_ropen(s))) { xio_close(f); } else { x_error("Help file %s not found",s); return; } } s1=xio_fixpath(s); sprintf(s,"NetPositive %s &",s1); system(s); free(s1);}extern "C" {struct gui_driver be_gui_driver ={ be_dorootmenu, /*dorootmenu*/ be_enabledisable, /*enabledisable*/ be_menu, /*menu*/ be_dialog, /*dialog*/ be_help, /*help*/};struct ui_driver be_driver ={ "BeOS", be_init, be_get_size, be_processevents, be_getmouse, be_uninit, NULL, // set_color() be_set_range, be_print, be_display, be_alloc_buffers, be_free_buffers, be_flip_buffers, be_mousetype, NULL, // flush() 0, // text width (see be_init) 0, // text height (see be_init) params, // command-line parameters UPDATE_AFTER_PALETTE|PIXELSIZE|RESOLUTION, 0.02979, 0.02930, // this is for my monitor in 1024x768 1024, 768, 0, // image type (see be_init) 0, NCOLORS-1, NCOLORS, 0, 0, 0, &be_gui_driver};struct ui_driver be_direct_driver ={ "DirectWindow", be_direct_init, be_get_size, be_processevents, be_getmouse, be_direct_uninit, NULL, // set_color() be_set_range, be_print, be_display, be_alloc_buffers, be_free_buffers, be_flip_buffers, be_mousetype, NULL, // flush() 0, // text width (see be_init) 0, // text height (see be_init) directparams, // command-line parameters UPDATE_AFTER_PALETTE|PIXELSIZE|RESOLUTION, 0.02979, 0.02930, // this is for my monitor in 1024x768 1024, 768, 0, // image type (see be_init) 0, NCOLORS-1, NCOLORS, 0, 0, 0, &be_gui_driver};struct ui_driver be_screen_driver ={ "WindowScreen", be_screen_init, be_screen_get_size, be_processevents, be_getmouse, be_screen_uninit, NULL, // set_color() be_screen_set_range, be_screen_print, be_screen_display, be_screen_alloc_buffers, be_screen_free_buffers, be_flip_buffers, be_screen_mousetype, NULL, // flush() 0, // text width (see be_init) 0, // text height (see be_init) screenparams, // command-line parameters UPDATE_AFTER_PALETTE|PIXELSIZE|RESOLUTION, 0.02979, 0.02930, // this is for my monitor in 1024x768 1024, 768, 0, // image type (see be_init) 0, 256, 255, //10, 128+10,128, 0, 0, 0};}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -