Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygengraphctl.c
Go to the documentation of this file.
00001 /* 00002 * ReactOS Task Manager 00003 * 00004 * graphctl.c 00005 * 00006 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org> 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License along 00019 * with this program; if not, write to the Free Software Foundation, Inc., 00020 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 00021 */ 00022 00023 #include <precomp.h> 00024 00025 WNDPROC OldGraphCtrlWndProc; 00026 00027 static void GraphCtrl_Init(TGraphCtrl* this) 00028 { 00029 int i; 00030 00031 this->m_hWnd = 0; 00032 this->m_hParentWnd = 0; 00033 this->m_dcGrid = 0; 00034 this->m_dcPlot = 0; 00035 this->m_bitmapOldGrid = 0; 00036 this->m_bitmapOldPlot = 0; 00037 this->m_bitmapGrid = 0; 00038 this->m_bitmapPlot = 0; 00039 this->m_brushBack = 0; 00040 00041 this->m_penPlot[0] = 0; 00042 this->m_penPlot[1] = 0; 00043 this->m_penPlot[2] = 0; 00044 this->m_penPlot[3] = 0; 00045 00046 /* since plotting is based on a LineTo for each new point 00047 * we need a starting point (i.e. a "previous" point) 00048 * use 0.0 as the default first point. 00049 * these are public member variables, and can be changed outside 00050 * (after construction). Therefore m_perviousPosition could be set to 00051 * a more appropriate value prior to the first call to SetPosition. 00052 */ 00053 this->m_dPreviousPosition[0] = 0.0; 00054 this->m_dPreviousPosition[1] = 0.0; 00055 this->m_dPreviousPosition[2] = 0.0; 00056 this->m_dPreviousPosition[3] = 0.0; 00057 00058 /* public variable for the number of decimal places on the y axis */ 00059 this->m_nYDecimals = 3; 00060 00061 /* set some initial values for the scaling until "SetRange" is called. 00062 * these are protected varaibles and must be set with SetRange 00063 * in order to ensure that m_dRange is updated accordingly 00064 */ 00065 /* m_dLowerLimit = -10.0; */ 00066 /* m_dUpperLimit = 10.0; */ 00067 this->m_dLowerLimit = 0.0; 00068 this->m_dUpperLimit = 100.0; 00069 this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit; /* protected member variable */ 00070 00071 /* m_nShiftPixels determines how much the plot shifts (in terms of pixels) */ 00072 /* with the addition of a new data point */ 00073 this->m_nShiftPixels = 4; 00074 this->m_nHalfShiftPixels = this->m_nShiftPixels/2; /* protected */ 00075 this->m_nPlotShiftPixels = this->m_nShiftPixels + this->m_nHalfShiftPixels; /* protected */ 00076 00077 /* background, grid and data colors */ 00078 /* these are public variables and can be set directly */ 00079 this->m_crBackColor = RGB( 0, 0, 0); /* see also SetBackgroundColor */ 00080 this->m_crGridColor = RGB( 0, 128, 64); /* see also SetGridColor */ 00081 this->m_crPlotColor[0] = RGB(255, 255, 255); /* see also SetPlotColor */ 00082 this->m_crPlotColor[1] = RGB(100, 255, 255); /* see also SetPlotColor */ 00083 this->m_crPlotColor[2] = RGB(255, 100, 255); /* see also SetPlotColor */ 00084 this->m_crPlotColor[3] = RGB(255, 255, 100); /* see also SetPlotColor */ 00085 00086 /* protected variables */ 00087 for (i = 0; i < MAX_PLOTS; i++) 00088 { 00089 this->m_penPlot[i] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[i]); 00090 } 00091 this->m_brushBack = CreateSolidBrush(this->m_crBackColor); 00092 00093 /* public member variables, can be set directly */ 00094 strcpy(this->m_strXUnitsString, "Samples"); /* can also be set with SetXUnits */ 00095 strcpy(this->m_strYUnitsString, "Y units"); /* can also be set with SetYUnits */ 00096 00097 /* protected bitmaps to restore the memory DC's */ 00098 this->m_bitmapOldGrid = NULL; 00099 this->m_bitmapOldPlot = NULL; 00100 } 00101 00102 void GraphCtrl_Dispose(TGraphCtrl* this) 00103 { 00104 int plot; 00105 00106 for (plot = 0; plot < MAX_PLOTS; plot++) 00107 DeleteObject(this->m_penPlot[plot]); 00108 00109 /* just to be picky restore the bitmaps for the two memory dc's */ 00110 /* (these dc's are being destroyed so there shouldn't be any leaks) */ 00111 00112 if (this->m_bitmapOldGrid != NULL) SelectObject(this->m_dcGrid, this->m_bitmapOldGrid); 00113 if (this->m_bitmapOldPlot != NULL) SelectObject(this->m_dcPlot, this->m_bitmapOldPlot); 00114 if (this->m_bitmapGrid != NULL) DeleteObject(this->m_bitmapGrid); 00115 if (this->m_bitmapPlot != NULL) DeleteObject(this->m_bitmapPlot); 00116 if (this->m_dcGrid != NULL) DeleteDC(this->m_dcGrid); 00117 if (this->m_dcPlot != NULL) DeleteDC(this->m_dcPlot); 00118 if (this->m_brushBack != NULL) DeleteObject(this->m_brushBack); 00119 } 00120 00121 BOOL GraphCtrl_Create(TGraphCtrl* this, HWND hWnd, HWND hParentWnd, UINT nID) 00122 { 00123 BOOL result = 0; 00124 00125 GraphCtrl_Init(this); 00126 this->m_hParentWnd = hParentWnd; 00127 this->m_hWnd = hWnd; 00128 GraphCtrl_Resize(this); 00129 if (result != 0) 00130 GraphCtrl_InvalidateCtrl(this, FALSE); 00131 return result; 00132 } 00133 00134 void GraphCtrl_SetRange(TGraphCtrl* this, double dLower, double dUpper, int nDecimalPlaces) 00135 { 00136 /* ASSERT(dUpper > dLower); */ 00137 this->m_dLowerLimit = dLower; 00138 this->m_dUpperLimit = dUpper; 00139 this->m_nYDecimals = nDecimalPlaces; 00140 this->m_dRange = this->m_dUpperLimit - this->m_dLowerLimit; 00141 this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange; 00142 /* clear out the existing garbage, re-start with a clean plot */ 00143 GraphCtrl_InvalidateCtrl(this, FALSE); 00144 } 00145 00146 #if 0 00147 void TGraphCtrl::SetXUnits(const char* string) 00148 { 00149 strncpy(m_strXUnitsString, string, sizeof(m_strXUnitsString) - 1); 00150 /* clear out the existing garbage, re-start with a clean plot */ 00151 InvalidateCtrl(); 00152 } 00153 00154 void TGraphCtrl::SetYUnits(const char* string) 00155 { 00156 strncpy(m_strYUnitsString, string, sizeof(m_strYUnitsString) - 1); 00157 /* clear out the existing garbage, re-start with a clean plot */ 00158 InvalidateCtrl(); 00159 } 00160 #endif 00161 00162 void GraphCtrl_SetGridColor(TGraphCtrl* this, COLORREF color) 00163 { 00164 this->m_crGridColor = color; 00165 /* clear out the existing garbage, re-start with a clean plot */ 00166 GraphCtrl_InvalidateCtrl(this, FALSE); 00167 } 00168 00169 void GraphCtrl_SetPlotColor(TGraphCtrl* this, int plot, COLORREF color) 00170 { 00171 this->m_crPlotColor[plot] = color; 00172 DeleteObject(this->m_penPlot[plot]); 00173 this->m_penPlot[plot] = CreatePen(PS_SOLID, 0, this->m_crPlotColor[plot]); 00174 /* clear out the existing garbage, re-start with a clean plot */ 00175 GraphCtrl_InvalidateCtrl(this, FALSE); 00176 } 00177 00178 void GraphCtrl_SetBackgroundColor(TGraphCtrl* this, COLORREF color) 00179 { 00180 this->m_crBackColor = color; 00181 DeleteObject(this->m_brushBack); 00182 this->m_brushBack = CreateSolidBrush(this->m_crBackColor); 00183 /* clear out the existing garbage, re-start with a clean plot */ 00184 GraphCtrl_InvalidateCtrl(this, FALSE); 00185 } 00186 00187 void GraphCtrl_InvalidateCtrl(TGraphCtrl* this, BOOL bResize) 00188 { 00189 /* There is a lot of drawing going on here - particularly in terms of */ 00190 /* drawing the grid. Don't panic, this is all being drawn (only once) */ 00191 /* to a bitmap. The result is then BitBlt'd to the control whenever needed. */ 00192 int i; 00193 int nCharacters; 00194 //int nTopGridPix, nMidGridPix, nBottomGridPix; 00195 00196 HPEN oldPen; 00197 HPEN solidPen = CreatePen(PS_SOLID, 0, this->m_crGridColor); 00198 /* HFONT axisFont, yUnitFont, oldFont; */ 00199 /* char strTemp[50]; */ 00200 00201 /* in case we haven't established the memory dc's */ 00202 /* CClientDC dc(this); */ 00203 HDC dc = GetDC(this->m_hParentWnd); 00204 00205 /* if we don't have one yet, set up a memory dc for the grid */ 00206 if (this->m_dcGrid == NULL) 00207 { 00208 this->m_dcGrid = CreateCompatibleDC(dc); 00209 this->m_bitmapGrid = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight); 00210 this->m_bitmapOldGrid = (HBITMAP)SelectObject(this->m_dcGrid, this->m_bitmapGrid); 00211 } 00212 else if(bResize) 00213 { 00214 // the size of the drawing area has changed 00215 // so create a new bitmap of the appropriate size 00216 if(this->m_bitmapGrid != NULL) 00217 { 00218 this->m_bitmapGrid = (HBITMAP)SelectObject(this->m_dcGrid, this->m_bitmapOldGrid); 00219 DeleteObject(this->m_bitmapGrid); 00220 this->m_bitmapGrid = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight); 00221 SelectObject(this->m_dcGrid, this->m_bitmapGrid); 00222 } 00223 } 00224 00225 SetBkColor(this->m_dcGrid, this->m_crBackColor); 00226 00227 /* fill the grid background */ 00228 FillRect(this->m_dcGrid, &this->m_rectClient, this->m_brushBack); 00229 00230 /* draw the plot rectangle: */ 00231 /* determine how wide the y axis scaling values are */ 00232 nCharacters = abs((int)log10(fabs(this->m_dUpperLimit))); 00233 nCharacters = max(nCharacters, abs((int)log10(fabs(this->m_dLowerLimit)))); 00234 00235 /* add the units digit, decimal point and a minus sign, and an extra space */ 00236 /* as well as the number of decimal places to display */ 00237 nCharacters = nCharacters + 4 + this->m_nYDecimals; 00238 00239 /* adjust the plot rectangle dimensions */ 00240 /* assume 6 pixels per character (this may need to be adjusted) */ 00241 /* m_rectPlot.left = m_rectClient.left + 6*(nCharacters); */ 00242 this->m_rectPlot.left = this->m_rectClient.left; 00243 this->m_nPlotWidth = this->m_rectPlot.right - this->m_rectPlot.left;/* m_rectPlot.Width(); */ 00244 00245 /* draw the plot rectangle */ 00246 oldPen = (HPEN)SelectObject(this->m_dcGrid, solidPen); 00247 MoveToEx(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.top, NULL); 00248 LineTo(this->m_dcGrid, this->m_rectPlot.right+1, this->m_rectPlot.top); 00249 LineTo(this->m_dcGrid, this->m_rectPlot.right+1, this->m_rectPlot.bottom+1); 00250 LineTo(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.bottom+1); 00251 /* LineTo(m_dcGrid, m_rectPlot.left, m_rectPlot.top); */ 00252 00253 /* draw the horizontal axis */ 00254 for (i = this->m_rectPlot.top; i < this->m_rectPlot.bottom; i += 12) 00255 { 00256 MoveToEx(this->m_dcGrid, this->m_rectPlot.left, this->m_rectPlot.top + i, NULL); 00257 LineTo(this->m_dcGrid, this->m_rectPlot.right, this->m_rectPlot.top + i); 00258 } 00259 00260 /* draw the vertical axis */ 00261 for (i = this->m_rectPlot.left; i < this->m_rectPlot.right; i += 12) 00262 { 00263 MoveToEx(this->m_dcGrid, this->m_rectPlot.left + i, this->m_rectPlot.bottom, NULL); 00264 LineTo(this->m_dcGrid, this->m_rectPlot.left + i, this->m_rectPlot.top); 00265 } 00266 00267 SelectObject(this->m_dcGrid, oldPen); 00268 DeleteObject(solidPen); 00269 00270 #if 0 00271 /* create some fonts (horizontal and vertical) */ 00272 /* use a height of 14 pixels and 300 weight */ 00273 /* (these may need to be adjusted depending on the display) */ 00274 axisFont = CreateFont (14, 0, 0, 0, 300, 00275 FALSE, FALSE, 0, ANSI_CHARSET, 00276 OUT_DEFAULT_PRECIS, 00277 CLIP_DEFAULT_PRECIS, 00278 DEFAULT_QUALITY, 00279 DEFAULT_PITCH|FF_SWISS, "Arial"); 00280 yUnitFont = CreateFont (14, 0, 900, 0, 300, 00281 FALSE, FALSE, 0, ANSI_CHARSET, 00282 OUT_DEFAULT_PRECIS, 00283 CLIP_DEFAULT_PRECIS, 00284 DEFAULT_QUALITY, 00285 DEFAULT_PITCH|FF_SWISS, "Arial"); 00286 00287 /* grab the horizontal font */ 00288 oldFont = (HFONT)SelectObject(m_dcGrid, axisFont); 00289 00290 /* y max */ 00291 SetTextColor(m_dcGrid, m_crGridColor); 00292 SetTextAlign(m_dcGrid, TA_RIGHT|TA_TOP); 00293 sprintf(strTemp, "%.*lf", m_nYDecimals, m_dUpperLimit); 00294 TextOut(m_dcGrid, m_rectPlot.left-4, m_rectPlot.top, strTemp, wcslen(strTemp)); 00295 00296 /* y min */ 00297 SetTextAlign(m_dcGrid, TA_RIGHT|TA_BASELINE); 00298 sprintf(strTemp, "%.*lf", m_nYDecimals, m_dLowerLimit); 00299 TextOut(m_dcGrid, m_rectPlot.left-4, m_rectPlot.bottom, strTemp, wcslen(strTemp)); 00300 00301 /* x min */ 00302 SetTextAlign(m_dcGrid, TA_LEFT|TA_TOP); 00303 TextOut(m_dcGrid, m_rectPlot.left, m_rectPlot.bottom+4, "0", 1); 00304 00305 /* x max */ 00306 SetTextAlign(m_dcGrid, TA_RIGHT|TA_TOP); 00307 sprintf(strTemp, "%d", m_nPlotWidth/m_nShiftPixels); 00308 TextOut(m_dcGrid, m_rectPlot.right, m_rectPlot.bottom+4, strTemp, wcslen(strTemp)); 00309 00310 /* x units */ 00311 SetTextAlign(m_dcGrid, TA_CENTER|TA_TOP); 00312 TextOut(m_dcGrid, (m_rectPlot.left+m_rectPlot.right)/2, 00313 m_rectPlot.bottom+4, m_strXUnitsString, wcslen(m_strXUnitsString)); 00314 00315 /* restore the font */ 00316 SelectObject(m_dcGrid, oldFont); 00317 00318 /* y units */ 00319 oldFont = (HFONT)SelectObject(m_dcGrid, yUnitFont); 00320 SetTextAlign(m_dcGrid, TA_CENTER|TA_BASELINE); 00321 TextOut(m_dcGrid, (m_rectClient.left+m_rectPlot.left)/2, 00322 (m_rectPlot.bottom+m_rectPlot.top)/2, m_strYUnitsString, wcslen(m_strYUnitsString)); 00323 SelectObject(m_dcGrid, oldFont); 00324 #endif 00325 /* at this point we are done filling the the grid bitmap, */ 00326 /* no more drawing to this bitmap is needed until the setting are changed */ 00327 00328 /* if we don't have one yet, set up a memory dc for the plot */ 00329 if (this->m_dcPlot == NULL) 00330 { 00331 this->m_dcPlot = CreateCompatibleDC(dc); 00332 this->m_bitmapPlot = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight); 00333 this->m_bitmapOldPlot = (HBITMAP)SelectObject(this->m_dcPlot, this->m_bitmapPlot); 00334 } 00335 else if(bResize) 00336 { 00337 // the size of the drawing area has changed 00338 // so create a new bitmap of the appropriate size 00339 if(this->m_bitmapPlot != NULL) 00340 { 00341 this->m_bitmapPlot = (HBITMAP)SelectObject(this->m_dcPlot, this->m_bitmapOldPlot); 00342 DeleteObject(this->m_bitmapPlot); 00343 this->m_bitmapPlot = CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight); 00344 SelectObject(this->m_dcPlot, this->m_bitmapPlot); 00345 } 00346 } 00347 00348 /* make sure the plot bitmap is cleared */ 00349 SetBkColor(this->m_dcPlot, this->m_crBackColor); 00350 FillRect(this->m_dcPlot, &this->m_rectClient, this->m_brushBack); 00351 00352 /* finally, force the plot area to redraw */ 00353 InvalidateRect(this->m_hParentWnd, &this->m_rectClient, TRUE); 00354 ReleaseDC(this->m_hParentWnd, dc); 00355 } 00356 00357 double GraphCtrl_AppendPoint(TGraphCtrl* this, 00358 double dNewPoint0, double dNewPoint1, 00359 double dNewPoint2, double dNewPoint3) 00360 { 00361 /* append a data point to the plot & return the previous point */ 00362 double dPrevious; 00363 00364 dPrevious = this->m_dCurrentPosition[0]; 00365 this->m_dCurrentPosition[0] = dNewPoint0; 00366 this->m_dCurrentPosition[1] = dNewPoint1; 00367 this->m_dCurrentPosition[2] = dNewPoint2; 00368 this->m_dCurrentPosition[3] = dNewPoint3; 00369 GraphCtrl_DrawPoint(this); 00370 /* Invalidate(); */ 00371 return dPrevious; 00372 } 00373 00374 void GraphCtrl_Paint(TGraphCtrl* this, HWND hWnd, HDC dc) 00375 { 00376 HDC memDC; 00377 HBITMAP memBitmap; 00378 HBITMAP oldBitmap; /* bitmap originally found in CMemDC */ 00379 00380 /* RECT rcClient; */ 00381 /* GetClientRect(hWnd, &rcClient); */ 00382 /* FillSolidRect(dc, &rcClient, RGB(255, 0, 255)); */ 00383 /* m_nClientWidth = rcClient.right - rcClient.left; */ 00384 /* m_nClientHeight = rcClient.bottom - rcClient.top; */ 00385 00386 /* no real plotting work is performed here, */ 00387 /* just putting the existing bitmaps on the client */ 00388 00389 /* to avoid flicker, establish a memory dc, draw to it */ 00390 /* and then BitBlt it to the client */ 00391 memDC = CreateCompatibleDC(dc); 00392 memBitmap = (HBITMAP)CreateCompatibleBitmap(dc, this->m_nClientWidth, this->m_nClientHeight); 00393 oldBitmap = (HBITMAP)SelectObject(memDC, memBitmap); 00394 00395 if (memDC != NULL) 00396 { 00397 /* first drop the grid on the memory dc */ 00398 BitBlt(memDC, 0, 0, this->m_nClientWidth, this->m_nClientHeight, this->m_dcGrid, 0, 0, SRCCOPY); 00399 /* now add the plot on top as a "pattern" via SRCPAINT. */ 00400 /* works well with dark background and a light plot */ 00401 BitBlt(memDC, 0, 0, this->m_nClientWidth, this->m_nClientHeight, this->m_dcPlot, 0, 0, SRCPAINT); /* SRCPAINT */ 00402 /* finally send the result to the display */ 00403 BitBlt(dc, 0, 0, this->m_nClientWidth, this->m_nClientHeight, memDC, 0, 0, SRCCOPY); 00404 } 00405 SelectObject(memDC, oldBitmap); 00406 DeleteObject(memBitmap); 00407 DeleteDC(memDC); 00408 } 00409 00410 void GraphCtrl_DrawPoint(TGraphCtrl* this) 00411 { 00412 /* this does the work of "scrolling" the plot to the left 00413 * and appending a new data point all of the plotting is 00414 * directed to the memory based bitmap associated with m_dcPlot 00415 * the will subsequently be BitBlt'd to the client in Paint 00416 */ 00417 int currX, prevX, currY, prevY; 00418 HPEN oldPen; 00419 RECT rectCleanUp; 00420 int i; 00421 00422 if (this->m_dcPlot != NULL) 00423 { 00424 /* shift the plot by BitBlt'ing it to itself 00425 * note: the m_dcPlot covers the entire client 00426 * but we only shift bitmap that is the size 00427 * of the plot rectangle 00428 * grab the right side of the plot (excluding m_nShiftPixels on the left) 00429 * move this grabbed bitmap to the left by m_nShiftPixels 00430 */ 00431 BitBlt(this->m_dcPlot, this->m_rectPlot.left, this->m_rectPlot.top+1, 00432 this->m_nPlotWidth, this->m_nPlotHeight, this->m_dcPlot, 00433 this->m_rectPlot.left+this->m_nShiftPixels, this->m_rectPlot.top+1, 00434 SRCCOPY); 00435 00436 /* establish a rectangle over the right side of plot */ 00437 /* which now needs to be cleaned up proir to adding the new point */ 00438 rectCleanUp = this->m_rectPlot; 00439 rectCleanUp.left = rectCleanUp.right - this->m_nShiftPixels; 00440 00441 /* fill the cleanup area with the background */ 00442 FillRect(this->m_dcPlot, &rectCleanUp, this->m_brushBack); 00443 00444 /* draw the next line segement */ 00445 for (i = 0; i < MAX_PLOTS; i++) 00446 { 00447 /* grab the plotting pen */ 00448 oldPen = (HPEN)SelectObject(this->m_dcPlot, this->m_penPlot[i]); 00449 00450 /* move to the previous point */ 00451 prevX = this->m_rectPlot.right-this->m_nPlotShiftPixels; 00452 prevY = this->m_rectPlot.bottom - 00453 (long)((this->m_dPreviousPosition[i] - this->m_dLowerLimit) * this->m_dVerticalFactor); 00454 MoveToEx(this->m_dcPlot, prevX, prevY, NULL); 00455 00456 /* draw to the current point */ 00457 currX = this->m_rectPlot.right-this->m_nHalfShiftPixels; 00458 currY = this->m_rectPlot.bottom - 00459 (long)((this->m_dCurrentPosition[i] - this->m_dLowerLimit) * this->m_dVerticalFactor); 00460 LineTo(this->m_dcPlot, currX, currY); 00461 00462 /* Restore the pen */ 00463 SelectObject(this->m_dcPlot, oldPen); 00464 00465 /* if the data leaks over the upper or lower plot boundaries 00466 * fill the upper and lower leakage with the background 00467 * this will facilitate clipping on an as needed basis 00468 * as opposed to always calling IntersectClipRect 00469 */ 00470 if ((prevY <= this->m_rectPlot.top) || (currY <= this->m_rectPlot.top)) 00471 { 00472 RECT rc; 00473 rc.bottom = this->m_rectPlot.top+1; 00474 rc.left = prevX; 00475 rc.right = currX+1; 00476 rc.top = this->m_rectClient.top; 00477 FillRect(this->m_dcPlot, &rc, this->m_brushBack); 00478 } 00479 if ((prevY >= this->m_rectPlot.bottom) || (currY >= this->m_rectPlot.bottom)) 00480 { 00481 RECT rc; 00482 rc.bottom = this->m_rectClient.bottom+1; 00483 rc.left = prevX; 00484 rc.right = currX+1; 00485 rc.top = this->m_rectPlot.bottom+1; 00486 /* RECT rc(prevX, m_rectPlot.bottom+1, currX+1, m_rectClient.bottom+1); */ 00487 FillRect(this->m_dcPlot, &rc, this->m_brushBack); 00488 } 00489 00490 /* store the current point for connection to the next point */ 00491 this->m_dPreviousPosition[i] = this->m_dCurrentPosition[i]; 00492 } 00493 } 00494 } 00495 00496 void GraphCtrl_Resize(TGraphCtrl* this) 00497 { 00498 /* NOTE: Resize automatically gets called during the setup of the control */ 00499 GetClientRect(this->m_hWnd, &this->m_rectClient); 00500 00501 /* set some member variables to avoid multiple function calls */ 00502 this->m_nClientHeight = this->m_rectClient.bottom - this->m_rectClient.top;/* m_rectClient.Height(); */ 00503 this->m_nClientWidth = this->m_rectClient.right - this->m_rectClient.left;/* m_rectClient.Width(); */ 00504 00505 /* the "left" coordinate and "width" will be modified in */ 00506 /* InvalidateCtrl to be based on the width of the y axis scaling */ 00507 #if 0 00508 this->m_rectPlot.left = 20; 00509 this->m_rectPlot.top = 10; 00510 this->m_rectPlot.right = this->m_rectClient.right-10; 00511 this->m_rectPlot.bottom = this->m_rectClient.bottom-25; 00512 #else 00513 this->m_rectPlot.left = 0; 00514 this->m_rectPlot.top = -1; 00515 this->m_rectPlot.right = this->m_rectClient.right-0; 00516 this->m_rectPlot.bottom = this->m_rectClient.bottom-0; 00517 #endif 00518 00519 /* set some member variables to avoid multiple function calls */ 00520 this->m_nPlotHeight = this->m_rectPlot.bottom - this->m_rectPlot.top;/* m_rectPlot.Height(); */ 00521 this->m_nPlotWidth = this->m_rectPlot.right - this->m_rectPlot.left;/* m_rectPlot.Width(); */ 00522 00523 /* set the scaling factor for now, this can be adjusted */ 00524 /* in the SetRange functions */ 00525 this->m_dVerticalFactor = (double)this->m_nPlotHeight / this->m_dRange; 00526 } 00527 00528 #if 0 00529 void TGraphCtrl::Reset() 00530 { 00531 /* to clear the existing data (in the form of a bitmap) */ 00532 /* simply invalidate the entire control */ 00533 InvalidateCtrl(); 00534 } 00535 #endif 00536 00537 extern TGraphCtrl PerformancePageCpuUsageHistoryGraph; 00538 extern TGraphCtrl PerformancePageMemUsageHistoryGraph; 00539 extern HWND hPerformancePageCpuUsageHistoryGraph; 00540 extern HWND hPerformancePageMemUsageHistoryGraph; 00541 00542 INT_PTR CALLBACK 00543 GraphCtrl_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 00544 { 00545 RECT rcClient; 00546 HDC hdc; 00547 PAINTSTRUCT ps; 00548 00549 switch (message) 00550 { 00551 case WM_ERASEBKGND: 00552 return TRUE; 00553 /* 00554 * Filter out mouse & keyboard messages 00555 */ 00556 /* case WM_APPCOMMAND: */ 00557 case WM_CAPTURECHANGED: 00558 case WM_LBUTTONDBLCLK: 00559 case WM_LBUTTONDOWN: 00560 case WM_LBUTTONUP: 00561 case WM_MBUTTONDBLCLK: 00562 case WM_MBUTTONDOWN: 00563 case WM_MBUTTONUP: 00564 case WM_MOUSEACTIVATE: 00565 case WM_MOUSEHOVER: 00566 case WM_MOUSELEAVE: 00567 case WM_MOUSEMOVE: 00568 /* case WM_MOUSEWHEEL: */ 00569 case WM_NCHITTEST: 00570 case WM_NCLBUTTONDBLCLK: 00571 case WM_NCLBUTTONDOWN: 00572 case WM_NCLBUTTONUP: 00573 case WM_NCMBUTTONDBLCLK: 00574 case WM_NCMBUTTONDOWN: 00575 case WM_NCMBUTTONUP: 00576 /* case WM_NCMOUSEHOVER: */ 00577 /* case WM_NCMOUSELEAVE: */ 00578 case WM_NCMOUSEMOVE: 00579 case WM_NCRBUTTONDBLCLK: 00580 case WM_NCRBUTTONDOWN: 00581 case WM_NCRBUTTONUP: 00582 /* case WM_NCXBUTTONDBLCLK: */ 00583 /* case WM_NCXBUTTONDOWN: */ 00584 /* case WM_NCXBUTTONUP: */ 00585 case WM_RBUTTONDBLCLK: 00586 case WM_RBUTTONDOWN: 00587 case WM_RBUTTONUP: 00588 /* case WM_XBUTTONDBLCLK: */ 00589 /* case WM_XBUTTONDOWN: */ 00590 /* case WM_XBUTTONUP: */ 00591 case WM_ACTIVATE: 00592 case WM_CHAR: 00593 case WM_DEADCHAR: 00594 case WM_GETHOTKEY: 00595 case WM_HOTKEY: 00596 case WM_KEYDOWN: 00597 case WM_KEYUP: 00598 case WM_KILLFOCUS: 00599 case WM_SETFOCUS: 00600 case WM_SETHOTKEY: 00601 case WM_SYSCHAR: 00602 case WM_SYSDEADCHAR: 00603 case WM_SYSKEYDOWN: 00604 case WM_SYSKEYUP: 00605 return 0; 00606 00607 case WM_NCCALCSIZE: 00608 return 0; 00609 00610 case WM_SIZE: 00611 if (hWnd == hPerformancePageMemUsageHistoryGraph) 00612 { 00613 GraphCtrl_Resize(&PerformancePageMemUsageHistoryGraph); 00614 GraphCtrl_InvalidateCtrl(&PerformancePageMemUsageHistoryGraph, TRUE); 00615 } 00616 if (hWnd == hPerformancePageCpuUsageHistoryGraph) 00617 { 00618 GraphCtrl_Resize(&PerformancePageCpuUsageHistoryGraph); 00619 GraphCtrl_InvalidateCtrl(&PerformancePageCpuUsageHistoryGraph, TRUE); 00620 } 00621 return 0; 00622 00623 case WM_PAINT: 00624 hdc = BeginPaint(hWnd, &ps); 00625 GetClientRect(hWnd, &rcClient); 00626 if (hWnd == hPerformancePageMemUsageHistoryGraph) 00627 GraphCtrl_Paint(&PerformancePageMemUsageHistoryGraph, hWnd, hdc); 00628 if (hWnd == hPerformancePageCpuUsageHistoryGraph) 00629 GraphCtrl_Paint(&PerformancePageCpuUsageHistoryGraph, hWnd, hdc); 00630 EndPaint(hWnd, &ps); 00631 return 0; 00632 } 00633 00634 /* 00635 * We pass on all non-handled messages 00636 */ 00637 return CallWindowProcW((WNDPROC)OldGraphCtrlWndProc, hWnd, message, wParam, lParam); 00638 } Generated on Sun May 27 2012 04:17:46 for ReactOS by
1.7.6.1
|