📄 w32g_subwin2.c
字号:
/* TiMidity++ -- MIDI to WAVE converter and player Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp> Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi> 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 w32g_subwin2.c: Written by Daisuke Aoki <dai@y7.net>*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include <stdio.h>#include <stdlib.h>#include <process.h>#include <stddef.h>#ifndef NO_STRING_H#include <string.h>#else#include <strings.h>#endif#include "timidity.h"#include "common.h"#include "instrum.h"#include "playmidi.h"#include "readmidi.h"#include "output.h"#include "controls.h"#include "tables.h"#include "miditrace.h"#include "reverb.h"#ifdef SUPPORT_SOUNDSPEC#include "soundspec.h"#endif /* SUPPORT_SOUNDSPEC */#include "recache.h"#include "arc.h"#include "strtab.h"#include "wrd.h"#include "mid.defs"#include "w32g.h"#include <shlobj.h>#include <commctrl.h>#include <windowsx.h>#include "w32g_res.h"#include "w32g_utl.h"#include "w32g_pref.h"#include "w32g_subwin.h"#include "w32g_ut2.h"#include "w32g_dib.h"#include "w32g_wrd.h"#include "w32g_mag.h"extern int gdi_lock_ex ( DWORD timeout );#if 0static int gdi_lock_result;#define GDI_LOCK_EX(timeout) ( \ ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "GDI_LOCK_EX(%s: %d)", __FILE__, __LINE__ ), \ gdi_lock_result = gdi_lock_ex(timeout), \ ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "GDI_LOCK_EX_RESULT(%d)", gdi_lock_result ), \ gdi_lock_result \)#define GDI_LOCK() { \ ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "GDI_LOCK(%s: %d)", __FILE__, __LINE__ ); \ gdi_lock(); \}#define GDI_UNLOCK() { \ ctl->cmsg(CMSG_INFO, VERB_VERBOSE, "GDI_UNLOCK(%s: %d)", __FILE__, __LINE__ ); \ gdi_unlock(); \}#else#define GDI_LOCK() { gdi_lock(); }#define GDI_LOCK_EX(timeout) gdi_lock_ex(timeout)#define GDI_UNLOCK() { gdi_unlock(); }#endif#if defined(__CYGWIN32__) || defined(__MINGW32__)#ifndef TPM_TOPALIGN#define TPM_TOPALIGN 0x0000L#endif#endifextern void VprintfEditCtlWnd(HWND hwnd, char *fmt, va_list argList);extern void PrintfEditCtlWnd(HWND hwnd, char *fmt, ...);extern void PutsEditCtlWnd(HWND hwnd, char *str);extern void ClearEditCtlWnd(HWND hwnd);#ifndef _mbbtype#ifndef _MBC_SINGLE#define _MBC_SINGLE (0)#endif#ifndef _MBC_LEAD#define _MBC_LEAD (1)#endif#ifndef _MBC_TRAIL#define _MBC_TRAIL (2)#endif#ifndef _MBC_ILLEGAL#define _MBC_ILLEGAL (-1)#endif#define is_sjis_kanji1(x) ((((unsigned char)(x))>=0x81 && ((unsigned char)(x))<=0x9f) || (((unsigned char)(x))>=0xe0 && ((unsigned char)(x))<=0xfc))#define is_sjis_kanji2(x) ((((unsigned char)(x))>=0x40 && ((unsigned char)(x))<=0x7e) || (((unsigned char)(x))>=0x80 && ((unsigned char)(x))<=0xfc))static int ___sjis_mbbtype(unsigned char c, int mbtype){ if(mbtype==_MBC_LEAD){ if(is_sjis_kanji2(c)) return _MBC_TRAIL; else return _MBC_ILLEGAL; } else { if(is_sjis_kanji1(c)) return _MBC_LEAD; else return _MBC_SINGLE; }}static int _mbbtype(unsigned char c, int mbtype){ return ___sjis_mbbtype(c,mbtype);}#endifstatic RGBQUAD RGBtoRGBQUAD ( COLORREF color );static COLORREF RGBQUADtoRGB ( RGBQUAD rq );// ****************************************************************************// Wrd Window#define MAG_WORK_WIDTH 800#define MAG_WORK_HEIGHT 640#define COLOR_MASK_WHITE RGB(0xFF,0xFF,0xFF)#define COLOR_MASK_BLACK RGB(0x00,0x00,0x00)WRDWNDINFO WrdWndInfo;static int WrdWndInfoReset(HWND hwnd);static int WrdWndInfoApply(void);w32g_wrd_wnd_t w32g_wrd_wnd;BOOL SetWrdWndActive(void){ if ( IsWindowVisible(hWrdWnd) ) { w32g_wrd_wnd.active = TRUE; } else { w32g_wrd_wnd.active = FALSE; } return w32g_wrd_wnd.active;}static void wrd_graphic_terminate ( void );static void wrd_graphic_init ( HDC hdc );static void wrd_graphic_tone_change ( int index, int tone );static void wrd_graphic_set_pal ( int index, int pal_index, COLORREF color );static void wrd_graphic_plane_change ( int active, int display );static void wrd_graphic_reset ( int index );static void wrd_graphic_reset_all ( void );static void wrd_graphic_apply ( RECT *lprc, int index, int lockflag );static void wrd_graphic_update ( RECT *lprc, int lockflag );static void wrd_text_update ( int x_from, int y_from, int x_to, int y_to, int lockflag );static int volatile wrd_graphic_pal_init_flag = 0;static HANDLE volatile hMutexWrd = NULL;static BOOL wrd_wnd_lock_ex ( DWORD timeout ){ if ( hMutexWrd == NULL ) { hMutexWrd = CreateMutex ( NULL, FALSE, NULL ); if ( hMutexWrd == NULL ) return FALSE; } if ( WaitForSingleObject ( hMutexWrd, timeout )== WAIT_FAILED ) { return FALSE; } return TRUE;}static BOOL wrd_wnd_lock (void){ return wrd_wnd_lock_ex ( INFINITE );}static void wrd_wnd_unlock (void){ ReleaseMutex ( hMutexWrd );}BOOL CALLBACK WrdWndProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);BOOL CALLBACK WrdCanvasWndProc(HWND hwnd, UINT uMess, WPARAM wParam, LPARAM lParam);static int volatile wrd_wnd_initflag = 1;void TerminateWrdWnd ( void ){ wrd_wnd_lock(); w32g_wrd_wnd.active = FALSE; if ( !wrd_wnd_initflag ) { DeleteDC ( w32g_wrd_wnd.hmdc ); DeleteObject ( (HGDIOBJ) w32g_wrd_wnd.hbitmap ); DeleteObject ( (HGDIOBJ) w32g_wrd_wnd.hbmp_tmask ); DeleteObject ( (HGDIOBJ) w32g_wrd_wnd.hbmp_work ); DeleteObject ( (HGDIOBJ) w32g_wrd_wnd.hNullBrush ); DeleteObject ( (HGDIOBJ) w32g_wrd_wnd.hNullPen ); } wrd_graphic_terminate (); memset ( &w32g_wrd_wnd, 0, sizeof (w32g_wrd_wnd_t) ); wrd_wnd_unlock();}void InitWrdWnd(HWND hParentWnd){ WNDCLASS wndclass ; HICON hIcon; wrd_wnd_lock(); if ( wrd_wnd_initflag ) { memset ( &w32g_wrd_wnd, 0, sizeof (w32g_wrd_wnd_t) ); wrd_wnd_initflag = 0; } if (hWrdWnd != NULL) { DestroyWindow(hWrdWnd); hWrdWnd = NULL; } TerminateWrdWnd (); INILoadWrdWnd(); w32g_wrd_wnd.hNullBrush = GetStockObject ( NULL_BRUSH ); w32g_wrd_wnd.hNullPen = GetStockObject ( NULL_PEN ); hWrdWnd = CreateDialog (hInst,MAKEINTRESOURCE(IDD_DIALOG_WRD),hParentWnd,WrdWndProc); WrdWndInfoReset(hWrdWnd); INILoadWrdWnd(); ShowWindow(hWrdWnd,SW_HIDE); w32g_wrd_wnd.draw_skip = 0; w32g_wrd_wnd.font_height = 16; w32g_wrd_wnd.font_width = 8; w32g_wrd_wnd.row = 80; w32g_wrd_wnd.col = 25; w32g_wrd_wnd.width = w32g_wrd_wnd.font_width * w32g_wrd_wnd.row; w32g_wrd_wnd.height = w32g_wrd_wnd.font_height * w32g_wrd_wnd.col; w32g_wrd_wnd.pals[W32G_WRDWND_BLACK] = RGB ( 0x00, 0x00, 0x00 ); w32g_wrd_wnd.pals[W32G_WRDWND_RED] = RGB ( 0xFF, 0x00, 0x00 ); w32g_wrd_wnd.pals[W32G_WRDWND_BLUE] = RGB ( 0x00, 0x00, 0xFF ); w32g_wrd_wnd.pals[W32G_WRDWND_PURPLE] = RGB ( 0xFF, 0x00, 0xFF ); w32g_wrd_wnd.pals[W32G_WRDWND_GREEN] = RGB ( 0x00, 0xFF, 0x00 ); w32g_wrd_wnd.pals[W32G_WRDWND_LIGHTBLUE] = RGB ( 0x00, 0xFF, 0xFF ); w32g_wrd_wnd.pals[W32G_WRDWND_YELLOW] = RGB ( 0xFF, 0xFF, 0xFF ); w32g_wrd_wnd.pals[W32G_WRDWND_WHITE] = RGB ( 0xFF, 0xFF, 0xFF ); w32g_wrd_wnd.flag = WRD_FLAG_DEFAULT; wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_CLASSDC; wndclass.lpfnWndProc = WrdCanvasWndProc ; wndclass.cbClsExtra = 0 ; wndclass.cbWndExtra = 0 ; wndclass.hInstance = hInst ; wndclass.hIcon = NULL; wndclass.hCursor = LoadCursor(0,IDC_ARROW) ;// wndclass.hbrBackground = (HBRUSH)(COLOR_SCROLLBAR + 1); wndclass.hbrBackground = w32g_wrd_wnd.hNullBrush; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = "wrd canvas wnd"; RegisterClass(&wndclass); w32g_wrd_wnd.hwnd = CreateWindowEx(0,"wrd canvas wnd",0,WS_CHILD, CW_USEDEFAULT,0,w32g_wrd_wnd.width,w32g_wrd_wnd.height, hWrdWnd,0,hInst,0); w32g_wrd_wnd.hdc = GetDC(w32g_wrd_wnd.hwnd); // 戝尦 w32g_wrd_wnd.hbitmap = CreateCompatibleBitmap(w32g_wrd_wnd.hdc,w32g_wrd_wnd.width,w32g_wrd_wnd.height); w32g_wrd_wnd.hmdc = CreateCompatibleDC(w32g_wrd_wnd.hdc); w32g_wrd_wnd.hgdiobj_hmdcprev = SelectObject(w32g_wrd_wnd.hmdc,w32g_wrd_wnd.hbitmap); SelectObject ( w32g_wrd_wnd.hmdc, w32g_wrd_wnd.hNullBrush ); SelectObject ( w32g_wrd_wnd.hmdc, w32g_wrd_wnd.hNullPen ); // 儚乕僋 w32g_wrd_wnd.hbmp_work = CreateCompatibleBitmap(w32g_wrd_wnd.hdc,w32g_wrd_wnd.width,w32g_wrd_wnd.height); // 僥僉僗僩儅僗僋// w32g_wrd_wnd.hbmp_tmask = CreateBitmap ( w32g_wrd_wnd.width, w32g_wrd_wnd.height, 1, 1, NULL); w32g_wrd_wnd.hbmp_tmask = CreateCompatibleBitmap(w32g_wrd_wnd.hdc,w32g_wrd_wnd.width,w32g_wrd_wnd.height); { HDC hmdc; RECT rc; HBRUSH hbrush = CreateSolidBrush ( COLOR_MASK_BLACK ); SetRect ( &rc, 0, 0, w32g_wrd_wnd.width, w32g_wrd_wnd.height ); hmdc = CreateCompatibleDC ( w32g_wrd_wnd.hmdc ); SelectObject ( hmdc, w32g_wrd_wnd.hbmp_tmask ); FillRect ( hmdc, &rc, hbrush ); SelectObject ( hmdc, w32g_wrd_wnd.hbmp_work ); FillRect ( hmdc, &rc, hbrush ); DeleteDC ( hmdc ); DeleteObject ( hbrush ); } // 僌儔僼傿僢僋 wrd_graphic_init ( w32g_wrd_wnd.hdc ); ReleaseDC(w32g_wrd_wnd.hwnd,w32g_wrd_wnd.hdc); { char fontname[1024]; if ( PlayerLanguage == LANGUAGE_JAPANESE ) strcpy(fontname,"俵俽 柧挬"); else strcpy(fontname,"Times New Roman"); w32g_wrd_wnd.hFont = CreateFont(w32g_wrd_wnd.font_height,w32g_wrd_wnd.font_width,0,0,FW_DONTCARE,FALSE,FALSE,FALSE, DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, FIXED_PITCH | FF_MODERN ,fontname); } hIcon = LoadImage(hInst, MAKEINTRESOURCE(IDI_ICON_TIMIDITY), IMAGE_ICON, 16, 16, 0); if (hIcon!=NULL) SendMessage(hWrdWnd,WM_SETICON,FALSE,(LPARAM)hIcon); wrd_wnd_unlock(); WrdWndReset(); w32g_wrd_wnd.active = FALSE; MoveWindow(w32g_wrd_wnd.hwnd,0,0,w32g_wrd_wnd.width,w32g_wrd_wnd.height,TRUE); WrdWndClear ( TRUE ); ShowWindow(w32g_wrd_wnd.hwnd,SW_SHOW); UpdateWindow(w32g_wrd_wnd.hwnd); UpdateWindow(hWrdWnd); WrdWndInfoApply();}static void wrd_graphic_terminate ( void ){ int index; wrd_wnd_lock(); GdiFlush (); for ( index = 0; index < W32G_WRDWND_GRAPHIC_PLANE_MAX; index++ ) { if ( w32g_wrd_wnd.graphic_dib[index] != NULL ) { dib_free ( w32g_wrd_wnd.graphic_dib[index] ); w32g_wrd_wnd.graphic_dib[index] = NULL; } } if ( w32g_wrd_wnd.bits_mag_work != NULL ) free ( w32g_wrd_wnd.bits_mag_work ); wrd_wnd_unlock();}// 僾儗乕儞 index 偺僌儔僼傿僢僋偺弶婜壔static void wrd_graphic_init ( HDC hdc ){ int index; wrd_wnd_lock(); wrd_graphic_terminate (); for ( index = 0; index < W32G_WRDWND_GRAPHIC_PLANE_MAX; index++ ) { w32g_wrd_wnd.graphic_dib[index] = dib_create ( w32g_wrd_wnd.width, w32g_wrd_wnd.height ); w32g_wrd_wnd.modified_graphic[index] = TRUE; } w32g_wrd_wnd.bits_mag_work = (char *) safe_malloc ( MAG_WORK_WIDTH * MAG_WORK_HEIGHT ); w32g_wrd_wnd.index_active = 0; w32g_wrd_wnd.index_display = 0; wrd_wnd_unlock(); wrd_graphic_reset_all ();}static void wrd_graphic_plane_change ( int active, int display ){ wrd_wnd_lock(); w32g_wrd_wnd.index_active = active; w32g_wrd_wnd.index_display = display; wrd_wnd_unlock();}static void wrd_graphic_reset ( int index ){ RECT rc; wrd_wnd_lock(); memset ( w32g_wrd_wnd.graphic_dib[index]->bits, 0, w32g_wrd_wnd.graphic_dib[index]->width * w32g_wrd_wnd.graphic_dib[index]->height ); dib_set_pals ( w32g_wrd_wnd.graphic_dib[index], w32g_wrd_wnd.default_gpal, W32G_WRDWND_GRAPHIC_PALLETE_MAX );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -