📄 ui_be.cpp
字号:
/* * XaoS, a fast portable realtime fractal zoomer * Copyright © 1996,1997 by * * Jan Hubicka (hubicka@paru.cas.cz) * Thomas Marsh (tmarsh@austin.ibm.com) * * ui_be.cpp BeOS user interface code, Jens Kilian (jjk@acm.org) * * 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. */#include <cstdio>#include <cstring>#include <malloc.h>#include <Application.h>#include <Autolock.h>#include <Bitmap.h>#include <ScrollBar.h>#include <ByteOrder.h>#include <GraphicsDefs.h>#include <InterfaceDefs.h>#include <StringView.h>#include <View.h>#include <Point.h>#include <Rect.h>#include <Screen.h>#include <Box.h>#include <Alert.h>#include "XaoSWindow.h"#include "XaoSDirectWindow.h"#include "XaoSDirectScreen.h"#include "XaoSMenu.h"#include "XaoSView.h"#include "MenuItem.h"#include "XaoSDirectView.h"#include "XaoSScreenView.h"#include "XaoSEvent.h"#include "XaoSDialog.h"#include "version.h"#include "cursor.h"#include "fconfig.h"#include "ui.h"#include "xmenu.h"#include "xerror.h"#include "archaccel.h"static void be_enabledisable(struct uih_context *c, CONST char *name);static int visible=0;static XaoSMenu *gpMenu;static BView *mainView;static BWindow *gpWindow; // our BWindowstatic XaoSWindow *gpNormalWindow; // our BWindow for normal modestatic XaoSDirectWindow *gpDirectWindow; // our BWindow for direct modestatic XaoSDirectScreen *gpDirectScreen; // our BWindow for direct screen modestatic XaoSView *gpView; // our BViewstatic XaoSDirectView *gpDirectView; // our BView for direct modestatic BStringView *sView;static BBox *boxView;static int fullscreen;static BRect *Previous=NULL;static int isfullscreen;const int NCOLORS = 256; // # of colors in 8-bit modestatic int ignorequit=0;static color_space gColorSpace; // color space to usestatic BBitmap *gpDisplayBuffer[2]; // display bufferstatic size_t gBufferSize; // size of buffer memorystatic char *gpFractalBuffers[2] = // fractal buffers{ 0, 0};static int gCurrentBuffer;extern int be_noalert;extern struct ui_driver be_driver, be_direct_driver, be_screen_driver;static int color8bit = 0; // parameters settable from command linestatic int bitmap = 0;static int truecolor = 0;static int hicolor = 0;static int realcolor = 0;static int grayscale = 0;static char *window_size = 0;static int view_width = XSIZE;static int view_height = YSIZE;static int async;static CONST char *screen_mode="640x480x8";static port_id mEventPort=0;#define DIRECTWINDOW 1#define DIRECTSCREEN 2static int direct=0;static void be_screen_display(void);void be_get_imagespecs(int cs, int *imagetype, int *rmask, int *gmask, int *bmask){ switch(cs) { case B_GRAY1: *imagetype = UI_MIBITMAP; break; case B_GRAY8: /* BeOS conversion routines don't seems to support this*/ *imagetype = UI_GRAYSCALE; break; case B_CMAP8: *imagetype = UI_FIXEDCOLOR; break; case B_RGB24: /*Untested*/ case B_RGB24_BIG: *imagetype = UI_TRUECOLOR24; *rmask = 0x000000ff; *gmask = 0x0000ff00; *bmask = 0x00ff0000; x_fatalerror("24bpp truecolor support is not compiled in. Contact authors\n"); break; case B_RGB32: *imagetype = UI_TRUECOLOR; *rmask = B_HOST_TO_LENDIAN_INT32(0x00ff0000); *gmask = B_HOST_TO_LENDIAN_INT32(0x0000ff00); *bmask = B_HOST_TO_LENDIAN_INT32(0x000000ff); break; case B_RGB32_BIG: /*Untested*/ *imagetype = UI_TRUECOLOR; *rmask = B_HOST_TO_BENDIAN_INT32(0x00ff0000); *gmask = B_HOST_TO_BENDIAN_INT32(0x0000ff00); *bmask = B_HOST_TO_BENDIAN_INT32(0x000000ff); break; case B_RGB15: *imagetype = UI_TRUECOLOR16; *rmask = B_HOST_TO_LENDIAN_INT16(31 * 32 * 32); *gmask = B_HOST_TO_LENDIAN_INT16(31 * 32); *bmask = B_HOST_TO_LENDIAN_INT16(31); break; case B_RGB16: *imagetype = UI_TRUECOLOR16; *rmask = B_HOST_TO_LENDIAN_INT16(31 * 64 * 32); *gmask = B_HOST_TO_LENDIAN_INT16(63 * 32); *bmask = B_HOST_TO_LENDIAN_INT16(31); break; case B_RGB15_BIG: /*Untested*/ *imagetype = UI_TRUECOLOR16; *rmask = B_HOST_TO_BENDIAN_INT16(31 * 32 * 32); *gmask = B_HOST_TO_BENDIAN_INT16(31 * 32); *bmask = B_HOST_TO_BENDIAN_INT16(31); break; case B_RGB16_BIG: /*Untested*/ *imagetype = UI_TRUECOLOR16; *rmask = B_HOST_TO_BENDIAN_INT16(31 * 64 * 32); *gmask = B_HOST_TO_BENDIAN_INT16(63 * 32); *bmask = B_HOST_TO_BENDIAN_INT16(31); break; default: x_fatalerror("Unsupported image type %i. Plase contact authors!", cs); }}// Return display buffer size.static void be_get_size(int *x, int *y){ // Select the display mode, trying to optimize performance. BScreen screen; color_space cs = screen.ColorSpace(); const union { char c[4]; int32 i; } test = { { 'B', 'e', 'O', 'S' } }; const bool bigEndian = test.i == 'BeOS'; if (!direct) { if (color8bit) cs=B_CMAP8; if (truecolor && cs!=B_RGB32 && cs!=B_RGB24 && cs!=B_RGB32_BIG && cs!=B_RGB24_BIG) cs=B_RGB32; if (hicolor && cs!=B_RGB16 && cs!=B_RGB16 && cs!=B_RGB16_BIG && cs!=B_RGB16_BIG) cs=B_RGB16; if (realcolor && cs!=B_RGB15 && cs!=B_RGB15 && cs!=B_RGB15_BIG && cs!=B_RGB15_BIG) cs=B_RGB15; if (grayscale) cs=B_GRAY8; if (bitmap) cs=B_GRAY1; } else { /* Wait until cs is set. FIXME this is hack expecting that mov is atomic...grr */ do {cs=gpDirectWindow->fFormat;} while(!cs); } if (cs==B_RGB16 || cs==B_RGB16_BIG) cs=bigEndian?B_RGB16_BIG: B_RGB16; if (cs==B_RGB15 || cs==B_RGB15_BIG) cs=bigEndian?B_RGB15_BIG: B_RGB15; be_get_imagespecs(cs, &be_driver.imagetype, &be_driver.rmask, &be_driver.gmask, &be_driver.bmask); gColorSpace=cs; be_direct_driver.imagetype = be_driver.imagetype; be_direct_driver.rmask = be_driver.rmask; be_direct_driver.gmask = be_driver.gmask; be_direct_driver.bmask = be_driver.bmask; *x = view_width; *y = view_height;}// XaoS has a somewhat different notion of buttons than BeOS ...static int map_be_buttons(uint32 beButtons, uint32 /*modifiers*/){ const uint32 bothButtons = B_PRIMARY_MOUSE_BUTTON|B_SECONDARY_MOUSE_BUTTON; if ((beButtons & bothButtons) == bothButtons) { // Left + right button -> middle, for serial mice (still buggy in DR9). return BUTTON2; } return ((beButtons & B_PRIMARY_MOUSE_BUTTON) ? BUTTON1 : 0) | ((beButtons & B_SECONDARY_MOUSE_BUTTON) ? BUTTON3 : 0) | ((beButtons & B_TERTIARY_MOUSE_BUTTON) ? BUTTON2 : 0);}voidbe_setfullscreen(){ if(isfullscreen!=fullscreen) { isfullscreen=fullscreen; if(fullscreen) { if (Previous) Previous=NULL; Previous = new BRect(gpWindow->Frame()); BScreen a_screen(gpWindow); gpWindow->MoveTo(a_screen.Frame().left, a_screen.Frame().top); gpWindow->ResizeTo(a_screen.Frame().Width(), a_screen.Frame().Height()); } else { gpWindow->ResizeTo(Previous->Width(), Previous->Height()); gpWindow->MoveTo(Previous->left, Previous->top); Previous = NULL; delete Previous; } }}// Read the mouse.static void be_getmouse(int *x, int *y, int *buttons){ BPoint mouseLocation; uint32 mouseButtons; { BAutolock locker(gpWindow); if (direct == DIRECTSCREEN) mainView->GetMouse(&mouseLocation, &mouseButtons); else gpView->GetMouse(&mouseLocation, &mouseButtons); } *x = (int)mouseLocation.x; *y = (int)mouseLocation.y; *buttons = map_be_buttons(mouseButtons, modifiers());}// Get next event from keyboard, mouse, etc.static void be_processevents(int wait, int *x, int *y, int *buttons, int *k){ static int currX = 0, currY = 0; static int currButtons = 0; static int cursorMask = 0; if (!visible) gpWindow->Show(), visible=0; if (wait && direct == DIRECTSCREEN) { snooze(16000); wait=0; } if (wait || port_count(/*gpView->EventPort()*/mEventPort) > 0) { do { // Read events from our message port. int32 eventCode; XaoSEvent event; if (read_port(/*gpView->EventPort()*/ mEventPort, &eventCode, &event, sizeof(XaoSEvent)) < B_NO_ERROR) { break; } // Handle event. switch (eventCode) { case XaoSEvent::KeyDown: switch (event.keyEvent.bytes[0]) { case B_LEFT_ARROW: cursorMask |= 1; ui_key(UIKEY_LEFT); break; case B_RIGHT_ARROW: cursorMask |= 2; ui_key(UIKEY_RIGHT); break; case B_UP_ARROW: cursorMask |= 4; ui_key(UIKEY_UP); break; case B_DOWN_ARROW: cursorMask |= 8; ui_key(UIKEY_DOWN); break; case B_PAGE_UP: cursorMask |= 4; ui_key(UIKEY_PGUP); break; case B_PAGE_DOWN: cursorMask |= 8; ui_key(UIKEY_PGDOWN); break; case B_HOME: ui_key(UIKEY_HOME); break; case B_END: ui_key(UIKEY_END); break; case B_BACKSPACE: ui_key(UIKEY_BACKSPACE); break; case B_TAB: ui_key(UIKEY_TAB); break; case B_ESCAPE: ui_key(UIKEY_ESC); break; default: if (event.keyEvent.numBytes == 1) { if (event.keyEvent.bytes[0] == B_F1_KEY) { event.keyEvent.bytes[0] = 'h'; } if (ui_key(event.keyEvent.bytes[0]) == 2) { return; } } break; } break; case XaoSEvent::KeyUp: switch (event.keyEvent.bytes[0]) { case B_LEFT_ARROW: cursorMask &= ~1; break; case B_RIGHT_ARROW: cursorMask &= ~2; break; case B_UP_ARROW: cursorMask &= ~4; break; case B_DOWN_ARROW: cursorMask &= ~8; break; default: break; } break; case XaoSEvent::Mouse: currX = event.mouseEvent.x; currY = event.mouseEvent.y; currButtons = map_be_buttons(event.mouseEvent.buttons, event.mouseEvent.modifiers); break; case XaoSEvent::Quit: if (!ignorequit) ui_quit(); else ignorequit=0; break; case XaoSEvent::Menu: ui_menuactivate(event.command, NULL); break; case XaoSEvent::Dialog: ui_menuactivate(event.dialogEvent.command, event.dialogEvent.param); break; case XaoSEvent::Redraw: be_screen_display(); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -