// TODO: Pass the event object around instead of keeping a global one void Mouse_Pressed() { if(had_text_freeze > 0) { had_text_freeze--; return; } if(overall_mode != MODE_STARTUP) { location mousePos(event.mouseButton.x, event.mouseButton.y); volatile bool doneScrolling = false; if(mousePos.in(text_sbar->getBounds())) { mainPtr.setActive(false); boost::thread updater(std::bind(handleUpdateWhileScrolling, std::ref(doneScrolling), REFRESH_TRANS)); text_sbar->handleClick(mousePos); doneScrolling = true; updater.join(); redraw_screen(REFRESH_TRANS); } else if(mousePos.in(item_sbar->getBounds())) { mainPtr.setActive(false); boost::thread updater(std::bind(handleUpdateWhileScrolling, std::ref(doneScrolling), REFRESH_INVEN)); item_sbar->handleClick(mousePos); doneScrolling = true; updater.join(); redraw_screen(REFRESH_INVEN); } else if(overall_mode == MODE_SHOPPING && mousePos.in(shop_sbar->getBounds())) { mainPtr.setActive(false); boost::thread updater(std::bind(handleUpdateWhileScrolling, std::ref(doneScrolling), REFRESH_DLOG)); shop_sbar->handleClick(mousePos); doneScrolling = true; updater.join(); redraw_screen(REFRESH_DLOG); } else All_Done = handle_action(event); } else All_Done = handle_startup_press({event.mouseButton.x, event.mouseButton.y}); menu_activate(); }
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; POINT press; HMENU menu; RECT dlg_rect; RECT wind_rect; short handled = 0; short store_ulx; short store_uly; short sbar_pos; short which_sbar; short old_setting; short smin; short smax; // First, handle window size GetWindowRect(mainPtr,&wind_rect); switch (display_mode) { //case 0 is center case 1: store_ulx = 0; store_uly = 0; break; case 2: store_ulx = wind_rect.right - 550 - 21; store_uly = 0; break; case 3: store_ulx = 0; store_uly = wind_rect.bottom - 422 - 24 - 21; break; case 4: store_ulx = wind_rect.right - 550 - 21; store_uly = wind_rect.bottom - 422 - 24 - 21; break; case 5: store_ulx = 0; store_uly = 0; break; default: store_ulx = ((wind_rect.right - wind_rect.left) - 536) / 2 - 30; store_uly = ((wind_rect.bottom - wind_rect.top) - 478) / 2 + 8; break; } store_ulx -= store_ulx % 8; store_uly -= store_uly % 8; if ((store_ulx != ulx) || (store_uly != uly)) { ulx = store_ulx; uly = store_uly; adjust_window_mode(); } switch (message) { case WM_KEYDOWN: if (hwnd != mainPtr) check_cd_event(hwnd,message,wParam,lParam); else { cursor_go(); All_Done = handle_syskeystroke(wParam,lParam,&handled); check_game_done(); } if (handled == 1) FlushEvents(0); return 0; case WM_CHAR: if (hwnd != mainPtr) check_cd_event(hwnd,message,wParam,lParam); else { cursor_go(); All_Done = handle_keystroke(wParam,lParam); check_game_done(); } return 0; case WM_LBUTTONDOWN: cursor_stay(); if (hwnd != mainPtr) check_cd_event(hwnd,message,wParam,lParam); else { SetFocus(hwnd); press = MAKEPOINT(lParam); if (in_startup_mode == false) All_Done = handle_action(press, wParam,lParam); else All_Done = handle_startup_press(press); change_cursor(press); check_game_done(); } return 0; break; case WM_RBUTTONDOWN: cursor_stay(); if (hwnd != mainPtr) check_cd_event(hwnd,message,wParam,lParam); else { SetFocus(hwnd); press = MAKEPOINT(lParam); if (in_startup_mode == false) All_Done = handle_action(press, wParam,-2); else All_Done = handle_startup_press(press); change_cursor(press); check_game_done(); } return 0; break; case WM_ACTIVATE: if (hwnd == mainPtr) { WORD fActive = LOWORD(wParam); if ((fActive == WA_ACTIVE) ||(fActive == WA_CLICKACTIVE)) { window_in_front = true; GetClientRect(hwnd,&dlg_rect); InvalidateRect(hwnd,&dlg_rect,false); } if (fActive == WA_INACTIVE) { cursor_stay(); anim_onscreen = false; window_in_front = false; } } return 0; case WM_ERASEBKGND: if (hwnd != mainPtr) break; block_erase = false; return 1; case WM_MOUSEMOVE: if (store_mouse != lParam) cursor_stay(); store_mouse = lParam; press = MAKEPOINT(lParam); if (hwnd == mainPtr) { change_cursor(press); if ((overall_mode > MODE_COMBAT) && (overall_mode < MODE_TALKING)) draw_targeting_line(press); } return 0; case WM_PAINT: if ((block_erase == true) && (hwnd == mainPtr)) { block_erase = false; } BeginPaint(hwnd,&ps); EndPaint(hwnd,&ps); if (hwnd != mainPtr) check_cd_event(hwnd,message,wParam,lParam); else { string_added = true; reset_text_bar(); if (in_startup_mode == true) draw_startup(0); else if (first_update == true) { first_update = false; if (overall_mode == MODE_OUTDOORS) redraw_screen(0); if ((overall_mode > MODE_OUTDOORS) & (overall_mode < MODE_COMBAT)) redraw_screen(1); // 1st update never combat } else refresh_screen(overall_mode); } return 0; case WM_TIMER: switch(wParam) { case 1: if ((in_startup_mode == false) && (anim_onscreen == true) && (window_in_front == true) && (give_delays == false)) { if(PSD[SDF_NO_TER_ANIM] != 1) anim_ticks++; initiate_redraw(); } break; case 2: if ((overall_mode > MODE_COMBAT) && (overall_mode < MODE_TALKING)) { GetCursorPos(&press); press.x -= wind_rect.left + 3; press.y -= wind_rect.top + 41; draw_targeting_line(press); } if ((in_startup_mode == true) && (window_in_front == true)) draw_startup_anim(); break; } return 0; case WM_COMMAND: // 1006 is dummy event // creation events 2000 spend xp 2001 pick graphic 2002 finish up if (hwnd == mainPtr) { menu = GetMenu(mainPtr); All_Done = handle_menu((short) LOWORD(wParam), menu); check_game_done(); } else check_cd_event(hwnd,message,wParam,lParam); return 0; case WM_VSCROLL: which_sbar = GetWindowLong((HWND) lParam, GWL_ID); switch (which_sbar) {// 1 text 2 items 3 shop case 1: sbar_pos = GetScrollPos(text_sbar,SB_CTL); switch (wParam ) { case SB_PAGEDOWN: sbar_pos += 11; break; case SB_LINEDOWN: sbar_pos++; break; case SB_PAGEUP: sbar_pos -= 11; break; case SB_LINEUP: sbar_pos--; break; case SB_TOP: sbar_pos = 0; break; case SB_BOTTOM: sbar_pos = 57; break; case SB_THUMBPOSITION: case SB_THUMBTRACK: sbar_pos = LOWORD(lParam); break; } if (sbar_pos < 0) sbar_pos = 0; if (sbar_pos > 58) sbar_pos = 58; { // SetScrollPos(text_sbar,SB_CTL,sbar_pos,true); lpsi.nPos = sbar_pos; lpsi.fMask = SIF_POS; SetScrollInfo(text_sbar,SB_CTL,&lpsi,true); } string_added = true; print_buf(); break; case 2: old_setting = sbar_pos = GetScrollPos(item_sbar,SB_CTL); GetScrollRange(item_sbar,SB_CTL,(int *) &smin,(int *) &smax); switch (wParam ) { case SB_PAGEDOWN: sbar_pos += (stat_window == 7) ? 2 : 8; break; case SB_LINEDOWN: sbar_pos++; break; case SB_PAGEUP: sbar_pos -= (stat_window == 7) ? 2 : 8; break; case SB_LINEUP: sbar_pos--; break; case SB_TOP: sbar_pos = 0; break; case SB_BOTTOM: sbar_pos = smax; break; case SB_THUMBPOSITION: case SB_THUMBTRACK: sbar_pos = LOWORD(lParam); break; } if (sbar_pos < 0) sbar_pos = 0; if (sbar_pos > smax) sbar_pos = smax; { // SetScrollPos(item_sbar,SB_CTL,sbar_pos,true); lpsi.nPos = sbar_pos; lpsi.fMask = SIF_POS; SetScrollInfo(item_sbar,SB_CTL,&lpsi,true); } if (sbar_pos != old_setting) put_item_screen(stat_window,1); break; case 3: old_setting = sbar_pos = GetScrollPos(shop_sbar,SB_CTL); GetScrollRange(shop_sbar,SB_CTL,(int *) &smin,(int *) &smax); switch (wParam ) { case SB_PAGEDOWN: sbar_pos += 8; break; case SB_LINEDOWN: sbar_pos++; break; case SB_PAGEUP: sbar_pos -= 8; break; case SB_LINEUP: sbar_pos--; break; case SB_TOP: sbar_pos = 0; break; case SB_BOTTOM: sbar_pos = smax; break; case SB_THUMBPOSITION: case SB_THUMBTRACK: sbar_pos = LOWORD(lParam); break; } if (sbar_pos < 0) sbar_pos = 0; if (sbar_pos > smax) sbar_pos = smax; { // SetScrollPos(shop_sbar,SB_CTL,sbar_pos,true); lpsi.nPos = sbar_pos; lpsi.fMask = SIF_POS; SetScrollInfo(shop_sbar,SB_CTL,&lpsi,true); } if (sbar_pos != old_setting) draw_shop_graphics(0,shop_sbar_rect); break; } SetFocus(mainPtr); return 0; case WM_DESTROY: case WM_CLOSE: if (hwnd == mainPtr) { lose_graphics(); PostQuitMessage(0); } return 0; case WM_QUIT: if (hwnd == mainPtr) lose_graphics(); break; } return DefWindowProc(hwnd,message,wParam,lParam); }