//============================================================== // 道を作る //============================================================== void CDunHard::CreateRoad(int uRoomA, int uRoomB) { RECT *pRectA, *pRectB; RECT *pRoomA, *pRoomB; pRectA = &m_Rect[uRoomA].Rect; pRectB = &m_Rect[uRoomB].Rect; pRoomA = &m_Rect[uRoomA].Room; pRoomB = &m_Rect[uRoomB].Room; //-- 区画は上下か左右のどちらで繋がっているかで処理をわける -- // 上下で繋がっているか? if(pRectA->bottom == pRectB->top || pRectA->top == pRectB->bottom) { int uX1, uX2, uY; uX1 = GetRand(RECT_W(*pRoomA)) + pRoomA->left; uX2 = GetRand(RECT_W(*pRoomB)) + pRoomB->left; if(pRectA->top > pRectB->top) { // B // A uY = pRectA->top; FillRect(uX1, uY + 1, uX1 + 1, pRoomA->top + 1, FALSE, FALSE); // Aと横道をつなぐ道を作る FillRect(uX2, pRoomB->bottom - 1, uX2 + 1, uY, FALSE, FALSE); // Bと横道をつなぐ道を作る } else { // A // B uY = pRectB->top; FillRect(uX1, pRoomA->bottom - 1, uX1 + 1, uY, FALSE, FALSE); FillRect(uX2, uY, uX2 + 1, pRoomB->top + 1, FALSE, FALSE); } FillHLine(uX1, uX2, uY, FALSE); // 横道を作る } // 左右で繋がっているか? else if(pRectA->right == pRectB->left || pRectA->left == pRectB->right ) { int uY1, uY2, uX; uY1 = GetRand(pRoomA->bottom - pRoomA->top) + pRoomA->top; uY2 = GetRand(pRoomB->bottom - pRoomB->top) + pRoomB->top; if(pRectA->left > pRectB->left) { // BA uX = pRectA->left; FillRect(pRoomB->right - 1, uY2, uX, uY2 + 1, FALSE, FALSE); FillRect(uX + 1, uY1, pRoomA->left + 1, uY1 + 1, FALSE, FALSE); } else { // AB uX = pRectB->left; FillRect(pRoomA->right - 1, uY1, uX, uY1 + 1, FALSE, FALSE); FillRect(uX, uY2, pRoomB->left + 1, uY2 + 1, FALSE, FALSE); } FillVLine(uY1, uY2, uX, FALSE); // 横道を作る } }
void render_line_sel( struct text_rendition *info, struct line_layout *ll ) { int base_x = ll->base_x; int base_y = ll->base_y; UINT_32 line_start = ll->line_start; UINT_32 line_end = ll->line_end; int sel_start_x = ll->sel_start_x; int sel_end_x = ll->sel_end_x; if (info->sel_from <= line_end && info->sel_to >= line_start) { int x, y, w, h; if (info->sel_from >= line_start) x = sel_start_x; else x = base_x; if (info->sel_to <= line_end) w = sel_end_x - x; else w = (base_x + info->line_width) - x; x += info->origin_x; h = info->line_height; y = base_y - h; XFillRectangle( info->ctx_dsp, info->ctx_win, info->ctx_gc, x + RECT_X(info->sel_bleed), y + RECT_Y(info->sel_bleed), w + RECT_W(info->sel_bleed), h + RECT_H(info->sel_bleed) ); } }
//============================================================== // それぞれの区画から部屋を作る //============================================================== void CDunHard::CreateRoom(int uRectIndex ) { int w, h, cw, ch, sw, sh, rw, rh, rx ,ry; RECT *pRect = &m_Rect[uRectIndex].Rect; // 区画情報 RECT *pRoom = &m_Rect[uRectIndex].Room; // これから作る部屋情報 // 矩形の大きさを計算 w = RECT_W(*pRect) - 3; h = RECT_H(*pRect) - 3; // 区画に入る最小部屋の余裕を求める cw = w - MIN_ROOM_SIZE; ch = h - MIN_ROOM_SIZE; // 部屋の大きさを決定する sw = GetRand(cw); sh = GetRand(ch); rw = w - sw; rh = h - sh; // 迷路を作る関係上、部屋サイズが奇数になるようにする if (rw % 2 == 0) { rw++; if (rw >= w) { rw -= 2; } } if (rh % 2 == 0) { rh++; if (rh >= h) { rh -= 2; } } // 部屋の位置を決定する rx = GetRand(sw) + 2; ry = GetRand(sh) + 2; // 求めた結果から部屋の情報を設定 pRoom->left = pRect->left + rx; pRoom->top = pRect->top + ry; pRoom->right = pRoom->left + rw; pRoom->bottom = pRoom->top + rh; // 部屋を作る FillRect( pRoom->left, pRoom->top, pRoom->right, pRoom->bottom, FALSE, TRUE); // 迷路化 m_Rect[uRectIndex].bMaze = false; if (rw >= MIN_MAZING || rh >= MIN_MAZING) { // ランダムで、1/2 if (GetRand(2)) { CreateMaze(uRectIndex); m_Rect[uRectIndex].bMaze = true; } } }
/* * OnInitDialog() */ BOOL sd_OnInitDialog(HWND storeDlg, HWND focusCtrl, LPARAM lParam) { int firstItem; int listItemCnt; int i, j; RECT clientRect; RECT lbxRect; RECT lbxPosRect; int lbxHeight; HWND okBtn; HWND cancelBtn; AREA otherCtrlArea; DWORD style; DWORD exStyle; BOOL loaded; /* * Set up the window. */ Window_Center(storeDlg, sd_parentWnd); sd_nameLcd = GetDlgItem(storeDlg, IDC_NAME_LCD); LcdCtrl_TextInit(sd_nameLcd, TX81Z_NAME_LEN); /* * Cache control handles */ okBtn = GetDlgItem(storeDlg, IDOK); cancelBtn = GetDlgItem(storeDlg, IDCANCEL); sd_lbx[0] = GetDlgItem(storeDlg, IDC_STORE1_LBX); sd_lbx[1] = GetDlgItem(storeDlg, IDC_STORE2_LBX); /* * Initialize the list boxes. */ TxLbx_Init(sd_lbx[0], &sd_txProps); TxLbx_Init(sd_lbx[1], &sd_txProps); /* * Initialize control settings. */ LcdCtrl_SetText(sd_nameLcd, sd_srcItemName); if (sd_itemToStore == SI_VCED) { firstItem = SI_VMEM; listItemCnt = 16; } else { /* sd_itemToStore == SI_PCED */ firstItem = SI_PMEM; listItemCnt = 12; } /* * Resize list boxes to fit their items exactly. */ GetClientRect(sd_lbx[0], &lbxRect); lbxRect.bottom = listItemCnt * 13; style = (DWORD) GetWindowLong(sd_lbx[0], GWL_STYLE); exStyle = (DWORD) GetWindowLong(sd_lbx[0], GWL_EXSTYLE); AdjustWindowRectEx(&lbxRect, style, FALSE, exStyle); lbxHeight = RECT_H(lbxRect); Window_GetParentRelativeRect(sd_lbx[0], storeDlg, &lbxPosRect); #define SPACING 6 /* * Move the OK button. */ Window_GetParentRelativeArea(okBtn, storeDlg, &otherCtrlArea); SetWindowPos(okBtn, NULL, otherCtrlArea.x , lbxPosRect.top + lbxHeight + SPACING, 0, 0 , SWP_NOSIZE | SWP_NOZORDER); /* * Move the cancel button. */ Window_GetParentRelativeArea(cancelBtn, storeDlg, &otherCtrlArea); otherCtrlArea.y = lbxPosRect.top + lbxHeight + SPACING; SetWindowPos(cancelBtn, NULL, otherCtrlArea.x, otherCtrlArea.y, 0, 0 , SWP_NOSIZE | SWP_NOZORDER); /* * Set the dialog position. */ GetClientRect(storeDlg, &clientRect); style = (DWORD) GetWindowLong(storeDlg, GWL_STYLE); exStyle = (DWORD) GetWindowLong(storeDlg, GWL_EXSTYLE); clientRect.bottom = AREA_B(otherCtrlArea) + SPACING; AdjustWindowRectEx(&clientRect, style, FALSE, exStyle); SetWindowPos(storeDlg, NULL, 0, 0, RECT_W(clientRect), RECT_H(clientRect) , SWP_NOMOVE | SWP_NOZORDER); /* * For each list box. */ loaded = Snapshot_IsItemGroupLoaded(&Prog_snapshot, firstItem); for (j = 0; j < 2; j++) { /* * Size the list box vertically to fit the number of items. */ SetWindowPos(sd_lbx[j], NULL, 0, 0, RECT_W(lbxRect), lbxHeight , SWP_NOMOVE | SWP_NOZORDER); /* * Add the list items. */ for (i = 0; i < listItemCnt; i++) { _TUCHAR text[40]; int index = i + j * listItemCnt; TXLBX_ATTR itemAttr; Snapshot_FormatName(&Prog_snapshot, firstItem + index , NF_NUMBER_AND_NAME, text); if (Snapshot_IsItemDirty(&Prog_snapshot, firstItem + index)) { itemAttr = TA_DIRTY; } else if (loaded) { itemAttr = TA_NORMAL; } else { itemAttr = TA_UNLOADED; } TxLbx_AddItem(sd_lbx[j], text, 0, itemAttr); } } return TRUE; }
//============================================================== // 区画を分ける //============================================================== void CDunHard::SplitRect(int nParentRectIndex, int nFlagHV) { DUNRECT *pParent, *pChild; RECT *pRect; int nChildIndex1 = 0, nChildIndex2 = 0; // わける区画情報を取得 pParent = &m_Rect[nParentRectIndex]; pRect = &pParent->Rect; //--------- // 分割する //--------- if((nFlagHV & 1) == 0) { // 横に分割する nFlagHV |= 1; // 区分を分割できるか?チェック if(RECT_W(*pRect) >= (MIN_ROOM_SIZE + 3) * 2 + 1) { int a, b, ab, p; // 左端のA点を求める a = MIN_ROOM_SIZE + 3; // 右端のB点を求める b = RECT_W(*pRect) - MIN_ROOM_SIZE - 4; // ABの距離を求める ab = b - a; // AB間のどこかに決定する p = a + GetRand(ab + 1); // 新しく右の区画を作成する pChild = CreateRect(pRect->left + p, pRect->top, pRect->right, pRect->bottom); // 元の区画の右を p 地点に移動させて、左側の区画とする pParent->Rect.right = pChild->Rect.left; // 子の部屋をさらに分割する nChildIndex1 = DunrectToIndex(pChild); SplitRect(nChildIndex1, 0); } } if((nFlagHV & 2) == 0) { // 縦に分割する nFlagHV |= 2; // 区分を分割できるか?チェック if( RECT_H(*pRect) >= (MIN_ROOM_SIZE+3)*2+1 ) { int a, b, ab, p; a = MIN_ROOM_SIZE + 3; b = RECT_H(*pRect) - MIN_ROOM_SIZE - 4; ab = b - a; p = a + GetRand(ab + 1); // 新しく下の区画を作成する pChild = CreateRect(pRect->left, pRect->top + p, pRect->right, pRect->bottom); // 元の区画の下を p 地点に移動させて、上側の区画とする pParent->Rect.bottom = pChild->Rect.top; // 子の部屋をさらに分割する nChildIndex2 = DunrectToIndex(pChild); SplitRect(nChildIndex2, 0); } } // 部屋を作る CreateRoom(nParentRectIndex); // 子供とつなげる if(nChildIndex1) { CreateRoad( nParentRectIndex, nChildIndex1 ); } if(nChildIndex2) { CreateRoad( nParentRectIndex, nChildIndex2 ); } }
/* * Create - displays the dialog box */ HWND RemoteWnd_Create(HWND parentWnd) { HWND remoteWnd; if (Prog_remoteWnd) { if (IsIconic(Prog_remoteWnd)) { OpenIcon(Prog_remoteWnd); } BringWindowToTop(Prog_remoteWnd); remoteWnd = Prog_remoteWnd; } else { RECT wndRect = { 60, 60, 685, 120 }; DWORD wndExStyles = WS_EX_LEFT; DWORD wndStyles = WS_POPUPWINDOW | WS_CAPTION | WS_SYSMENU; int i; if (!AdjustWindowRectEx(&wndRect, wndStyles, FALSE, wndExStyles)) { MsgBox_LastErrorF(parentWnd, _T("Error adjusting window rect")); } remoteWnd = CreateWindowEx( wndExStyles /* extended styles */ , RemoteWnd_className /* window class */ , _T("Remote") /* caption text */ , wndStyles /* styles */ , wndRect.left, wndRect.top /* left, top */ , RECT_W(wndRect), RECT_H(wndRect) /* width, height */ , NULL /* parent window */ , (HMENU) NULL /* menu */ , Prog_instance /* program instance */ , NULL /* creation data */ ); if (!remoteWnd) { MsgBox_LastErrorF(parentWnd , _T("Error creating remote control window")); return NULL; } /* * Add "Stay On Top" system menu item. */ Window_AddSysMenuItem(remoteWnd, _T("Stay On Top"), IDM_STAY_ON_TOP , TRUE); rw_StayOnTop(remoteWnd); /* * Initialize buttons. */ for (i = 0; i < btnInitCnt; i++) { HWND btn = CreateWindowEx( 0 /* extended styles */ , _T("BUTTON") /* window class */ , _T("TX81Z Remote") /* caption text */ , BS_OWNERDRAW | WS_CHILD | WS_VISIBLE /* styles */ , btnInits[i].x, btnInits[i].y /* left, top */ , btnInits[i].w, btnInits[i].h /* width, height */ , remoteWnd /* parent window */ , (HMENU) btnInits[i].btnID /* menu */ , Prog_instance /* program instance */ , NULL /* creation data */ ); if (!btn) { MsgBox_LastErrorF(parentWnd , _T("Error creating remote control button")); return NULL; } rw_origBtnProc = (WNDPROC) SetWindowLong(btn, GWL_WNDPROC , (long) rw_BtnProc); } ShowWindow(remoteWnd, SW_SHOW); } return remoteWnd; }
/* * OnInitDialog() */ BOOL mfd_OnInitDialog(HWND mtfDlg, HWND focusCtrl, LPARAM lParam) { HWND ctrl; int i; SPECIALLCDINIT noteLcdInit = { IDC_MT_NOTE_1, 3, 13, 109 , Prog_keyNameStrings[13], NULL }; NUMLCDINIT fineLcdInit = { IDC_MT_FINE_1, 3, 0, 63, -31, NULL }; NUMLCDINIT fullLcdInit = { IDC_MT_FULL_1, 4, 0, 6143, 0, NULL }; _TUCHAR noteName[5]; mfd_dlgData.wnd = Prog_mtfDlg = mtfDlg; /* * Adjust the window position. */ if (IsRectEmpty(&Prog_mtfDlgPlacement.rcNormalPosition)) { Window_Center(mtfDlg, mfd_parentWnd); GetWindowPlacement(mtfDlg, &Prog_mtfDlgPlacement); } /* * Set up dialog controls. */ for (i = 0; i < mfd_initCnt; i++) { int topOffset = 34 * i; /* * Create note label. */ KybdCtrl_KeyToText(i, noteName); ctrl = CreateWindow( _T("Static") /* window class */ , noteName /* caption text */ , WS_CHILD | WS_GROUP | WS_VISIBLE /* styles */ | SS_LEFT , 3, 7 + topOffset /* left, top */ , 26, 13 /* width, height */ , mtfDlg /* parent window */ , (HMENU) IDC_STATIC /* control ID */ , Prog_instance /* program instance */ , NULL /* creation data */ ); if (!ctrl) { Error_LastErrorF(_T("Error creating %s note label"), noteName); return FALSE; } SetWindowFont(ctrl, Prog_tahomaFont, FALSE); /* * Create Note LCD. */ ctrl = CreateWindow( _T("LcdCtrl") /* window class */ , NULL /* caption text */ , WS_CHILD | WS_TABSTOP | WS_VISIBLE /* styles */ | LCS_SMALL | LCS_TEXT | LCS_LEFT_SB , 32, topOffset /* left, top */ , 324, 13 /* width, height */ , mtfDlg /* parent window */ , (HMENU) (IDC_MT_NOTE_1 + (i << 1)) /* control ID */ , Prog_instance /* program instance */ , NULL /* creation data */ ); if (!ctrl) { Error_LastErrorF(_T("Error creating %s note LCD"), noteName); return FALSE; } LcdCtrl_SpecialInit(ctrl, ¬eLcdInit); KeyNav_SubclassLcdCtrl(ctrl); /* * Create fine LCD. */ ctrl = CreateWindow( _T("LcdCtrl") /* window class */ , NULL /* caption text */ , WS_CHILD | WS_TABSTOP | WS_VISIBLE /* styles */ | LCS_SMALL | LCS_NUMERIC | LCS_SHOWPLUS | LCS_LEFT_SB , 360, topOffset /* left, top */ , 143, 13 /* width, height */ , mtfDlg /* parent window */ , (HMENU) (IDC_MT_FINE_1 + (i << 1)) /* control ID */ , Prog_instance /* program instance */ , NULL /* creation data */ ); if (!ctrl) { Error_LastErrorF(_T("Error creating %s fine LCD"), noteName); return FALSE; } LcdCtrl_NumInit(ctrl, &fineLcdInit); KeyNav_SubclassLcdCtrl(ctrl); /* * Create full range LCD. */ ctrl = CreateWindow( _T("LcdCtrl") /* window class */ , NULL /* caption text */ , WS_CHILD | WS_TABSTOP | WS_VISIBLE /* styles */ | LCS_SMALL | LCS_NUMERIC | LCS_LEFT_SB , 32, 15 + topOffset /* left, top */ , 471, 13 /* width, height */ , mtfDlg /* parent window */ , (HMENU) (IDC_MT_FULL_1 + i) /* control ID */ , Prog_instance /* program instance */ , NULL /* creation data */ ); if (!ctrl) { Error_LastErrorF(_T("Error creating %s full range LCD"), noteName); return FALSE; } LcdCtrl_NumInit(ctrl, &fullLcdInit); KeyNav_SubclassLcdCtrl(ctrl); /* * Create frequency static control. */ ctrl = CreateWindow( _T("Static") /* window class */ , NULL /* caption text */ , WS_CHILD | WS_VISIBLE | SS_RIGHT /* styles */ | SS_SUNKEN , 508, 7 + topOffset /* left, top */ , 40, 16 /* width, height */ , mtfDlg /* parent window */ , (HMENU) (IDC_MT_FREQ_1 + i) /* control ID */ , Prog_instance /* program instance */ , NULL /* creation data */ ); if (!ctrl) { Error_LastErrorF(_T("Error creating %s frequency display"), noteName); return FALSE; } SetWindowFont(ctrl, Prog_tahomaFont, FALSE); } /* * Set up the undo infrastructure. */ mfd_dlgData.menu = GetMenu(mtfDlg); mfd_dlgData.undo = Undo_Create(); /* * Init control values. */ MTGen_InitControlValues(&mfd_dlgData); /* * Set up the scrolling dialog module. */ if (!(mfd_dialog = Dialog_Create(mtfDlg))) return FALSE; Dialog_UpdateScrollBars(mfd_dialog); /* * Adjust and display the window. */ #define RC Prog_mtfDlgPlacement.rcNormalPosition MoveWindow(mtfDlg, RC.left, RC.top , RECT_W(RC) + GetSystemMetrics(SM_CXHSCROLL) , RECT_H(RC) + GetSystemMetrics(SM_CYVSCROLL), TRUE); MoveWindow(mtfDlg, RC.left, RC.top, RECT_W(RC), RECT_H(RC), TRUE); #undef RC ShowWindow(mtfDlg, SW_SHOWNORMAL); return TRUE; }