// Quadtree를 4개의 자식 트리로 부분분할(subdivide)한다. BOOL ZQuadTree::_SubDivide() { int nTopEdgeCenter; int nBottomEdgeCenter; int nLeftEdgeCenter; int nRightEdgeCenter; int nCentralPoint; // 상단변 가운데 nTopEdgeCenter = ( m_nCorner[CORNER_TL] + m_nCorner[CORNER_TR] ) / 2; // 하단변 가운데 nBottomEdgeCenter = ( m_nCorner[CORNER_BL] + m_nCorner[CORNER_BR] ) / 2; // 좌측변 가운데 nLeftEdgeCenter = ( m_nCorner[CORNER_TL] + m_nCorner[CORNER_BL] ) / 2; // 우측변 가운데 nRightEdgeCenter = ( m_nCorner[CORNER_TR] + m_nCorner[CORNER_BR] ) / 2; // 한가운데 nCentralPoint = ( m_nCorner[CORNER_TL] + m_nCorner[CORNER_TR] + m_nCorner[CORNER_BL] + m_nCorner[CORNER_BR] ) / 4; // 더이상 분할이 불가능한가? 그렇다면 SubDivide() 종료 if( (m_nCorner[CORNER_TR] - m_nCorner[CORNER_TL]) <= 1 ) { return FALSE; } // 4개의 자식노드 추가 m_pChild[CORNER_TL] = _AddChild( m_nCorner[CORNER_TL], nTopEdgeCenter, nLeftEdgeCenter, nCentralPoint ); m_pChild[CORNER_TR] = _AddChild( nTopEdgeCenter, m_nCorner[CORNER_TR], nCentralPoint, nRightEdgeCenter ); m_pChild[CORNER_BL] = _AddChild( nLeftEdgeCenter, nCentralPoint, m_nCorner[CORNER_BL], nBottomEdgeCenter ); m_pChild[CORNER_BR] = _AddChild( nCentralPoint, nRightEdgeCenter, nBottomEdgeCenter, m_nCorner[CORNER_BR] ); return TRUE; }
bool AVQuadTree::_SubDivide() { int topCenter, leftCenter, rightCenter, bottomCenter, realCenter; topCenter = (m_nCorner[DIR_TL] + m_nCorner[DIR_TR]) / 2; leftCenter = (m_nCorner[DIR_TL] + m_nCorner[DIR_BL]) / 2; rightCenter = (m_nCorner[DIR_TR] + m_nCorner[DIR_BR]) / 2; bottomCenter = (m_nCorner[DIR_BL] + m_nCorner[DIR_BR]) / 2; realCenter = (m_nCorner[DIR_TL] + m_nCorner[DIR_TR] + m_nCorner[DIR_BL] + m_nCorner[DIR_BR]) / 4; if( (m_nCorner[DIR_TR] - m_nCorner[DIR_TL]) <= 1 ) return false; m_pChild[DIR_TL] = _AddChild(m_nCorner[DIR_TL], topCenter, leftCenter, realCenter); m_pChild[DIR_TR] = _AddChild(topCenter, m_nCorner[DIR_TR], realCenter, rightCenter); m_pChild[DIR_BL] = _AddChild(leftCenter, realCenter, m_nCorner[DIR_BL], bottomCenter); m_pChild[DIR_BR] = _AddChild(realCenter, rightCenter, bottomCenter, m_nCorner[DIR_BR]); return true; }
bool ZQuadTree::_SubDivide() { Point nTopEdgeCenter; Point nBottomEdgeCenter; Point nLeftEdgeCenter; Point nRightEdgeCenter; Point nCentralPoint; if(m_nCorner[CORNER_TR].x - m_nCorner[CORNER_TL].x <= MIN_SIZE) return false; //상단변 가운데 nTopEdgeCenter.x = (m_nCorner[CORNER_TL].x + m_nCorner[CORNER_TR].x)/2; nTopEdgeCenter.y = m_nCorner[CORNER_TL].y; //하단변 가운데 nBottomEdgeCenter.x = (m_nCorner[CORNER_BL].x + m_nCorner[CORNER_BR].x)/2; nBottomEdgeCenter.y = m_nCorner[CORNER_BL].y; //좌측변 가운데 nLeftEdgeCenter.x = m_nCorner[CORNER_TL].x; nLeftEdgeCenter.y = (m_nCorner[CORNER_TL].y + m_nCorner[CORNER_BL].y)/2; //우측변 가운데 nRightEdgeCenter.x = m_nCorner[CORNER_TR].x; nRightEdgeCenter.y = (m_nCorner[CORNER_TR].y + m_nCorner[CORNER_BR].y)/2; nCentralPoint.x = (m_nCorner[CORNER_TL].x + m_nCorner[CORNER_TR].x)/2; nCentralPoint.y = (m_nCorner[CORNER_TR].y + m_nCorner[CORNER_BR].y)/2; //4개의 자식노드 추가 m_pChild[CORNER_TL] = _AddChild(m_nCorner[CORNER_TL], nTopEdgeCenter, nLeftEdgeCenter, nCentralPoint); m_pChild[CORNER_TR] = _AddChild(nTopEdgeCenter, m_nCorner[CORNER_TR], nCentralPoint, nRightEdgeCenter); m_pChild[CORNER_BL] = _AddChild(nLeftEdgeCenter, nCentralPoint, m_nCorner[CORNER_BL], nBottomEdgeCenter); m_pChild[CORNER_BR] = _AddChild(nCentralPoint, nRightEdgeCenter, nBottomEdgeCenter, m_nCorner[CORNER_BR]); return true; }
WM_HWIN WM_CreateWindowAsChild( int x0, int y0, int width, int height ,WM_HWIN hWinParent ,U16 Style ,WM_CALLBACK* cb ,int NumExtraBytes) { WM_Obj* pWin; WM_HWIN hWin; WM_LOCK(); Style |= WM__CreateFlags; /* Get Parent info */ if (!hWinParent) { if (WM__NumWindows) { hWinParent = WM_HBKWIN; } } if (hWinParent) { GUI_RECT Rect; WM_MESSAGE Msg; Msg.MsgId = WM_GETCLIENTRECT_ABS; Msg.Data.p = &Rect; WM_SendMessage(hWinParent, &Msg); x0 += Rect.x0; y0 += Rect.y0; if (width==0) width = Rect.x1-Rect.x0+1; if (height==0) height = Rect.y1-Rect.y0+1; } if ((hWin = (WM_HWIN) WM_ALLOC(NumExtraBytes+sizeof(WM_Obj))) == 0) { GUI_DEBUG_ERROROUT("WM_CreateWindow: No memory to create window"); } else { WM__NumWindows++; pWin = WM_H2P(hWin); memset (pWin, 0, sizeof(WM_Obj)); /* erase this data structure The explicit zero-init is no longer needed since the entire data structure is already zeroed. The advantage is that it reduces program size. */ pWin->Rect.x0 = x0; pWin->Rect.y0 = y0; pWin->Rect.x1 = x0+width-1; pWin->Rect.y1 = y0+height-1; pWin->Status = WM_SF_INUSE; /* Mark window as in use */ pWin->cb = cb; /* Add to linked lists */ pWin->hParent = hWinParent; _AddChild(hWinParent, hWin, Style & WM_CF_STAYONTOP); _AddToLinList(hWin); /* Put Window on top (or bottom) of windows stack */ if (Style & WM_CF_ACTIVATE /*| (cb==NULL)*/) { WM_SelectWindow(hWin); /* This is not needed if callbacks are being used, but it does not cost a lot and makes life easier ... */ } /* Mark client area as invalid */ WM__SendMsgNoData(hWin, WM_CREATE); /* Handle the Style flags, one at a time */ if (Style & WM_CF_SHOW) { WM_ShowWindow(hWin); } /* Hide if parent is not visible */ if (hWinParent) { WM_Obj* pWinParent = WM_H2P(hWinParent); if (!(pWinParent->Status & WM_SF_ISVIS)) { WM_HideWindow(hWin); } } /* Copy the flags which can simply be accepted */ pWin->Status |= (Style & (WM_SF_MEMDEV|WM_SF_STAYONTOP|WM_SF_HASTRANS)); } WM_UNLOCK(); return hWin; }
//----创建窗口------------------------------------------------------------------ //描述: 该函数可以创建主窗口和子窗口(控件) //参数:proc: 窗口过程回调函数 // Text: 窗口文字指针 // Style: 窗口风格(具体参考窗口风格组合说明) // x,y,w,h: 桌面窗口位置和大小 // hParent: 父窗口句柄.如果是NULL,则默认桌面为父窗口. // WinId: 窗口Id.如果是主窗口,该参数被忽略. // pdata: 用户自定义附加数据. //返回:窗口句柄. //------------------------------------------------------------------------------ HWND CreateWindow(WNDPROC *pfWinProc, const char *Text,u32 Style, s32 x,s32 y,s32 w,s32 h, HWND hParent,u32 WinId,const void *pdata) { WINDOW *pwin=NULL; struct tagGkWinRsc *pGkWin=NULL; if(NULL==hParent) { hParent =GetDesktopWindow(); } if(HWND_Lock(hParent)) { pwin =WIN_Alloc(); if(NULL!=pwin) { //初始化窗口数据 _InitWindow(pwin,pfWinProc,Text,Style,x,y,w,h,hParent,WinId); x =pwin->WinRect.left; y =pwin->WinRect.top; w =RectW(&pwin->WinRect); h =RectH(&pwin->WinRect); pGkWin =(struct tagGkWinRsc*)malloc(sizeof(struct tagGkWinRsc)); if(Style&WS_CHILD) { if(!GK_ApiCreateGkwin(pGkWinDesktop, pGkWin,x,y,x+w,y+h, RGB(0,0,0), CN_WINBUF_BUF, pwin->Name, CN_SYS_PF_DISPLAY, 0,0,0)) { free(pGkWin); return NULL; } pwin->mutex_lock =hParent->mutex_lock; //子窗口使用父窗口锁 pwin->pMsgQ =hParent->pMsgQ; //子窗口使用父窗口消息队列 pwin->EventID =hParent->EventID; pwin->Zorder =hParent->Zorder-1; GK_ApiSetPrio(pGkWin,pwin->Zorder,100*mS); } else { if(!GK_ApiCreateGkwin(pGkWinDesktop, pGkWin,x,y,x+w,y+h, RGB(0,0,0), CN_WINBUF_BUF, pwin->Name, CN_SYS_PF_DISPLAY, 0,0,0)) { free(pGkWin); return NULL; } pwin->mutex_lock =Lock_MutexCreate(NULL); pwin->pMsgQ =GUI_CreateMsgQ(32); pwin->EventID =Djy_MyEventId(); pwin->Zorder =hParent->Zorder-1; GK_ApiSetPrio(pGkWin,pwin->Zorder,100*mS); } pwin->pGkWin = pGkWin; //将新窗口添加到父窗口 _AddChild(hParent,pwin); } HWND_Unlock(hParent); if(NULL!=pwin) { SendMessage(pwin,MSG_CREATE,(u32)pdata,0); InvalidateWindow(pwin); } } return pwin; }