From e5c5db1804aee689c03039ebc9aeca387091c854 Mon Sep 17 00:00:00 2001 From: iks Date: Sat, 7 Mar 2009 21:36:47 +0000 Subject: [PATCH] =?utf8?q?windows=E7=89=88=E3=81=AB=E3=83=9E=E3=82=A6?= =?utf8?q?=E3=82=B9=E3=82=92=E4=BD=BF=E3=81=A3=E3=81=9F=E7=94=BB=E9=9D=A2?= =?utf8?q?=E3=82=B3=E3=83=94=E3=83=BC=E3=82=A2=E3=83=B3=E3=83=89=E3=83=9A?= =?utf8?q?=E3=83=BC=E3=82=B9=E3=83=88=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD?= =?utf8?q?=E5=8A=A0=E3=80=82(from=20XAngband)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/main-win.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 151 insertions(+), 1 deletion(-) diff --git a/src/main-win.c b/src/main-win.c index 2fddbbf9f..0bf6c49e7 100644 --- a/src/main-win.c +++ b/src/main-win.c @@ -76,7 +76,7 @@ #ifdef WINDOWS - +#include #include /* @@ -196,7 +196,9 @@ /* * This may need to be removed for some compilers XXX XXX XXX */ +#if 0 #define STRICT +#endif /* * Exclude parts of WINDOWS.H that are not needed @@ -575,6 +577,14 @@ static COLORREF win_clr[256]; */ static bool Term_no_press = FALSE; +/* + * Copy and paste + */ +static bool mouse_down = FALSE; +static bool paint_rect = FALSE; +static int mousex = 0, mousey = 0; +static int oldx, oldy; + /* * The "simple" color values @@ -1926,6 +1936,28 @@ static void term_data_redraw(term_data *td) } +void Term_inversed_area(HWND hWnd, int x, int y, int w, int h) +{ + HDC hdc; + HPEN oldPen; + HBRUSH myBrush, oldBrush; + + term_data *td = (term_data *)GetWindowLong(hWnd, 0); + int tx = td->size_ow1 + x * td->tile_wid; + int ty = td->size_oh1 + y * td->tile_hgt; + int tw = w * td->tile_wid - 1; + int th = h * td->tile_hgt - 1; + + hdc = GetDC(hWnd); + myBrush = CreateSolidBrush(RGB(255, 255, 255)); + oldBrush = SelectObject(hdc, myBrush); + oldPen = SelectObject(hdc, GetStockObject(NULL_PEN) ); + + PatBlt(hdc, tx, ty, tw, th, PATINVERT); + + SelectObject(hdc, oldBrush); + SelectObject(hdc, oldPen); +} @@ -4339,6 +4371,124 @@ LRESULT FAR PASCAL AngbandWndProc(HWND hWnd, UINT uMsg, return 0; } + case WM_LBUTTONDOWN: + { + mousex = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1); + mousey = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1); + mouse_down = TRUE; + oldx = mousex; + oldy = mousey; + return 0; + } + + case WM_LBUTTONUP: + { + HGLOBAL hGlobal; + LPSTR lpStr; + int i, j, sz; + int dx = abs(oldx - mousex) + 1; + int dy = abs(oldy - mousey) + 1; + int ox = (oldx > mousex) ? mousex : oldx; + int oy = (oldy > mousey) ? mousey : oldy; + + mouse_down = FALSE; + paint_rect = FALSE; + +#ifdef JP + sz = (dx + 3) * dy; +#else + sz = (dx + 2) * dy; +#endif + hGlobal = GlobalAlloc(GHND, sz + 1); + if (hGlobal == NULL) return 0; + lpStr = (LPSTR)GlobalLock(hGlobal); + + for (i = 0; i < dy; i++) + { +#ifdef JP + char *s; + char **scr = data[0].t.scr->c; + + C_MAKE(s, (dx + 1), char); + strncpy(s, &scr[oy + i][ox], dx); + + if (ox > 0) + { + if (iskanji(scr[oy + i][ox - 1])) s[0] = ' '; + } + + if (ox + dx < data[0].cols) + { + if (iskanji(scr[oy + i][ox + dx - 1])) s[dx - 1] = ' '; + } + + for (j = 0; j < dx; j++) + { + if (s[j] == 127) s[j] = '#'; + *lpStr++ = s[j]; + } +#else + for (j = 0; j < dx; j++) + { + *lpStr++ = data[0].t.scr->c[oy + i][ox + j]; + } +#endif + if (dy > 1) + { + *lpStr++ = '\r'; + *lpStr++ = '\n'; + } + } + + GlobalUnlock(hGlobal); + if (OpenClipboard(hWnd) == 0) + { + GlobalFree(hGlobal); + return 0; + } + EmptyClipboard(); + SetClipboardData(CF_TEXT, hGlobal); + CloseClipboard(); + + Term_redraw(); + + return 0; + } + + case WM_MOUSEMOVE: + { + if (mouse_down) + { + int dx, dy; + int cx = MIN(LOWORD(lParam) / td->tile_wid, td->cols - 1); + int cy = MIN(HIWORD(lParam) / td->tile_hgt, td->rows - 1); + int ox, oy; + + if (paint_rect) + { + dx = abs(oldx - mousex) + 1; + dy = abs(oldy - mousey) + 1; + ox = (oldx > mousex) ? mousex : oldx; + oy = (oldy > mousey) ? mousey : oldy; + Term_inversed_area(hWnd, ox, oy, dx, dy); + } + else + { + paint_rect = TRUE; + } + + dx = abs(cx - mousex) + 1; + dy = abs(cy - mousey) + 1; + ox = (cx > mousex) ? mousex : cx; + oy = (cy > mousey) ? mousey : cy; + Term_inversed_area(hWnd, ox, oy, dx, dy); + + oldx = cx; + oldy = cy; + } + return 0; + } + case WM_INITMENU: { setup_menus(); -- 2.11.0