From 55837e5115f73a0f5d71e679cab36a60331e088d Mon Sep 17 00:00:00 2001 From: kichikuou Date: Thu, 1 Oct 2020 16:55:45 +0900 Subject: [PATCH] Remove xcore graphics backend This removes X11 specific code, making SDL2 a hard dependency. X-based environments are continue to be supported via SDL2. This also removes joystick_linux.c which was only used if SDL2 was not available. --- .github/workflows/linux.yml | 25 +- CMakeLists.txt | 45 +- README.md | 4 +- config.h.in | 3 - src/CMakeLists.txt | 19 +- src/ags.h | 1 - src/font.c | 8 - src/font.h | 7 - src/font_x11.c | 228 ----- src/graphicsdevice.h | 4 - src/joystick_linux.c | 148 ---- src/menu_null.c | 65 -- src/sdl_core.h | 1 - src/xcore.h | 173 ---- src/xcore_cursor.c | 257 ------ src/xcore_draw.c | 606 ------------- src/xcore_event.c | 260 ------ src/xcore_image.c | 1620 ----------------------------------- src/xcore_image.h | 61 -- src/xcore_input.c | 354 -------- src/xcore_maskupdate.c | 372 -------- src/xcore_mode.c | 186 ---- src/xcore_private.h | 136 --- src/xcore_video.c | 528 ------------ src/xsys35rc.sample | 21 +- src/xsystem35.c | 72 +- 26 files changed, 20 insertions(+), 5184 deletions(-) delete mode 100644 src/font_x11.c delete mode 100644 src/joystick_linux.c delete mode 100644 src/menu_null.c delete mode 100644 src/xcore.h delete mode 100644 src/xcore_cursor.c delete mode 100644 src/xcore_draw.c delete mode 100644 src/xcore_event.c delete mode 100644 src/xcore_image.c delete mode 100644 src/xcore_image.h delete mode 100644 src/xcore_input.c delete mode 100644 src/xcore_maskupdate.c delete mode 100644 src/xcore_mode.c delete mode 100644 src/xcore_private.h delete mode 100644 src/xcore_video.c diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index 45bfec1..5213068 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -15,7 +15,7 @@ jobs: - name: Install Deps run: | sudo apt update - sudo apt install libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev + sudo apt install libgtk2.0-dev libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev - name: Build run: | @@ -27,26 +27,3 @@ jobs: - name: Test run: ctest --output-on-failure working-directory: out/${{ matrix.build-type }} - - build-x11: - runs-on: ubuntu-latest - - name: Linux X11 - steps: - - uses: actions/checkout@v2 - - - name: Install Deps - run: | - sudo apt update - sudo apt install libgtk2.0-dev - - - name: Build - run: | - mkdir -p out - cd out - cmake ../ - make - - - name: Test - run: ctest --output-on-failure - working-directory: out diff --git a/CMakeLists.txt b/CMakeLists.txt index 1aabd37..89f395d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,6 @@ check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION) check_symbol_exists(uname "sys/utsname.h" HAVE_UNAME) if (EMSCRIPTEN) - set(SDL2_FOUND 1) set(FREETYPE_FOUND 1) set(HAVE_JPEG 1) set(DEFAULT_FONT_PATH /fonts/) @@ -44,7 +43,6 @@ elseif (ANDROID) if (NOT DEFINED ENABLE_MODULES) set(ENABLE_MODULES 1) endif() - set(SDL2_FOUND 1) set(SDL2MIXER_FOUND 1) set(SDL2TTF_FOUND 1) find_library(ndk_zlib z) @@ -59,11 +57,6 @@ else() find_package(ZLIB REQUIRED) - optional_find_package(X11) - if (X11_xf86vmode_FOUND) - set(HAVE_XF86VMODE 1) - endif() - optional_find_package(GTK2 COMPONENTS gtk) if (GTK2_FOUND) set(ENABLE_GTK 1) @@ -72,7 +65,7 @@ else() optional_find_package(Freetype) include(FindPkgConfig) - optional_pkg_check_modules(SDL2 IMPORTED_TARGET sdl2) + pkg_check_modules(SDL2 IMPORTED_TARGET sdl2) optional_pkg_check_modules(SDL2MIXER IMPORTED_TARGET SDL2_mixer) optional_pkg_check_modules(SDL2TTF IMPORTED_TARGET SDL2_ttf) @@ -85,19 +78,6 @@ else() endif() -# Graphics - -if (X11_FOUND) - set(SRC_GRAPHDEV xcore_draw.c xcore_video.c xcore_mode.c xcore_event.c xcore_cursor.c xcore_maskupdate.c image.c xcore_image.c) - set(SUMMARY_GRAPHDEV "X11") -elseif (SDL2_FOUND) - set(SRC_GRAPHDEV sdl_video.c sdl_draw.c sdl_event.c sdl_image.c sdl_cursor.c image.c) - set(SUMMARY_GRAPHDEV "SDL2") - set(ENABLE_SDL 1) -else() - message(FATAL_ERROR "*** No graphic device available ***") -endif() - # Menu if (EMSCRIPTEN) @@ -116,10 +96,8 @@ elseif (GTK2_FOUND) include_directories(${Intl_INCLUDE_DIRS}) link_libraries(${Intl_LIBRARIES}) endif() -elseif (ENABLE_SDL) - set(SRC_MENU menu_sdl.c sdl_input.c) else () - set(SRC_MENU menu_null.c) + set(SRC_MENU menu_sdl.c sdl_input.c) endif() # PCM audio @@ -204,34 +182,20 @@ endif() if (EMSCRIPTEN OR ANDROID) set(SRC_JOYSTICK joystick_dmy.c) -elseif (ENABLE_SDL) +else() set(SRC_JOYSTICK joystick_sdl.c) set(SUMMARY_JOYSTICK "SDL") set(HAVE_SDLJOY 1) -else() - check_include_file(linux/joystick.h HAVE_LINUX_JOYSTICK_H) - if (HAVE_LINUX_JOYSTICK_H) - set(SRC_JOYSTICK joystick_linux.c) - set(SUMMARY_JOYSTICK "Linux ioctl") - set(JOY_DEVICE "/dev/js0" CACHE STRING "joystick device") - else () - set(SRC_JOYSTICK joystick_dmy.c) - endif () endif() # Font -if (X11_FOUND) - list(APPEND SRC_FONT font_x11.c) - list(APPEND SUMMARY_FONT "x11") - set(ENABLE_X11FONT 1) -endif() if (FREETYPE_FOUND) list(APPEND SRC_FONT font_freetype2.c) list(APPEND SUMMARY_FONT "freetype2") set(ENABLE_FT2 1) endif() -if (NOT X11_FOUND AND SDL2TTF_FOUND) +if (SDL2TTF_FOUND) list(APPEND SRC_FONT font_sdlttf.c) list(APPEND SUMMARY_FONT "SDL_ttf") set(ENABLE_SDLTTF 1) @@ -253,7 +217,6 @@ endfunction() message("xsystem35 summary:") message("------------------") -print_summary(graphics ${SUMMARY_GRAPHDEV}) print_summary(audio ${SUMMARY_AUDIO}) print_summary(cdrom ${SUMMARY_CDROM}) print_summary(midi ${SUMMARY_MIDI}) diff --git a/README.md b/README.md index 5f04c44..93abddd 100644 --- a/README.md +++ b/README.md @@ -8,14 +8,12 @@ Prebuilt binaries for Windows and Android can be downloaded from the [Releases]( ## Build ### Linux (Debian / Ubuntu) - $ sudo apt install build-essential cmake libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev + $ sudo apt install build-essential cmake libgtk2.0-dev libsdl2-dev libsdl2-ttf-dev libsdl2-mixer-dev $ mkdir -p out/debug $ cd out/debug $ cmake -DCMAKE_BUILD_TYPE=Debug ../../ $ make && make install -You can choose between X11 and SDL2 as the graphics backend. If both libraries are found, X11 is used by default, but if `-DENABLE_X11=NO` flag is given to the `cmake` invocation, then SDL2 will be used. - ### MacOS [Homebrew](https://brew.sh/index_ja) is needed. diff --git a/config.h.in b/config.h.in index 0b0bcf4..b374cf4 100644 --- a/config.h.in +++ b/config.h.in @@ -20,10 +20,8 @@ #cmakedefine ENABLE_MIDI_SEQMIDI @ENABLE_MIDI_SEQMIDI@ #cmakedefine ENABLE_MODULES @ENABLE_MODULES@ #cmakedefine ENABLE_NLS @ENABLE_NLS@ -#cmakedefine ENABLE_SDL @ENABLE_SDL@ #cmakedefine ENABLE_SDLMIXER @ENABLE_SDLMIXER@ #cmakedefine ENABLE_SDLTTF @ENABLE_SDLTTF@ -#cmakedefine ENABLE_X11FONT @ENABLE_X11FONT@ #cmakedefine CDROM_DEVICE "@CDROM_DEVICE@" #cmakedefine JOY_DEVICE "@JOY_DEVICE@" @@ -38,7 +36,6 @@ #cmakedefine HAVE_SDLJOY @HAVE_SDLJOY@ #cmakedefine HAVE_SIGACTION @HAVE_SIGACTION@ #cmakedefine HAVE_UNAME @HAVE_UNAME@ -#cmakedefine HAVE_XF86VMODE @HAVE_XF86VMODE@ #define DEFAULT_GOTHIC_TTF "@DEFAULT_FONT_PATH@MTLc3m.ttf" #define DEFAULT_MINCHO_TTF "@DEFAULT_FONT_PATH@mincho.otf" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f0f8eb..0d0a17e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,7 +24,6 @@ target_sources(xsystem35 PRIVATE ${SRC_AUDIO} ${SRC_CDROM} ${SRC_MIDI} - ${SRC_GRAPHDEV} ${SRC_FONT} ${SRC_MENU} ${SRC_JOYSTICK}) @@ -35,6 +34,11 @@ target_sources(xsystem35 PRIVATE cmdk.c cmdl.c cmdm.c cmdn.c cmdo.c cmdp.c cmdq.c cmds.c cmdt.c cmdu.c cmdv.c cmdw.c cmdy.c cmdz.c cmd2F.c cmd2F60.c) +# Graphics + +target_sources(xsystem35 PRIVATE + sdl_video.c sdl_draw.c sdl_event.c sdl_image.c sdl_cursor.c image.c) + # CG target_sources(xsystem35 PRIVATE pms.c vsp.c bmp.c qnt.c) @@ -99,22 +103,13 @@ elseif (ANDROID) else() # non-emscripten, non-android target_link_libraries(xsystem35 PRIVATE m ZLIB::ZLIB) - if (X11_FOUND) - target_include_directories(xsystem35 PRIVATE ${X11_INCLUDE_DIR}) - target_link_libraries(xsystem35 PRIVATE ${X11_LIBRARIES}) - if (X11_xf86vmode_FOUND) - target_link_libraries(xsystem35 PRIVATE ${X11_Xxf86vm_LIB}) - endif() - endif() + target_link_libraries(xsystem35 PRIVATE PkgConfig::SDL2) if (GTK2_FOUND) target_link_libraries(xsystem35 PRIVATE GTK2::gtk) endif() if (FREETYPE_FOUND) target_link_libraries(xsystem35 PRIVATE Freetype::Freetype) endif() - if (ENABLE_SDL) - target_link_libraries(xsystem35 PRIVATE PkgConfig::SDL2) - endif() if (SDL2MIXER_FOUND) target_link_libraries(xsystem35 PRIVATE PkgConfig::SDL2MIXER) endif() @@ -136,7 +131,7 @@ else() # non-emscripten, non-android endif() # FIXME: set up dependency for xsystem35 on this -if (ENABLE_SDL AND NOT EMSCRIPTEN AND NOT ANDROID) +if (NOT EMSCRIPTEN AND NOT ANDROID) add_custom_target(sdl_keytable.h COMMAND perl ../tools/xsyskey.pl ${SDL2_INCLUDE_DIRS} > sdl_keytable.h WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/ags.h b/src/ags.h index ed7fa16..3d1dd5e 100644 --- a/src/ags.h +++ b/src/ags.h @@ -219,7 +219,6 @@ extern void ags_fader_callback(); /* フォント関連 */ typedef enum { - FONT_X11, FONT_FT2, FONT_SDLTTF } fontdev_t; diff --git a/src/font.c b/src/font.c index 524ef66..e84cebb 100644 --- a/src/font.c +++ b/src/font.c @@ -34,11 +34,6 @@ void font_init(int dev) { switch(dev) { -#ifdef ENABLE_X11FONT - case FONT_X11: - nact->ags.font = font_x11_new(); - break; -#endif #ifdef ENABLE_FT2 case FONT_FT2: nact->ags.font = font_ft2_new(); @@ -50,9 +45,6 @@ void font_init(int dev) { break; #endif default: -#ifndef ENABLE_SDL - nact->ags.font = font_x11_new(); -#endif break; } } diff --git a/src/font.h b/src/font.h index 06cd70a..09dc57c 100644 --- a/src/font.h +++ b/src/font.h @@ -60,13 +60,6 @@ extern FONT *font_ft2_new(); extern FONT *font_sdlttf_new(); #endif -#ifdef ENABLE_X11FONT -extern FONT *font_x11_new(); -#endif - -/* デフォルトのフォント名 */ -#define FONT_DEFAULTNAME_X "-*-*-medium-r-normal--%d-*-*-*-c-*-jisx0208.1983-0,-*-*-medium-r-normal--%d-*-*-*-c-*-jisx0201.1976-0,*" - #ifdef __EMSCRIPTEN__ int load_mincho_font(void); #endif diff --git a/src/font_x11.c b/src/font_x11.c deleted file mode 100644 index c033fef..0000000 --- a/src/font_x11.c +++ /dev/null @@ -1,228 +0,0 @@ -/* - * font_x11.c access to x11 font device - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: font_x11.c,v 1.11 2003/01/31 12:58:28 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include - -#include -#include - -#include "portab.h" -#include "system.h" -#include "font.h" -#include "ags.h" -#include "xcore.h" -#include "xcore_private.h" -#include "antialiase.h" - -/* fontset の為の情報 */ -typedef struct { - int size; - int type; - XFontSet id; -} FontTable; - -#define FONTTABLEMAX 256 -static FontTable fonttbl[FONTTABLEMAX]; -static int fontcnt = 0; -static XFontSet fontset; -static int font_ascent, font_descent; - -/* Font Glyph を取得するためのPixmapとGC */ -static Pixmap pix_glyph; -static GC gc_pix_glyph; -static agsurface_t img_glyph; - -static FONT *this; - -#define GLYPH_PIXMAP_WIDTH 800 /* 文字イメージを取得する為のPixmapの大きさ */ -#define GLYPH_PIXMAP_HEIGHT 150 - -static void font_insert(int size, int type, XFontSet fontset) { - fonttbl[fontcnt].size = size; - fonttbl[fontcnt].type = type; - fonttbl[fontcnt].id = fontset; - - if (fontcnt >= (FONTTABLEMAX -1)) { - WARNING("Font table is full.\n"); - } else { - fontcnt++; - } -} - -static FontTable *font_lookup(int size, int type) { - int i; - - for (i = 0; i < fontcnt; i++) { - if (fonttbl[i].size == size && fonttbl[i].type == type) { - return &fonttbl[i]; - } - } - return NULL; -} - -static void font_x11_sel_font(int type, int size) { - XFontStruct **font_structs; - char **font_names; - int i, num_fonts; - FontTable *tbl; - - if (NULL == (tbl = font_lookup(size, type))) { - char name[256]; - char **miss, *def; - int n_miss; - XFontSet fs; - - if (type > 3) type = FONT_GOTHIC; - - /* set size */ - snprintf(name, sizeof(name), this->name[type], size, size); - - fs = XCreateFontSet(x11_display, name, &miss, &n_miss, &def); - if (n_miss > 0) { - for (i = 0; i < n_miss; i++) { - WARNING("can't load font %s\n", miss[i]); - } - XFreeStringList(miss); - SYSERROR("Font Load failed\n"); - } - font_insert(size, type, fs); - fontset = fs; - } else { - fontset = tbl->id; - } - - /* 最大のフォントの高さの取得 */ - num_fonts = XFontsOfFontSet(fontset, &font_structs, &font_names); - font_ascent = font_descent = 0; - for (i = 0; i < num_fonts; i++) { - font_ascent = max(font_ascent, font_structs[i]->ascent); - font_descent = max(font_descent, font_structs[i]->descent); - } -} - -static agsurface_t *get_drawn_glyph(const char *str, int w) { - XImage *src; - agsurface_t *dst; - - XSetForeground(x11_display, gc_pix_glyph, 0); - XFillRectangle(x11_display, pix_glyph, gc_pix_glyph, 0, 0, GLYPH_PIXMAP_WIDTH, GLYPH_PIXMAP_HEIGHT); - - XSetForeground(x11_display, gc_pix_glyph, 1); - XmbDrawString(x11_display, pix_glyph, fontset, gc_pix_glyph, 0, font_ascent, str, strlen(str)); - - src = XGetImage(x11_display, pix_glyph, 0, 0, w, font_ascent + font_descent, AllPlanes, ZPixmap); - - dst = malloc(sizeof(agsurface_t)); - - dst->width = w; - dst->height = font_ascent + font_descent; - dst->bytes_per_line = src->bytes_per_line; - dst->pixel = (BYTE *)src->data; - dst->bytes_per_pixel = x11_workinfo->cimg.bytes_per_pixel; - - src->data = NULL; - XDestroyImage(src); - - return dst; -} - -static agsurface_t *font_x11_get_glyph(const char *str_utf8) { - int w = XmbTextEscapement(fontset, str_utf8, strlen(str_utf8)); - - if (w == 0) - return NULL; - - agsurface_t *dst = get_drawn_glyph(str_utf8, w); - image_get_glyph(dst, &img_glyph); - - if (this->antialiase_on) { - aa_make(img_glyph.pixel, w, dst->height, img_glyph.bytes_per_line); - } - - img_glyph.width = dst->width; - img_glyph.height = dst->height; - - free(dst->pixel); - free(dst); - return &img_glyph; -} - -static int font_x11_draw_glyph(int x, int y, const char *str_utf8, int col) { - int w = XmbTextEscapement(fontset, str_utf8, strlen(str_utf8)); - if (w == 0) - return 0; - - if (!x11_dibinfo->shared) { - /* 一度 Pixmap に書いてからイメージを取得してDIBへ */ - agsurface_t *dst = get_drawn_glyph(str_utf8, w); - - if (DIB_DEPTH == dib_depth_candidate) { - image_getGlyphImage(DIB, dst, x, y, PAL2PIC(col)); - } else { - image_getGlyphImageNto8(DIB, dst, x, y, col); - } - free(dst); - } else { - Xcore_setForeground(col); - XmbDrawString(x11_display, x11_pixmap, fontset, x11_gc_pix, x, y + font_ascent, str_utf8, strlen(str_utf8)); - x11_needSync = TRUE; - } - return w; -} - -static boolean drawable() { - return !this->antialiase_on; -} - - -FONT *font_x11_new() { - FONT *f = malloc(sizeof(FONT)); - - f->sel_font = font_x11_sel_font; - f->get_glyph = font_x11_get_glyph; - f->draw_glyph = font_x11_draw_glyph; - f->self_drawable = drawable; - f->antialiase_on = FALSE; - - /* Glyph取得のためのPixmapとGCとagsurface_tを用意 */ - pix_glyph = XCreatePixmap(x11_display, x11_window, - GLYPH_PIXMAP_WIDTH, GLYPH_PIXMAP_HEIGHT, WIN_DEPTH); - gc_pix_glyph = XCreateGC(x11_display, pix_glyph, 0, 0); - - img_glyph.width = GLYPH_PIXMAP_WIDTH; - img_glyph.height = GLYPH_PIXMAP_HEIGHT; - img_glyph.bytes_per_line = GLYPH_PIXMAP_WIDTH; - img_glyph.depth = 8; - img_glyph.bytes_per_pixel = 1; - img_glyph.pixel = malloc(GLYPH_PIXMAP_WIDTH * GLYPH_PIXMAP_HEIGHT); - - this = f; - - NOTICE("FontDevice X11\n"); - - return f; -} diff --git a/src/graphicsdevice.h b/src/graphicsdevice.h index 4510116..dd8a438 100644 --- a/src/graphicsdevice.h +++ b/src/graphicsdevice.h @@ -26,10 +26,6 @@ #include "config.h" -#if ENABLE_SDL #include "sdl_core.h" -#else -#include "xcore.h" -#endif #endif /* !__GRAPHICDEVICE__ */ diff --git a/src/joystick_linux.c b/src/joystick_linux.c deleted file mode 100644 index b78945b..0000000 --- a/src/joystick_linux.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - * joystick_linux.c joystick interface for linux (kernel 2.2.x) - * - * Copyright (C) 1999- Fumihiko Murata - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: joystick_linux.c,v 1.8 2000/11/25 13:09:08 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "joystick.h" -#include "portab.h" - -#ifndef JOY_DEVICE -#define JOY_DEVICE "/dev/js0" -#endif - -static char *dev_joy = JOY_DEVICE; -static int joy_fd=-1,joy_dat=0,joy_sens=19660; -static unsigned char joy_axes,joy_buttons; -static boolean joy_enable=TRUE; -static struct js_event js; - -void joy_set_devicename(char *name) { - if (0 == strcmp("none", name)) dev_joy = NULL; - else dev_joy = strdup(name); -} - -int joy_open(void) { - if( dev_joy == NULL ) return -1; - joy_fd=open(dev_joy,O_RDONLY); - if( joy_fd < 0 ) { - joy_enable=FALSE; - return joy_fd; - } - ioctl(joy_fd,JSIOCGAXES,&joy_axes); - ioctl(joy_fd,JSIOCGBUTTONS,&joy_buttons); - printf("open %s axes %d buttons %d\n",dev_joy,joy_axes,joy_buttons); - - return joy_fd; -} - -void joy_close(void) { - if( joy_fd < 0 ) return; - close(joy_fd); - return; -} - -int joy_getinfo(void) { - int err; - struct timeval tv; - fd_set set; - int max_fd; - - return 0; - if( joy_fd < 0 || !joy_enable ) return 0; - max_fd = joy_fd+1; - tv.tv_sec = 0; - tv.tv_usec = 1000; - FD_ZERO(&set); - FD_SET(joy_fd,&set); - while( select(max_fd,&set,NULL,NULL,&tv) ) { - if( FD_ISSET(joy_fd,&set) ) { - err=read(joy_fd,&js,sizeof(js)); - if( err != sizeof(js) ) return joy_dat; - switch(js.type & ~JS_EVENT_INIT) { - case JS_EVENT_BUTTON: - if( js.number < 4 ) { - joy_dat &= ~(1<<(js.number+4)); - joy_dat |= js.value<<(js.number+4); - } - break; - case JS_EVENT_AXIS: - if( js.number == 0 ) { - joy_dat &= ~(0x0c); - if( js.value > joy_sens ) joy_dat |= 8; - if( js.value < -joy_sens ) joy_dat |= 4; - } else if( js.number == 1 ) { - joy_dat &= ~(0x03); - if( js.value > joy_sens ) joy_dat |= 2; - if( js.value < -joy_sens ) joy_dat |= 1; - } - break; - } - } - } - return joy_dat; -} - -#if 0 -boolean joy_getinfo(int *data) { - int err; - - if( joy_fd < 0 || !joy_enable ) return FALSE; - - err = read(joy_fd, &js, sizeof(js)); - if( err != sizeof(js) ) { - *data = joy_dat; - return TRUE; - } - switch(js.type & ~JS_EVENT_INIT) { - case JS_EVENT_BUTTON: - if( js.number < 4 ) { - joy_dat &= ~(1<<(js.number+4)); - joy_dat |= js.value<<(js.number+4); - } - break; - case JS_EVENT_AXIS: - if( js.number == 0 ) { - joy_dat &= ~(0x0c); - if( js.value > joy_sens ) joy_dat |= 8; - if( js.value < -joy_sens ) joy_dat |= 4; - } else if( js.number == 1 ) { - joy_dat &= ~(0x03); - if( js.value > joy_sens ) joy_dat |= 2; - if( js.value < -joy_sens ) joy_dat |= 1; - } - break; - } - *data = joy_dat; - return TRUE; -} -#endif diff --git a/src/menu_null.c b/src/menu_null.c deleted file mode 100644 index a568b8c..0000000 --- a/src/menu_null.c +++ /dev/null @@ -1,65 +0,0 @@ -/* - * menu_null.c popup menu for null - * - * Copyright (C) 2000- Masaki Chikama (Wren) - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: menu_null.c,v 1.2 2003/01/25 01:34:50 chikama Exp $ */ - -#include "config.h" - -#include - -#include "portab.h" -#include "nact.h" -#include "menu.h" - -void menu_open(void) { - return; -} - -void menu_quitmenu_open(void) { - nact->is_quit = TRUE; - return; -} - -boolean menu_inputstring(INPUTSTRING_PARAM *p) { - p->newstring = p->oldstring; - return TRUE; -} - -boolean menu_inputstring2(INPUTSTRING_PARAM *p) { - p->newstring = p->oldstring; - return TRUE; -} - -boolean menu_inputnumber(INPUTNUM_PARAM *p) { - p->value = p->def; - return TRUE; -} - -void menu_msgbox_open(char *msg) { - return; -} - -void menu_init(void) { - return; -} - -void menu_gtkmainiteration() { - return; -} diff --git a/src/sdl_core.h b/src/sdl_core.h index 9f31737..320fb8c 100644 --- a/src/sdl_core.h +++ b/src/sdl_core.h @@ -173,7 +173,6 @@ extern boolean sdl_inputString(struct inputstring_param *); /* misc */ #define ResourceInit(c,v) sdl_ResourceInit((c),(v)) -#define SetNoShmMode() /* NO */ #define Sleep(ms) sdl_sleep(ms) #define WaitVsync() sdl_wait_vsync() diff --git a/src/xcore.h b/src/xcore.h deleted file mode 100644 index 9962b71..0000000 --- a/src/xcore.h +++ /dev/null @@ -1,173 +0,0 @@ -/* - * xcore.h Xlibとの通信 - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore.h,v 1.42 2003/04/22 16:34:28 chikama Exp $ */ - -#ifndef __XCORE_H__ -#define __XCORE_H__ - -#include "config.h" -#include -#include "portab.h" -#include "image.h" -#include "xcore_image.h" -#include "cursor.h" -#include "ags.h" - -/* 初期化関係 */ -extern int Xcore_Initilize(void); -extern void Xcore_Remove(void); - -/* ウィンド関係 */ -extern void Xcore_setWorldSize(int width, int height, int depth); -extern void Xcore_setWindowSize(int x, int y, int width, int height); -extern void Xcore_setWindowTitle(char *name); -extern void Xcore_getWindowInfo(DispInfo *info); -extern void Xcore_fullScreen(boolean on); -extern agsurface_t *Xcore_getDIB(); - -/* 画面更新 */ -extern void Xcore_updateArea(MyRectangle *src, MyPoint *dst); -extern void Xcore_sync(); - -/* パレット関係 */ -extern void Xcore_setPalette(Palette256 *pal, int src, int cnt); -extern void Xcore_setForeground(unsigned long col); - -/* 描画関係 */ -extern void Xcore_drawRectangle(int x, int y, int w, int h, unsigned long col); -extern void Xcore_fillRectangle(int x, int y, int w, int h, unsigned long col); -extern void Xcore_drawLine(int x0, int y0, int x1, int y1, unsigned long col); -extern int Xcore_drawString(int x, int y, const char *str_utf8, unsigned long col); -extern void Xcore_copyArea(int sx, int sy, int w, int h, int dx, int dy); -// extern void Xcore_drawTT(int x, int y, int w, int h, const char *bitmap, int ww, boolean antialiased); -extern int Xcore_eCopyArea(int sx, int sy, int w, int h, int dx, int dy, int t,int opt, boolean flg, int spCol); -extern void Xcore_zoom(int x, int y, int w, int h); -extern void Xcore_restoreRegion(void *img, int x, int y); -extern void Xcore_delRegion(void *img); -extern void Xcore_putRegion(void *img, int x, int y); -extern void *Xcore_saveRegion(int x, int y, int w, int h); -extern void Xcore_copyRegion(void *i, int sx, int sy, int w, int h, int dx, int dy); -extern void Xcore_maskupdate(int sx, int sy, int w, int h, int dx, int dy, int func, int step); - -/* フォント関連 */ -// extern FONT *Xcore_getFontDevice(void); -extern void Xcore_setFontDevice(struct _FONT *f); - -/* fader */ -extern void Xcore_fadeIn(int step); -extern void Xcore_fadeOut(int step); -extern void Xcore_whiteIn(int step); -extern void Xcore_whiteOut(int step); - -/* key/pointer 関係 */ -extern int Xcore_getMouseInfo(MyPoint *p); -extern int Xcore_getKeyInfo(); -extern void Xcore_setCursorLocation(int x, int y); -extern boolean Xcore_cursorNew(BYTE* data, int no, CursorImage *cursorImage, TCursorDirEntry *cursordirentry); -extern void Xcore_setCursorType(int type); -extern int Xcore_keywait(int ms, boolean cancel); -extern void Xcore_setAutoRepeat(boolean bool); - -/* misc */ -// extern void Xcore_mainloop(int (*idle_func)(void)); -extern void Xcore_eventCallnack(); -extern void Xcore_setNoShmMode(); -extern void Xcore_mainIterarion(); -extern boolean RawKeyInfo[256]; - -/* 初期化関係 */ -#define GraphicsInitilize() Xcore_Initilize() -#define GraphicsRemove() Xcore_Remove() - -/* ウィンド関係 */ -#define GetWindowInfo(info) Xcore_getWindowInfo(info) -#define SetWorldSize(w,h,d) Xcore_setWorldSize((w),(h),(d)) -#define SetWindowSize(x,y,w,h) Xcore_setWindowSize((x),(y),(w),(h)) -#define SetWindowTitle(size) Xcore_setWindowTitle((size)) -#define GetDIB() Xcore_getDIB() - -/* 画面更新 */ -#define DspDeviceSync() Xcore_sync() -#define UpdateArea(src,dst) Xcore_updateArea((src),(dst)) -#define FullScreen(on) Xcore_fullScreen(on) - -/* パレット関係 */ -#define SetPalette(pal,src,cnt) Xcore_setPalette((pal),(src),(cnt)) -#define SetForeground(col) Xcore_setForeground((col)) - -/* 描画関係 */ -#define DrawString(x,y,str_utf8,col) Xcore_drawString((x),(y),(str_utf8),(col)) -#define FillRectangle(x,y,w,h,col) Xcore_fillRectangle((x),(y),(w),(h),(col)) -#define CopyArea(sx,sy,w,h,dx,dy) Xcore_copyArea((sx),(sy),(w),(h),(dx),(dy)) -#define CopyAreaSP(sx,sy,w,h,dx,dy,col) image_copyAreaSP(nact->ags.dib, (sx),(sy),(w),(h),(dx),(dy),(col)) -#define DrawLine(x0,y0,x1,y1,col) Xcore_drawLine((x0),(y0),(x1),(y1),(col)) -#define DrawTT(x,y,w,h,bm,ww,anti) Xcore_drawTT((x),(y),(w),(h),(bm),(ww),(anti)) -#define ScaledCopyArea(sx,sy,sw,sh,dx,dy,dw,dh,mirror_sw) image_scaledCopyArea(NULL,nact->ags.dib,sx,sy,sw,sh,dx,dy,dw,dh,mirror_sw) -#define Zoom(x,y,w,h) Xcore_zoom(x,y,w,h) -#define WrapColor(x,y,w,h,p1,p2) image_wrapColor(nact->ags.dib,x,y,w,h,p1,p2) -#define GetPixel(x,y,cell) image_getPixel(nact->ags.dib,x,y,cell) -#define DrawImage8_fromData(info,x,y,w,h) image_drawImage8_fromData(nact->ags.dib, info,x,y,w,h) -#define DrawImage16_fromData(info,x,y,w,h) image_drawImage16_fromData(nact->ags.dib, info,x,y,w,h) -#define CopyAreaSP16_shadow(sx,sy,w,h,dx,dy) image_copyAreaSP16_shadow(nact->ags.dib,sx,sy,w,h,dx,dy,255) -#define CopyAreaSP16_shadow_withRate(sx,sy,w,h,dx,dy,lv) image_copyAreaSP16_shadow(nact->ags.dib,sx,sy,w,h,dx,dy,lv) -#define CopyAreaSP16_alphaLevel(sx,sy,w,h,dx,dy,lv) image_copyAreaSP16_alphaLevel(nact->ags.dib,sx,sy,w,h,dx,dy,lv) -#define CopyAreaSP16_alphaBlend(sx,sy,w,h,dx,dy,lv) image_copyAreaSP16_alphaBlend(nact->ags.dib,sx,sy,w,h,dx,dy,lv) -#define CopyAreaSP16_whiteLevel(sx,sy,w,h,dx,dy,lv) image_copyAreaSP16_whiteLevel(nact->ags.dib,sx,sy,w,h,dx,dy,lv) -#define Copy_from_alpha(sx,sy,w,h,dx,dy,flg) image_copy_from_alpha(nact->ags.dib,sx,sy,w,h,dx,dy,flg) -#define Copy_to_alpha(sx,sy,w,h,dx,dy,flg) image_copy_to_alpha(nact->ags.dib,sx,sy,w,h,dx,dy,flg) -#define ChangeColorArea(x,y,w,h,s,d,c) Xcore_changeColorArea(x,y,w,h,s,d,c) -#define DrawRectangle(x,y,w,h,col) Xcore_drawRectangle((x),(y),(w),(h),(col)) -#define Mosaic(sx,sy,w,h,dx,dy,sl) image_Mosaic(nact->ags.dib,(sx),(sy),(w),(h),(dx),(dy),(sl)) -#define RestoreRegion(img,x,y) image_restoreRegion(nact->ags.dib,(img),(x),(y)) -#define SaveRegion(x,y,w,h) image_saveRegion(nact->ags.dib,(x),(y),(w),(h)) -#define DelRegion(i) image_delRegion(i) -#define PutRegion(i,x,y) image_putRegion(nact->ags.dib,i,x,y) -#define CopyRegion(i,sx,sy,w,h,dx,dy) image_copyRegion(i,sx,sy,w,h,nact->ags.dib,dx,dy) -#define Maskupdate(sx,sy,w,h,dx,dy,f,st) Xcore_maskupdate(sx,sy,w,h,dx,dy,f,st) - -/* フォント関連 */ -#define SetFontDevice(f) Xcore_setFontDevice(f) - -/* fader 関連 */ -#define FadeOut Xcore_fadeOut -#define FadeIn Xcore_fadeIn -#define WhiteIn Xcore_whiteIn -#define WhiteOut Xcore_whiteOut - -/* key/pointer 関係 */ -#define GetKeyInfo() Xcore_getKeyInfo() -#define SetCursorType(t) Xcore_setCursorType((t)) -#define GetMouseInfo(info) Xcore_getMouseInfo(info) -#define Keywait(r,flg) Xcore_keywait(r,flg) -#define SetCursorLocation(x,y) Xcore_setCursorLocation((x),(y)) -#define CursorNew(d,no,i,dir) Xcore_cursorNew((d),(no),(i),(dir)) -#define SetAutoRepeat(b) Xcore_setAutoRepeat(b); - -/* misc */ -// #define Mainloop(ptr) Xcore_mainloop(ptr) -#define SetNoShmMode Xcore_setNoShmMode -// #define MainIteration() Xcore_mainIteration() -#define EventCallback Xcore_eventCallback -#define Sleep(ms) usleep((ms) * 1000) -#define WaitVsync() Sleep(16) - -#endif /* !__XCORE_H__ */ diff --git a/src/xcore_cursor.c b/src/xcore_cursor.c deleted file mode 100644 index 62282a9..0000000 --- a/src/xcore_cursor.c +++ /dev/null @@ -1,257 +0,0 @@ -/* - * xcore_cursor.c カーソル処理 for Xcore - * - * Copyright (C) 2000- TAJIRI Yasuhiro - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore_cursor.c,v 1.8 2001/03/30 19:16:38 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include -#include -#include -#include - -#include "portab.h" -#include "system.h" -#include "cursor.h" -#include "xcore_private.h" - -/* マウスカーソルフォントイメージ*/ -#include "bitmaps/curbm0.xbm" -#include "bitmaps/curbm1.xbm" -#include "bitmaps/curbm2.xbm" -#include "bitmaps/curbm3.xbm" -#include "bitmaps/curbm4.xbm" -#include "bitmaps/curbm5.xbm" -#include "bitmaps/curbm6.xbm" -#include "bitmaps/maskbm0.xbm" -#include "bitmaps/maskbm1.xbm" -#include "bitmaps/maskbm2.xbm" -#include "bitmaps/maskbm3.xbm" -#include "bitmaps/maskbm4.xbm" -#include "bitmaps/maskbm5.xbm" -#include "bitmaps/maskbm6.xbm" - -static Cursor cursor[256]; -static GC cursorGC; - -/* mouse cursur の初期化 */ -void x11_init_cursor(void) { - XColor black, white; - Pixmap curPix[7], maskPix[7],tmpPixmap; - MyPoint spot[7] = {{10, 6}, {15, 15}, {14, 15}, {14, 15}, {14, 14}, {15, 15},{16,16}}; - - black.pixel = 0x00000000; - black.red = 0; - black.green = 0; - black.blue = 0; - white.pixel = 0xffffffff; - white.red = 0xffff; - white.green = 0xffff; - white.blue = 0xffff; - - curPix[0] = XCreateBitmapFromData(x11_display, x11_window, curbm0_bits, - curbm0_width, curbm0_height); - maskPix[0] = XCreateBitmapFromData(x11_display, x11_window, maskbm0_bits, - maskbm0_width, maskbm0_height); - curPix[1] = XCreateBitmapFromData(x11_display, x11_window, curbm1_bits, - curbm1_width, curbm1_height); - maskPix[1] = XCreateBitmapFromData(x11_display, x11_window, maskbm1_bits, - maskbm1_width, maskbm1_height); - curPix[2] = XCreateBitmapFromData(x11_display, x11_window, curbm2_bits, - curbm2_width, curbm2_height); - maskPix[2] = XCreateBitmapFromData(x11_display, x11_window, maskbm2_bits, - maskbm2_width, maskbm2_height); - curPix[3] = XCreateBitmapFromData(x11_display, x11_window, curbm3_bits, - curbm3_width, curbm3_height); - maskPix[3] = XCreateBitmapFromData(x11_display, x11_window, maskbm3_bits, - maskbm3_width, maskbm3_height); - curPix[4] = XCreateBitmapFromData(x11_display, x11_window, curbm4_bits, - curbm4_width, curbm4_height); - maskPix[4] = XCreateBitmapFromData(x11_display, x11_window, maskbm4_bits, - maskbm4_width, maskbm4_height); - curPix[5] = XCreateBitmapFromData(x11_display, x11_window, curbm5_bits, - curbm5_width, curbm5_height); - maskPix[5] = XCreateBitmapFromData(x11_display, x11_window, maskbm5_bits, - maskbm5_width, maskbm5_height); - curPix[6] = XCreateBitmapFromData(x11_display, x11_window, curbm6_bits, - curbm6_width, curbm6_height); - maskPix[6] = XCreateBitmapFromData(x11_display, x11_window, maskbm6_bits, - maskbm6_width, maskbm6_height); - - cursor[CURSOR_ARROW] = XCreatePixmapCursor(x11_display, curPix[0], maskPix[0], - &black, &white, spot[0].x, spot[0].y); - cursor[CURSOR_CROSS] = XCreateFontCursor(x11_display, XC_tcross); - cursor[CURSOR_IBEAM] = cursor[CURSOR_ICON] = XCreateFontCursor(x11_display, XC_icon); - cursor[CURSOR_NO] = XCreateFontCursor(x11_display, XC_X_cursor); - cursor[CURSOR_SIZE] = XCreatePixmapCursor(x11_display, curPix[6], maskPix[6], - &black, &white, spot[6].x, spot[6].y); - cursor[CURSOR_SIZEALL] = cursor[CURSOR_SIZE]; - cursor[CURSOR_SIZENESW] = XCreatePixmapCursor(x11_display, curPix[4], maskPix[4], - &black, &white, spot[4].x, spot[4].y); - cursor[CURSOR_SIZENS] = XCreatePixmapCursor(x11_display, curPix[2], maskPix[2], - &black, &white, spot[2].x, spot[2].y); - cursor[CURSOR_SIZENWSE] = XCreatePixmapCursor(x11_display, curPix[3], maskPix[3], - &black, &white, spot[3].x, spot[3].y); - cursor[CURSOR_SIZEWE] = XCreatePixmapCursor(x11_display, curPix[1], maskPix[1], - &black, &white, spot[1].x, spot[1].y); - cursor[CURSOR_UPARROW] = XCreateFontCursor(x11_display, XC_sb_up_arrow); -// cursor[CURSOR_WAIT] = XCreateFontCursor(x11_display, XC_watch); - cursor[CURSOR_WAIT] = XCreatePixmapCursor(x11_display, curPix[5], maskPix[5], - &black, &white, spot[5].x, spot[5].y); - - if ((tmpPixmap = XCreatePixmap(x11_display,x11_window, 1, 1, 1))) - { - cursorGC = XCreateGC( x11_display, tmpPixmap, 0, NULL ); - XSetGraphicsExposures( x11_display, cursorGC, False ); - XFreePixmap( x11_display, tmpPixmap ); - } -} - -boolean Xcore_cursorNew(BYTE* data, int no, CursorImage *cursorImage, TCursorDirEntry *cursordirentry) { - int xormasklen, andmasklen, xornum; - int i, j, k, l; - int h = 0; - BYTE *buf1, *buf2, *buf3,*buf4; - Pixmap xorPix, andPix; - XColor bg, fg; - - bg.pixel = 0xffffff; - bg.red = cursorImage->icColors[0].rgbRed*256; - bg.green = cursorImage->icColors[0].rgbGreen*256; - bg.blue = cursorImage->icColors[0].rgbBlue*256; - fg.pixel = 0xffffff; - fg.red = cursorImage->icColors[1].rgbRed*256; - fg.green = cursorImage->icColors[1].rgbGreen*256; - fg.blue = cursorImage->icColors[1].rgbBlue*256; - - xornum = (cursordirentry->bWidth * cursordirentry->bHeight); - xormasklen = (xornum * cursorImage->icHeader.biBitCount) / 8; - NOTICE("Cursor: xormasklen==%d, xornum==%d\n", xormasklen, xornum); - - andmasklen = xornum / 8; - cursorImage->xormasklen = xormasklen; - cursorImage->andmasklen = andmasklen; - - - buf1 = malloc(sizeof(BYTE) * xornum); - buf2 = malloc(sizeof(BYTE) * xornum); - buf3 = malloc(sizeof(BYTE) * xornum); - buf4 = malloc(sizeof(BYTE) * xornum); - - memcpy(buf1, data, min(xormasklen, xornum)); - data += xormasklen; - - memcpy(buf2, data, min(andmasklen, xornum)); - data += andmasklen; - -#define height cursordirentry->bHeight -#define width cursordirentry->bWidth - - for (j = 0; j < height; j++) { - for (i = 0; i < width * cursorImage->icHeader.biBitCount /8; i++) { - k = buf1[(height-j-1)*height*cursorImage->icHeader.biBitCount/8+i]; - l = buf2[(height-j-1)*height*cursorImage->icHeader.biBitCount/8+i]; -#define SWAPBITS(x) ((x& 1)<<7|(x& 2)<<5|(x& 4)<<3|(x& 8)<<1|\ - (x&0x10)>>1|(x&0x20)>>3|(x&0x40)>>5|(x&0x80)>>7) - buf3[h] = SWAPBITS(l); - buf4[h] = SWAPBITS(k); - h++; -#undef SWAPBITS - } - } - xorPix = XCreateBitmapFromData(x11_display, x11_window, buf3, width, height); - andPix = XCreateBitmapFromData(x11_display, x11_window, buf4, width, height); - - /*ここから、XOR,ANDがたから、X用のカーソルに作りかえ*/ - /*wine-991114 windows/x11drv/mouse.cより引用 - * X11 mouse driver - * - * Copyright 1998 Ulrich Weigand - */ - { - Pixmap pixmapBits, pixmapMask, pixmapMaskInv; - pixmapBits = XCreatePixmap( x11_display, x11_window, - width, height, 1 ); - pixmapMask = XCreatePixmap( x11_display, x11_window, - width, height, 1 ); - pixmapMaskInv = XCreatePixmap( x11_display, x11_window, - width, height, 1 ); - - if (pixmapBits && pixmapMask && xorPix && andPix) - { - XSetFunction( x11_display, cursorGC, GXcopy ); - XCopyArea( x11_display, xorPix, pixmapBits, cursorGC, - 0, 0, width, height, 0, 0 ); - XCopyArea( x11_display, xorPix, pixmapMask, cursorGC, - 0, 0, width, height, 0, 0 ); - XCopyArea( x11_display, xorPix, pixmapMaskInv, cursorGC, - 0, 0, width, height, 0, 0 ); - XSetFunction( x11_display, cursorGC, GXand ); - XCopyArea( x11_display, andPix, pixmapMaskInv, cursorGC, - 0, 0, width, height, 0, 0 ); - XSetFunction( x11_display, cursorGC, GXandReverse ); - XCopyArea( x11_display, andPix, pixmapBits, cursorGC, - 0, 0, width, height, 0, 0 ); - XSetFunction( x11_display, cursorGC, GXorReverse ); - XCopyArea( x11_display, andPix, pixmapMask, cursorGC, - 0, 0, width, height, 0, 0 ); - XSetFunction( x11_display, cursorGC, GXor ); - XCopyArea( x11_display, pixmapMaskInv, pixmapMask, cursorGC, - 0, 0, width, height, 1, 1 ); - XCopyArea( x11_display, pixmapMaskInv, pixmapBits, cursorGC, - 0, 0, width, height, 1, 1 ); - XSetFunction( x11_display, cursorGC, GXcopy ); - cursor[no] = XCreatePixmapCursor(x11_display, pixmapBits, pixmapMask, - &fg, &bg, cursordirentry->wxHotspot, - cursordirentry->wyHotspot); - } - - if (xorPix) XFreePixmap( x11_display, xorPix ); - if (andPix) XFreePixmap(x11_display, andPix ); - if (pixmapBits) XFreePixmap( x11_display, pixmapBits ); - if (pixmapMask) XFreePixmap( x11_display, pixmapMask ); - if (pixmapMaskInv) XFreePixmap( x11_display, pixmapMaskInv ); - } - - free(buf1); - free(buf2); - free(buf3); - free(buf4); - -#undef height -#undef width - - return TRUE; -} - -/* マウスの位置の移動 */ -void Xcore_setCursorLocation(int x, int y) { - XWarpPointer(x11_display, x11_window, x11_window, - 0, 0, 0, 0, - x + winoffset_x, y + winoffset_y); - XFlush(x11_display); -} - -/* マウスカーソルの形状の設定 */ -void Xcore_setCursorType(int type) { - XDefineCursor(x11_display, x11_window, cursor[type]); -} diff --git a/src/xcore_draw.c b/src/xcore_draw.c deleted file mode 100644 index 766e9f9..0000000 --- a/src/xcore_draw.c +++ /dev/null @@ -1,606 +0,0 @@ -/* - * xcore_draw.c X11 draw to DIB - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore_draw.c,v 1.7 2004/10/31 04:18:06 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include -#include - -#ifdef X_LOCALE -#include -#else -#include -#endif - -#include - -#include "portab.h" -#include "font.h" -#include "ags.h" -#include "image.h" -#include "nact.h" -#include "xcore.h" -#include "xcore_private.h" - -static void Xcore_updateAll(); -static void rect_comimg(agsurface_t *src, agsurface_t *dst, int sx, int sy, int sw, int sh); -static void workImageToWindow(); -static void DIBToWorkImage(int sx, int sy, int w, int h, int dx, int dy); - - -/* 全画面更新 */ -static void Xcore_updateAll() { - MyRectangle src; - MyPoint dst; - - src.x = view_x; - src.y = view_y; - src.width = min(DIB->width, view_w); - src.height = min(DIB->height, view_h); - dst.x = dst.y = 0; - Xcore_updateArea(&src, &dst); -} - -/* offscreenの指定領域をWindowへ転送 */ -void Xcore_updateArea(MyRectangle *src, MyPoint *dst) { - agsurface_t _dib, _work; - - if (x11_dibinfo->shared) { - XCopyArea(x11_display, x11_pixmap, x11_window, x11_gc_pix, - src->x, src->y, src->width, src->height, - winoffset_x + dst->x, winoffset_y + dst->y); - } else { - if (DIB_DEPTH == 8) { - if (WIN_DEPTH == 8) { - XPutImage(x11_display, x11_window, - x11_gc_pix, x11_dibinfo->ximg, - src->x, src->y, - winoffset_x + dst->x, winoffset_y + dst->y, - src->width, src->height); - } else { - rect_comimg(DIB, &_dib, - src->x, src->y, src->width, src->height); - rect_comimg(WORK, &_work, - dst->x, dst->y, src->width, src->height); - - image_expandPixel(&_dib, &_work, 255); - - if (x11_workinfo->shared) { - XShmPutImage(x11_display, x11_window, - x11_gc_win, x11_workinfo->ximg, - dst->x, dst->y, - winoffset_x + dst->x, winoffset_y + dst->y, - src->width, src->height, False); - } else { - XPutImage(x11_display, x11_window, - x11_gc_win, x11_workinfo->ximg, - dst->x, dst->y, - winoffset_x + dst->x, winoffset_y + dst->y, - src->width, src->height); - } - } - } else { - if (packed24bpp) { - rect_comimg(DIB, &_dib, - src->x, src->y, src->width, src->height); - rect_comimg(WORK, &_work, - dst->x, dst->y, src->width, src->height); - - image_trans_pixel_24to24p(&_dib, &_work); - - XPutImage(x11_display, x11_window, - x11_gc_win, x11_workinfo->ximg, - dst->x, dst->y, - winoffset_x + dst->x, winoffset_y + dst->y, - src->width, src->height); - } else { - XPutImage(x11_display, x11_window, - x11_gc_pix, x11_dibinfo->ximg, - src->x, src->y, - winoffset_x + dst->x, winoffset_y + dst->y, - src->width, src->height); - } - } - } - - XSync(x11_display, False); x11_needSync = False; -} - -/* draw rectangle */ -void Xcore_drawRectangle(int x, int y, int w, int h, unsigned long col) { - if (!x11_dibinfo->shared) { - image_drawRectangle(DIB, x, y, w, h, PAL2PIC(col)); - } else { - Xcore_setForeground(col); - XDrawRectangle(x11_display, x11_pixmap, x11_gc_pix, x, y, w - 1, h - 1); - x11_needSync = TRUE; - } -} - -/* fill rectangle */ -void Xcore_fillRectangle(int x, int y, int w, int h, unsigned long col) { - if (!x11_dibinfo->shared) { - image_fillRectangle(DIB, x, y, w, h, PAL2PIC(col)); - } else { - Xcore_setForeground(col); - XFillRectangle(x11_display, x11_pixmap, x11_gc_pix, x, y, w, h); - x11_needSync = TRUE; - } -} - -/* copy area */ -void Xcore_copyArea(int sx, int sy, int w, int h, int dx, int dy) { - if (!x11_dibinfo->shared) { - image_copyArea(DIB, sx, sy, w, h, dx, dy); - } else { - XCopyArea(x11_display, x11_pixmap, x11_pixmap, x11_gc_pix, - sx, sy, w, h, dx, dy); - x11_needSync = TRUE; - } -} - -/* 直線描画 */ -void Xcore_drawLine(int x1, int y1, int x2, int y2, unsigned long col) { - if (!x11_dibinfo->shared) { - image_drawLine(DIB, x1, y1, x2, y2, PAL2PIC(col)); - } else { - Xcore_setForeground(col); - XDrawLine(x11_display, x11_pixmap, x11_gc_pix, x1, y1, x2, y2); - x11_needSync = TRUE; - } -} - -int Xcore_drawString(int x, int y, const char *str_utf8, unsigned long col) { - int w; - - if (x11_font->self_drawable()) { - w = x11_font->draw_glyph(x, y, str_utf8, col); - x11_needSync = TRUE; - } else { - agsurface_t *glyph = x11_font->get_glyph(str_utf8); - - if (glyph == NULL) return 0; - - if (x11_font->antialiase_on && DIB_DEPTH != 8) { - if (x > 0) x -= 1; - if (y > 0) y -= 1; - image_draw_antialiased_pattern(DIB, glyph, - x, y, - glyph->width +2, glyph->height +2, - PAL2PIC(col)); - } else { - image_draw_pattern(DIB, glyph, - x, y, - glyph->width, glyph->height, - PAL2PIC(col)); - } - w = glyph->width; - } - - return w; -} - -void Xcore_zoom(int x, int y, int w, int h) { - if (DIB_DEPTH == WIN_DEPTH) { - agsurface_t _dib, _work; - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - rect_comimg(DIB, &_dib, x, y, w, h); - image_scaledCopyArea(DIB, &_work, x, y, w, h, - 0, 0, view_w, view_h, 0); - workImageToWindow(); - } else { - /* TODO */ - } -} - -/* Color の複数個指定 */ -void Xcore_setPalette(Palette256 *pal, int src, int cnt) { - int i; - - if (x11_visual->class == PseudoColor) { - for (i = 0; i < cnt; i++) { - x11_col[src + i].pixel = src + i; - x11_col[src + i].flags = DoRed | DoGreen | DoBlue; - x11_col[src + i].red = pal->red [src + i] * 257; - x11_col[src + i].green = pal->green[src + i] * 257; - x11_col[src + i].blue = pal->blue [src + i] * 257; - } - XStoreColors(x11_display, x11_cm, &x11_col[src], cnt); - } -} - -/* foreground のセット */ -void Xcore_setForeground(unsigned long col) { - static unsigned long fc = 0; - - if (fc == col && x11_visual->class == PseudoColor) return; - - fc = col; - - if (x11_visual->class != PseudoColor) { - XSetForeground(x11_display, x11_gc_pix, PAL2PIC(col)); - } else { - XSetForeground(x11_display, x11_gc_pix, col); - } -} - -/* background のセット */ -void Xcore_setBackground(unsigned long col) { - static unsigned long bc = 0; - - if (bc == col) return; - - bc = col; - - if (x11_visual->class != PseudoColor) { - XSetBackground(x11_display, x11_gc_win, PAL2PIC(col)); - } else { - XSetBackground(x11_display, x11_gc_win, col); - } -} - -/* X-Serverとの同期を取る */ -void Xcore_sync() { - if (x11_needSync) { XSync(x11_display, False); x11_needSync = FALSE; } -} - -static void rect_comimg(agsurface_t *src, agsurface_t *dst, int sx, int sy, int sw, int sh) { - memcpy(dst, src, sizeof(agsurface_t)); - - //dst->x = sx; - //dst->y = sy; - dst->width = sw; - dst->height = sh; - dst->pixel = GETOFFSET_PIXEL(src, sx, sy); -} - -/* fader で workImage の内容をWindowに描画 */ -static void workImageToWindow() { - if (x11_workinfo->shared) { - XSync(x11_display, False); - XShmPutImage(x11_display, x11_window, - x11_gc_win, x11_workinfo->ximg, - 0, 0, - winoffset_x, winoffset_y, - view_w, view_h, False); - } else { - XPutImage(x11_display, x11_window, - x11_gc_win, x11_workinfo->ximg, - 0, 0, - winoffset_x, winoffset_y, - view_w, view_h); - } -} - -/* DIB から work image への展開 */ -static void DIBToWorkImage(int sx, int sy, int w, int h, int dx, int dy) { - if (DIB_DEPTH == dib_depth_candidate) { - int y; - BYTE *src = GETOFFSET_PIXEL(&(x11_dibinfo->cimg), sx, sy); - BYTE *dst = GETOFFSET_PIXEL(&(x11_workinfo->cimg), dx, dy); - for (y = 0; y < h; y++) { - memcpy(dst, src, w * x11_dibinfo->cimg.bytes_per_pixel); - src += x11_dibinfo->cimg.bytes_per_line; - dst += x11_workinfo->cimg.bytes_per_line; - } - } else { - agsurface_t _dib, _work; - rect_comimg(DIB, &_dib, sx, sy, w, h); - rect_comimg(WORK, &_work, dx, dy, w, h); - image_expandPixel(&_dib, &_work, 255); - } -} - -/* 指定の明度以上に明るさを設定 */ -/* (255-col)/255 * val + col */ -static void setWhiteness8(int val) { - int i; - Palette256 *pal = nact->sys_pal; - - for (i = 0; i < 256; i++) { - x11_col[i].pixel = i; - x11_col[i].flags = DoRed | DoGreen | DoBlue; - x11_col[i].red = ((((255 - pal->red[i]) * val) / 256) + pal->red[i]) * 257; - x11_col[i].green = ((((255 - pal->green[i]) * val) / 256) + pal->green[i]) * 257; - x11_col[i].blue = ((((255 - pal->blue[i]) * val) / 256) + pal->blue[i]) * 257; - } - XStoreColors(x11_display, x11_cm, x11_col, 256); -} - -/* 指定の明度以下に明るさを抑える */ -static void setBlightness8(int val) { - int i; - Palette256 *pal = nact->sys_pal; - - for (i =0; i < 256; i++) { - x11_col[i].pixel = i; - x11_col[i].flags = DoRed | DoGreen | DoBlue; - x11_col[i].red = (val * pal->red[i] / 255) * 257; - x11_col[i].green = (val * pal->green[i] / 255) * 257; - x11_col[i].blue = (val * pal->blue[i] / 255) * 257; - } - XStoreColors(x11_display, x11_cm, x11_col, 256); -} - -static int fadestep[256] = -{0,1,3,4,6,7,9,10,12,14,15,17,18,20,21,23,25,26,28,29,31,32,34,36,37,39,40, - 42,43,45,46,48,49,51,53,54,56,57,59,60,62,63,65,66,68,69,71,72,74,75,77,78, - 80,81,83,84,86,87,89,90,92,93,95,96,97,99,100,102,103,105,106,108,109,110, - 112,113,115,116,117,119,120,122,123,124,126,127,128,130,131,132,134,135,136, - 138,139,140,142,143,144,146,147,148,149,151,152,153,155,156,157,158,159,161, - 162,163,164,166,167,168,169,170,171,173,174,175,176,177,178,179,181,182,183, - 184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202, - 203,204,205,206,207,208,209,210,211,211,212,213,214,215,216,217,217,218,219, - 220,221,221,222,223,224,225,225,226,227,227,228,229,230,230,231,232,232,233, - 234,234,235,235,236,237,237,238,238,239,239,240,241,241,242,242,243,243,244, - 244,244,245,245,246,246,247,247,247,248,248,249,249,249,250,250,250,251,251, - 251,251,252,252,252,252,253,253,253,253,254,254,254,254,254,254,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255}; - -static void fadein_8_n8(int step) { - static agsurface_t _dib, _work; - - if (step == 0) { - rect_comimg(DIB, &_dib, view_x, view_y, view_w, view_h); - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - } - image_expandPixel(&_dib, &_work, fadestep[step]); - workImageToWindow(); -} - -static void fadein_n8(int step) { - static agsurface_t _dib, _work; - - if (step == 0) { - rect_comimg(DIB, &_dib, view_x, view_y, view_w, view_h); - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - memset(_work.pixel, 0, x11_workinfo->cimg.bytes_per_pixel * view_w * view_h); - } - if (step == 255) { - ags_updateFull(); - return; - } - image_fadeIn(&_dib, &_work, step /16); - workImageToWindow(); -} - -static void fadeout_8_n8(int step) { - static agsurface_t _dib, _work; - - if (step == 0) { - rect_comimg(DIB, &_dib, view_x, view_y, view_w, view_h); - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - } - if (step == 255) { - Xcore_setBackground(0); - XClearWindow(x11_display, x11_window); - return; - } - image_expandPixel(&_dib, &_work, fadestep[255 - step]); - workImageToWindow(); -} - -static void fadeout_n8(int step) { - static agsurface_t _work; - - if (step == 0) { - DIBToWorkImage(view_x, view_y, view_w, view_h, 0, 0); - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - } - if (step == 255) { - Xcore_setBackground(0); - XClearWindow(x11_display, x11_window); - return; - } - image_fadeOut(&_work, (255-step)/16, 0); - workImageToWindow(); -} - -static void whitein_8_n8(int step) { - static agsurface_t _dib, _work; - - if (step == 0) { - rect_comimg(DIB, &_dib, view_x, view_y, view_w, view_h); - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - } - image_expandPixel(&_dib, &_work, fadestep[255-step]+255); - workImageToWindow(); -} - -static void whitein_n8(int step) { - static agsurface_t _dib, _work; - - if (step == 0) { - rect_comimg(DIB, &_dib, view_x, view_y, view_w, view_h); - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - } - if (step == 255) { - ags_updateFull(); - return; - } - image_fadeIn(&_dib, &_work, (255-step)/16); - workImageToWindow(); -} - -static void whiteout_8_n8(int step) { - static agsurface_t _dib, _work; - - if (step == 0) { - rect_comimg(DIB, &_dib, view_x, view_y, view_w, view_h); - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - } - image_expandPixel(&_dib, &_work, fadestep[step]+255); - workImageToWindow(); -} - -static void whiteout_n8(int step) { - static agsurface_t _work; - - if (step == 0) { - DIBToWorkImage(view_x, view_y, view_w, view_h, 0, 0); - rect_comimg(WORK, &_work, 0, 0, view_w, view_h); - } - if (step == 255) { - memset(x11_workinfo->cimg.pixel, 255, x11_workinfo->cimg.bytes_per_pixel * view_w * view_h); - workImageToWindow(); - return; - } - image_fadeOut(&_work, step/16, 0xffffffff); - workImageToWindow(); -} - -void Xcore_fadeIn(int step) { - - if (step == 0) { - Xcore_sync(); - } - - if (DIB_DEPTH == 8) { - if (WIN_DEPTH == 8) { - if (step == 0) Xcore_updateAll(); - setBlightness8(fadestep[step]); - } else { - fadein_8_n8(step); - } - } else { - fadein_n8(step); - } -} - -void Xcore_fadeOut(int step) { - - if (step == 0) { - Xcore_sync(); - } - - if (DIB_DEPTH == 8) { - if (WIN_DEPTH == 8) { - setBlightness8(fadestep[255-step]); - } else { - fadeout_8_n8(step); - } - } else { - fadeout_n8(step); - } -} - -void Xcore_whiteIn(int step) { - - if (step == 0) { - Xcore_sync(); - } - - if (DIB_DEPTH == 8) { - if (WIN_DEPTH == 8) { - if (step == 0) Xcore_updateAll(); - setWhiteness8(fadestep[step]); - } else { - whitein_8_n8(step); - } - } else { - whitein_n8(step); - } -} - -void Xcore_whiteOut(int step) { - - if (step == 0) { - Xcore_sync(); - } - - if (DIB_DEPTH == 8) { - if (WIN_DEPTH == 8) { - setWhiteness8(fadestep[255-step]); - } else { - whiteout_8_n8(step); - } - } else { - whiteout_n8(step); - } -} - -Pixmap x11_clip_from_DIB(int sx, int sy, int w, int h) { - agsurface_t _dib, _work; - Pixmap clippix; - - clippix = XCreatePixmap(x11_display, x11_window, w, h, WIN_DEPTH); - - if (x11_dibinfo->shared) { - XCopyArea(x11_display, x11_pixmap, clippix, x11_gc_pix, - sx, sy, w, h, 0, 0); - } else { - if (DIB_DEPTH == 8) { - if (WIN_DEPTH == 8) { - XPutImage(x11_display, clippix, - x11_gc_pix, x11_dibinfo->ximg, - sx, sy, 0, 0, w, h); - } else { - rect_comimg(DIB, &_dib, - sx, sy, w, h); - rect_comimg(WORK, &_work, - 0, 0, w, h); - - image_expandPixel(&_dib, &_work, 255); - - if (x11_workinfo->shared) { - XShmPutImage(x11_display, clippix, - x11_gc_win, x11_workinfo->ximg, - 0, 0, - 0, 0, - sx, sy, False); - } else { - XPutImage(x11_display, clippix, - x11_gc_win, x11_workinfo->ximg, - 0, 0, - 0, 0, - w, h); - } - } - } else { - if (packed24bpp) { - rect_comimg(DIB, &_dib, - sx, sy, w, h); - rect_comimg(WORK, &_work, - 0, 0, w, h); - - image_trans_pixel_24to24p(&_dib, &_work); - - XPutImage(x11_display, clippix, - x11_gc_win, x11_workinfo->ximg, - 0, 0, - 0, 0, - w, h); - } else { - XPutImage(x11_display, clippix, - x11_gc_pix, x11_dibinfo->ximg, - sx, sy, - 0, 0, - w, h); - } - } - } - - return clippix; -} diff --git a/src/xcore_event.c b/src/xcore_event.c deleted file mode 100644 index 1d15e84..0000000 --- a/src/xcore_event.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * xcore_event.c X11 event handler - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore_event.c,v 1.12 2004/10/31 04:18:06 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "portab.h" -#include "system.h" -#include "xcore.h" -#include "xcore_private.h" -#include "nact.h" -#include "counter.h" -#include "input.h" -#include "menu.h" -#include "joystick.h" -#include "xcore_input.c" - -static boolean xcore_getEvent(void); -static int check_button(void); - -/* pointer の状態 */ -static int mousex, mousey; - -static boolean xcore_getEvent(void) { - XEvent e; - Window root, child; - int rx, ry, wx, wy; - int mask; - boolean getkey = FALSE, msg_skip = FALSE; - - while(XPending(x11_display)) { - XNextEvent(x11_display, &e); - switch(e.type) { - case LeaveNotify: - mousex = -1; mousey = -1; // mouseb = 0; - memset(RawKeyInfo, 0, sizeof(RawKeyInfo)); - getkey = TRUE; - if (x11_fs_on) { - XUngrabPointer(x11_display, CurrentTime); - XSync(x11_display, False); - } - break; - case EnterNotify: - if (x11_fs_on) { - XGrabPointer(x11_display, x11_window, True, 0, - GrabModeAsync, GrabModeAsync, - x11_window, None, CurrentTime); - XSync(x11_display, False); - } - break; - case MotionNotify: - if (!XQueryPointer(x11_display, x11_window, &root, &child, &rx, &ry, &wx, &wy, &mask)) - break; - mousex = wx; mousey = wy; - if (nact->ags.eventcb) { - agsevent_t agse; - agse.type = AGSEVENT_MOUSE_MOTION; - agse.d1 = wx; agse.d2 = wy; agse.d3 = 0; - nact->ags.eventcb(&agse); - } - break; - -#if 0 - case ButtonPress: - mouseb |= (1 << e.xbutton.button); - getkey = TRUE; - break; - - case ButtonRelease: - mouseb &= (0xffffffff ^ (1 << e.xbutton.button)); - getkey = TRUE; - break; -#endif - case ButtonPress: - case ButtonRelease: - buttonEventProcess((XButtonEvent *)&e); - getkey = TRUE; - break; - - case Expose: { - MyRectangle src; - MyPoint dst; - XExposeEvent *ev = (XExposeEvent *)&e; - if (ev->count == 0) { - src.x = view_x + ev->x - winoffset_x; - src.y = view_y + ev->y - winoffset_y; - src.width = min(DIB->width, ev->width); - src.height = min(DIB->height, ev->height); - dst.x = ev->x - winoffset_x; - dst.y = ev->y - winoffset_y; - if (src.x > view_w || src.x < 0) break; - if (src.y > view_h || src.y < 0) break; - Xcore_updateArea(&src, &dst); - } - break; - } - - case KeyPress: - keyEventProsess((XKeyEvent *)&e); - getkey = TRUE; - break; - - case KeyRelease: { - KeySym sym; - - keyEventProsess((XKeyEvent *)&e); - sym = XkbKeycodeToKeysym(x11_display, e.xkey.keycode, 0, 0); - if (sym == XK_F4) { - Xcore_fullScreen(!x11_fs_on); - } else if (sym == XK_F1) { - msg_skip = TRUE; - } - getkey = TRUE; - break; - } - - case ClientMessage: - if (e.xclient.message_type == atom_wmprot && - e.xclient.data.l[0] == atom_delwin) { - menu_quitmenu_open(); - } - break; - } - } - - if (msg_skip) set_skipMode(!get_skipMode()); - return getkey; -} - -int Xcore_keywait(int msec, boolean cancel) { - boolean bool = FALSE; - int key = 0, retval, rest = msec; - int cnt = get_high_counter(SYSTEMCOUNTER_MSEC); - - if (msec < 0) return 0; -#if 1 - while (msec > (get_high_counter(SYSTEMCOUNTER_MSEC) - cnt)) { - bool = xcore_getEvent(); - //key = check_button() | Xcore_getKeyInfo() | joy_getinfo(); - key |= check_button() | Xcore_getKeyInfo() | joy_getinfo(); - if( cancel && key ) break; - rest = msec - (get_high_counter(SYSTEMCOUNTER_MSEC) - cnt); - if (rest < 0) break; - if (rest < 10) { - usleep(1000 * rest); - } else { - usleep(10000); - } - nact->callback(); - } -#endif -#if 0 - while (rest > 0) { - struct timeval tv; - fd_set fdset; - int x11_fd = ConnectionNumber(x11_display); - - FD_ZERO(&fdset); - FD_SET(x11_fd, &fdset); - - cnt = get_high_counter(SYSTEMCOUNTER_MSEC); - tv.tv_sec = 0; - if (rest < 100) { - tv.tv_usec = rest * 1000; - } else { - tv.tv_usec = 100 * 1000; - } - retval = select(x11_fd + 1, &fdset, NULL, NULL, &tv); - if (retval > 0) { - if (FD_ISSET(x11_fd, &fdset)) { - bool = xcore_getEvent(); - } - } else if (retval < 0) { - perror("select"); - } - if (bool) { - key |= (check_button() | Xcore_getKeyInfo()); - if (cancel) break; - } - rest -= (get_high_counter(SYSTEMCOUNTER_MSEC) - cnt); - nact->callback(); - } -#endif - return key; -} - -/* キー情報の取得 */ -int Xcore_getKeyInfo() { - xcore_getEvent(); - - return ((RawKeyInfo[KEY_UP] || RawKeyInfo[KEY_PAD_8]) | - ((RawKeyInfo[KEY_DOWN] || RawKeyInfo[KEY_PAD_2]) << 1) | - ((RawKeyInfo[KEY_LEFT] || RawKeyInfo[KEY_PAD_4]) << 2) | - ((RawKeyInfo[KEY_RIGHT] || RawKeyInfo[KEY_PAD_6]) << 3) | - (RawKeyInfo[KEY_ENTER] << 4) | - (RawKeyInfo[KEY_SPACE] << 5) | - (RawKeyInfo[KEY_ESC] << 6) | - (RawKeyInfo[KEY_TAB] << 7)); -} - -/* mouse 情報の取得 */ -int Xcore_getMouseInfo(MyPoint *p) { - xcore_getEvent(); - - if (mousex < 0) { - if (p) { - p->x=0; p->y=0; - } - return 0; - } - - if (p) { - p->x = mousex - winoffset_x; - p->y = mousey - winoffset_y; - } - return check_button(); -} - -/* mouse のボタン状態の取得 */ -static int check_button(void) { - int m1, m2; - - if (RawKeyInfo[KEY_MOUSE_MIDDLE]) { - menu_open(); - } else { - m1 = RawKeyInfo[KEY_MOUSE_LEFT] ? SYS35KEY_RET : 0; - m2 = RawKeyInfo[KEY_MOUSE_RIGHT] ? SYS35KEY_SPC : 0; - return m1|m2; - } - return 0; -} diff --git a/src/xcore_image.c b/src/xcore_image.c deleted file mode 100644 index f6aa378..0000000 --- a/src/xcore_image.c +++ /dev/null @@ -1,1620 +0,0 @@ -/* - * xcore_image.c image操作 for X11 - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: image.c,v 1.40 2003/08/30 21:29:16 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include "portab.h" -#include "system.h" -#include "image.h" -#include "cg.h" -#include "config.h" -#include "nact.h" -#include "graphicsdevice.h" -#include "alpha_plane.h" -#include "ags.h" - -/* private variables */ -static Palette xpal[256]; /* pal & pixel 値 */ - -/* private methods */ -static void trans_index2pixels(int depth, int lv, cgdata *cg); - -/******************************************************************************/ -/* private methods image操作 8bpp */ -/******************************************************************************/ - -static void image_drawRectangle8(agsurface_t *dib, int x, int y, int w, int h, int col) { - BYTE *dst = GETOFFSET_PIXEL(dib, x, y); - int i; - - /* top */ - memset(dst, col, w); - - /* side */ - h-=2; - for (i = 0; i < h; i++) { - dst += dib->bytes_per_line; - *dst = col; - *(dst + w - 1) = col; - } - - /* bottom */ - dst += dib->bytes_per_line; - memset(dst, col, w); -} - -static void image_copyArea8(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy) { - BYTE *src = GETOFFSET_PIXEL(dib, sx, sy); - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - - if (sy <= dy && dy < (sy + h)) { - src += (h-1) * dib->bytes_per_line; - dst += (h-1) * dib->bytes_per_line; - - while (h--) { - memmove(dst, src, w); - src -= dib->bytes_per_line; - dst -= dib->bytes_per_line; - } - } else { - while(h--) { - memmove(dst, src, w); - src += dib->bytes_per_line; - dst += dib->bytes_per_line; - } - } -} - -static void image_getGlyphImage8to8(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = GETOFFSET_PIXEL(glyph, 0, 0); - BYTE *yd; - BYTE *ys; - - for (y = 0; y < glyph->height; y++) { - ys = src + y * glyph->bytes_per_line; - yd = dst + y * dib->bytes_per_line; - for (x = 0; x < glyph->width; x++) { - if (*ys != 0) { - *yd = col; - } - ys++; yd++; - } - } -} - -static void image_copyAreaSP8(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int width, int height, int sp) { - int x, y; - BYTE *pix_dst, *pix_src; - - for (y = 0; y < height; y++) { - pix_src = (BYTE *)(sdata + y * dib->bytes_per_line); - pix_dst = (BYTE *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < width; x++) { - if (*pix_src != (BYTE)sp) { - *pix_dst = *pix_src; - } - pix_src++; - pix_dst++; - } - } -} - -/******************************************************************************/ -/* private methods image操作 15bpp */ -/******************************************************************************/ - -static void drawImage16_fromData15(agsurface_t *dib, cgdata *cg, int dx, int dy, int w, int h) { - int x, y; - WORD *pic_src = (WORD *)(cg->pic + cg->data_offset); - BYTE *pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - WORD pic16; - WORD *yl; - - for (y = 0; y < h; y++) { - yl = (WORD *)(pic_dst + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - pic16 = *pic_src; - *yl = PIX15(RGB_PIXR16(pic16), RGB_PIXG16(pic16), RGB_PIXB16(pic16)); - (WORD *)yl ++; pic_src++; - } - pic_src += (cg->width - w); - } -} - -static void drawSprite16_fromData15(agsurface_t *dib, cgdata *cg, int dx, int dy, int w, int h) { - int x, y; - WORD pic16; - WORD *pic_src = (WORD *)(cg->pic + cg->data_offset); - BYTE *pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *pic_dst_a = GETOFFSET_ALPHA(dib, dx, dy); - WORD *yl, pic15; - BYTE *ya; - - for (y = 0; y < h; y++) { - yl = (WORD *)(pic_dst + y * dib->bytes_per_line); - ya = (BYTE *)(pic_dst_a + y * dib->width); - for (x = 0; x < w; x++) { - pic16 = *pic_src; - pic15 = PIX15(RGB_PIXR16(pic16),RGB_PIXG16(pic16),RGB_PIXB16(pic16)); - if (*ya == 255) { - *yl = pic15; - } else if (*ya > 0) { - *yl= ALPHABLEND15(pic15, *yl, *ya); - } - yl ++; ya++; pic_src++; - } - pic_src += (cg->width - w); - } -} - -static void image_wrapColor15(agsurface_t *dib, BYTE *dst, int w, int h, int col, int rate) { - int x, y; - WORD *yls, yld; - - yld = image_index2pixel(dib->depth, col); - - for (y = 0; y < h; y++) { - yls = (WORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yls = ALPHABLEND15(yld, *yls, rate); - yls++; - } - } -} - -static void image_copyAreaSP16_shadow15(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, BYTE *adata, int lv) { - int x, y; - WORD *yls, *yld; - BYTE *yla; - - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - yla = (BYTE *)(adata + y * dib->width); - for (x = 0; x < w; x++) { - *yld = ALPHABLEND15(*yls, *yld, (*yla * lv) / 255); - yls++; yld++; yla++; - } - } -} - -static void image_copyAreaSP16_alphaBlend15(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - WORD *yls, *yld; - - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = ALPHABLEND15(*yls, *yld, lv); - yls++; yld++; - } - } -} - -static void image_copyAreaSP16_alphaLevel15(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - WORD *yls, *yld; - - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = ALPHALEVEL15(*yls, lv); - yls++; yld++; - } - } -} - -static void image_copyAreaSP16_whiteLevel15(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - WORD *yls, *yld; - - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = WHITELEVEL15(*yls, lv); - yls++; yld++; - } - } -} - -void image_draw_antialiased_pattern15(agsurface_t *dib, agsurface_t *pattern, int dx, int dy, int dw, int dh, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = (BYTE *)pattern->pixel; - WORD *yd; - BYTE *ys; - - for (y = 0; y < dh; y++) { - ys = (BYTE *)(src + y * pattern->bytes_per_line); - yd = (WORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < dw; x++) { - if (*ys != 0) { - *yd = ALPHABLEND15(col, *yd, (BYTE)*ys); - } - ys++; yd++; - } - } -} - -/******************************************************************************/ -/* private methods image操作 16bpp */ -/******************************************************************************/ - -static void drawImage24_fromData16(agsurface_t *dib, cgdata *cg, int dx, int dy, int w, int h) { - int x, y; - BYTE* pic_src = (BYTE *)(cg->pic + cg->data_offset); - BYTE* pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - WORD *yl; - - for (y = 0; y < h; y++) { - yl = (WORD *)(pic_dst + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - BYTE r, g, b; - r = *pic_src; - g = *(pic_src+1); - b = *(pic_src+2); - *yl = PIX16(r,g,b); - yl ++; pic_src+=3; - } - pic_src += (cg->width - w); - } -} - -static void drawImage16_fromData16(agsurface_t *dib, cgdata *cg, int dx, int dy, int w, int h) { - int y; - WORD* pic_src = (WORD *)(cg->pic + cg->data_offset); - BYTE* pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - - for (y = 0; y < h; y++) { - memcpy(pic_dst, pic_src, w * 2); - pic_src += cg->width; - pic_dst += dib->bytes_per_line; - } -} - -static void drawSprite16_fromData16(agsurface_t *dib, cgdata *cg, int dx, int dy, int w, int h) { - int x, y; - WORD pic16; - WORD *pic_src = (WORD *)(cg->pic + cg->data_offset); - BYTE *pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *pic_dst_a = GETOFFSET_ALPHA(dib, dx, dy); - WORD *yl; - BYTE *ya; - - for (y = 0; y < h; y++) { - yl = (WORD *)(pic_dst + y * dib->bytes_per_line); - ya = (BYTE *)(pic_dst_a + y * dib->width); - for (x = 0; x < w; x++) { - pic16 = *pic_src; - if (*ya == 255) { - *yl = pic16; - } else if (*ya > 0) { - *yl= ALPHABLEND16(pic16, *yl, *ya); - } - yl++; ya++; pic_src++; - } - pic_src += (cg->width - w); - } -} - -static void expandPixel8to16(agsurface_t *src, agsurface_t *dst) { - int x, y; - WORD *yd; - BYTE *ys; - - for (y = 0; y < src->height; y++) { - ys = (BYTE *)(src->pixel + y * src->bytes_per_line); - yd = (WORD *)(dst->pixel + y * dst->bytes_per_line); - for (x = 0; x < src->width; x++) { - *yd = xpal[*ys].pixel; - ys++; yd++; - } - } -} - - -static void image_drawRectangle16(agsurface_t *dib, int x, int y, int w, int h, int col) { - BYTE *dst = GETOFFSET_PIXEL(dib, x, y); - int i; - - /* top */ - for (i = 0; i < w; i++) { - *((WORD *)dst + i) = col; - } - - /* side */ - h-=2; - for (i = 0; i < h; i++) { - dst += dib->bytes_per_line; - *((WORD *)dst) = col; - *((WORD *)dst + w - 1) = col; - } - - /* bottom */ - dst += dib->bytes_per_line; - for (i = 0; i < w; i++) { - *((WORD *)dst + i) = col; - } -} - -static void image_copyArea16(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy) { - BYTE *src = GETOFFSET_PIXEL(dib, sx, sy); - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - - if (sy <= dy && dy < (sy + h)) { - src += (h-1) * dib->bytes_per_line; - dst += (h-1) * dib->bytes_per_line; - - while (h--) { - memmove(dst, src, w * 2); - src -= dib->bytes_per_line; - dst -= dib->bytes_per_line; - } - } else { - while(h--) { - memmove(dst, src, w * 2); - src += dib->bytes_per_line; - dst += dib->bytes_per_line; - } - } -} - -static void image_getGlyphImage16to16(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = (BYTE *)glyph->pixel; - WORD *yd; - WORD *ys; - - for (y = 0; y < glyph->height; y++) { - ys = (WORD *)(src + y * glyph->bytes_per_line); - yd = (WORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < glyph->width; x++) { - if (*ys != 0) { - *yd = col; - } - ys++; yd++; - } - } -} - -static void image_wrapColor16(agsurface_t *dib, BYTE *dst, int w, int h, int col, int rate) { - int x, y; - WORD *yls, yld; - - yld = image_index2pixel(dib->depth, col); - - if (nact->mmx_is_ok) { -// if (0) { -#ifdef ENABLE_MMX - int alpha = rate | rate << 8 | rate << 16 | rate << 24; - ablend16_dpd(dst, yld, dst, alpha, w, h, dib->bytes_per_line, dib->bytes_per_line); -#endif - } else { - for (y = 0; y < h; y++) { - yls = (WORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yls = ALPHABLEND16(yld, *yls, rate); - yls++; - } - } - } -} - -static void image_copyAreaSP16_shadow16(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, BYTE *adata, int lv) { - int x, y; - WORD *yls, *yld; - BYTE *yla; - - if (nact->mmx_is_ok) { -// if (0) { -#ifdef ENABLE_MMX - ablend16_ppp(ddata, sdata, ddata, adata, w, h, dib->bytes_per_line, dib->bytes_per_line, dib->bytes_per_line, dib->width, lv); -#endif - } else { - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - yla = (BYTE *)(adata + y * dib->width); - for (x = 0; x < w; x++) { - *yld = ALPHABLEND16(*yls, *yld, (*yla * lv) / 255); - yls++; yld++; yla++; - } - } - } -} - -static void image_copyAreaSP16_transparent16(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int pal) { - int x, y; - WORD *yls, *yld; - WORD yla = image_index2pixel(dib->depth, pal); - - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - if (*yls != yla) { - *yld = *yls; - } - yls++; yld++; - } - } -} - -static void image_copyAreaSP16_alphaBlend16(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - - if (nact->mmx_is_ok) { -// if (0) { -#ifdef ENABLE_MMX - int alpha = lv | lv << 8 | lv << 16 | lv << 24; - ablend16_ppd(ddata, sdata, ddata, alpha, w, h, dib->bytes_per_line, dib->bytes_per_line, dib->bytes_per_line); -#endif - } else { - WORD *yls, *yld; - - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = ALPHABLEND16(*yls, *yld, lv); - yls++; yld++; - } - } - } -} - -static void image_copyAreaSP16_alphaLevel16(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - WORD *yls, *yld; - - if (nact->mmx_is_ok) { -// if (0) { -#ifdef ENABLE_MMX - int alpha; - lv = 255 - lv; - alpha = lv | lv << 8 | lv << 16 | lv << 24; - ablend16_dpd(ddata, 0, sdata, alpha, w, h, dib->bytes_per_line, dib->bytes_per_line); -#endif - } else { - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = ALPHALEVEL16(*yls, lv); - yls++; yld++; - } - } - } -} - -static void image_copyAreaSP16_whiteLevel16(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - WORD *yls, *yld; - - for (y = 0; y < h; y++) { - yls = (WORD *)(sdata + y * dib->bytes_per_line); - yld = (WORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = WHITELEVEL16(*yls, lv); - yls++; yld++; - } - } -} - - -void image_draw_antialiased_pattern16(agsurface_t *dib, agsurface_t *pattern, int dx, int dy, int dw, int dh, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = (BYTE *)pattern->pixel; - WORD *yd; - BYTE *ys; - - for (y = 0; y < dh; y++) { - ys = (BYTE *)(src + y * pattern->bytes_per_line); - yd = (WORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < dw; x++) { - if (*ys != 0) { - *yd = ALPHABLEND16(col, *yd, (BYTE)*ys); - } - ys++; yd++; - } - } -} - -/******************************************************************************/ -/* private methods image操作 packed 24bpp */ -/******************************************************************************/ - -static void expandPixel8to24p(agsurface_t *src, agsurface_t *dst) { - Palette256 *pal = nact->sys_pal; - int x, y; - BYTE *yd; - BYTE *ys; - - for (y = 0; y < src->height; y++) { - ys = (BYTE *)(src->pixel + y * src->bytes_per_line); - yd = (BYTE *)(dst->pixel + y * dst->bytes_per_line); - for (x = 0; x < src->width; x++) { - *yd = pal->blue[*ys]; yd++; - *yd = pal->green[*ys]; yd++; - *yd = pal->red[*ys]; yd++; ys++; - } - } -} - -void image_trans_pixel_24to24p(agsurface_t *src, agsurface_t *dst) { - int x, y; - BYTE *yd; - DWORD *ys; - - for (y = 0; y < src->height; y++) { - ys = (DWORD *)(src->pixel + y * src->bytes_per_line); - yd = (BYTE *)(dst->pixel + y * dst->bytes_per_line); - for (x = 0; x < src->width; x++) { - *yd = PIXB24(*ys); yd++; - *yd = PIXG24(*ys); yd++; - *yd = PIXR24(*ys); yd++; ys++; - } - } -} - -static void image_getGlyphImage24pto24(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = (BYTE *)glyph->pixel; - DWORD *yd; - BYTE *ys; - - for (y = 0; y < glyph->height; y++) { - ys = (BYTE *)(src + y * glyph->bytes_per_line); - yd = (DWORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < glyph->width; x++) { - if (*ys != 0) { - *yd = col; - } - ys+=3; yd++; - } - } -} - -/******************************************************************************/ -/* private methods image操作 24/32bpp */ -/******************************************************************************/ - -static void drawImage16_fromData24(agsurface_t *dib, cgdata *cg, int dx, int dy, int w, int h) { - int x, y; - WORD pic16; - WORD *pic_src = (WORD *)(cg->pic + cg->data_offset); - BYTE *pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - DWORD *yl; - - for (y = 0; y < h; y++) { - yl = (DWORD *)(pic_dst + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - pic16 = *pic_src; - *yl = PIX24(RGB_PIXR16(pic16),RGB_PIXG16(pic16),RGB_PIXB16(pic16)); - yl ++; pic_src++; - } - pic_src += (cg->width - w); - } -} - -static void drawSprite16_fromData24(agsurface_t *dib, cgdata *cg, int dx, int dy, int w, int h) { - int x, y; - WORD pic16; - WORD *pic_src = (WORD *)(cg->pic + cg->data_offset); - BYTE *pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *pic_dst_a = GETOFFSET_ALPHA(dib, dx, dy); - DWORD *yl, pic24; - BYTE *ya; - - for (y = 0; y < h; y++) { - yl = (DWORD *)(pic_dst + y * dib->bytes_per_line); - ya = (BYTE *)(pic_dst_a + y * dib->width); - for (x = 0; x < w; x++) { - pic16 = *pic_src; - pic24 = PIX24(RGB_PIXR16(pic16),RGB_PIXG16(pic16),RGB_PIXB16(pic16)); - if (*ya == 255) { - *yl = pic24; - } else if (*ya > 0) { - *yl = ALPHABLEND24(pic24, *yl, *ya); - } - yl ++; ya++; pic_src++; - } - pic_src += (cg->width - w); - } -} - -static void expandPixel8to24(agsurface_t *src, agsurface_t *dst) { - int x, y; - DWORD *yd; - BYTE *ys; - - for (y = 0; y < src->height; y++) { - ys = (BYTE *)(src->pixel + y * src->bytes_per_line); - yd = (DWORD *)(dst->pixel + y * dst->bytes_per_line); - for (x = 0; x < src->width; x++) { - *yd = xpal[*ys].pixel; - ys++; yd++; - } - } -} - -static void image_drawRectangle24(agsurface_t *dib, int x, int y, int w, int h, int col) { - BYTE *dst = GETOFFSET_PIXEL(dib, x, y); - int i; - - /* top */ - for (i = 0; i < w; i++) { - *((DWORD *)dst + i) = col; - } - - /* side */ - h-=2; - for (i = 0; i < h; i++) { - dst += dib->bytes_per_line; - *((DWORD *)dst) = col; - *((DWORD *)dst + w - 1) = col; - } - - /* bottom */ - dst += dib->bytes_per_line; - for (i = 0; i < w; i++) { - *((DWORD *)dst + i) = col; - } -} - -static void image_copyArea24(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy) { - BYTE *src = GETOFFSET_PIXEL(dib, sx, sy); - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - - if (sy <= dy && dy < (sy + h)) { - src += (h-1) * dib->bytes_per_line; - dst += (h-1) * dib->bytes_per_line; - - while (h--) { - memmove(dst, src, w * 4); - src -= dib->bytes_per_line; - dst -= dib->bytes_per_line; - } - } else { - while(h--) { - memmove(dst, src, w * 4); - src += dib->bytes_per_line; - dst += dib->bytes_per_line; - } - } -} - -static void image_getGlyphImage24to24(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = (BYTE *)glyph->pixel; - DWORD *yd; - DWORD *ys; - - for (y = 0; y < glyph->height; y++) { - ys = (DWORD *)(src + y * glyph->bytes_per_line); - yd = (DWORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < glyph->width; x++) { - if (*ys != 0) { - *yd = col; - } - ys++; yd++; - } - } -} - -static void image_wrapColor24(agsurface_t *dib, BYTE *dst, int w, int h, int col, int rate) { - int x, y; - DWORD *yls, yld; - - yld = image_index2pixel(dib->depth, col); - - for (y = 0; y < h; y++) { - yls = (DWORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yls = ALPHABLEND24(yld, *yls, rate); - yls++; - } - } -} - -static void image_copyAreaSP16_shadow24(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, BYTE *adata, int lv) { - int x, y; - DWORD *yls, *yld; - BYTE *yla; - - for (y = 0; y < h; y++) { - yls = (DWORD *)(sdata + y * dib->bytes_per_line); - yld = (DWORD *)(ddata + y * dib->bytes_per_line); - yla = (BYTE *)(adata + y * dib->width); - for (x = 0; x < w; x++) { - *yld = ALPHABLEND24(*yls, *yld, (*yla * lv) / 255); - yls++; yld++; yla++; - } - } -} - -static void image_copyAreaSP16_transparent24(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int pal) { - int x, y; - DWORD *yls, *yld; - DWORD yla = image_index2pixel(dib->depth, pal) & 0xf0f0f0; - - for (y = 0; y < h; y++) { - yls = (DWORD *)(sdata + y * dib->bytes_per_line); - yld = (DWORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - if ((*yls & 0xf0f0f0) != yla) { - *yld = *yls; - } - yls++; yld++; - } - } -} - -static void image_copyAreaSP16_alphaBlend24(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - DWORD *yls, *yld; - - for (y = 0; y < h; y++) { - yls = (DWORD *)(sdata + y * dib->bytes_per_line); - yld = (DWORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = ALPHABLEND24(*yls, *yld, lv); - yls++; yld++; - } - } -} - -static void image_copyAreaSP16_alphaLevel24(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - DWORD *yls, *yld; - - for (y = 0; y < h; y++) { - yls = (DWORD *)(sdata + y * dib->bytes_per_line); - yld = (DWORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = ALPHALEVEL24(*yls, lv); - yls++; yld++; - } - } -} - -static void image_copyAreaSP16_whiteLevel24(agsurface_t *dib, BYTE *sdata, BYTE *ddata, int w, int h, int lv) { - int x, y; - DWORD *yls, *yld; - - for (y = 0; y < h; y++) { - yls = (DWORD *)(sdata + y * dib->bytes_per_line); - yld = (DWORD *)(ddata + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - *yld = WHITELEVEL24(*yls, lv); - yls++; yld++; - } - } -} - -void image_draw_antialiased_pattern24(agsurface_t *dib, agsurface_t *pattern, int dx, int dy, int dw, int dh, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = (BYTE *)pattern->pixel; - DWORD *yd; - BYTE *ys; - - for (y = 0; y < dh; y++) { - ys = (BYTE *)(src + y * pattern->bytes_per_line); - yd = (DWORD *)(dst + y * dib->bytes_per_line); - for (x = 0; x < dw; x++) { - if (*ys) { - *yd = ALPHABLEND24(col, *yd, (BYTE)*ys); - } - ys++; yd++; - } - } -} - - -static void (*draw_image24_from_data)(agsurface_t *, cgdata *, int, int, int, int); -static void (*draw_sprite16_from_data)(agsurface_t *, cgdata *, int, int, int, int); -static void (*draw_image16_from_data)(agsurface_t *, cgdata *, int, int, int, int); -static void (*draw_rectangle)(agsurface_t*, int, int, int, int, int); -static void (*copy_area)(agsurface_t*, int, int, int, int, int, int); -static void (*copy_area_ablend_sda)(agsurface_t *, BYTE *, BYTE *, int, int, BYTE *, int); -static void (*copy_area_ablend_sd)(agsurface_t *, BYTE *, BYTE *, int, int, int); -static void (*copy_area_alevel)(agsurface_t *, BYTE *, BYTE *, int, int, int); -static void (*copy_area_wlevel)(agsurface_t *, BYTE *, BYTE *, int, int, int); -static void (*wrap_color)(agsurface_t *, BYTE *, int, int, int, int); -static void (*copy_area_sprite)(agsurface_t *, BYTE *, BYTE *, int, int, int); -static void (*draw_antialiased_pattern)(agsurface_t *, agsurface_t *, int, int, int, int, int); - -/* - * dib の depth に応じた関数の設定 - * depth: dib depth -*/ -void xcore_image_setdepth(int depth) { - switch(depth) { - case 8: - draw_rectangle = image_drawRectangle8; - copy_area = image_copyArea8; - copy_area_sprite = image_copyAreaSP8; - break; - case 15: - // draw_image24_from_data = drawImage24_fromData15; - draw_sprite16_from_data = drawSprite16_fromData15; - draw_image16_from_data = drawImage16_fromData15; - draw_rectangle = image_drawRectangle16; - copy_area = image_copyArea16; - copy_area_ablend_sda = image_copyAreaSP16_shadow15; - copy_area_ablend_sd = image_copyAreaSP16_alphaBlend15; - copy_area_alevel = image_copyAreaSP16_alphaLevel15; - copy_area_wlevel = image_copyAreaSP16_whiteLevel15; - wrap_color = image_wrapColor15; - copy_area_sprite = image_copyAreaSP16_transparent16; - draw_antialiased_pattern = image_draw_antialiased_pattern15; - break; - case 16: - draw_image24_from_data = drawImage24_fromData16; - draw_sprite16_from_data = drawSprite16_fromData16; - draw_image16_from_data = drawImage16_fromData16; - draw_rectangle = image_drawRectangle16; - copy_area = image_copyArea16; - copy_area_ablend_sda = image_copyAreaSP16_shadow16; - copy_area_ablend_sd = image_copyAreaSP16_alphaBlend16; - copy_area_alevel = image_copyAreaSP16_alphaLevel16; - copy_area_wlevel = image_copyAreaSP16_whiteLevel16; - wrap_color = image_wrapColor16; - copy_area_sprite = image_copyAreaSP16_transparent16; - draw_antialiased_pattern = image_draw_antialiased_pattern16; - break; - case 24: - case 32: - //draw_image24_from_data = drawImage24_fromData32; - draw_sprite16_from_data = drawSprite16_fromData24; - draw_image16_from_data = drawImage16_fromData24; - draw_rectangle = image_drawRectangle24; - copy_area = image_copyArea24; - copy_area_ablend_sda = image_copyAreaSP16_shadow24; - copy_area_ablend_sd = image_copyAreaSP16_alphaBlend24; - copy_area_alevel = image_copyAreaSP16_alphaLevel24; - copy_area_wlevel = image_copyAreaSP16_whiteLevel24; - wrap_color = image_wrapColor24; - copy_area_sprite = image_copyAreaSP16_transparent24; - draw_antialiased_pattern = image_draw_antialiased_pattern24; - break; - default: - break; - } -} - - -static void trans_index2pixels(int depth, int lv, cgdata *cg) { - Palette256 *pal; - int i, i_st = 0, i_ed = 256, r, g, b; - - if (cg == NULL) { - pal = nact->sys_pal; - } else { - pal = cg->pal; - if (cg->type == ALCG_VSP) { - i_st = (cg->vsp_bank << 4); - i_ed = i_st + 16; - } - } - switch(depth) { - case 8: - for (i = i_st; i < i_ed; i++) { - xpal[i].r = pal->red [i]; - xpal[i].g = pal->green[i]; - xpal[i].b = pal->blue [i]; - xpal[i].pixel = i; - } - break; - case 15: - if (lv == 255) { - for (i = i_st; i < i_ed; i++) { - xpal[i].pixel = PIX15(pal->red[i], pal->green[i], pal->blue[i]); - } - } else if (lv < 255) { - for (i = i_st; i < i_ed; i++) { - xpal[i].pixel = PIX15((pal->red [i]*lv)>>8, - (pal->green[i]*lv)>>8, - (pal->blue [i]*lv)>>8); - } - } else { - lv -= 255; - for (i = i_st; i < i_ed; i++) { - r = pal->red[i]; - g = pal->green[i]; - b = pal->blue[i]; - xpal[i].pixel = PIX15((((255-r)*lv)>>8)+r, - (((255-g)*lv)>>8)+g, - (((255-b)*lv)>>8)+b); - } - } - break; - case 16: - if (lv == 255) { - for (i = i_st; i < i_ed; i++) { - xpal[i].pixel = PIX16(pal->red[i], pal->green[i], pal->blue[i]); - } - } else if (lv < 255) { - for (i = i_st; i < i_ed; i++) { - xpal[i].pixel = PIX16((pal->red [i]*lv)>>8, - (pal->green[i]*lv)>>8, - (pal->blue [i]*lv)>>8); - } - } else { - lv -= 255; - for (i = i_st; i < i_ed; i++) { - r = pal->red[i]; - g = pal->green[i]; - b = pal->blue[i]; - xpal[i].pixel = PIX16((((255-r)*lv)>>8)+r, - (((255-g)*lv)>>8)+g, - (((255-b)*lv)>>8)+b); - } - } - break; - case 24: - case 32: - if (lv == 255) { - for (i = i_st; i < i_ed; i++) { - xpal[i].pixel = PIX24(pal->red[i], pal->green[i], pal->blue[i]); - } - } else if (lv < 255) { - for (i = i_st; i < i_ed; i++) { - xpal[i].pixel = PIX24((pal->red [i]*lv)>>8, - (pal->green [i]*lv)>>8, - (pal->blue [i]*lv)>>8); - } - } else { - lv -= 255; - for (i = i_st; i < i_ed; i++) { - r = pal->red[i]; - g = pal->green[i]; - b = pal->blue[i]; - xpal[i].pixel = PIX24((((255-r)*lv)>>8)+r, - (((255-g)*lv)>>8)+g, - (((255-b)*lv)>>8)+b); - } - } - break; - default: - WARNING("Unknown depth\n"); - break; - } - nact->sys_pal_changed = FALSE; -} - - -/* 色の拡大 */ -void image_expandPixel(agsurface_t *img_src, agsurface_t *img_dst, int lv) { - static int prelv = 0; - if (img_src->depth != 8) return; - - if (nact->sys_pal_changed || prelv != lv) trans_index2pixels(img_dst->depth, lv, NULL); - - switch(img_dst->bytes_per_pixel) { - case 2: - expandPixel8to16(img_src, img_dst); - break; - case 3: - expandPixel8to24p(img_src, img_dst); - break; - case 4: - expandPixel8to24(img_src, img_dst); - break; - default: - break; - } - prelv = lv; -} - -/* - * 拡大・縮小コピー - */ -void image_scaledCopyArea(agsurface_t *src, agsurface_t *dst, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mirror) { - float a1, a2, xd, yd; - int *row, *col; - int x, y; - BYTE *sdata, *ddata; - agsurface_t *srccpy = NULL; - - /* src が NULL の場合,領域が重なる場合を考えて copy を作る */ - if (src == NULL) { - srccpy = image_saveRegion(dst, sx, sy, sw, sh); - src = srccpy; - sx = sy = 0; - } - - sdata = GETOFFSET_PIXEL(src, sx, sy); - ddata = GETOFFSET_PIXEL(dst, dx, dy); - - a1 = (float)sw / (float)dw; - a2 = (float)sh / (float)dh; - // src width と dst width が同じときに問題があるので+1 - row = calloc(dw+1, sizeof(int)); - // 1おおきくして初期化しないと col[dw-1]とcol[dw]が同じになる - // 可能性がある。 - col = calloc(dh+1, sizeof(int)); - - if (mirror & 1) { - /* 上下反転 added by tajiri@wizard */ - for (yd = sh - a2, y = 0; y < dh; y++) { - col[y] = yd; yd -= a2; - } - } else { - for (yd = 0.0, y = 0; y < dh; y++) { - col[y] = yd; yd += a2; - } - } - if (mirror & 2) { - /* 左右反転 added by tajiri@wizard */ - for (xd = sw - a1, x = 0; x < dw; x++) { - row[x] = xd; xd -= a1; - } - } else { - for (xd = 0.0, x = 0; x < dw; x++) { - row[x] = xd; xd += a1; - } - } - -#define SCALEDCOPYAREA(type) { \ - int x, y; \ - type *sl, *dl; \ - BYTE *_sl, *_dl; \ - for (y = 0; y < dh; y++) { \ - sl = (type *)(sdata + *(y + col) * src->bytes_per_line);\ - dl = (type *)(ddata + y * dst->bytes_per_line);\ - for (x = 0; x < dw; x++) { \ - *(dl + x) = *(sl + *(row + x)); \ - } \ - _dl = (BYTE *)dl; \ - while(*(col + y) == *(col + y + 1)) { \ - _sl = _dl; \ - _dl += dst->bytes_per_line; \ - memcpy(_dl, _sl, dw * sizeof(type)); \ - y++; \ - } \ - }} - - switch(dst->depth) { - case 8: - SCALEDCOPYAREA(BYTE); break; - case 15: - case 16: - SCALEDCOPYAREA(WORD); break; - case 24: - case 32: - SCALEDCOPYAREA(DWORD); break; - default: - break; - } - - free(row); - free(col); - - if (srccpy != NULL) { - image_delRegion(srccpy); - } -} - -/* - * dibに8bitCGの描画 - */ -void image_drawImage8_fromData(agsurface_t *dib, cgdata *cg, int dx, int dy, int w, int h) { -#define DRAWSPRITEFROMDATA8(type) { \ - int x, y; \ - BYTE *pic_src = cg->pic + cg->data_offset; \ - BYTE *pic_dst = GETOFFSET_PIXEL(dib, dx, dy); \ - type *yl; \ - for (y = 0; y < h; y++) { \ - yl = (type *)(pic_dst + y * dib->bytes_per_line);\ - for (x = 0; x < w; x++) { \ - if (*pic_src != (BYTE)cg->spritecolor) { \ - *yl = xpal[(*pic_src)].pixel; \ - } \ - yl++; pic_src++; \ - } \ - pic_src += (cg->width - w); \ - }} -#define DRAWIMAGEFROMDATA8(type) { \ - int x, y; \ - BYTE *pic_src = cg->pic + cg->data_offset; \ - BYTE *pic_dst = GETOFFSET_PIXEL(dib, dx, dy); \ - type *yl; \ - for (y = 0; y bytes_per_line);\ - for (x = 0; x < w; x++) { \ - *yl = xpal[(*pic_src)].pixel; \ - yl++; pic_src++; \ - } \ - pic_src += (cg->width - w); \ - }} - - if (cg->spritecolor >= 0) { - switch(dib->depth) { - case 8: - { - int x, y; - BYTE *pic_src = cg->pic + cg->data_offset; - BYTE *pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *yl; - for (y = 0; y < h; y++) { - yl = (BYTE *)(pic_dst + y * dib->bytes_per_line); - for (x = 0; x < w; x++) { - if (*pic_src != (BYTE)cg->spritecolor) { - *yl = (*pic_src); - } - yl++; pic_src++; - } - pic_src += (cg->width - w); - } - break; - } - case 15: - case 16: - if (nact->sys_pal_changed) - trans_index2pixels(dib->depth, cg->alphalevel, cg); - DRAWSPRITEFROMDATA8(WORD); break; - case 24: - case 32: - if (nact->sys_pal_changed) - trans_index2pixels(dib->depth, cg->alphalevel, cg); - DRAWSPRITEFROMDATA8(DWORD); break; - default: - break; - } - } else { - switch(dib->depth) { - case 8: - { - int y; - BYTE* pic_src = cg->pic + cg->data_offset; - BYTE* pic_dst = GETOFFSET_PIXEL(dib, dx, dy); - - for (y = 0; y < h; y++) { - memcpy(pic_dst, pic_src, w); - pic_src += cg->width; - pic_dst += dib->bytes_per_line; - } - break; - } - case 15: - case 16: - if (nact->sys_pal_changed) - trans_index2pixels(dib->depth, cg->alphalevel, cg); - DRAWIMAGEFROMDATA8(WORD); break; - case 24: - case 32: - if (nact->sys_pal_changed) - trans_index2pixels(dib->depth, cg->alphalevel, cg); - DRAWIMAGEFROMDATA8(DWORD); break; - default: - break; - } - } -} - -/* - * dibに16bitCGの描画 - */ -void image_drawImage16_fromData(agsurface_t *dib, cgdata *cg, int x, int y, int w, int h) { - BYTE *pic_save = NULL; - - /* set alpha Level */ - if (cg->alphalevel != 255) { - pic_save = cg->pic; - cg->pic = changeImage16AlphaLevel(cg); - } - - if (cg->spritecolor >= 0) { - draw_sprite16_from_data(dib, cg, x, y, w, h); - } else { - draw_image16_from_data(dib, cg, x, y, w, h); - } - - if (cg->alphalevel != 255) { - free(cg->pic); - cg->pic = pic_save; - } -} - -/* - * dib に矩形を描画 - */ -void image_drawRectangle(agsurface_t *dib, int x, int y, int w, int h, int col) { - draw_rectangle(dib, x, y, w, h, col); -} - -/* - * dib の指定領域をコピー - */ -void image_copyArea(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy) { - copy_area(dib, sx, sy, w, h, dx, dy); -} - -/* - * 16bit専用の dib の指定領域コピー alphaつき - */ -void image_copyAreaSP16_shadow(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int lv) { - BYTE *sdata = GETOFFSET_PIXEL(dib, sx, sy); - BYTE *ddata = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *adata = GETOFFSET_ALPHA(dib, sx, sy); - - copy_area_ablend_sda(dib, sdata, ddata, w, h, adata, lv); -} - -/* - * 16bit専用の dib の指定領域コピー - * srcのイメージを lvの明度でコピー CE 2001 - */ -void image_copyAreaSP16_alphaBlend(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int lv) { - BYTE *sdata = GETOFFSET_PIXEL(dib, sx, sy); - BYTE *ddata = GETOFFSET_PIXEL(dib, dx, dy); - - copy_area_ablend_sd(dib, sdata, ddata, w, h, lv); -} - -void image_copyAreaSP16_alphaLevel(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int lv) { - BYTE *sdata = GETOFFSET_PIXEL(dib, sx, sy); - BYTE *ddata = GETOFFSET_PIXEL(dib, dx, dy); - - copy_area_alevel(dib, sdata, ddata, w, h, lv); -} - -void image_copyAreaSP16_whiteLevel(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int lv) { - BYTE *sdata = GETOFFSET_PIXEL(dib, sx, sy); - BYTE *ddata = GETOFFSET_PIXEL(dib, dx, dy); - - copy_area_wlevel(dib, sdata, ddata, w, h, lv); -} - - -/* - * 指定範囲にパレット col を rate の割合で重ねる CK1 - */ -void image_wrapColor(agsurface_t *dib, int sx, int sy, int w, int h, int col, int rate) { - BYTE *sdata = GETOFFSET_PIXEL(dib, sx, sy); - - wrap_color(dib, sdata, w, h, col, rate); -} - -/* - * dib のピクセル情報を取得 - */ -void image_getPixel(agsurface_t *dib, int x, int y, Palette *cell) { - BYTE *dst = GETOFFSET_PIXEL(dib, x, y); - - switch(dib->depth) { - case 8: - cell->pixel = *dst; break; - case 15: - cell->r = PIXR15(*(WORD *)dst); - cell->g = PIXG15(*(WORD *)dst); - cell->b = PIXB15(*(WORD *)dst); - break; - case 16: - cell->r = PIXR16(*(WORD *)dst); - cell->g = PIXG16(*(WORD *)dst); - cell->b = PIXB16(*(WORD *)dst); - break; - case 24: - case 32: - cell->r = PIXR24(*(DWORD *)dst); - cell->g = PIXG24(*(DWORD *)dst); - cell->b = PIXB24(*(DWORD *)dst); - break; - default: - break; - } -} - -/* - * dib から領域の切り出し - */ -agsurface_t* image_saveRegion(agsurface_t *dib, int x, int y, int w, int h) { - agsurface_t *i = malloc(sizeof(agsurface_t)); - int j; - BYTE *ys = GETOFFSET_PIXEL(dib, x, y); - BYTE *yd; - - // printf("save region %d,%d,%d,%d\n", x, y, w, h); - - i->width = w; - i->height = h; - i->bytes_per_line = w * dib->bytes_per_pixel; - i->bytes_per_pixel = dib->bytes_per_pixel; - i->pixel = yd = malloc(sizeof(char) * (w * h * dib->bytes_per_pixel)); - - for (j = 0; j < h; j++) { - memcpy(yd, ys, w * dib->bytes_per_pixel); - yd += (w * dib->bytes_per_pixel); - ys += dib->bytes_per_line; - } - return i; -} - -/* - * dib にセーブした領域を回復 - */ -void image_putRegion(agsurface_t *dib, agsurface_t *dst, int x, int y) { - BYTE *yd = GETOFFSET_PIXEL(dib, x, y); - BYTE *ys = GETOFFSET_PIXEL(dst, 0, 0); - int i; - int width, height; - - width = dst->width; - height = dst->height; - - if (x + width > dib->width) width = dib->width - x; - if (y + height > dib->height) height = dib->height - y; - - // printf("dibinfo %d, %d\n", dib->width, dib->height); - // printf("reginfo %d, %d\n", dst->width, dst->height); - // printf("width,height %d, %d\n", width, height); - - for (i = 0; i < height; i++) { - memcpy(yd, ys, width * dst->bytes_per_pixel); - ys += (dst->width * dst->bytes_per_pixel); - yd += dib->bytes_per_line; - } -} - -/* - * dib に dstを描画後、後始末 - */ -void image_restoreRegion(agsurface_t *dib, agsurface_t *dst, int x, int y) { - image_putRegion(dib, dst, x, y); - free(dst->pixel); - free(dst); -} - -/* - * save した領域の解放 - */ -void image_delRegion(agsurface_t *r) { - free(r->pixel); - free(r); -} - - -/* - * dib にセーブした領域からコピー - */ -void image_copyRegion(agsurface_t *src, int sx, int sy, int w, int h, agsurface_t *dib, int dx, int dy) { - int y; - BYTE *sdata = GETOFFSET_PIXEL(src, sx, sy); - BYTE *ddata = GETOFFSET_PIXEL(dib, dx, dy); - - for (y = 0; y < h; y++) { - memcpy(ddata, sdata, w * dib->bytes_per_pixel); - sdata += src->bytes_per_line; - ddata += dib->bytes_per_line; - } -} - - -/* - * dibに gpyphイメージを描画 - */ -void image_getGlyphImage(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - switch(glyph->bytes_per_pixel) { - case 1: - image_getGlyphImage8to8(dib, glyph, dx, dy, col); break; - case 2: - image_getGlyphImage16to16(dib, glyph, dx, dy, col); break; - case 3: - image_getGlyphImage24pto24(dib, glyph, dx, dy, col); break; - case 4: - image_getGlyphImage24to24(dib, glyph, dx, dy, col); break; - default: - break; - } -} - -/* - * img : 8bit DIB の先頭 - * glyph : 文字の書かれているイメージ (大きさ込) depth 15/16 - * dx, dy : 表示位置 - * col : 色 - */ -static void image_getGlyphImage16to8(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = GETOFFSET_PIXEL(glyph, 0, 0); - BYTE *yd; - WORD *ys; - - for (y = 0; y < glyph->height; y++) { - ys = (WORD *)(src + y * glyph->bytes_per_line); - yd = dst + y * dib->bytes_per_line; - for (x = 0; x < glyph->width; x++) { - if (*ys != 0) { - *yd = col; - } - ys++; yd++; - } - } -} - -static void image_getGlyphImage24to8(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = GETOFFSET_PIXEL(glyph, 0, 0); - BYTE *yd; - DWORD *ys; - - for (y = 0; y < glyph->height; y++) { - ys = (DWORD *)(src + y * glyph->bytes_per_line); - yd = dst + y * dib->bytes_per_line; - for (x = 0; x < glyph->width; x++) { - if (*ys == 1) { - *yd = col; - } - ys++; yd++; - } - } -} - -static void image_getGlyphImage24pto8(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - int x, y; - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); - BYTE *src = GETOFFSET_PIXEL(glyph, 0, 0); - BYTE *yd; - BYTE *ys; - - for (y = 0; y < glyph->height; y++) { - ys = (BYTE *)(src + y * glyph->bytes_per_line); - yd = dst + y * dib->bytes_per_line; - for (x = 0; x < glyph->width; x++) { - if (*ys == 1) { - *yd = col; - } - ys+=3; yd++; - } - } -} - -void image_getGlyphImageNto8(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col) { - switch(glyph->bytes_per_pixel) { - case 2: - image_getGlyphImage16to8(dib, glyph, dx, dy, col); break; - case 3: - image_getGlyphImage24pto8(dib, glyph, dx, dy, col); break; - case 4: - image_getGlyphImage24to8(dib, glyph, dx, dy, col); break; - } -} - - -/* - * dib に指定のパレット sp を抜いてコピー - */ -void image_copyAreaSP(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int col) { - BYTE *sdata = GETOFFSET_PIXEL(dib, sx, sy); - BYTE *ddata = GETOFFSET_PIXEL(dib, dx, dy); - - copy_area_sprite(dib, sdata, ddata, w, h, col); -} - -void image_get_glyph(agsurface_t *gls, agsurface_t *gld) { - BYTE *dst = GETOFFSET_PIXEL(gld, 0, 0); - int x, y; - int dw = gls->width, dh = gls->height; - - switch(gls->bytes_per_pixel) { - case 1: - { - BYTE *src = GETOFFSET_PIXEL(gls, 0, 0); - for (y = 0; y < dh; y++) { - memcpy(dst, src, dw); - src += gls->bytes_per_line; - dst += gld->bytes_per_line; - } - break; - } - case 2: - { - WORD *src; - for (y = 0; y < dh; y++) { - src = (WORD *)(gls->pixel + y * gls->bytes_per_line); - dst = (BYTE *)(gld->pixel + y * gld->bytes_per_line); - for (x = 0; x < dw; x++) { - *dst = (*src) ? 1 : 0; - src++; dst++; - } - } - break; - } - case 3: - { - BYTE *src; - for (y = 0; y < dh; y++) { - src = (BYTE *)(gls->pixel + y * gls->bytes_per_line); - dst = (BYTE *)(gld->pixel + y * gld->bytes_per_line); - for (x = 0; x < dw; x++) { - *dst = (*src) ? 1 : 0; - src+=3; dst++; - } - } - break; - } - case 4: - { - DWORD *src; - for (y = 0; y < dh; y++) { - src = (DWORD *)(gls->pixel + y * gls->bytes_per_line); - dst = (BYTE *)(gld->pixel + y * gld->bytes_per_line); - for (x = 0; x < dw; x++) { - *dst = (*src) ? 1 : 0; - src++; dst++; - } - } - break; - } - } -} - -void image_draw_antialiased_pattern(agsurface_t *dib, agsurface_t *pattern, int dx, int dy, int dw, int dh, int col) { - draw_antialiased_pattern(dib, pattern, dx, dy, dw, dh, col); -} - -void image_draw_pattern(agsurface_t *dib, agsurface_t *pattern, int dx, int dy, int dw, int dh, int col) { -#define DRAWPATTERN(type) { \ - int x, y; \ - BYTE *dst = GETOFFSET_PIXEL(dib, dx, dy); \ - BYTE *src = (BYTE *)pattern->pixel; \ - type *yd; \ - BYTE *ys; \ - for (y = 0; y < dh; y++) { \ - ys = (BYTE *)(src + y * pattern->bytes_per_line); \ - yd = (type *)(dst + y * dib->bytes_per_line); \ - for (x = 0; x < dw; x++) { \ - if (*ys) { \ - *yd = col; \ - } \ - ys++; yd++; \ - } \ - }} - - switch(dib->depth) { - case 8: - DRAWPATTERN(BYTE); break; - case 15: - case 16: - DRAWPATTERN(WORD); break; - case 24: - case 32: - DRAWPATTERN(DWORD); break; - } -} diff --git a/src/xcore_image.h b/src/xcore_image.h deleted file mode 100644 index 36a24a4..0000000 --- a/src/xcore_image.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * image.h image操作 - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: image.h,v 1.24 2003/01/12 10:48:50 chikama Exp $ */ - -#ifndef __XCORE_IMAGE__ -#define __XCORE_IMAGE__ - -#include "cg.h" -#include "ags.h" - -extern void xcore_image_setdepth(int); -extern void image_expandPixel(agsurface_t *img_src, agsurface_t *img_dst, int lv); -extern void image_scaledCopyArea(agsurface_t *dib, agsurface_t *src, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, int mirror); - -extern void image_drawImage8_fromData(agsurface_t *img, cgdata *cg, int x, int y, int w, int h); -extern void image_drawImage16_fromData(agsurface_t *img, cgdata *cg, int x, int y, int w, int h); -extern void image_drawRectangle(agsurface_t *dib, int x, int y, int w, int h, int col); -extern void image_copyArea(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy); -extern void image_copyAreaSP(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int col); -extern void image_copyAreaSP16_shadow(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int lv); -extern void image_copyAreaSP16_alphaBlend(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int col); -extern void image_copyAreaSP16_alphaLevel(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int col); -extern void image_copyAreaSP16_whiteLevel(agsurface_t *dib, int sx, int sy, int w, int h, int dx, int dy, int col); -extern void image_wrapColor(agsurface_t *dib, int sx, int sy, int w, int h, int col, int rate); -extern void image_getPixel(agsurface_t *dib, int x, int y, Palette *cell); - -extern agsurface_t* image_saveRegion(agsurface_t *dib, int x, int y, int w, int h); -extern void image_putRegion(agsurface_t *dib, agsurface_t *dst, int x, int y); -extern void image_restoreRegion(agsurface_t *dib, agsurface_t *dst, int x, int y); -extern void image_copyRegion(agsurface_t *src, int sx, int sy, int w, int h, agsurface_t *dib, int dx, int dy); -extern void image_delRegion(agsurface_t *r); - -extern void image_getGlyphImage(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col); -extern void image_getGlyphImageNto8(agsurface_t *dib, agsurface_t *glyph, int dx, int dy, int col); -extern void image_changeColorArea8(agsurface_t *dib, int sx, int sy, int w, int h, int src, int dst, int cnt); -extern void image_get_glyph(agsurface_t *gls, agsurface_t *gld); -extern void image_draw_antialiased_pattern(agsurface_t *dib, agsurface_t *pattern, int dx, int dy, int dw, int dh, int col); -extern void image_draw_pattern(agsurface_t *dib, agsurface_t *pattern, int dx, int dy, int dw, int dh, int col); -extern void image_trans_pixel_24to24p(agsurface_t *src, agsurface_t *dst); - -#endif /* __XCORE_IMAGE__ */ - diff --git a/src/xcore_input.c b/src/xcore_input.c deleted file mode 100644 index 0d63483..0000000 --- a/src/xcore_input.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * xcore_input.c キー入力処理 - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore_input.c,v 1.13 2003/04/25 17:23:55 chikama Exp $ */ - -#include "key.h" -#include -#include "ags.h" - - -boolean RawKeyInfo[256]; -static int convertKeyCode(unsigned int keycode); -static void keyEventProsess(XKeyEvent *e); -static void buttonEventProcess(XButtonEvent *e); - - -static void keyEventProsess(XKeyEvent *e) { - agsevent_t agse; - boolean bool; - int code = convertKeyCode(e->keycode); - - if (e->type == KeyPress) { - bool = TRUE; - agse.type = AGSEVENT_KEY_PRESS; - } else { - bool = FALSE; - agse.type = AGSEVENT_KEY_RELEASE; - } - - RawKeyInfo[code] = bool; - - if (nact->ags.eventcb) { - agse.d1 = e->x; - agse.d2 = e->y; - agse.d3 = code; - nact->ags.eventcb(&agse); - } -} - -static void buttonEventProcess(XButtonEvent *e) { - agsevent_t agse; - boolean bool; - - if (e->type == ButtonPress) { - bool = TRUE; - agse.type = AGSEVENT_BUTTON_PRESS; - } else { - bool = FALSE; - agse.type = AGSEVENT_BUTTON_RELEASE; - } - - switch(e->button) { - case Button1: - RawKeyInfo[KEY_MOUSE_LEFT] = bool; - agse.d3 = AGSEVENT_BUTTON_LEFT; - break; - case Button2: - RawKeyInfo[KEY_MOUSE_MIDDLE] = bool; - agse.d3 = AGSEVENT_BUTTON_MID; - break; - case Button3: - RawKeyInfo[KEY_MOUSE_RIGHT] = bool; - agse.d3 = AGSEVENT_BUTTON_RIGHT; - break; - case Button4: - agse.d3 = AGSEVENT_WHEEL_UP; - break; - case Button5: - agse.d3 = AGSEVENT_WHEEL_DN; - break; - default: - break; - } - - if (nact->ags.eventcb) { - agse.d1 = e->x; - agse.d2 = e->y; - nact->ags.eventcb(&agse); - } -} - -static int convertKeyCode(unsigned int keycode) { - KeySym sym = XkbKeycodeToKeysym(x11_display, keycode, 0, 0); - switch(sym) { - case XK_BackSpace: - return KEY_BS; - case XK_Tab: - return KEY_TAB; - case XK_Clear: - return KEY_CLEAR; - case XK_Return: - case XK_KP_Enter: - return KEY_ENTER; - case XK_Shift_L: - case XK_Shift_R: - return KEY_SHIFT; - case XK_Control_L: - case XK_Control_R: - return KEY_CTRL; - case XK_Alt_L: - case XK_Alt_R: - return KEY_ALT; - case XK_Pause: - return KEY_PAUSE; - case XK_Caps_Lock: - return KEY_CAPSLOCK; - case XK_Kanji: - return KEY_KANAKAN; - case XK_Escape : - return KEY_ESC; - case XK_space: - return KEY_SPACE; - case XK_Page_Up: - return KEY_PAGEUP; - case XK_Page_Down: - return KEY_PAGEDOWN; - case XK_End: - return KEY_END; - case XK_Home: - return KEY_HOME; - case XK_Left: - return KEY_LEFT; - case XK_Up: - return KEY_UP; - case XK_Right: - return KEY_RIGHT; - case XK_Down: - return KEY_DOWN; - case XK_Select: - return KEY_SELECT; - case XK_Execute: - return KEY_EXECUTE; - case XK_Print: - return KEY_PRINTSCREEN; - case XK_Insert: - return KEY_INS; - case XK_Delete: - return KEY_DEL; - case XK_Help: - return KEY_HELP; - case XK_0: - return KEY_0; - case XK_1: - return KEY_1; - case XK_2: - return KEY_2; - case XK_3: - return KEY_3; - case XK_4: - return KEY_4; - case XK_5: - return KEY_5; - case XK_6: - return KEY_6; - case XK_7: - return KEY_7; - case XK_8: - return KEY_8; - case XK_9: - return KEY_9; - case XK_a: - case XK_A: - return KEY_A; - case XK_b: - case XK_B: - return KEY_B; - case XK_c: - case XK_C: - return KEY_C; - case XK_d: - case XK_D: - return KEY_D; - case XK_e: - case XK_E: - return KEY_E; - case XK_f: - case XK_F: - return KEY_F; - case XK_g: - case XK_G: - return KEY_G; - case XK_h: - case XK_H: - return KEY_H; - case XK_i: - case XK_I: - return KEY_I; - case XK_j: - case XK_J: - return KEY_J; - case XK_k: - case XK_K: - return KEY_K; - case XK_l: - case XK_L: - return KEY_L; - case XK_m: - case XK_M: - return KEY_M; - case XK_n: - case XK_N: - return KEY_N; - case XK_o: - case XK_O: - return KEY_O; - case XK_p: - case XK_P: - return KEY_P; - case XK_q: - case XK_Q: - return KEY_Q; - case XK_r: - case XK_R: - return KEY_R; - case XK_s: - case XK_S: - return KEY_S; - case XK_t: - case XK_T: - return KEY_T; - case XK_u: - case XK_U: - return KEY_U; - case XK_v: - case XK_V: - return KEY_V; - case XK_w: - case XK_W: - return KEY_W; - case XK_x: - case XK_X: - return KEY_X; - case XK_y: - case XK_Y: - return KEY_Y; - case XK_z: - case XK_Z: - return KEY_Z; - case XK_KP_Insert: - case XK_KP_0: - return KEY_PAD_0; - case XK_KP_End: - case XK_KP_1: - return KEY_PAD_1; - case XK_KP_Down: - case XK_KP_2: - return KEY_PAD_2; - case XK_KP_Page_Down: - case XK_KP_3: - return KEY_PAD_3; - case XK_KP_Left: - case XK_KP_4: - return KEY_PAD_4; - case XK_KP_5: - return KEY_PAD_5; - case XK_KP_Right: - case XK_KP_6: - return KEY_PAD_6; - case XK_KP_Home: - case XK_KP_7: - return KEY_PAD_7; - case XK_KP_Up: - case XK_KP_8: - return KEY_PAD_8; - case XK_KP_Page_Up: - case XK_KP_9: - return KEY_PAD_9; - case XK_KP_Multiply: - return KEY_PAD_STAR; - case XK_KP_Add: - return KEY_PAD_PLUS; - case XK_KP_Separator: - return KEY_PAD_SEP; - case XK_KP_Subtract: - return KEY_PAD_MINUS; - case XK_KP_Delete: - return KEY_PAD_DOT; - case XK_KP_Divide: - return KEY_PAD_SLASH; - case XK_F1: - return KEY_F1; - case XK_F2: - return KEY_F2; - case XK_F3: - return KEY_F3; - case XK_F4: - return KEY_F4; - case XK_F5: - return KEY_F5; - case XK_F6: - return KEY_F6; - case XK_F7: - return KEY_F7; - case XK_F8: - return KEY_F8; - case XK_F9: - return KEY_F9; - case XK_F10: - return KEY_F10; - case XK_F11: - return KEY_F11; - case XK_F12: - return KEY_F12; - case XK_F13: - return KEY_F13; - case XK_F14: - return KEY_F14; - case XK_F15: - return KEY_F15; - case XK_F16: - return KEY_F16; - case XK_F17: - return KEY_F17; - case XK_F18: - return KEY_F18; - case XK_F19: - return KEY_F19; - case XK_F20: - return KEY_F20; - case XK_F21: - return KEY_F21; - case XK_F22: - return KEY_F22; - case XK_F23: - return KEY_F23; - case XK_F24: - return KEY_F24; - case XK_Num_Lock: - return KEY_NUMLOCK; - case XK_Scroll_Lock: - return KEY_SCROLL_LOCK; - default: - return KEY_UNDEFINED; - } - return KEY_UNDEFINED; -} diff --git a/src/xcore_maskupdate.c b/src/xcore_maskupdate.c deleted file mode 100644 index 95f975e..0000000 --- a/src/xcore_maskupdate.c +++ /dev/null @@ -1,372 +0,0 @@ -/* - * xcore_maskupdate.c X11 mask 付き update - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore_maskupdate.c,v 1.4 2002/05/02 17:21:32 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#include "portab.h" -#include "xcore_private.h" - -static Pixmap maskpix; /* clipmask 用 Bitmap */ -static Pixmap clippix; /* copy 元 Pixmap */ -static Pixmap savepix; /* copy 先 Pixmap */ -static Pixmap doublepix;/* double buffer 用 Pixmap */ -static GC maskgc; /* clipmask Bitmap 用 GC */ - -static void draw_5star(double mul, double rad, int off_x, int off_y); -static void draw_6star(double mul, double rad, int off_x, int off_y); -static void draw_windwheel_90(double rad, int r, int off_x, int off_y); -static void draw_windwheel_180(double rad, int r, int off_x, int off_y); -static void draw_windwheel_360(double rad, int r, int off_x, int off_y); - -/* - * 五芒星を描く - * mul : 倍率 (1 で 100 * 100) の星が描かれる - * rad : 回転角度(radian) - * off_x: 中心座標の x 方向 offset - * off_y: 中心座標の y 方向 offset - */ -static void draw_5star(double mul, double rad, int off_x, int off_y) { - static XPoint pt[] = { - { 0, -50}, - {-29, 40}, - { 47, -15}, - {-47, -15}, - { 29, 40} - }; - XPoint p[5]; - int i; - - /* - * x' cos(X) -sin(X) mul 0 x - * = * * - * y' sin(X) cos(X) 0 mul y - */ - for (i = 0; i < 5; i++) { - p[i].x = mul * (pt[i].x * cos(rad) - pt[i].y * sin(rad)) + off_x; - p[i].y = mul * (pt[i].x * sin(rad) + pt[i].y * cos(rad)) + off_y; - } - - XFillPolygon(x11_display, maskpix, maskgc, p, 5, Complex, CoordModeOrigin); -} - -/* - * 六芒星を描く - * mul : 倍率 (1 で 100 * 100) の星が描かれる - * rad : 回転角度(radian) - * off_x: 中心座標の x 方向 offset - * off_y: 中心座標の y 方向 offset - */ -static void draw_6star(double mul, double rad, int off_x, int off_y) { - static XPoint pt1[] = { - { 0, -50}, - {-43, 25}, - { 43, 25} - }; - static XPoint pt2[] = { - {-43, -25}, - { 0, 50}, - { 43, -25} - }; - XPoint p[3]; - int i; - - for (i = 0; i < 3; i++) { - p[i].x = mul * (pt1[i].x * cos(rad) - pt1[i].y * sin(rad)) + off_x; - p[i].y = mul * (pt1[i].x * sin(rad) + pt1[i].y * cos(rad)) + off_y; - } - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); - - for (i = 0; i < 3; i++) { - p[i].x = mul * (pt2[i].x * cos(rad) - pt2[i].y * sin(rad)) + off_x; - p[i].y = mul * (pt2[i].x * sin(rad) + pt2[i].y * cos(rad)) + off_y; - } - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); -} - -/* - * 扇型の中心角 (てきとー) - * 0.2 radian - */ -#define WHEELDELTA 0.2 - -/* - * 風車90° - * rad : 回転角 (radian) 0 - pi/2 - * r : 半径 - * off_x: 中心座標の x 方向 offset - * off_y: 中心座標の y 方向 offset - */ -static void draw_windwheel_90(double rad, int r, int off_x, int off_y) { - XPoint p[3]; - - p[0].x = 0 + off_x; - p[0].y = 0 + off_y; - - p[1].x = r * sin(rad) + off_x; - p[1].y = -r * cos(rad) + off_y; - - p[2].x = r * sin(rad + WHEELDELTA) + off_x; - p[2].y = -r * cos(rad + WHEELDELTA) + off_y; - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); - - p[1].x = r * cos(rad) + off_x; - p[1].y = r * sin(rad) + off_y; - - p[2].x = r * cos(rad + WHEELDELTA) + off_x; - p[2].y = r * sin(rad + WHEELDELTA) + off_y; - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); - - p[1].x = -r * sin(rad) + off_x; - p[1].y = r * cos(rad) + off_y; - - p[2].x = -r * sin(rad + WHEELDELTA) + off_x; - p[2].y = r * cos(rad + WHEELDELTA) + off_y; - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); - p[1].x = -r * cos(rad) + off_x; - p[1].y = -r * sin(rad) + off_y; - - p[2].x = -r * cos(rad + WHEELDELTA) + off_x; - p[2].y = -r * sin(rad + WHEELDELTA) + off_y; - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); -} - -/* - * 風車180° - * rad : 回転角 (radian) 0 - pi - * r : 半径 - * off_x: 中心座標の x 方向 offset - * off_y: 中心座標の y 方向 offset - */ -static void draw_windwheel_180(double rad, int r, int off_x, int off_y) { - XPoint p[3]; - - p[0].x = 0 + off_x; - p[0].y = 0 + off_y; - - - p[1].x = -r * cos(rad) + off_x; - p[1].y = -r * sin(rad) + off_y; - - p[2].x = -r * cos(rad + WHEELDELTA) + off_x; - p[2].y = -r * sin(rad + WHEELDELTA) + off_y; - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); - - p[1].x = r * cos(rad) + off_x; - p[1].y = r * sin(rad) + off_y; - - p[2].x = r * cos(rad + WHEELDELTA) + off_x; - p[2].y = r * sin(rad + WHEELDELTA) + off_y; - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); -} - -/* - * 風車180° - * rad : 回転角 (radian) 0 - 2pi - * r : 半径 - * off_x: 中心座標の x 方向 offset - * off_y: 中心座標の y 方向 offset - */ -static void draw_windwheel_360(double rad, int r, int off_x, int off_y) { - XPoint p[3]; - - p[0].x = 0 + off_x; - p[0].y = 0 + off_y; - - p[1].x = -r * cos(rad) + off_x; - p[1].y = -r * sin(rad) + off_y; - - p[2].x = -r * cos(rad + WHEELDELTA) + off_x; - p[2].y = -r * sin(rad + WHEELDELTA) + off_y; - - XFillPolygon(x11_display, maskpix, maskgc, p, 3, Convex, CoordModeOrigin); - -} - -/* - * マスク付き領域更新 - * sx: コピー元 x 座標 - * sy: コピー元 y 座標 - * w : コピー元 width - * h : コピー元 height - * dx: コピー先 x 座標 - * dy: コピー先 y 座標 - * func: マスク種類 - * 44: 五芒星(内->外) - * 45: 五芒星(外->内) - * 46: 六芒星(内->外) - * 47: 六芒星(外->内) - * 50: 風車90° - * 51: 風車180° - * 52: 風車360° - * step: 呼び出し番号 0 - 256 - */ -void Xcore_maskupdate(int sx, int sy, int w, int h, int dx, int dy, int func, int step) { - GC gc; - - dx -= view_x; - dy -= view_y; - - if (step == 0) { - /* 最初にいろいろと準備 */ - XSync(x11_display, False); - /* コピー元を DIB から pixmap に持って来る */ - clippix = x11_clip_from_DIB(sx, sy, w, h); - - /* clip mask 用 Pixmap の生成 */ - maskpix = XCreatePixmap(x11_display, x11_window, w, h, 1); - maskgc = XCreateGC(x11_display, maskpix, None, NULL); - - /* clipmask 用 Pixmap の初期化 */ - XSetForeground(x11_display, maskgc, 0); - XFillRectangle(x11_display, maskpix, maskgc, 0, 0, w, h); - - /* 線が交差するときの塗りつぶしのルールを設定 */ - XSetFillRule(x11_display, maskgc, WindingRule); - - /* 更新先の Window の領域を保存 */ - savepix = XCreatePixmap(x11_display, x11_window, w, h, WIN_DEPTH); - XCopyArea(x11_display, x11_window, savepix, x11_gc_pix, - winoffset_x + dx, winoffset_y + dy, w, h, 0, 0); - - /* ダブルバッファ用に Pixmap を確保 */ - doublepix = XCreatePixmap(x11_display, x11_window, w, h, WIN_DEPTH); - XCopyArea(x11_display, x11_window, doublepix, x11_gc_pix, - winoffset_x + dx, winoffset_y + dy, w, h, 0, 0); - - XSync(x11_display, False); - return; - } else if (step == 256) { - /* 最後に後始末 */ -#if 0 - XCopyArea(x11_display, clippix, x11_window, x11_gc_pix, - 0, 0, w, h, winoffset_x + dx, winoffset_y + dy); -#endif -#if 0 - XCopyArea(x11_display, clippix, x11_pixmap, x11_gc_pix, - 0, 0, w, h, winoffset_x + dx, winoffset_y + dy); - ags_updateFull(); -#endif - ags_copyArea(sx, sy, w, h, dx + view_x, dy + view_y); - ags_updateArea(dx + view_x, dy + view_y, w, h); - XFreePixmap(x11_display, maskpix); - - XFreePixmap(x11_display, clippix); - XFreePixmap(x11_display, savepix); - XFreePixmap(x11_display, doublepix); - XFreeGC(x11_display, maskgc); - - return; - } - - /* clipmask 用の GC を生成 (毎回生成しなくても良いかも?) */ - gc = XCreateGC(x11_display, clippix, None, NULL); - XSetClipMask(x11_display, gc, maskpix); - XSetClipOrigin(x11_display, gc, 0, 0); - - switch(func) { - case 44: - case 46: - /* 内から外へ */ - XSetForeground(x11_display, maskgc, 0); - XFillRectangle(x11_display, maskpix, maskgc, 0, 0, w, h); - XSetForeground(x11_display, maskgc, 1); - break; - case 45: - case 47: - /* 外から内へ */ - XSetForeground(x11_display, maskgc, 1); - XFillRectangle(x11_display, maskpix, maskgc, 0, 0, w, h); - XSetForeground(x11_display, maskgc, 0); - break; - default: - XSetForeground(x11_display, maskgc, 1); - } - - /* mask を描画 */ - switch(func) { - case 44: - draw_5star(1.5 * (max(w,h) * step) / (256 * 50.0), - 1.0 * M_PI * step / 256, w/2, h/2); - break; - - case 45: - draw_5star(1.5 * (max(w,h) * (256-step)) / (256 * 50.0), - 1.0 * M_PI * step / 256, w/2, h/2); - break; - - case 46: - draw_6star((max(w,h) * step) / (256 * 50.0), - 1.0 * M_PI * step / 256, w/2, h/2); - break; - - case 47: - draw_6star((max(w,h) * (256-step)) / (256 * 50.0), - 1.0 * M_PI * step / 256, w/2, h/2); - break; - - case 50: - draw_windwheel_90(0.5 * M_PI * step / 256, sqrt(w*w+h*h)/2, - w/2, h/2); - break; - case 51: - draw_windwheel_180(1.0 * M_PI * step / 256, sqrt(w*w+h*h)/2, - w/2, h/2); - break; - case 52: - draw_windwheel_360(2.0 * M_PI * step / 256, sqrt(w*w+h*h)/2, - w/2, h/2); - break; - } - - /* double buffer へ 保存した window の内容をコピー */ - XCopyArea(x11_display, savepix, doublepix, x11_gc_win, - 0, 0, w, h, 0, 0); - - /* コピー元の内容を mask付きで double buffer へコピー */ - XCopyArea(x11_display, clippix, doublepix, gc, - 0, 0, w, h, 0, 0); - - /* double buffer から window へコピー */ - XCopyArea(x11_display, doublepix, x11_window, x11_gc_win, - 0, 0, w, h, winoffset_x + dx, winoffset_y + dy); - - /* 同期 */ - XSync(x11_display, False); - - /* clipmask 用 gc の破棄 */ - XFreeGC(x11_display, gc); -} diff --git a/src/xcore_mode.c b/src/xcore_mode.c deleted file mode 100644 index 77a86bb..0000000 --- a/src/xcore_mode.c +++ /dev/null @@ -1,186 +0,0 @@ -/* - * xcore_mode.c X11 video mode and full-screen - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore_mode.c,v 1.7 2003/01/31 12:58:28 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include -#include - -#ifdef HAVE_XF86VMODE -# include -#endif - -#include "portab.h" -#include "system.h" -#include "xcore.h" -#include "xcore_private.h" - -#ifdef HAVE_XF86VMODE -static int vm_count; -static XF86VidModeModeInfo **vm_modelines; -#endif -static boolean have_vm; - -void x11_vm_init(void) { -#ifdef HAVE_XF86VMODE - int foo, bar, i, ma, mi; - - if (XF86VidModeQueryExtension(x11_display, &foo, &bar)) { - XF86VidModeQueryVersion(x11_display, &ma, &mi); - - NOTICE("VidMode version %d.%d\n", ma, mi); - have_vm = TRUE; - - XF86VidModeGetAllModeLines(x11_display, XDefaultScreen(x11_display), - &vm_count, &vm_modelines); - NOTICE(" available video mode(s):"); - for (i = 0; i < vm_count; i++) { - NOTICE(" %dx%d", - vm_modelines[i]->hdisplay, vm_modelines[i]->vdisplay); - } - fprintf(stderr,"\n"); - } -#endif -} - -void x11_vm_exit() { -#ifdef HAVE_XF86VMODE - if (x11_fs_on) { - XF86VidModeSwitchToMode(x11_display, XDefaultScreen(x11_display), - vm_modelines[0]); - } -#endif - -} - -static int search_preferable_fullscreen_mode() { -#ifdef HAVE_XF86VMODE - int i, vm = 0, delta = INT_MAX; - - /* すべてのmodeのなかで最も適切なモードを選択 */ - for (i = 0; i < vm_count; i++) { - if (vm_modelines[i]->hdisplay >= view_w && - vm_modelines[i]->vdisplay >= view_y) { - int deltaw = vm_modelines[i]->hdisplay - view_w; - int deltah = vm_modelines[i]->vdisplay - view_h; - if (delta > (deltaw + deltah)) { - vm = i; - delta = deltaw + deltah; - } - } - } - return vm; -#else - return 0; -#endif - -} - -static void set_vidmode(int mode) { -#ifdef HAVE_XF86VMODE - XF86VidModeSwitchToMode(x11_display, DefaultScreen(x11_display), vm_modelines[mode]); -#endif -} - -/* Fullscreen 移行前の Window の座標 */ -static int winsave_x, winsave_y; - -static void enter_fullscreen() { -#ifdef HAVE_XF86VMODE - int w, h, b, d; - Window root; - - XGetGeometry(x11_display, x11_window, &root, &winsave_x, &winsave_y, - &w, &h, &b, &d); - Xcore_setWindowSize(view_x, view_y, view_w, view_h); - XSync(x11_display, False); -#endif -} - -static void quit_fullscreen() { -#ifdef HAVE_XF86VMODE - XF86VidModeSwitchToMode(x11_display, DefaultScreen(x11_display), vm_modelines[0]); - XUngrabPointer(x11_display, CurrentTime); - XMoveWindow(x11_display, x11_window, winsave_x, winsave_y); - XSync(x11_display, False); -#endif -} - -void Xcore_fullScreen(boolean on) { - if (!have_vm) return; - -#if HAVE_XF86VMODE - if (on && !x11_fs_on) { - x11_fs_on = TRUE; - enter_fullscreen(); - } else if (!on && x11_fs_on) { - quit_fullscreen(); - x11_fs_on = FALSE; - } - XSync(x11_display, False); -#endif -} - -/* Windowの大きさの変更 */ -void Xcore_setWindowSize(int x, int y, int width, int height) { - - view_x = x; - view_y = y; - - if (width == view_w && height == view_h && !x11_fs_on) return; - - view_w = width; - view_h = height; - -#ifdef HAVE_XF86VMODE - if (x11_fs_on) { - int mode = search_preferable_fullscreen_mode(); - NOTICE("width = %d, height = %d\n", - vm_modelines[mode]->hdisplay, - vm_modelines[mode]->vdisplay); - if (vm_modelines[mode]->hdisplay != view_w || - vm_modelines[mode]->vdisplay != view_h) { - winoffset_x = (vm_modelines[mode]->hdisplay - view_w)/2; - winoffset_y = (vm_modelines[mode]->vdisplay - view_h)/2; - width = vm_modelines[mode]->hdisplay; - height = vm_modelines[mode]->vdisplay; - XClearWindow(x11_display, x11_window); - } else { - winoffset_x = winoffset_y = 0; - } - XMoveWindow(x11_display, x11_window, 0, 0); - set_vidmode(mode); - XF86VidModeSetViewPort(x11_display, XDefaultScreen(x11_display), 0, 0); - - XGrabPointer(x11_display, x11_window, True, 0, - GrabModeAsync, GrabModeAsync, x11_window, None, CurrentTime); - XSync(x11_display, False); - } -#endif - - XResizeWindow(x11_display, x11_window, width, height); - x11_makeWorkImage(width, height); - XFlush(x11_display); -} diff --git a/src/xcore_private.h b/src/xcore_private.h deleted file mode 100644 index be32f2b..0000000 --- a/src/xcore_private.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * xcore_private.c X11 only private data - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore_private.h,v 1.5 2003/06/29 15:28:12 chikama Exp $ */ - -#ifndef __XCORE_PRIVATE_H__ -#define __XCORE_PRIVATE_H__ - -#include "config.h" - -#include -#include -#include - -#include "portab.h" -#include "ags.h" -#include "image.h" - -struct _FONT; - -/* dib/work image 情報 */ -typedef struct { - XImage *ximg; /* XImage/ShmXImage 使用時の XImage */ - XShmSegmentInfo info; /* Shared Pixmap info */ - boolean shared; /* is Shared Pixmap ? */ - agsurface_t cimg; /* Common Image for image manupilate */ -} IMAGEINFO; - -struct xcore_private_data { - boolean local_X11; /* flag: TRUE if local display */ - Display *dsp; /* Used for event and window management */ - Visual *vis; /* Vidusl of Current Window */ - - Window win; /* Main Window */ - int win_depth; /* Main Window Depth */ - int winoffset_x; /* draw offset in Window x */ - int winoffset_y; /* y */ - - Atom atom_wmprot; /* window manager protocol atom */ - Atom atom_delwin; /* close-window protocol atom */ - - GC gc_win; /* The Graphics context for drawing to Window */ - - GC gc_pix; /* The Graphics context for drawing to Pixmap */ - Pixmap pix; /* Pixmap for offscreen image */ - - int dib_depth_candidate; /* DIB depth if required pixmap depth isnt 8 */ - - struct _FONT *fontinfo; /* font object */ - - boolean noSHM; /* dont have X-SHM extension */ - - boolean packed24bpp; /* window is packed 24 bpp? */ - - /* SharedPixmapを使用中にXの描画が入った場合 XSyncを発行するためのフラグ */ - boolean needSync; - - boolean fullscreen; /* FullScreen Mode である */ - - IMAGEINFO *dib; /* DIB? information */ - int view_x; - int view_y; - int view_width; - int view_height; - - IMAGEINFO *work; - - XColor col[256]; /* palette and color map */ - Colormap cm; -}; - -extern void x11_init_cursor(void); -extern void x11_makeWorkImage(int w, int h); -extern void x11_vm_init(void); -extern void x11_vm_exit(void); -extern Pixmap x11_clip_from_DIB(int sx, int sy, int w, int h); - - -extern struct xcore_private_data *x11_videodev; - -#define local_X11 (x11_videodev->local_X11) -#define x11_display (x11_videodev->dsp) -#define x11_visual (x11_videodev->vis) -#define x11_window (x11_videodev->win) -#define winoffset_x (x11_videodev->winoffset_x) -#define winoffset_y (x11_videodev->winoffset_y) -#define atom_delwin (x11_videodev->atom_delwin) -#define atom_wmprot (x11_videodev->atom_wmprot) -#define x11_gc_win (x11_videodev->gc_win) -#define x11_gc_pix (x11_videodev->gc_pix) -#define x11_pixmap (x11_videodev->pix) -#define dib_depth_candidate (x11_videodev->dib_depth_candidate) -#define x11_font (x11_videodev->fontinfo) -#define x11_noSHM (x11_videodev->noSHM) -#define packed24bpp (x11_videodev->packed24bpp) -#define x11_needSync (x11_videodev->needSync) -#define x11_dibinfo (x11_videodev->dib) -#define x11_workinfo (x11_videodev->work) -#define view_x (x11_videodev->view_x) -#define view_y (x11_videodev->view_y) -#define view_w (x11_videodev->view_width) -#define view_h (x11_videodev->view_height) -#define x11_cm (x11_videodev->cm) -#define x11_col (x11_videodev->col) -#define x11_fs_on (x11_videodev->fullscreen) -#define DRAW_BY_X (!x11_dibinfo->shared) -#define DIB (&(x11_dibinfo->cimg)) -#define DIB_DEPTH (x11_dibinfo->cimg.depth) -#define WIN_DEPTH (x11_videodev->win_depth) - -#define WORK (&(x11_workinfo->cimg)) - -// #define WROK_DEPTH (x11_workinfo->cimg.depth) - -#define PAL2PIC(i) image_index2pixel(DIB_DEPTH, i) - - -#endif /* __XCORE_PRIVATE_H__ */ diff --git a/src/xcore_video.c b/src/xcore_video.c deleted file mode 100644 index 2d083cd..0000000 --- a/src/xcore_video.c +++ /dev/null @@ -1,528 +0,0 @@ -/* - * xcore_video.c X11 video init - * - * Copyright (C) 1997-1998 Masaki Chikama (Wren) - * 1998- - * - * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * -*/ -/* $Id: xcore_video.c,v 1.15 2003/06/29 15:28:12 chikama Exp $ */ - -#include "config.h" - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include -#include - -#ifdef X_LOCALE -#include -#else -#include -#endif - -#include - -#include "portab.h" -#include "system.h" -#include "font.h" -#include "joystick.h" -#include "xsystem35.h" -#include "xcore.h" -#include "xcore_private.h" - -static void check_SHMext(void); -static void check_packed24bpp(void); -static void init_window(void); -static void init_offscreen(void); -static void releaseDIB(void); -static void makeNonShmXImage(IMAGEINFO *simg, int w, int h, int depth); -static boolean makeShmXImage(IMAGEINFO *simg, int w, int h, int depth); -static void releaseNonShmXImage(IMAGEINFO *simg); -static void releaseShmXImage(IMAGEINFO *simg); -static void makeDIB(int w, int h, int depth); -static void releaseWorkImage(); - - -struct xcore_private_data *x11_videodev; -static boolean noshm; - -/* init/remove */ - -int Xcore_Initilize(void) { - char *display; - - x11_videodev = calloc(1, sizeof(struct xcore_private_data)); - x11_noSHM = noshm; - - /* locale init ( for no gtk option ) */ - if (setlocale(LC_ALL,"") == NULL) { - if (setlocale(LC_ALL, "C") == NULL) { - SYSERROR("locale not supported\n"); - } - } - - - /* Open the X11 display */ - display = NULL; /* Get it from DISPLAY environment variable */ - - if ((strncmp(XDisplayName(display), ":", 1) == 0) || - (strncmp(XDisplayName(display), "unix:", 5) == 0)) { - local_X11 = TRUE; - } else { - local_X11 = FALSE; - } - - x11_display = XOpenDisplay(NULL); - if (x11_display == NULL) { - SYSERROR("Can't Open Display\n"); - } - - /* check packed 24 bpp */ - check_packed24bpp(); - - /* check SHM extension is avaibale */ - check_SHMext(); - - /* create toplevel window */ - init_window(); - - /* map window to display */ - XMapWindow(x11_display, x11_window); - - /* discpriter init */ - //x11_selinfo.fd_x = ConnectionNumber(x11_display); - - /* event mask */ - XSelectInput(x11_display, x11_window, ExposureMask | - KeyPressMask | KeyReleaseMask | - LeaveWindowMask | EnterWindowMask | - ButtonPressMask | ButtonReleaseMask | -// PointerMotionMask | PointerMotionHintMask); - PointerMotionMask); - /* ???? */ - XSetGraphicsExposures(x11_display, x11_gc_win, False); - - /* create initial off-screen */ - init_offscreen(); - - /* Window title bar */ - XStoreName(x11_display, x11_window, "XSystem3.5 Version "VERSION); - - /* wm hint */ - atom_wmprot = XInternAtom(x11_display, "WM_PROTOCOLS", False); - atom_delwin = XInternAtom(x11_display, "WM_DELETE_WINDOW", False); - XSetWMProtocols(x11_display, x11_window, &atom_delwin, 1); - - /* init cursor */ - x11_init_cursor(); - - /* final */ - XFlush(x11_display); - - /* window size set */ - Xcore_setWindowSize(0, 0, SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT); - - return 0; -} - -/* remove X */ -void Xcore_Remove(void) { - if (x11_videodev == NULL) return; - - if (x11_display != NULL) { - NOTICE("Now X shutdown ... "); - - x11_vm_exit(); - - if (x11_workinfo != NULL) { - releaseWorkImage(); - } - - if (x11_dibinfo != NULL) { - releaseDIB(); - } - XCloseDisplay(x11_display); - - joy_close(); - - NOTICE("Done!\n"); - } -} - - - -/* SHMext を使用しないモードに設定 */ -void Xcore_setNoShmMode(void) { - // x11_noSHM = TRUE; - noshm = TRUE; -} - -/* SHMext が使用できるかチェック */ -static void check_SHMext(void) { - int major, minor; - Bool pixmaps; - -#if defined(__osf__) - x11_noSHM = TRUE; /* buggy X at least DIGITAL UNIX V4.0F */ -#endif - - if (x11_noSHM) return; - - if (local_X11) { - x11_noSHM = FALSE; - return; - } - - if (False == XShmQueryVersion(x11_display, &major, &minor, &pixmaps)) { - WARNING("MIT-SHMextension is not supported\n"); - goto errexit; - } - - if (False == pixmaps) { - WARNING("SharedPixmap is not supported\n"); - goto errexit; - } - - if (ZPixmap != XShmPixmapFormat(x11_display)) { - WARNING("SharedPixmap's format is not ZPixmap\n"); - goto errexit; - } - - x11_noSHM = FALSE; - return; - - errexit: - x11_noSHM = TRUE; - return; -} - -static void check_packed24bpp(void) { - XPixmapFormatValues *list; - int i, cnt; - - list = XListPixmapFormats(x11_display, &cnt); - if (list == NULL) return; - - for (i = 0; i < cnt; i++) { - if (list[i].depth == 24 && list[i].bits_per_pixel == 24) { - packed24bpp = TRUE; - break; - } - } - XFree(list); -} - - -/* create toplevel window */ -static void init_window(void) { - int depth = DefaultDepth(x11_display, 0); - boolean simple = FALSE; - int attrib_mask; - XSetWindowAttributes at; - XVisualInfo vinfo; - - memset(&at, 0, sizeof(at)); - - if (depth == 8) { - /* 8bit の時 15/16/24bit True Color の visual を持っているか? */ - if (True == XMatchVisualInfo(x11_display, None, 16, TrueColor, &vinfo)) { - WIN_DEPTH = 16; - } else if (True == XMatchVisualInfo(x11_display, None, 15, TrueColor, &vinfo)) { - WIN_DEPTH = 15; - } else if (True == XMatchVisualInfo(x11_display, None, 24, TrueColor, &vinfo)) { - WIN_DEPTH = 24; - } else if (True == XMatchVisualInfo(x11_display, None, 8, PseudoColor, &vinfo)) { - WIN_DEPTH = 8; - simple = TRUE; - } else { - SYSERROR("No required Visual\n"); - } - } else { - simple = TRUE; - if (False == XMatchVisualInfo(x11_display, None, depth, TrueColor, &vinfo)) { - SYSERROR("No required Visual\n"); - } - WIN_DEPTH = depth; - } - - x11_visual = vinfo.visual; - - if (simple) { - x11_window = XCreateSimpleWindow(x11_display, RootWindow(x11_display, 0), - 0, 0, - SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT, - 0, 0, 0); - /* colormap */ - if (x11_visual->class == PseudoColor) { - x11_cm = XCreateColormap(x11_display, RootWindow(x11_display,0), x11_visual, AllocAll); - XSetWindowColormap(x11_display, x11_window, x11_cm); - } else { - x11_cm = DefaultColormap(x11_display, 0); - } - /* backing store */ - at.backing_store = WhenMapped; - XChangeWindowAttributes(x11_display, x11_window, CWBackingStore, &at); - } else { - XVisualInfo *vinfo_g; - int vinfo_n; - - vinfo.depth = WIN_DEPTH; - vinfo_g = XGetVisualInfo(x11_display, VisualDepthMask | VisualClassMask| VisualRedMaskMask, &vinfo, &vinfo_n); - if (vinfo_g == NULL) { - SYSERROR("No required Visual\n"); - } - x11_visual = vinfo_g->visual; - XFree(vinfo_g); - - at.background_pixel = BlackPixel (x11_display, 0); - at.border_pixel = BlackPixel (x11_display, 0); - at.backing_store = WhenMapped; - attrib_mask = CWBorderPixel | CWBackPixel | CWColormap | CWBackingStore; - x11_cm = at.colormap = XCreateColormap(x11_display, RootWindow(x11_display, 0), x11_visual, AllocNone); - x11_window = XCreateWindow(x11_display, RootWindow(x11_display, 0), - 0, 0, SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT, - 0, WIN_DEPTH, - InputOutput, x11_visual, attrib_mask, &at); - } - - /* determin dib depth candidate */ - dib_depth_candidate = (depth == 16 && vinfo.red_mask == 0x7c00) ? 15: WIN_DEPTH; - - /* create graphic context for window */ - x11_gc_win = XCreateGC(x11_display, x11_window, 0, 0); - - /* for fullscreen window init */ - x11_vm_init(); - -} - -static void init_offscreen(void) { - makeDIB(SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT, SYS35_DEFAULT_DEPTH); - - x11_makeWorkImage(SYS35_DEFAULT_WIDTH, SYS35_DEFAULT_HEIGHT); -} - -/* OffScreenImageに関する情報の解放 */ -static void releaseDIB(void) { - XFreePixmap(x11_display, x11_pixmap); - XFreeGC(x11_display, x11_gc_pix); - - if (x11_dibinfo->shared) { - releaseShmXImage(x11_dibinfo); - } else { - releaseNonShmXImage(x11_dibinfo); - } -} - -static void makeNonShmXImage(IMAGEINFO *simg, int w, int h, int depth) { - simg->ximg = XCreateImage(x11_display, x11_visual, depth, ZPixmap, 0, NULL, w, h, packed24bpp ? 8 : 32, 0); - - /* XXXX */ - if (depth == 32 && packed24bpp) { - simg->ximg->bytes_per_line = w * 4; - } - - if (NULL == (simg->ximg->data = malloc(simg->ximg->bytes_per_line * h))) { - NOMEMERR(); - } - -#ifdef WORDS_BIGENDIAN - simg->ximg->byte_order = MSBFirst; -#else - simg->ximg->byte_order = LSBFirst; -#endif -} - -static boolean makeShmXImage(IMAGEINFO *simg, int w, int h, int depth) { - simg->ximg = XShmCreateImage(x11_display, x11_visual, depth, ZPixmap, NULL, &simg->info, w, h); - - if ((simg->info.shmid = shmget(IPC_PRIVATE, - simg->ximg->bytes_per_line * h, - IPC_CREAT | 0666)) < 0) { - WARNING("shmget: size:%x %s\n", - simg->ximg->bytes_per_line * h, strerror(errno)); - XDestroyImage(simg->ximg); - return FALSE; - } - - if ((char *)-1 == (simg->info.shmaddr = simg->ximg->data = shmat(simg->info.shmid, 0, 0))) { - SYSERROR("shmat: %s\n", strerror(errno)); - } - - simg->info.readOnly = False; - XShmAttach(x11_display, &simg->info); - - return TRUE; -} - -static void releaseNonShmXImage(IMAGEINFO *simg) { - XDestroyImage(simg->ximg); -} - -static void releaseShmXImage(IMAGEINFO *simg) { - XShmDetach(x11_display, &simg->info); - XDestroyImage(simg->ximg); - - if (0 > shmdt(simg->info.shmaddr)) { - SYSERROR("shmdt: %s\n", strerror(errno)); - } - - if (0 > shmctl(simg->info.shmid, IPC_RMID, 0)) { - SYSERROR("shmctl: %s\n", strerror(errno)); - } -} - -static void makeDIB(int w, int h, int depth) { - static boolean alloced = FALSE; - - if (WIN_DEPTH == 8 && depth != 8) { - SYSERROR("You cannot play highcolor game in 256 color mode\n"); - } - - if (alloced) { - releaseDIB(); - free(x11_dibinfo); - } - - x11_dibinfo = malloc(sizeof(IMAGEINFO)); - - if (depth != 8) { - depth = dib_depth_candidate; - } - - if (x11_noSHM || - packed24bpp || - depth != WIN_DEPTH || - !makeShmXImage(x11_dibinfo, w, h, depth)) { - makeNonShmXImage(x11_dibinfo, w, h, packed24bpp ? 32 : depth); - x11_pixmap = XCreatePixmap(x11_display, x11_window, w, h, WIN_DEPTH); - x11_dibinfo->shared = FALSE; - } else { - x11_pixmap = XShmCreatePixmap(x11_display, x11_window, x11_dibinfo->ximg->data, &x11_dibinfo->info, w, h, depth); - x11_dibinfo->shared = TRUE; - } - - x11_gc_pix = XCreateGC(x11_display, x11_pixmap, 0, 0); - - x11_dibinfo->cimg.width = w; - x11_dibinfo->cimg.height = h; - x11_dibinfo->cimg.pixel = x11_dibinfo->ximg->data; - x11_dibinfo->cimg.bytes_per_line = x11_dibinfo->ximg->bytes_per_line; - x11_dibinfo->cimg.depth = depth; - x11_dibinfo->cimg.bytes_per_pixel = (depth == 8 ? 1 : - depth == 15 || depth == 16 ? 2 : - depth == 24 || depth == 32 ? 4 : 1); - x11_dibinfo->cimg.alpha = NULL; - - image_setdepth(depth); - xcore_image_setdepth(depth); - alloced = TRUE; -} - -/* fader用のImageを解放 */ -static void releaseWorkImage() { - if (x11_workinfo->shared) { - releaseShmXImage(x11_workinfo); - } else { - releaseNonShmXImage(x11_workinfo); - } -} - -/* fader/ecopy用のImageを確保 */ -void x11_makeWorkImage(int w, int h) { - static boolean alloced = FALSE; - - if (alloced) { - releaseWorkImage(); - free(x11_workinfo); - } - - x11_workinfo = malloc(sizeof(IMAGEINFO)); - - if (x11_noSHM || - packed24bpp || - !makeShmXImage(x11_workinfo, w, h, WIN_DEPTH)) { - makeNonShmXImage(x11_workinfo, w, h, WIN_DEPTH); - x11_workinfo->shared = FALSE; - } else { - x11_workinfo->shared = TRUE; - } - - XSync(x11_display, False); - - x11_workinfo->cimg.width = w; - x11_workinfo->cimg.height = h; - x11_workinfo->cimg.pixel = x11_workinfo->ximg->data; - x11_workinfo->cimg.bytes_per_line = x11_workinfo->ximg->bytes_per_line; - x11_workinfo->cimg.depth = x11_workinfo->ximg->depth; - x11_workinfo->cimg.bytes_per_pixel = (WIN_DEPTH == 8 ? 1 : - WIN_DEPTH == 15 || WIN_DEPTH == 16 ? 2 : - WIN_DEPTH == 24 && packed24bpp ? 3 : - WIN_DEPTH == 24 || WIN_DEPTH == 32 ? 4 : 1); - x11_workinfo->cimg.alpha = NULL; - - alloced = TRUE; -} - -void Xcore_setFontDevice(struct _FONT *f) { - x11_font = f; -} - -/* name is UTF-8 */ -void Xcore_setWindowTitle(char *name) { - XmbSetWMProperties (x11_display, x11_window, - name, name, NULL, 0, NULL, NULL, NULL); -} - -/* offscreen の設定 */ -void Xcore_setWorldSize(int width, int height, int depth) { - makeDIB(width, height, depth); - Xcore_fillRectangle(0, 0, width, height, 0); - XSync(x11_display, False); -} - -/* Windowの size と depth の取得 */ -void Xcore_getWindowInfo(DispInfo *info) { - info->width = DisplayWidth(x11_display, 0); - info->height = DisplayHeight(x11_display, 0); - info->depth = WIN_DEPTH; -} - -/* - DIBの取得 - SharedPixma / XImage / MemoryImageのいずれか - */ -agsurface_t *Xcore_getDIB(void) { - return DIB; -} - -/* AutoRepeat の設定 */ -void Xcore_setAutoRepeat(boolean bool) { - if (bool) { - XAutoRepeatOn(x11_display); - } else { - XAutoRepeatOff(x11_display); - } -} diff --git a/src/xsys35rc.sample b/src/xsys35rc.sample index 04c207b..573fd9a 100644 --- a/src/xsys35rc.sample +++ b/src/xsys35rc.sample @@ -5,20 +5,11 @@ # --------------------------------------------------------- # 使用するフォントデバイスの選択 -# (x11,ft2,sdlが使用可能です) +# (ft2,sdlが使用可能です) # font_device: sdl -# --------------------------------------------------------- -# 使用するフォントの指定 for x11 -# フォントサイズの場所を %d にするのを忘れないで下さい。 -# - -font_mincho: -*-mincho-medium-r-normal--%d-0-0-0-c-0-jisx0208.1983-0,-*-mincho-medium-r-normal--%d-0-0-0-c-0-jisx0201.1976-0 - -font_gothic: -*-*-medium-r-normal--%d-*-*-*-c-*-jisx0208.1983-0,-*-*-medium-r-normal--%d-*-*-*-c-*-jisx0201.1976-0 - # ------------------------------------------------------------ -# 使用するフォントの指定 for FreeType / SDL_ttf +# 使用するフォントの指定 # #ttfont_mincho: /usr/local/share/xsystem35/fonts/mincho.otf @@ -89,14 +80,6 @@ font_gothic: -*-*-medium-r-normal--%d-*-*-*-c-*-jisx0208.1983-0,-*-*-medium-r-no # ------------------------------------------------------------ -# ----------------------------------------------------------- -# X の SharedMemoryExtension を使わない設定 -# Xdec(DigitalUNIX), Xpmac(LinuxPPC)で必要 - -#no_shm: Yes - -# ------------------------------------------------------------ - # ----------------------------------------------------------- # リソースファイルによるマウスカーソルの形状変更を無効にする # にする場合、以下を Yes にする (なにも指定しない場合は有効) diff --git a/src/xsystem35.c b/src/xsystem35.c index 08582de..db2e63d 100644 --- a/src/xsystem35.c +++ b/src/xsystem35.c @@ -38,9 +38,7 @@ # include #endif -#ifdef ENABLE_SDL -# include -#endif +#include #ifdef __EMSCRIPTEN__ #include @@ -94,16 +92,13 @@ static int debuglv = DEBUGLEVEL; static int audio_buffer_size = 0; /* font name from rcfile */ -static char *fontname[FONTTYPEMAX]; static char *fontname_tt[FONTTYPEMAX] = {DEFAULT_GOTHIC_TTF, DEFAULT_MINCHO_TTF}; static char fontface[FONTTYPEMAX]; #ifdef ENABLE_SDLTTF #define DEFAULT_FONT_DEVICE FONT_SDLTTF -#elif defined(ENABLE_SDL) -#define DEFAULT_FONT_DEVICE FONT_FT2 #else -#define DEFAULT_FONT_DEVICE FONT_X11 +#define DEFAULT_FONT_DEVICE FONT_FT2 #endif static fontdev_t fontdev = DEFAULT_FONT_DEVICE; @@ -125,7 +120,6 @@ static void sys35_usage(boolean verbose) { puts("Usage: xsystem35 [OPTIONS]\n"); puts("OPTIONS"); puts(" -gamefile file : set game resource file to 'file'"); - puts(" -no-shm : don't use MIT-SHM (use in another display)"); puts(" -devcd device : set cdrom device name to 'device'"); puts(" -devmidi device: set midi device name to 'device'"); @@ -151,24 +145,15 @@ static void sys35_usage(boolean verbose) { #ifdef ENABLE_FT2 puts(" -devfont ft2 : FreeType"); #endif -#ifdef ENABLE_X11FONT - puts(" -devfont x11 : x11"); -#endif #ifdef ENABLE_SDLTTF puts(" : default is sdl"); -#elif defined(ENABLE_SDL) - puts(" : default is ft2"); #else - puts(" : default is x11"); + puts(" : default is ft2"); #endif -#if defined(ENABLE_SDLTTF) || defined(ENABLE_FT2) puts(" -ttfont_mincho: set TrueType font for mincho"); puts(" -ttfont_gothic: set TrueType font for mincho"); -#endif - puts(" -font_mincho : set X11(gtk) font for mincho"); - puts(" -font_gothic : set X11(gtk) font for mincho"); #ifdef DEBUG puts(" -debuglv # : debug level"); @@ -252,11 +237,6 @@ static int check_fontdev(char *devname) { if (0 == strcmp(devname, "ft2")) { return FONT_FT2; } -#endif -#ifdef ENABLE_X11FONT - if (0 == strcmp(devname, "x11")) { - return FONT_X11; - } #endif return DEFAULT_FONT_DEVICE; } @@ -275,23 +255,8 @@ static void sys35_init() { ags_init(); for (i = 0; i < FONTTYPEMAX; i++) { - switch(fontdev) { - case FONT_FT2: - case FONT_SDLTTF: - nact->ags.font->name[i] = fontname_tt[i]; - nact->ags.font->face[i] = fontface[i]; - break; - - case FONT_X11: - if (fontname[i] == NULL) { - nact->ags.font->name[i] = strdup(FONT_DEFAULTNAME_X); - } else { - nact->ags.font->name[i] = fontname[i]; - } - break; - default: - break; - } + nact->ags.font->name[i] = fontname_tt[i]; + nact->ags.font->face[i] = fontface[i]; } ags_fullscreen(fs_on); @@ -364,8 +329,6 @@ static void sys35_ParseOption(int *argc, char **argv) { } fclose(fp); gameResourceFile = argv[i + 1]; - } else if (0 == strcmp(argv[i], "-no-shm")) { - SetNoShmMode(); } else if (0 == strcmp(argv[i], "-devcd")) { if (argv[i + 1] != NULL) { cd_set_devicename(argv[i + 1]); @@ -392,14 +355,6 @@ static void sys35_ParseOption(int *argc, char **argv) { if (argv[i + 1] != NULL) { fontdev = check_fontdev(argv[i + 1]); } - } else if (0 == strcmp(argv[i], "-font_gothic")) { - if (argv[i + 1] != NULL) { - fontname[FONT_GOTHIC] = argv[i + 1]; - } - } else if (0 == strcmp(argv[i], "-font_mincho")) { - if (argv[i + 1] != NULL) { - fontname[FONT_MINCHO] = argv[i + 1]; - } } else if (0 == strcmp(argv[i], "-ttfont_gothic")) { if (argv[i + 1] != NULL) { fontname_tt[FONT_GOTHIC] = argv[i + 1]; @@ -429,16 +384,6 @@ static void check_profile() { if (param) { fontdev = check_fontdev(param); } - /* ゴシックフォントの設定 */ - param = get_profile("font_gothic"); - if (param) { - fontname[FONT_GOTHIC] = param; - } - /* 明朝フォントの設定 */ - param = get_profile("font_mincho"); - if (param) { - fontname[FONT_MINCHO] = param; - } /* ゴシックフォント(TT)の設定 */ param = get_profile("ttfont_gothic"); if (param) { @@ -496,13 +441,6 @@ static void check_profile() { } midi_set_output_device(*param | subdev); } - /* no-shm flag */ - param = get_profile("no_shm"); - if (param) { - if (0 == strcmp(param, "Yes")) { - SetNoShmMode(); - } - } /* disable image cursor */ param = get_profile("no_imagecursor"); if (param) {