00001
00002 #include "mBarRange.h"
00003
00004
00005
00006
00007 DEFINE_EVENT_TYPE(wxEVT_TSBAR)
00008 DEFINE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL)
00009 DEFINE_EVENT_TYPE(wxEVT_TSBAR_START)
00010 DEFINE_EVENT_TYPE(wxEVT_TSBAR_END)
00011 DEFINE_EVENT_TYPE(wxEVT_TSBAR_MOVED)
00012 DEFINE_EVENT_TYPE(wxEVT_SELECTION_END)
00013
00014
00015
00016
00017
00018
00019
00020 IMPLEMENT_CLASS(mBarRange, wxScrolledWindow)
00021 BEGIN_EVENT_TABLE(mBarRange, wxScrolledWindow)
00022 EVT_PAINT (mBarRange::OnPaint)
00023 EVT_SIZE (mBarRange::OnSize)
00024 EVT_MOTION (mBarRange::OnMouseMove)
00025 EVT_RIGHT_DOWN (mBarRange :: onShowPopupMenu)
00026 EVT_MENU(cntID_CHANGE_COLOR, mBarRange :: onChangePartColor)
00027 EVT_MENU(cntID_ENABLE_ACTUAL, mBarRange :: onEnableRange_Actual)
00028 EVT_MENU(cntID_MOVABLE_ACTUAL_BAR, mBarRange :: onMovable_ActualWithBar)
00029
00030
00031 EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
00032 EVT_LEFT_UP( mBarRange :: onLeftClickUp)
00033
00034
00035
00036 END_EVENT_TABLE()
00037
00038
00039
00040
00041
00042
00043 mBarRange::mBarRange(wxWindow *parent, int w, int h)
00044 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
00045 {
00046 acceptedClick = true;
00047 _bitmap_bar = NULL;
00048 SetWidth (w);
00049 SetHeight(h);
00050 _initialPoint = 0;
00051 trianglesHalfWidth = 5;
00052
00053 wxColour start_Colour;
00054
00055
00056 start_Colour = wxColour(0,0,255);
00057 actual_Colour = wxColour(255,255,202);
00058 end_Colour = wxColour(0,0,255);
00059 bar_Colour = wxColour(255,0,255);
00060 backgroundColor = parent ->GetBackgroundColour();
00061 guideLineColor = wxColour(255,0,0);
00062
00063
00064
00065 _moveActualWithBar = false;
00066 _in_rangeProperty = false;
00067 _selectionMoveId = -1;
00068 realX_vertical_line = -1;
00069 activeState = false;
00070 _actual=0;
00071 deviceEndMargin = 0;
00072
00073 SetOrientation(true);
00074 setIfWithActualDrawed(true);
00075
00076 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
00077 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
00078 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
00079
00080 SetSize(w,h);
00081 }
00082
00083
00084
00085
00086
00087 mBarRange::~mBarRange()
00088 {
00089 }
00090
00091
00092
00093 void mBarRange::DrawBar()
00094 {
00095
00096 if(_orientation)
00097 {
00098 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
00099 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
00100
00101 }
00102
00103 else
00104 {
00105 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
00106 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
00107 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
00108 }
00109 }
00110
00111
00112
00113
00114
00115
00116 bool mBarRange::GetInRangeProperty()
00117 {
00118 return _in_rangeProperty;
00119 }
00120
00121 void mBarRange::SetInRangeProperty(bool in)
00122 {
00123 _in_rangeProperty=in;
00124 }
00125
00126
00127
00128 bool mBarRange::IsActualInRange()
00129 {
00130 return ( _actual <= _end && _actual >= _start );
00131 }
00132
00133
00134
00135
00136 bool mBarRange::GetOrientation()
00137 {
00138 return _orientation;
00139 }
00140
00141 void mBarRange::SetOrientation(bool orientation)
00142 {
00143 if(_orientation)
00144 {
00145 SetSize(_h,_w);
00146 }
00147 _orientation=orientation;
00148
00149 }
00150
00151
00152
00153
00154 int mBarRange::GetPixelStart()
00155 {
00156 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
00157 }
00158
00159
00160
00161 void mBarRange::SetPixelStart(int i)
00162 {
00163 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
00164
00165 }
00166
00167
00168
00169 int mBarRange::GetPixelActual()
00170 {
00171 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
00172 }
00173
00174
00175
00176 void mBarRange::SetPixelActual(int i)
00177 {
00178 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
00179 }
00180
00181
00182
00183 int mBarRange::GetPixelEnd()
00184 {
00185 return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
00186 }
00187
00188
00189
00190 void mBarRange::SetPixelEnd(int i)
00191 {
00192 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
00193 }
00194
00195
00196
00197
00198 double mBarRange::GetMax()
00199 {
00200 return _max;
00201 }
00202
00203
00204 void mBarRange::SetMax(double i)
00205 {
00206 _max=i;
00207 }
00208
00209
00210
00211
00212 double mBarRange::GetMin()
00213 {
00214 return _min;
00215 }
00216
00217
00218 void mBarRange::SetMin(double i)
00219 {
00220 _min=i;
00221 }
00222
00223
00224
00225
00226
00227 int mBarRange::GetWidth()
00228 {
00229 return _w;
00230 }
00231
00232 void mBarRange::SetWidth(int w)
00233 {
00234 _w=w;
00235 }
00236
00237 int mBarRange::GetHeight()
00238 {
00239 return _h;
00240 }
00241
00242
00243 void mBarRange::SetHeight(int h)
00244 {
00245 _h=h;
00246 }
00247
00248
00249
00250
00251
00252 int mBarRange::GetStart()
00253 {
00254 return _start;
00255
00256 }
00257
00258
00259
00260 void mBarRange::SetStart(int newstart)
00261 {
00262 if(newstart<_min)
00263 newstart = _min;
00264 _start = newstart;
00265 RefreshForce();
00266 }
00267
00268
00269
00270
00271 int mBarRange::GetEnd()
00272 {
00273 return _end;
00274 }
00275
00276
00277
00278 void mBarRange::SetEnd(int nwend)
00279 {
00280 if(nwend>_max)
00281 _end = _max;
00282 _end=nwend;
00283 RefreshForce();
00284 }
00285
00286
00287
00288 int mBarRange::GetActual()
00289 {
00290 return _actual;
00291 }
00292
00293 void mBarRange::SetActual(int actual)
00294 {
00295 if(actual<_min)
00296 _actual = _min;
00297 else if (actual>_max)
00298 _actual = _max;
00299 _actual=actual;
00300 RefreshForce();
00301 }
00302
00303
00304
00305
00306 int mBarRange::GetTrianglesHalfWidth()
00307 {
00308 return trianglesHalfWidth;
00309 }
00310
00311 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
00312 {
00313 trianglesHalfWidth = nwTriHalfWidth;
00314 }
00315
00316 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
00317 {
00318 wxRect rectTotal = GetClientRect();
00319 if(_orientation)
00320 {
00321 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
00322 }
00323 else
00324 {
00325 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
00326 }
00327 _selectionMoveId = -1;
00328 Refresh();
00329 }
00330
00331
00332
00333 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
00334 {
00335
00336
00337
00338
00339
00340
00341 wxScrolledWindow::Refresh(false);
00342
00343
00344
00345
00346
00347
00348 }
00349
00350
00351
00352
00353
00354 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
00355 {
00356
00357
00358
00359
00360
00361
00362
00363 if (_bitmap_bar!=NULL){
00364
00365 if(_orientation)
00366 {
00367 RefreshHorizontalView();
00368 wxMemoryDC temp_dc;
00369 temp_dc.SelectObject( *_bitmap_bar );
00370 wxPaintDC dc( this );
00371 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
00372
00373
00374
00375
00376
00377
00378
00379
00380 } else {
00381 RefreshVerticalView();
00382 wxMemoryDC temp_dc;
00383 temp_dc.SelectObject( *_bitmap_bar );
00384 wxPaintDC dc( this );
00385
00386 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396 }
00397 }
00398
00399
00400
00401
00402
00403
00404
00405 }
00406
00407
00408
00409 void mBarRange::RefreshHorizontalView()
00410 {
00411
00412
00413
00414
00415
00416
00417
00418 wxPoint points[3];
00419
00420
00421 int pxStart=GetPixelStart();
00422 int pxEnd=GetPixelEnd();
00423 int pxActual=GetPixelActual();
00424
00425
00426 int letterHeight = 9;
00427 int barHeight = 2*letterHeight;
00428 int tempHeight = _h-(6*letterHeight);
00429
00430
00431 if (_visibleLables)
00432 {
00433 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
00434 }
00435 else
00436 barHeight = _h;
00437
00438 wxMemoryDC temp_dc;
00439 temp_dc.SelectObject( *_bitmap_bar );
00440
00441
00442
00443
00444
00445 temp_dc.SetPen(wxPen( backgroundColor ));
00446 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
00447
00448 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
00449
00450
00451 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
00452 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
00453 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
00454 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
00455
00456
00457
00458 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
00459 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
00460 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
00461
00462
00463
00464 if( _selectionMoveId==4 )
00465 {
00466 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
00467 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
00468 }
00469 else
00470 {
00471 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
00472 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
00473 }
00474 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
00475
00476
00477 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
00478 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
00479 points[0].x= 0;
00480 points[0].y= barHeight;
00481 points[1].x= -trianglesHalfWidth-1;
00482 points[1].y= 0;
00483 points[2].x= trianglesHalfWidth+2;
00484 points[2].y= 0;
00485 temp_dc.DrawPolygon(3,points,pxStart,0);
00486 temp_dc.DrawPolygon(3,points,pxEnd,0);
00487
00488
00489 points[1].x = -trianglesHalfWidth;
00490 points[2].x = trianglesHalfWidth;
00491
00492
00493 if( _selectionMoveId == 1 )
00494 {
00495 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
00496 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
00497 }
00498 else
00499 {
00500 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
00501 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
00502 }
00503 temp_dc.DrawPolygon(3,points,pxStart,0);
00504
00505 if( _selectionMoveId == 2 )
00506 {
00507 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
00508 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
00509 }
00510 else
00511 {
00512 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
00513 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
00514 }
00515 temp_dc.DrawPolygon(3,points,pxEnd,0);
00516
00517 if( withActualDrawed )
00518 {
00519
00520 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
00521 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
00522 points[1].x = -trianglesHalfWidth-1;
00523 points[2].x = trianglesHalfWidth+2;
00524
00525 temp_dc.DrawPolygon(3,points,pxActual,0);
00526
00527
00528 if( _selectionMoveId==3 )
00529 {
00530 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
00531 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
00532 }
00533 else
00534 {
00535 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
00536 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
00537 }
00538 points[1].x = -trianglesHalfWidth;
00539 points[2].x = trianglesHalfWidth;
00540 temp_dc.DrawPolygon(3,points,pxActual,0);
00541 }
00542
00543 if (realX_vertical_line!=-1)
00544 {
00545 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
00546 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
00547 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
00548 }
00549
00550
00551
00552 if (_visibleLables)
00553 {
00554
00555
00556
00557
00558
00559
00560 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
00561 temp_dc.SetFont(font);
00562 temp_dc.SetTextForeground(*wxBLACK);
00563
00564
00565
00566 wxString text_min;
00567
00568 text_min.Printf(_T("%d"), (int)GetMin() );
00569
00570 temp_dc.DrawText(text_min,0,barHeight+1);
00571
00572
00573 wxString text_max;
00574
00575 text_max.Printf(_T("%d"), (int)GetMax() );
00576
00577
00578
00579 wxCoord tmpX,tmpY;
00580 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
00581 wxSize stringSize(tmpX,tmpY);
00582
00583 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth()),barHeight+1);
00584
00585
00586
00587 wxString text_start;
00588
00589 text_start.Printf(_T("%d"), (int)GetStart() );
00590
00591 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
00592
00593 wxString text_end;
00594
00595 text_end.Printf(_T("%d"), (int)GetEnd() );
00596
00597
00598 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
00599 stringSize.SetHeight(tmpY);
00600 stringSize.SetWidth(tmpX);
00601 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
00602 if( withActualDrawed )
00603 {
00604
00605 wxString text_actual;
00606
00607 text_actual.Printf(_T("%d"), (int)GetActual() );
00608
00609 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
00610 stringSize.SetHeight(tmpY);
00611 stringSize.SetWidth(tmpX);
00612 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
00613 }
00614 }
00615
00616
00617
00618
00619
00620 }
00621
00622
00623
00624
00625
00626 void mBarRange::RefreshVerticalView()
00627 {
00628
00629
00630
00631
00632
00633
00634 wxPoint points[3];
00635
00636 int px1=GetPixelStart();
00637 int px2=GetPixelEnd();
00638 int px3=GetPixelActual();
00639 int letterHeight = 9;
00640 int panelHeight = 9*3+_w;
00641
00642 int barWidth;
00643 if (_visibleLables)
00644 {
00645 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
00646 }
00647 else
00648 barWidth = _w;
00649
00650 wxMemoryDC temp_dc;
00651 temp_dc.SelectObject( *_bitmap_bar );
00652
00653
00654 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
00655 temp_dc.SetPen(wxPen( backgroundColor ));
00656
00657 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
00658
00659
00660 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
00661 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
00662 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
00663 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
00664
00665
00666 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
00667 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
00668 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
00669
00670
00671
00672 if( _selectionMoveId==4 )
00673 {
00674 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
00675 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
00676 }
00677 else
00678 {
00679 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
00680 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
00681 }
00682 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
00683
00684
00685
00686 points[0].x=_h;
00687 points[0].y=0;
00688 points[1].x=0;
00689 points[1].y=-trianglesHalfWidth-1;
00690 points[2].x=0;
00691 points[2].y=trianglesHalfWidth+2;
00692 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
00693 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
00694 temp_dc.DrawPolygon(3,points,0,px1);
00695 temp_dc.DrawPolygon(3,points,0,px2);
00696
00697
00698 points[0].x=_h;
00699 points[0].y=0;
00700 points[1].x=0;
00701 points[1].y=-trianglesHalfWidth;
00702 points[2].x=0;
00703 points[2].y=trianglesHalfWidth;
00704
00705 if( _selectionMoveId==1 )
00706 {
00707 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
00708 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
00709 }
00710 else
00711 {
00712 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
00713 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
00714 }
00715 temp_dc.DrawPolygon(3,points,0,px1);
00716
00717 if( _selectionMoveId==2 )
00718 {
00719 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
00720 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
00721 }
00722 else
00723 {
00724 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
00725 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
00726 }
00727 temp_dc.DrawPolygon(3,points,0,px2);
00728
00729 if( withActualDrawed )
00730 {
00731
00732 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
00733 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
00734 points[0].x=_h;
00735 points[0].y=0;
00736 points[1].x=0;
00737 points[1].y=-trianglesHalfWidth-1;
00738 points[2].x=0;
00739 points[2].y=trianglesHalfWidth+2;
00740 temp_dc.DrawPolygon(3,points,0,px3);
00741
00742
00743 points[0].x = _h;
00744 points[0].y = 0;
00745 points[1].x = 0;
00746 points[1].y = -trianglesHalfWidth;
00747 points[2].x = 0;
00748 points[2].y = trianglesHalfWidth;
00749 if( _selectionMoveId==3 )
00750 {
00751 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
00752 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
00753 }
00754 else
00755 {
00756 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
00757 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
00758 }
00759 temp_dc.DrawPolygon(3,points,0,px3);
00760 }
00761
00762 if (realX_vertical_line!=-1)
00763 {
00764 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
00765 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
00766 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
00767 }
00768
00769
00770 if (_visibleLables)
00771 {
00772
00773
00774
00775
00776
00777
00778
00779 temp_dc.SetBackgroundMode(wxTRANSPARENT);
00780 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
00781 temp_dc.SetFont(font);
00782 temp_dc.SetTextForeground(*wxBLACK);
00783
00784
00785
00786 wxString text_start;
00787
00788 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
00789 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
00790
00791 wxString text_end;
00792
00793 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
00794 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
00795 if( withActualDrawed )
00796 {
00797
00798 wxString text_actual;
00799
00800 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
00801 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
00802 }
00803
00804 wxString text_min;
00805
00806 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
00807 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
00808
00809 wxString text_max;
00810
00811 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
00812
00813 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
00814 }
00815
00816 }
00817
00818
00819 void mBarRange::RefreshForce()
00820 {
00821 Refresh();
00822 Update();
00823 }
00824
00825 void mBarRange::OnMouseMove(wxMouseEvent& event )
00826 {
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 if (activeState)
00837 {
00838 wxPoint point = event.GetPosition();
00839 int barHeight;
00840 if (_orientation)
00841 {
00842 setClickedX(point.x);
00843 barHeight = point.y;
00844 }
00845 else
00846 {
00847 setClickedX(point.y);
00848 barHeight = point.x;
00849 }
00850 int logicClick = getLogicValueofPixel(clickedX);
00851
00852 if( _selectionMoveId==-1 )
00853 {
00854 if (barHeight <=_h)
00855 {
00856 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
00857 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
00858 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
00859 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
00860
00861 if( in_actualT )
00862 _selectionMoveId = 3;
00863 else if(in_StartTri)
00864 _selectionMoveId = 1;
00865 else if( in_EndTri )
00866 _selectionMoveId = 2;
00867 else if( in_movingBar )
00868 _selectionMoveId = 4;
00869 }
00870 }
00871 else
00872 {
00873 if(acceptedClick)
00874 {
00875
00876 if( _selectionMoveId ==1 && event.LeftIsDown())
00877 {
00878 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
00879 if( validPos_StartTri && !_in_rangeProperty)
00880 {
00881 SetPixelStart(clickedX);
00882 RefreshForce();
00883 RefreshHorizontalView();
00884
00885
00886
00887 createAndSendEvent( wxEVT_TSBAR_START );
00888 }
00889
00890 else if (validPos_StartTri && _in_rangeProperty)
00891 {
00892 if(logicClick<=GetActual())
00893 {
00894 SetPixelStart(clickedX);
00895 RefreshForce();
00896
00897
00898
00899
00900 createAndSendEvent( wxEVT_TSBAR_START );
00901 }
00902 }
00903 }
00904
00905 else if( _selectionMoveId == 2 && event.LeftIsDown() )
00906 {
00907 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
00908 if( validPos_EndTri && !_in_rangeProperty )
00909 {
00910 SetPixelEnd(clickedX);
00911 RefreshForce();
00912
00913
00914
00915
00916 createAndSendEvent( wxEVT_TSBAR_END );
00917 }
00918
00919 else if( validPos_EndTri && _in_rangeProperty )
00920 {
00921 if(logicClick>=GetActual())
00922 {
00923 SetPixelEnd(clickedX);
00924 RefreshForce();
00925
00926
00927
00928
00929 createAndSendEvent( wxEVT_TSBAR_END );
00930 }
00931 }
00932 }
00933
00934 else if( _selectionMoveId == 3 && event.LeftIsDown())
00935 {
00936 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
00937
00938 if( validPos_ActualTri && !_in_rangeProperty )
00939 {
00940 SetPixelActual(clickedX);
00941 RefreshForce();
00942 RefreshHorizontalView();
00943
00944
00945
00946 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
00947
00948
00949
00950
00951 }
00952 else if( validPos_ActualTri && _in_rangeProperty )
00953
00954 {
00955 if( logicClick>=GetStart() && logicClick<=GetEnd())
00956 {
00957 SetPixelActual(clickedX);
00958 RefreshForce();
00959 RefreshHorizontalView();
00960
00961
00962
00963 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
00964 }
00965 }
00966 }
00967
00968 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
00969 {
00970
00971 if(_initialPoint == 0)
00972 {
00973 _initialPoint = logicClick;
00974 logicInitial_start = GetStart();
00975 logicInitial_end = GetEnd();
00976 logicInitial_actual = GetActual();
00977
00978 }
00979 int difference = logicClick -_initialPoint;
00980 int next_end = difference + logicInitial_end;
00981 int next_start = difference + logicInitial_start;
00982 int next_actual = difference + logicInitial_actual;
00983
00984
00985
00986
00987
00988 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
00989 {
00990 SetStart(next_start);
00991 SetEnd(next_end);
00992 if( _moveActualWithBar )
00993 {
00994 SetActual (next_actual);
00995
00996
00997
00998 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
00999 }
01000 RefreshForce();
01001 RefreshHorizontalView();
01002
01003
01004
01005
01006 createAndSendEvent( wxEVT_TSBAR_MOVED );
01007 }
01008
01009 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
01010 {
01011 SetStart(next_start);
01012 SetEnd(next_end);
01013 if( _moveActualWithBar )
01014 {
01015 SetActual (next_actual);
01016
01017
01018
01019 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
01020 }
01021 RefreshForce();
01022 RefreshHorizontalView();
01023
01024
01025
01026
01027 createAndSendEvent( wxEVT_TSBAR_MOVED );
01028 }
01029 }
01030 }
01031 if( !event.LeftIsDown())
01032 {
01033 _initialPoint=0;
01034 _selectionMoveId = -1;
01035 RefreshForce();
01036
01037
01038
01039
01040 createAndSendEvent(wxEVT_SELECTION_END);
01041 }
01042 }
01043 }
01044
01045
01046
01047
01048
01049
01050 }
01051
01052
01053
01054
01055
01056 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
01057 {
01058 _min = minRealValue;
01059 _max = maxRealValue;
01060 _start=_min;
01061 _end=_max;
01062 }
01063
01064
01065
01066
01067 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
01068 {
01069 _visibleLables = setVisibleLB;
01070 }
01071
01072
01073
01074
01075
01076 bool mBarRange ::getIfVisibleLabels ()
01077 {
01078 return _visibleLables;
01079 }
01080
01086 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
01087 {
01088 deviceStart_x = devStart_x;
01089 deviceStart_y = devStart_y;
01090
01091 if (GetPixelEnd()<0)
01092 {
01093 if (_orientation)
01094 {
01095 SetPixelStart(deviceStart_x);
01096 SetPixelEnd(_w+deviceStart_x);
01097 SetPixelActual(deviceStart_x);
01098 }
01099 else
01100 {
01101 SetPixelStart(deviceStart_x);
01102 SetPixelEnd(_h+deviceStart_x);
01103 SetPixelActual(deviceStart_x);
01104 }
01105 }
01106 DrawBar();
01107 }
01108
01112 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
01113 {
01114 if (activeState)
01115 {
01116 bool validClic = false;
01117 if (_orientation)
01118 {
01119 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
01120 }
01121 else
01122 {
01123 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
01124 }
01125 if (validClic)
01126 {
01127 if(_orientation)
01128 setClickedX(event.GetX());
01129 else
01130 setClickedX(event.GetY());
01131
01132 if (getClickedX()<=_h)
01133 {
01134 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
01135 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
01136 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
01137 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
01138
01139 if(in_StartTri)
01140 _selectionMoveId = 1;
01141 else if( in_EndTri )
01142 _selectionMoveId = 2;
01143 else if( in_actualT )
01144 _selectionMoveId = 3;
01145 else if( in_movingBar )
01146 _selectionMoveId = 4;
01147 }
01148 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
01149 }
01150 }
01151 }
01152
01157 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
01158 {
01159 bool okSelectedColor = false;
01160 wxColour selectedColour;
01161 wxColourData data;
01162 wxColourDialog dialog( GetParent(), &data);
01163
01164 if ( dialog.ShowModal() == wxID_OK )
01165 {
01166 selectedColour = dialog.GetColourData().GetColour();
01167 okSelectedColor = true;
01168 }
01169 if( okSelectedColor )
01170 {
01171 if (_selectionMoveId==1 )
01172 start_Colour = selectedColour;
01173 else if (_selectionMoveId==2 )
01174 end_Colour = selectedColour;
01175 else if( _selectionMoveId==3 )
01176 actual_Colour = selectedColour;
01177 else if( _selectionMoveId==4 )
01178 bar_Colour = selectedColour;
01179 }
01180 _selectionMoveId = -1;
01181 RefreshForce();
01182
01183 }
01184
01189 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
01190 {
01191 if (!_in_rangeProperty)
01192 {
01193 if(IsActualInRange())
01194 {
01195 SetInRangeProperty (true);
01196 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
01197 }
01198 }
01199 else
01200 {
01201 SetInRangeProperty (false);
01202 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
01203 }
01204 }
01205
01210 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
01211 {
01212 if (_moveActualWithBar )
01213 {
01214 _moveActualWithBar = false;
01215 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
01216 }
01217 else
01218 {
01219 if(IsActualInRange())
01220 {
01221 _moveActualWithBar = true;
01222 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
01223 }
01224 }
01225 }
01226
01227
01228
01229
01230
01231 void mBarRange :: setActiveStateTo (bool activeNow)
01232 {
01233 activeState = activeNow;
01234 }
01235
01236
01237
01238
01239
01240 bool mBarRange :: isActive()
01241 {
01242 return activeState;
01243 }
01244
01245
01246
01247
01248
01249 int mBarRange :: getRealX_vertical_line()
01250 {
01251 return realX_vertical_line;
01252 }
01253
01254
01255
01256
01257
01258 void mBarRange :: setRealX_vertical_line(int newReal_x)
01259 {
01260 realX_vertical_line = newReal_x;
01261 }
01262
01263
01264
01265
01266
01267 int mBarRange :: getDeviceEndX()
01268 {
01269 return deviceEndMargin;
01270 }
01271
01272
01273
01274
01275
01276 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
01277 {
01278 deviceEndMargin = newDeviceEnd_pixels;
01279 }
01280
01281
01282
01283
01284
01285 int mBarRange :: getClickedX()
01286 {
01287 return clickedX;
01288 }
01289
01290
01291
01292
01293
01294 void mBarRange :: setClickedX(int nwClickX)
01295 {
01296 clickedX = nwClickX;
01297 }
01298
01299
01300
01301
01302
01303
01304 float mBarRange :: getStartShowPorcentage()
01305 {
01306 return (float)( 1+(_start - _max)/(_max-_min));
01307 }
01308
01309
01310
01311
01312
01313 float mBarRange :: getEndShowPorcentage()
01314 {
01315 return (float) (1+(_end - _max)/(_max-_min));
01316 }
01317
01318
01319
01320
01321
01322 float mBarRange :: getActualShowPorcentage()
01323 {
01324 return (float) (1+(_actual - _max)/(_max-_min));
01325 }
01326
01327 int mBarRange :: getLogicValueofPixel(int thePixel)
01328 {
01329 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
01330 }
01331
01332
01333
01334
01335
01336 void mBarRange :: setIfWithActualDrawed(bool drawActual)
01337 {
01338 if(!withActualDrawed && drawActual)
01339 {
01340 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
01341 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
01342 }
01343 else if (withActualDrawed && !drawActual)
01344 {
01345 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
01346 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
01347 }
01348 withActualDrawed = drawActual;
01349 Refresh();
01350 }
01351
01352
01353
01354
01355
01356 bool mBarRange :: getIfWithActualDrawed()
01357 {
01358 return withActualDrawed;
01359 }
01360
01361 void mBarRange::createAndSendEvent(WXTYPE theEventType)
01362 {
01363 wxCommandEvent cevent( theEventType, GetId() );
01364 cevent.SetEventObject( this );
01365 GetEventHandler()->ProcessEvent( cevent );
01366 }
01367
01368
01369
01370
01371
01372 void mBarRange :: setBackgroundColor(wxColour theColor)
01373 {
01374 backgroundColor = theColor;
01375 }
01376
01377
01378
01379
01380
01381 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
01382 {
01383 guideLineColor = theNwGuideLineColor;
01384 }
01385
01386
01387
01388
01389
01390 wxColour mBarRange :: getGuideLineColour()
01391 {
01392 return guideLineColor;
01393 }
01394
01395 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
01396 {
01397 acceptedClick = true;
01398 }
01399
01400 void mBarRange ::onLeftClickUp(wxMouseEvent& event )
01401 {
01402 acceptedClick = false;
01403 }
01404
01405