📄 ui_be.cpp
字号:
case XaoSEvent::Resize: { if (direct == DIRECTSCREEN) ui_call_resize(); else { BAutolock locker(gpWindow); BRect bounds = gpView->Bounds(); if(view_width != (int)bounds.Width()+1 || view_height != (int)bounds.Height() + 1) { view_width = (int)bounds.Width() + 1, view_height = (int)bounds.Height() + 1; ui_call_resize(); } } } break; } } while (port_count(/*gpView->EventPort()*/mEventPort) > 0); } *x = currX; *y = currY; *buttons = currButtons; if(direct==DIRECTSCREEN) be_getmouse(x,y,buttons), gpDirectScreen->SetMouse(*x,*y); *k = cursorMask;}// Set the cursor shape.static void be_mousetype(int type){ switch (type) { case NORMALMOUSE: be_app->SetCursor(B_HAND_CURSOR); break; case WAITMOUSE: { static const char cursor[] = { // Clock face. 16, 1, 8, 8, 0x07, 0xe0, 0x1f, 0xf8, 0x38, 0x1c, 0x71, 0x8e, 0x61, 0x86, 0xc1, 0x83, 0xc1, 0x83, 0xc1, 0x83, 0xc1, 0xc3, 0xc0, 0xe3, 0xc0, 0x63, 0x60, 0x06, 0x70, 0x0e, 0x38, 0x1c, 0x1f, 0xf8, 0x07, 0xe0, 0x07, 0xe0, 0x1f, 0xf8, 0x3f, 0xfc, 0x7f, 0xfe, 0x7f, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0xfe, 0x7f, 0xfe, 0x3f, 0xfc, 0x1f, 0xf8, 0x07, 0xe0 }; be_app->SetCursor(cursor); } break; case REPLAYMOUSE: { static const char cursor[] = { // Stylized tape deck. 16, 1, 8, 8, 0x38, 0x38, 0x44, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x44, 0x3f, 0xf8, 0x00, 0x00, 0x01, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x38, 0x7c, 0x7c, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0x7c, 0x7c, 0x3f, 0xf8, 0x00, 0x00, 0x01, 0x00, 0x03, 0x80, 0x07, 0xc0, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; be_app->SetCursor(cursor); } break; }}// Display c-string <text> at x,ystatic void be_print(int x, int y, CONST char *text){ BAutolock locker(gpWindow); /*gpView->DrawText(BPoint(x, y), text, strlen(text));*/ sView->SetText(text);}// Display pixel buffer from fractal engine to window.static void be_display(void){ BAutolock locker(gpWindow); if(direct) { gpDirectView->SetBuffer(gpFractalBuffers[gCurrentBuffer], view_width, view_height); } else { if(!async) { gpView->SetBuffer(gpDisplayBuffer[gCurrentBuffer], 1); } else { memcpy(gpDisplayBuffer[0]->Bits(), gpFractalBuffers[gCurrentBuffer], gBufferSize); } } gpView->Draw(gpView->Bounds());}// Allocate fractal engine pixel buffers.static int be_alloc_buffers(char **buffer1, char **buffer2){ // Allocate the display bitmap gCurrentBuffer = 0; if(!direct) { int i; for(i=0;i<(async?1:2);i++) gpDisplayBuffer[i] = new BBitmap(BRect(B_ORIGIN, BPoint(view_width-1, view_height-1)), gColorSpace); gBufferSize = gpDisplayBuffer[0]->BytesPerRow() * view_height; if(async) { // Allocate the fractal buffers. BAutolock locker(gpWindow); gpView->SetBuffer(gpDisplayBuffer[0],0); for (int i = 0; i < 2; ++i) { gpFractalBuffers[i] = new char[gBufferSize]; } } else { gpFractalBuffers[0] = (char *)gpDisplayBuffer[0]->Bits(); gpFractalBuffers[1] = (char *)gpDisplayBuffer[1]->Bits(); } *buffer1 = gpFractalBuffers[0]; *buffer2 = gpFractalBuffers[1]; return gpDisplayBuffer[0]->BytesPerRow(); } else { int linesize=view_width*gpDirectWindow->fBytesPerPixel; linesize=(linesize+15)&~15; for (int i = 0; i < 2; ++i) { gpFractalBuffers[i] = new char[linesize*view_height]; } *buffer1 = gpFractalBuffers[0]; *buffer2 = gpFractalBuffers[1]; return linesize; } }// Deallocate fractal engine pixel buffers.static void be_free_buffers(char * /*buffer1*/, char * /*buffer2*/){ BAutolock locker(gpWindow); if (!direct) { gpView->SetBuffer(0,0); delete gpDisplayBuffer[0]; gpDisplayBuffer[0] = 0; if(!async) delete gpDisplayBuffer[1]; gpDisplayBuffer[1] = 0; } else gpDirectView->SetBuffer(0,0,0); if(async || direct) for (int i = 0; i < 2; ++i) { delete [] gpFractalBuffers[i]; gpFractalBuffers[i] = 0; }}// Switch current pixel buffer.static void be_flip_buffers(void){ gCurrentBuffer ^= 1;}static void be_set_range(ui_palette palette, int start, int end){ // 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; }}/*sizes of resizing button. FIXME: How to get this?*/#define WIDTH B_V_SCROLL_BAR_WIDTH#define HEIGHT B_H_SCROLL_BAR_HEIGHT#define BORDERWIDTH 2// Set up the driver.static int do_be_init(void){ int window_width=XSIZE; int window_height=YSIZE; int menuheight; status_t error = B_OK; // Evaluate parameters. isfullscreen=0; if (!mEventPort) mEventPort = create_port(100, "XaoS "XaoS_VERSION); if (window_size) { int width, height; sscanf(window_size, "%dx%d", &width, &height); if (width > 0) { window_width = width; } if (height > 1) { window_height = height; } } BRect windowRect(0,0,window_width,window_height); if (direct) { gpDirectWindow = new XaoSDirectWindow(windowRect, mEventPort, &error); gpWindow = gpDirectWindow; if (error!=B_OK) { gpDirectWindow->AllowQuit(); gpDirectWindow->QuitRequested(); gpWindow = NULL; } } else { gpNormalWindow = new XaoSWindow(windowRect, mEventPort); gpWindow = gpNormalWindow; } if(gpWindow != 0) { BAutolock locker(gpWindow); gpMenu = new XaoSMenu(mEventPort, "Menu Bar", window_width, window_height-HEIGHT); gpWindow->AddChild(gpMenu->menu); menuheight = (int)(gpMenu->menu->Bounds().bottom + 1.0); BRect viewRect(0,menuheight,window_width+1,window_height-HEIGHT); if(direct) { gpDirectView = new XaoSDirectView(viewRect, mEventPort); gpView = gpDirectView; } else gpView = new XaoSView(viewRect, mEventPort); if (gpView != 0) { BRect bounds=gpView->Bounds(); view_width = (int)bounds.Width()+1; view_height = (int)bounds.Height()+1; BRect boxRect(0,window_height-HEIGHT+2,window_width-WIDTH,window_height); boxView = new BBox(boxRect, "status-box", B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT, B_WILL_DRAW | B_FRAME_EVENTS, B_PLAIN_BORDER); boxView->SetViewColor(216, 216, 216, 0); BRect r=boxView->Bounds(); r.InsetBy(1,1); r.bottom+=2; sView = new BStringView(r, "status-bar", "ahoj", B_FOLLOW_BOTTOM | B_FOLLOW_LEFT_RIGHT); sView->SetAlignment(B_ALIGN_LEFT); boxView->AddChild(sView); gpWindow->AddChild(boxView, gpMenu->menu); gpWindow->AddChild(gpView, boxView); /*gpWindow->Show();*/ visible=0; be_setfullscreen(); return 1; } /*gpView !=0*/ delete gpMenu; gpDirectWindow->AllowQuit(); gpDirectWindow->QuitRequested(); gpWindow = NULL; } /* gpWindow*/ return 0;}void be_about(void){ be_app->PostMessage(B_ABOUT_REQUESTED);}void be_fullscreen(void){ fullscreen^=1; be_setfullscreen(); be_enabledisable(NULL, "fullscreen");}int be_is_fullscreen(void){ return fullscreen;}void be_mode(struct uih_context *c, int mode){ bitmap=truecolor=hicolor=realcolor=grayscale=color8bit=0; switch(mode) { case 1: bitmap=1; be_enabledisable(NULL, "grayscale1"); break; case 2: grayscale=1; be_enabledisable(NULL, "grayscale8"); break; case 3: color8bit=1; be_enabledisable(NULL, "color8bit"); break; case 4: realcolor=1; be_enabledisable(NULL, "truecolor15"); break; case 5: hicolor=1; be_enabledisable(NULL, "truecolor16"); break; case 6: truecolor=1; be_enabledisable(NULL, "truecolor32"); break; } ui_call_resize();}int be_modeselected(struct uih_context *c, int mode){ int m=0; if(bitmap) m=1; if(grayscale) m=2; if(color8bit) m=3; if(realcolor) m=4; if(hicolor) m=5; if(truecolor) m=6; return m==mode;}void be_copy(struct uih_context *c){ char *str; if (be_clipboard->Lock()) { str=ui_getpos(); be_clipboard->Clear(); BMessage *c=be_clipboard->Data(); c->AddData("image/x-xaos-position", B_MIME_TYPE, str, strlen(str)); be_clipboard->Commit(); be_clipboard->Unlock(); free(str); }}void be_paste(struct uih_context *c){ const void *str; ssize_t length; if (be_clipboard->Lock()) { BMessage *c=be_clipboard->Data(); if (c->FindData("image/x-xaos-position", B_MIME_TYPE, &str, &length) == B_OK) { char *str1=(char *)calloc(length+1,1); memcpy(str1,str,length); ui_loadstr(str1); } be_clipboard->Unlock(); }}static CONST menuitem winmenuitems[]={ MENUSEPARATOR("file"), MENUNOP ("file",NULL,"About XaoS","about",MENUFLAG_INCALC,be_about), MENUNOPCB ("ui",NULL,"Fullscreen","fullscreen",MENUFLAG_INCALC,be_fullscreen, be_is_fullscreen), SUBMENU ("ui", NULL, "Bitmap mode","bitmapm"), MENUINTRB ("bitmapm",NULL,"Default","default",MENUFLAG_INTERRUPT,(void (*)())be_mode, 0, (int (*)())be_modeselected), MENUSEPARATOR("bitmapm"), MENUINTRB ("bitmapm",NULL,"1BPP grayscale","grayscale1",MENUFLAG_INTERRUPT,(void (*)())be_mode, 1, (int (*)())be_modeselected), MENUINTRB ("bitmapm",NULL,"8BPP grayscale","grayscale8",MENUFLAG_INTERRUPT,(void (*)())be_mode, 2, (int (*)())be_modeselected), MENUINTRB ("bitmapm",NULL,"256 colors","color8bit",MENUFLAG_INTERRUPT,(void (*)())be_mode, 3, (int (*)())be_modeselected), MENUINTRB ("bitmapm",NULL,"32768 colors","truecolor15",MENUFLAG_INTERRUPT,(void (*)())be_mode, 4, (int (*)())be_modeselected), MENUINTRB ("bitmapm",NULL,"65536 colors","truecolor16",MENUFLAG_INTERRUPT,(void (*)())be_mode, 5, (int (*)())be_modeselected), MENUINTRB ("bitmapm",NULL,"16777216 colors","truecolor32",MENUFLAG_INTERRUPT,(void (*)())be_mode, 6, (int (*)())be_modeselected), MENUSEPARATOR("edit"), MENUNOP ("edit",NULL,"Copy","copy",MENUFLAG_INCALC,(void (*)())be_copy), MENUNOP ("edit",NULL,"Paste","paste",MENUFLAG_INTERRUPT,(void (*)())be_paste),};static CONST menuitem directmenuitems[]={ MENUSEPARATOR("file"), MENUNOP ("file",NULL,"About XaoS","about",MENUFLAG_INCALC,be_about), MENUNOPCB ("ui",NULL,"fullscreen","fullscreen",MENUFLAG_INCALC,be_fullscreen, be_is_fullscreen), MENUSEPARATOR("edit"), MENUNOP ("edit",NULL,"Copy","copy",MENUFLAG_INCALC,(void (*)())be_copy), MENUNOP ("edit",NULL,"Paste","paste",MENUFLAG_INTERRUPT,(void (*)())be_paste),};static CONST char * CONST depth[] ={"8bpp (256 colors)", "16bpp (65536 colors)", "32bpp (16777216 colors)", NULL};static CONST char * CONST resolution[] ={"640x480", "800x600", "1024x768", "1152x800", "1280x1024", "1600x1200", NULL};static menudialog be_screen_resdialog[] ={ DIALOGCHOICE ("Resolution", resolution, 0), DIALOGCHOICE ("Depth", depth, 0), {NULL}};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -