1 //----------------------------------------------------------------------------
5 //const wxEventType wxEVT_TSBAR = wxNewEventType();
7 DEFINE_EVENT_TYPE(wxEVT_TSBAR)
8 DEFINE_EVENT_TYPE(wxEVT_TSBAR_ACTUAL)
9 DEFINE_EVENT_TYPE(wxEVT_TSBAR_START)
10 DEFINE_EVENT_TYPE(wxEVT_TSBAR_END)
11 DEFINE_EVENT_TYPE(wxEVT_TSBAR_MOVED)
12 DEFINE_EVENT_TYPE(wxEVT_SELECTION_END)
16 //----------------------------------------------------------------------------
18 //----------------------------------------------------------------------------
20 IMPLEMENT_CLASS(mBarRange, wxScrolledWindow)
21 BEGIN_EVENT_TABLE(mBarRange, wxScrolledWindow)
22 EVT_PAINT (mBarRange::OnPaint)
23 EVT_SIZE (mBarRange::OnSize)
24 EVT_MOTION (mBarRange::OnMouseMove)
25 EVT_RIGHT_DOWN (mBarRange :: onShowPopupMenu)
26 EVT_MENU(cntID_CHANGE_COLOR, mBarRange :: onChangePartColor)
27 EVT_MENU(cntID_ENABLE_ACTUAL, mBarRange :: onEnableRange_Actual)
28 EVT_MENU(cntID_MOVABLE_ACTUAL_BAR, mBarRange :: onMovable_ActualWithBar)
31 EVT_LEFT_DOWN( mBarRange :: onLeftClicDown)
32 EVT_LEFT_UP( mBarRange :: onLeftClickUp)
34 EVT_CHAR( mBarRange :: onKey )
36 //how to catch the new event (our event)
37 //EVT_COMMAND (ID_MY_WINDOW, wxEVT_MY_EVENT, MyFrame::OnMyEvent)
41 //----------------------------------------------------------------------------
43 //----------------------------------------------------------------------------
45 mBarRange::mBarRange(wxWindow *parent, int w, int h)
46 :wxScrolledWindow(parent,-1,wxDefaultPosition,wxDefaultSize,wxTAB_TRAVERSAL)
53 trianglesHalfWidth = 5;
55 wxColour start_Colour;
57 // Setting the default parts colors
58 start_Colour = wxColour(0,0,255);
59 actual_Colour = wxColour(255,255,202);
60 end_Colour = wxColour(0,0,255);
61 bar_Colour = wxColour(255,0,255);
62 backgroundColor = parent ->GetBackgroundColour();
63 guideLineColor = wxColour(255,0,0);
65 //actual is in _start and end
66 //false means that it could be anywhere
67 _moveActualWithBar = false;
68 _in_rangeProperty = false;
69 _selectionMoveId = -1;
70 realX_vertical_line = -1;
76 setIfWithActualDrawed(true);
78 b_popmenu.Append (cntID_CHANGE_COLOR, _("Change Color"), _("Changes the color of the selected part"));
79 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
80 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
85 //----------------------------------------------------------------------------
87 //----------------------------------------------------------------------------
89 mBarRange::~mBarRange()
92 //---------------------------------------------------------------------------
93 //Draw bar: vertical or Horizontal
94 //---------------------------------------------------------------------------
95 void mBarRange::DrawBar()
100 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
101 _bitmap_bar = new wxBitmap(_w+1280,_h+100);
102 //SIL//_bitmap_info = new wxBitmap(_w+100+1280, _h+100);
107 SetWindowStyle(wxNO_FULL_REPAINT_ON_RESIZE);
108 _bitmap_bar = new wxBitmap(_h+deviceStart_y+100,_w+1280);
109 _bitmap_info = new wxBitmap(_h+deviceStart_y+100, _w+1280);
112 //----------------------------------------------------------------------------
114 //----------------------------------------------------------------------------
115 //----------------------------------------------------------------------------
116 //the property condition on actual triangle
117 //----------------------------------------------------------------------------
118 bool mBarRange::GetInRangeProperty()
120 return _in_rangeProperty;
122 //----------------------------------------------------------------------------
123 void mBarRange::SetInRangeProperty(bool in)
125 _in_rangeProperty=in;
127 //----------------------------------------------------------------------------
128 //the information about the actual triangle in range or not, true if is between start and end
129 //----------------------------------------------------------------------------
130 bool mBarRange::IsActualInRange()
132 return ( _actual <= _end && _actual >= _start );
135 //----------------------------------------------------------------------------
136 // the position of the rectangle, vertical or horizontal
137 //----------------------------------------------------------------------------
138 bool mBarRange::GetOrientation()
142 //-----------------------------------------------------------------------------
143 void mBarRange::SetOrientation(bool orientation)
149 _orientation=orientation;
152 //----------------------------------------------------------------------------
153 // _start of the pixel rectangle
154 //----------------------------------------------------------------------------
156 int mBarRange::GetPixelStart()
158 return ((_start - _min)*(_w-deviceEndMargin))/(_max - _min);
160 //----------------------------------------------------------------------------
161 // param i: value in pixels
162 //----------------------------------------------------------------------------
163 void mBarRange::SetPixelStart(int i)
165 _start = _min+((i - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
168 //----------------------------------------------------------------------------
169 // _actual of the pixel rectangle
170 //----------------------------------------------------------------------------
171 int mBarRange::GetPixelActual()
173 return ((_actual - _min)*(_w-deviceEndMargin))/(_max - _min);
175 //----------------------------------------------------------------------------
176 // param i: value in pixels
177 //----------------------------------------------------------------------------
178 void mBarRange::SetPixelActual(int i)
180 _actual = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
182 //----------------------------------------------------------------------------
183 // _end of the pixel rectangle
184 //----------------------------------------------------------------------------
185 int mBarRange::GetPixelEnd()
187 return ((_end - _min)*(_w-deviceEndMargin))/(_max - _min);
189 //----------------------------------------------------------------------------
190 // param i: value in pixels to be converted to real logical value
191 //----------------------------------------------------------------------------
192 void mBarRange::SetPixelEnd(int i)
194 _end = _min + (i-deviceStart_x)*(_max-_min)/(_w-deviceEndMargin);
196 //----------------------------------------------------------------------------
197 // Logical max of the triangle
198 //----------------------------------------------------------------------------
200 double mBarRange::GetMax()
205 //----------------------------------------------------------------------------
206 void mBarRange::SetMax(double i)
210 //----------------------------------------------------------------------------
211 // Logical min of the triangle
212 //----------------------------------------------------------------------------
214 double mBarRange::GetMin()
219 //----------------------------------------------------------------------------
220 void mBarRange::SetMin(double i)
225 //----------------------------------------------------------------------------
226 // pixel dimensions of the rectangle
227 //----------------------------------------------------------------------------
229 int mBarRange::GetWidth()
233 //----------------------------------------------------------------------------
234 void mBarRange::SetWidth(int w)
238 //----------------------------------------------------------------------------
239 int mBarRange::GetHeight()
244 //----------------------------------------------------------------------------
245 void mBarRange::SetHeight(int h)
250 //----------------------------------------------------------------------------
251 // Logical Start of the rectangle
252 //----------------------------------------------------------------------------
254 int mBarRange::filtreValue(int value)
265 int mBarRange::GetStart()
269 //----------------------------------------------------------------------------
270 // param start: value real units
271 //----------------------------------------------------------------------------
272 void mBarRange::SetStart(int newstart)
274 _start = filtreValue(newstart);
275 if (_start>_end) { _start=_end; }
276 if (_in_rangeProperty==true)
278 if (_start>_actual) { _start=_actual; }
282 //----------------------------------------------------------------------------
283 // Logical End of the rectangle
284 //----------------------------------------------------------------------------
286 int mBarRange::GetEnd()
290 //----------------------------------------------------------------------------
291 // param end: value pixel units
292 //----------------------------------------------------------------------------
293 void mBarRange::SetEnd(int newend)
295 _end = filtreValue(newend);
296 if (_end<_start) { _end=_start; }
297 if (_in_rangeProperty==true)
299 if (_end<_actual) { _end=_actual; }
303 //----------------------------------------------------------------------------
304 // logical Actual of the rectangle
305 //----------------------------------------------------------------------------
306 int mBarRange::GetActual()
310 //----------------------------------------------------------------------------
311 void mBarRange::SetActual(int newactual)
313 _actual = filtreValue(newactual);
314 if (_in_rangeProperty==true)
316 if (_actual<_start) { _actual=_start; }
317 if (_actual>_end) { _actual=_end; }
322 //----------------------------------------------------------------------------
324 //----------------------------------------------------------------------------
325 int mBarRange::GetTrianglesHalfWidth()
327 return trianglesHalfWidth;
329 //----------------------------------------------------------------------------
330 void mBarRange::SetTrianglesHalfWidth(int nwTriHalfWidth)
332 trianglesHalfWidth = nwTriHalfWidth;
335 void mBarRange::OnSize( wxSizeEvent &WXUNUSED(event) )
337 wxRect rectTotal = GetClientRect();
340 SetWidth( rectTotal.GetWidth() - deviceEndMargin );
344 SetWidth( rectTotal.GetHeight() - deviceEndMargin);
346 _selectionMoveId = -1;
350 //----------------------------------------------------------------------------
352 void mBarRange::Refresh(bool eraseBackground, const wxRect* rect)
354 wxScrolledWindow::Refresh(false);
358 //----------------------------------------------------------------------------
360 //----------------------------------------------------------------------------
361 void mBarRange::OnPaint( wxPaintEvent &WXUNUSED(event) )
363 if (_bitmap_bar!=NULL){
367 RefreshHorizontalView();
369 temp_dc.SelectObject( *_bitmap_bar );
370 wxPaintDC dc( this );
371 dc.Blit(deviceStart_x-(trianglesHalfWidth+2), deviceStart_y, _w-deviceEndMargin+2*(trianglesHalfWidth+2), _h, &temp_dc, 0, 0);
373 // if (_visibleLables)
375 // temp_dc.SelectObject( *_bitmap_info );
376 // dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+200, &temp_dc, deviceStart_x, deviceStart_y);
377 // //dc.Blit(deviceStart_x,deviceStart_y+_h, _w+deviceStart_x-deviceEndMargin, _h+deviceStart_y+60, &temp_dc, 0, 0);
381 RefreshVerticalView();
383 temp_dc.SelectObject( *_bitmap_bar );
384 wxPaintDC dc( this );
385 // dc.Blit(deviceStart_y,deviceStart_x, _h+deviceStart_y-deviceEndMargin,_w+deviceStart_x-deviceEndMargin, &temp_dc, 0, 0);
386 dc.Blit(deviceStart_y,deviceStart_x-(trianglesHalfWidth+2), _h,_w-deviceEndMargin+2*(trianglesHalfWidth+2), &temp_dc, 0, 0);
389 // if (_visibleLables)
391 // temp_dc.SelectObject( *_bitmap_info );
392 // dc.Blit(0,_w, _h+deviceStart_y+200, _w+deviceStart_x+200-deviceEndMargin, &temp_dc, deviceStart_y,_w+deviceStart_x);
401 //----------------------------------------------------------------------------
402 //Repaint the bar if it is horizontal
403 //----------------------------------------------------------------------------
404 void mBarRange::RefreshHorizontalView()
408 //int largestNumberWidthInPixels = 15; // JPRx
409 int pxStart = GetPixelStart();
410 int pxEnd = GetPixelEnd();
411 int pxActual = GetPixelActual();
415 int barHeight = 2*letterHeight;
416 int tempHeight = _h-(6*letterHeight);
421 barHeight = (tempHeight>0) ? tempHeight : (int) _h/2;
427 temp_dc.SelectObject( *_bitmap_bar );
430 // Background of this widget
433 temp_dc.SetPen(wxPen( backgroundColor ));
434 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
436 temp_dc.DrawRectangle(0,0,_w+2*trianglesHalfWidth,_h);
439 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
440 temp_dc.DrawLine(trianglesHalfWidth+2, 0, _w-deviceEndMargin, 0);
441 temp_dc.DrawLine(trianglesHalfWidth+2, barHeight, (_w-deviceEndMargin-trianglesHalfWidth-2), barHeight);
442 temp_dc.SetDeviceOrigin(trianglesHalfWidth+2,0);
446 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
447 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
448 temp_dc.DrawRectangle( pxStart , 0, pxEnd-pxStart, barHeight);
452 if( _selectionMoveId==4 )
454 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
455 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
459 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
460 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
462 temp_dc.DrawRectangle( pxStart,1, pxEnd-pxStart, barHeight );
464 // 2 Shadow Triangles: Start and End
465 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
466 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
468 points[0].y= barHeight;
469 points[1].x= -trianglesHalfWidth-1;
471 points[2].x= trianglesHalfWidth+2;
473 temp_dc.DrawPolygon(3,points,pxStart,0);
474 temp_dc.DrawPolygon(3,points,pxEnd,0);
476 // 2 Triangles: Start and End
477 points[1].x = -trianglesHalfWidth;
478 points[2].x = trianglesHalfWidth;
480 //first triangle (start)
481 if( _selectionMoveId == 1 )
483 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
484 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
488 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
489 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
491 temp_dc.DrawPolygon(3,points,pxStart,0);
492 //second triangle (end)
493 if( _selectionMoveId == 2 )
495 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
496 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
500 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
501 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
503 temp_dc.DrawPolygon(3,points,pxEnd,0);
505 if( withActualDrawed )
507 // 1 Shadow Triangle: Actual
508 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
509 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
510 points[1].x = -trianglesHalfWidth-1;
511 points[2].x = trianglesHalfWidth+2;
513 temp_dc.DrawPolygon(3,points,pxActual,0);
515 // 1 Triangle: Actual (red)
516 if( _selectionMoveId==3 )
518 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
519 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
523 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
524 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
526 points[1].x = -trianglesHalfWidth;
527 points[2].x = trianglesHalfWidth;
528 temp_dc.DrawPolygon(3,points,pxActual,0);
531 if (realX_vertical_line!=-1)
533 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
534 int pixelX_guide = ((realX_vertical_line - _min)*(_w-deviceEndMargin))/(_max - _min) ;
535 temp_dc.DrawLine(pixelX_guide, 0, pixelX_guide, barHeight);
538 //Information Device drawing
542 //temp_dc.SelectObject( *_bitmap_info );
543 /*temp_dc.SetBrush(wxBrush( colourParent ,wxSOLID ));
544 temp_dc.SetPen(wxPen( colourParent ,1,wxSOLID ));*/
545 //temp_dc.DrawRectangle(deviceStart_x,_h+deviceStart_y,_w+deviceStart_x+40,_h+deviceStart_y+40);
546 //temp_dc.DrawRectangle(0,_h,_w+40-deviceEndMargin,_h+40);
548 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
549 temp_dc.SetFont(font);
550 temp_dc.SetTextForeground(*wxBLACK);
553 //the **MIN** value, always at the same y level that corresponds to barHeight+1
555 // text_min<< GetMin();
556 text_min.Printf(_T("%d"), (int)GetMin() );
558 temp_dc.DrawText(text_min,0,barHeight+1);
560 //the **MAX** value always at the same place
562 // text_max << GetMax();
563 text_max.Printf(_T("%d"), (int)GetMax() );
565 //As there is a margin of 40 extra most numbers (max) should be visibles
566 // stringSize = temp_dc.GetTextExtent(text_max);
568 temp_dc.GetTextExtent(text_max,&tmpX,&tmpY);
569 wxSize stringSize(tmpX,tmpY);
571 temp_dc.DrawText(text_max,_w-deviceEndMargin -(stringSize.GetWidth())/*2*trianglesHalfWidth*/,barHeight+1);
573 //show logical values
574 //show the **START TRIANGLE** value
576 // text_start << GetStart();
577 text_start.Printf(_T("%d"), (int)GetStart() );
579 temp_dc.DrawText(text_start, pxStart,barHeight+2*letterHeight);
580 //show the **END TRIANGLE** value
582 // text_end << GetEnd();
583 text_end.Printf(_T("%d"), (int)GetEnd() );
585 // stringSize = temp_dc.GetTextExtent(text_end);
586 temp_dc.GetTextExtent(text_end,&tmpX,&tmpY);
587 stringSize.SetHeight(tmpY);
588 stringSize.SetWidth(tmpX);
589 temp_dc.DrawText(text_end, pxEnd-stringSize.GetWidth(),barHeight+3*letterHeight);
590 if( withActualDrawed )
592 //show the actual value of actual
593 wxString text_actual;
594 // text_actual << GetActual();
595 text_actual.Printf(_T("%d"), (int)GetActual() );
596 // stringSize = temp_dc.GetTextExtent(text_actual);
597 temp_dc.GetTextExtent(text_actual,&tmpX,&tmpY);
598 stringSize.SetHeight(tmpY);
599 stringSize.SetWidth(tmpX);
600 temp_dc.DrawText(text_actual, pxActual-(stringSize.GetWidth()/2),barHeight+letterHeight);
606 //----------------------------------------------------------------------------
607 //Repaint the bar if it is vertical
608 //----------------------------------------------------------------------------
610 void mBarRange::RefreshVerticalView()
614 int px1=GetPixelStart();
615 int px2=GetPixelEnd();
616 int px3=GetPixelActual();
617 int letterHeight = 9;
618 int panelHeight = 9*3+_w;
623 barWidth = (_w-30)>0 ? _w-30 : (int) _w/2;
629 temp_dc.SelectObject( *_bitmap_bar );
632 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
633 temp_dc.SetPen(wxPen( backgroundColor ));
635 temp_dc.DrawRectangle(0,0,_h,_w+2*trianglesHalfWidth);
638 temp_dc.SetPen(wxPen( wxColour(167,165,191) ,1,wxSOLID ));
639 temp_dc.DrawLine(0,trianglesHalfWidth+2, 0, _w-deviceEndMargin);
640 temp_dc.DrawLine(barWidth, trianglesHalfWidth+2, barWidth, (_w-deviceEndMargin-trianglesHalfWidth-2));
641 temp_dc.SetDeviceOrigin(0,trianglesHalfWidth+2);
644 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
645 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
646 temp_dc.DrawRectangle( 0,px1 ,_h, px2-px1 );
650 if( _selectionMoveId==4 )
652 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
653 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
657 temp_dc.SetBrush(wxBrush( bar_Colour,wxSOLID ));
658 temp_dc.SetPen(wxPen( wxColour(164,0,164),1,wxSOLID ));
660 temp_dc.DrawRectangle( 1,px1,_h, px2-px1);
663 // 2 Shadow Triangles: Start and End
667 points[1].y = -trianglesHalfWidth-1;
669 points[2].y = trianglesHalfWidth+2;
670 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
671 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
672 temp_dc.DrawPolygon(3,points,0,px1);
673 temp_dc.DrawPolygon(3,points,0,px2);
675 // 2 Triangles: Start and End
679 points[1].y = -trianglesHalfWidth;
681 points[2].y = trianglesHalfWidth;
682 //first triangle (start)
683 if( _selectionMoveId==1 )
685 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
686 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
690 temp_dc.SetBrush(wxBrush( start_Colour,wxSOLID ));
691 temp_dc.SetPen(wxPen( wxColour(0,51,204),1,wxSOLID ));
693 temp_dc.DrawPolygon(3,points,0,px1);
694 //second triangle (end)
695 if( _selectionMoveId==2 )
697 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
698 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
702 temp_dc.SetBrush(wxBrush( end_Colour,wxSOLID ));
703 temp_dc.SetPen(wxPen( wxColour(0,0,255),1,wxSOLID ));
705 temp_dc.DrawPolygon(3,points,0,px2);
707 if( withActualDrawed )
709 // 1 Shadow Triangle: Actual
710 temp_dc.SetBrush(wxBrush( wxColour(104,104,104),wxSOLID ));
711 temp_dc.SetPen(wxPen( wxColour(104,104,104),1,wxSOLID ));
715 points[1].y=-trianglesHalfWidth-1;
717 points[2].y=trianglesHalfWidth+2;
718 temp_dc.DrawPolygon(3,points,0,px3);
720 // 1 Triangle: Actual (red)
724 points[1].y = -trianglesHalfWidth;
726 points[2].y = trianglesHalfWidth;
727 if( _selectionMoveId==3 )
729 temp_dc.SetBrush(wxBrush( wxColour(128,255,0),wxSOLID ));
730 temp_dc.SetPen(wxPen( wxColour(0,128,0),1,wxSOLID ));
734 temp_dc.SetBrush(wxBrush( actual_Colour,wxSOLID ));
735 temp_dc.SetPen(wxPen( wxColour(205,160,5),1,wxSOLID ));
737 temp_dc.DrawPolygon(3,points,0,px3);
740 if (realX_vertical_line!=-1)
742 temp_dc.SetPen(wxPen( guideLineColor,1,wxDOT ));
743 int pixelX_guide = realX_vertical_line*_w/(_max-_min)+deviceStart_x;
744 temp_dc.DrawLine(0,pixelX_guide, _h, pixelX_guide);
747 //Information Device drawing
750 /*temp_dc.SelectObject( *_bitmap_info );
752 temp_dc.SetBrush(wxBrush( backgroundColor ,wxSOLID ));
753 temp_dc.SetPen(wxPen( backgroundColor ,1,wxSOLID ));
754 temp_dc.DrawRectangle(deviceStart_y,_w+deviceStart_x,_h+deviceStart_y+200,_w+deviceStart_x+200);
757 temp_dc.SetBackgroundMode(wxTRANSPARENT);
758 wxFont font(letterHeight-1, wxFONTFAMILY_SWISS, wxNORMAL, wxNORMAL);
759 temp_dc.SetFont(font);
760 temp_dc.SetTextForeground(*wxBLACK);
762 //show logical values
763 //show the actual value of start
765 // text_start<<"Start:"<< GetStart();
766 text_start.Printf(_T("%s %d"),_T("Start: "), (int)GetStart() );
767 temp_dc.DrawText( text_start ,deviceStart_y, _w+deviceStart_x+letterHeight+1);
768 //show the actual value of end
770 // text_end <<"End: "<<GetEnd();
771 text_end.Printf(_T("%s %d"),_T("End: "), (int)GetEnd() );
772 temp_dc.DrawText( text_end ,deviceStart_y,_w+deviceStart_x+letterHeight*2 );
773 if( withActualDrawed )
775 //show the actual value of actual
776 wxString text_actual;
777 // text_actual <<"Actual: " <<GetActual();
778 text_actual.Printf(_T("%s %d"),_T("Actual: "), (int)GetActual() );
779 temp_dc.DrawText( text_actual ,deviceStart_y,_w+deviceStart_x+letterHeight*3);
781 //the min value, always at the same place
783 // text_min<<"Min: " << GetMin();
784 text_min.Printf(_T("%s %d"),_T("Min: "), (int)GetMin() );
785 temp_dc.DrawText( text_min ,deviceStart_y,_w+deviceStart_x+3);
786 //the max value always at the samen place
788 // text_max <<"Max: "<< GetMax();
789 text_max.Printf(_T("%s %d"),_T("Max: "), (int)GetMax() );
790 //toca calcular cuantol lo corremos
791 temp_dc.DrawText(text_max,deviceStart_y,_w+deviceStart_x+43);
796 //----------------------------------------------------------------------------
797 void mBarRange::RefreshForce()
802 //----------------------------------------------------------------------------
803 void mBarRange::OnMouseMove(wxMouseEvent& event )
807 wxPoint point = event.GetPosition();
811 setClickedX(point.x);
816 setClickedX(point.y);
819 int logicClick = getLogicValueofPixel(clickedX);
821 if( _selectionMoveId==-1 )
825 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
826 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
827 bool in_actualT= withActualDrawed && (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
828 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
831 _selectionMoveId = 3;
833 _selectionMoveId = 1;
835 _selectionMoveId = 2;
836 else if( in_movingBar )
837 _selectionMoveId = 4;
844 //is in start triagle
845 if( _selectionMoveId ==1 && event.LeftIsDown())
847 bool validPos_StartTri = (logicClick<GetEnd() && logicClick >=_min);
848 if( validPos_StartTri && !_in_rangeProperty)
850 SetPixelStart(clickedX);
852 RefreshHorizontalView();
853 //-------------------------------------------
854 // Sending the event of start triangle moved
855 //-------------------------------------------
856 createAndSendEvent( wxEVT_TSBAR_START );
858 //start has to be less than actual
859 else if (validPos_StartTri && _in_rangeProperty)
861 if(logicClick<=GetActual())
863 SetPixelStart(clickedX);
865 // RefreshHorizontalView();
866 //-------------------------------------------
867 // Sending the event of start triangle moved
868 //-------------------------------------------
869 createAndSendEvent( wxEVT_TSBAR_START );
872 } // _selectionMoveId == 1
874 else if( _selectionMoveId == 2 && event.LeftIsDown() )
876 bool validPos_EndTri = logicClick>GetStart()&& logicClick<=_max;
877 if( validPos_EndTri && !_in_rangeProperty )
879 SetPixelEnd(clickedX);
881 // RefreshHorizontalView();
882 //-------------------------------------------
883 //Sending the event of end triangle moved
884 //-------------------------------------------
885 createAndSendEvent( wxEVT_TSBAR_END );
887 //the end triangle cant be less than actual
888 else if( validPos_EndTri && _in_rangeProperty )
890 if(logicClick>=GetActual())
892 SetPixelEnd(clickedX);
894 // RefreshHorizontalView();
895 //-------------------------------------------
896 //Sending the event of end triangle moved
897 //-------------------------------------------
898 createAndSendEvent( wxEVT_TSBAR_END );
902 //is the actual triangle
903 else if( _selectionMoveId == 3 && event.LeftIsDown())
905 bool validPos_ActualTri=(logicClick<=_max) && (logicClick>=_min);
906 //is in actual triangle but it could be anywhere
907 if( validPos_ActualTri && !_in_rangeProperty )
909 SetPixelActual(clickedX);
911 RefreshHorizontalView();
912 //-------------------------------------------
913 //Sending the event of actual triangle moved
914 //-------------------------------------------
915 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
916 // createAndSendEvent( 98765 );
918 else if( validPos_ActualTri && _in_rangeProperty )
919 // the tringle in between start and end
921 if( logicClick>=GetStart() && logicClick<=GetEnd())
923 SetPixelActual(clickedX);
925 RefreshHorizontalView();
926 //-------------------------------------------
927 //Sending the event of actual triangle moved
928 //-------------------------------------------
929 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
934 else if ( _selectionMoveId == 4 && event.LeftIsDown() )
936 //FILE * f=fopen("E:/borrar/file.txt","a+");
937 if(_initialPoint == 0)
939 _initialPoint = logicClick;
940 logicInitial_start = GetStart();
941 logicInitial_end = GetEnd();
942 logicInitial_actual = GetActual();
943 //SIL//fprintf(f,"\n\n---- Inicia draggin:\n logicInitial_start:%d, logicInitial_end:%d,logicInitial_actual:%d \n", _initialPoint,logicInitial_start,logicInitial_end,logicInitial_actual);
945 int difference = logicClick -_initialPoint;
946 int next_end = difference + logicInitial_end;
947 int next_start = difference + logicInitial_start;
948 int next_actual = difference + logicInitial_actual;
950 /*SIL//fprintf(f,"diff:%d, next_end%d, next_start%d, next_actual%d \n", difference,next_end,next_start,next_actual);
953 //if actual is not fixed to be in the middle
954 if( ((logicClick>next_start) && (logicClick<next_end)&& (next_end<=_max)&& (next_start>=_min)) && !_in_rangeProperty)
956 SetStart(next_start);
958 if( _moveActualWithBar )
960 SetActual (next_actual);
961 //-------------------------------------------
962 //Sending the event of actual triangle moved
963 //-------------------------------------------
964 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
967 RefreshHorizontalView();
969 //-------------------------------------------
970 // Sending the event that the bar ahs being moved
971 //-------------------------------------------
972 createAndSendEvent( wxEVT_TSBAR_MOVED );
974 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
975 createAndSendEvent( wxEVT_TSBAR_END );
976 createAndSendEvent( wxEVT_TSBAR_START );
978 //if actual has to be between start and end
979 else if(_in_rangeProperty && ((next_start<=GetActual()) && (next_end>=GetActual()) && (next_end<=_max)&& (next_start>=_min)) )
981 SetStart(next_start);
983 if( _moveActualWithBar )
985 SetActual (next_actual);
986 //-------------------------------------------
987 //Sending the event of actual triangle moved
988 //-------------------------------------------
989 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
992 RefreshHorizontalView();
994 //-------------------------------------------
995 // Sending the event that the bar ahs being moved
996 //-------------------------------------------
997 createAndSendEvent( wxEVT_TSBAR_MOVED );
999 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1000 createAndSendEvent( wxEVT_TSBAR_END );
1001 createAndSendEvent( wxEVT_TSBAR_START );
1005 if( !event.LeftIsDown())
1008 _selectionMoveId = -1;
1010 //-------------------------------------------
1011 //Sending a general event just because
1012 //-------------------------------------------
1013 //SIL//createAndSendEvent( wxEVT_TSBAR );
1014 createAndSendEvent(wxEVT_SELECTION_END);
1022 * Sets the represented minimum and maximunm values
1023 * param minRealValue The minimum represented value (real value)
1024 * param maxRealValue The maximum represented value (real value)
1026 void mBarRange :: setRepresentedValues ( double minRealValue, double maxRealValue)
1028 _min = minRealValue;
1029 _max = maxRealValue;
1035 * Sets the property for viewing or not the bar labels information
1037 void mBarRange :: setVisibleLabels ( bool setVisibleLB )
1039 _visibleLables = setVisibleLB;
1043 * Sets the property for viewing or not the bar labels information
1044 * return _visibleLables The state of visible labels or not
1046 bool mBarRange ::getIfVisibleLabels ()
1048 return _visibleLables;
1052 * Sets the device start drawing left-superior (pixel) start point
1053 * param deviceStart_x Pixel start for x-coord
1054 * param deviceStart_y Pixel start for y-coord
1056 void mBarRange :: setDeviceBlitStart ( wxCoord devStart_x, wxCoord devStart_y )
1058 deviceStart_x = devStart_x;
1059 deviceStart_y = devStart_y;
1060 // For the initialization case
1061 if (GetPixelEnd()<0)
1065 SetPixelStart(deviceStart_x);
1066 SetPixelEnd(_w+deviceStart_x);
1067 SetPixelActual(deviceStart_x);
1071 SetPixelStart(deviceStart_x);
1072 SetPixelEnd(_h+deviceStart_x);
1073 SetPixelActual(deviceStart_x);
1080 * Shows the popup menu
1082 void mBarRange :: onShowPopupMenu (wxMouseEvent& event)
1086 bool validClic = false;
1089 validClic = event.GetX() >= deviceStart_x && event.GetY()<= (_h + deviceStart_y);
1093 validClic = event.GetX()>=deviceStart_y && event.GetX()<= (_h+deviceStart_y) && event.GetY()>deviceStart_x;
1098 setClickedX(event.GetX());
1100 setClickedX(event.GetY());
1102 if (getClickedX()<=_h)
1104 bool in_StartTri = (clickedX>=GetPixelStart()-5+ deviceStart_x) && (clickedX<=GetPixelStart()+5+ deviceStart_x);
1105 bool in_EndTri = (clickedX>=GetPixelEnd()-5+ deviceStart_x) && (clickedX<=GetPixelEnd()+5+ deviceStart_x);
1106 bool in_actualT= (clickedX>=GetPixelActual()-5+ deviceStart_x) && (clickedX<=GetPixelActual()+5+ deviceStart_x);
1107 bool in_movingBar = (clickedX>GetPixelStart()+5+ deviceStart_x) && (clickedX<GetPixelEnd()-5+ deviceStart_x);
1110 _selectionMoveId = 1;
1111 else if( in_EndTri )
1112 _selectionMoveId = 2;
1113 else if( in_actualT )
1114 _selectionMoveId = 3;
1115 else if( in_movingBar )
1116 _selectionMoveId = 4;
1118 PopupMenu( &b_popmenu, event.GetX(), event.GetY());
1124 * Reacts to the cntID_ADD_COLOR_POINT wxCommandEvent and adds a color degrade point to the color bar.
1125 * param & anEvent The wxCommandEvent actioned event
1127 void mBarRange :: onChangePartColor ( wxCommandEvent& anEvent )
1129 bool okSelectedColor = false;
1130 wxColour selectedColour;
1132 wxColourDialog dialog( GetParent(), &data);
1134 if ( dialog.ShowModal() == wxID_OK )
1136 selectedColour = dialog.GetColourData().GetColour();
1137 okSelectedColor = true;
1139 if( okSelectedColor )
1141 if (_selectionMoveId==1 )
1142 start_Colour = selectedColour;
1143 else if (_selectionMoveId==2 )
1144 end_Colour = selectedColour;
1145 else if( _selectionMoveId==3 )
1146 actual_Colour = selectedColour;
1147 else if( _selectionMoveId==4 )
1148 bar_Colour = selectedColour;
1150 _selectionMoveId = -1;
1156 * Reacts to the cntID_ENABLE_ACTUAL (false) wxCommandEvent enables the actual to be between the the range.
1157 * param & anEvent The wxCommandEvent actioned event
1159 void mBarRange :: onEnableRange_Actual ( wxCommandEvent& anEvent )
1161 if (!_in_rangeProperty)
1163 if(IsActualInRange())
1165 SetInRangeProperty (true);
1166 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Disable actual in range"));
1171 SetInRangeProperty (false);
1172 b_popmenu.SetLabel (cntID_ENABLE_ACTUAL, _T("Enable actual in range"));
1177 * Reacts to the cntID_MOVABLE_ACTUAL_BAR wxCommandEvent by enabling or disabling the property of moving the actual triangle with the bar, just when it is inside of it.
1178 * param & anEvent The wxCommandEvent actioned event
1180 void mBarRange :: onMovable_ActualWithBar ( wxCommandEvent& anEvent )
1182 if (_moveActualWithBar )
1184 _moveActualWithBar = false;
1185 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual+bar simultaneously"));
1189 if(IsActualInRange())
1191 _moveActualWithBar = true;
1192 b_popmenu.SetLabel (cntID_MOVABLE_ACTUAL_BAR, _T("Move actual-bar independent"));
1199 * param activeNow The new state
1201 void mBarRange :: setActiveStateTo (bool activeNow)
1203 activeState = activeNow;
1207 * Gets the active state of the bar
1208 * return activeState The actual state
1210 bool mBarRange :: isActive()
1216 * Gets the real-x value to draw a vertical line
1217 * return realX_vertical_line The real x value for the vertical line
1219 int mBarRange :: getRealX_vertical_line()
1221 return realX_vertical_line;
1225 * Sets the real-x value to draw a vertical line
1226 * param newReal_x The new real x value for the vertical line
1228 void mBarRange :: setRealX_vertical_line(int newReal_x)
1230 realX_vertical_line = newReal_x;
1234 * Gets the device value form the end of this panel to the end of the drawing area in the device in pixels
1235 * return deviceEndMargin The value asigned to the right margin
1237 int mBarRange :: getDeviceEndX()
1239 return deviceEndMargin;
1243 * Sets the new device (deviceEndMargin) value form the end of this panel to the end of the drawing area in the device
1244 * param newDeviceEnd_pixels The new pixel value to asign to the right(horizontal view), underneath(vertical view) margin in pixels
1246 void mBarRange :: setDeviceEndMargin(int newDeviceEnd_pixels)
1248 deviceEndMargin = newDeviceEnd_pixels;
1252 * Gets the last clickedX pixel coord inside the bar with respect to the container panel.
1253 * return clickedX The x-coord pixel value
1255 int mBarRange :: getClickedX()
1261 * Sets the last clickedX pixel coord inside the bar with respect to the container panel.
1262 * param nwClickX The x-coord pixel value
1264 void mBarRange :: setClickedX(int nwClickX)
1266 clickedX = nwClickX;
1271 * Gets the start porcentage with respect to the represented values of the bar
1272 * return The porcentage represented by the start showing point
1274 float mBarRange :: getStartShowPorcentage()
1276 return (float)( 1+(_start - _max)/(_max-_min));
1280 * Gets the end porcentage with respect to the represented values of the bar
1281 * return The porcentage represented by the end showing point
1283 float mBarRange :: getEndShowPorcentage()
1285 return (float) (1+(_end - _max)/(_max-_min));
1289 * Gets the actual porcentage with respect to the represented values of the bar
1290 * return The porcentage represented by the actual showing point
1292 float mBarRange :: getActualShowPorcentage()
1294 return (float) (1+(_actual - _max)/(_max-_min));
1297 int mBarRange :: getLogicValueofPixel(int thePixel)
1299 return _min+((thePixel - deviceStart_x)*( _max - _min))/(_w-deviceEndMargin);
1303 * Sets the condition for knowing if the actual triangle is being drawed or not
1304 * param drawActual The condition to set for drawing or not the actual control (true for drawing)
1306 void mBarRange :: setIfWithActualDrawed(bool drawActual)
1308 if(!withActualDrawed && drawActual)
1310 b_popmenu.Append (cntID_ENABLE_ACTUAL, _("Enable actual in range"), _("Enables/Disables the actual triangle to be or not in range"));
1311 b_popmenu.Append (cntID_MOVABLE_ACTUAL_BAR, _("Move actual-bar simultaneously"), _("Disables the actual triangle to move with the bar"));
1313 else if (withActualDrawed && !drawActual)
1315 b_popmenu.Remove(cntID_ENABLE_ACTUAL);
1316 b_popmenu.Remove(cntID_MOVABLE_ACTUAL_BAR);
1318 withActualDrawed = drawActual;
1323 * Gets the condition for knowing if the actual triangle is being drawed or not
1324 * return withActualDrawed The condition for drawing or not the actual control
1326 bool mBarRange :: getIfWithActualDrawed()
1328 return withActualDrawed;
1331 void mBarRange::createAndSendEvent(WXTYPE theEventType)
1333 wxCommandEvent cevent( theEventType, GetId() );
1334 cevent.SetEventObject( this );
1335 GetEventHandler()->ProcessEvent( cevent );
1339 * Sets the background color od the bar
1340 * theColor The color to set to the backgroundColor
1342 void mBarRange :: setBackgroundColor(wxColour theColor)
1344 backgroundColor = theColor;
1348 * Sets the guide line color
1349 * param theNwGuideLineColor The color to set to the guideLineColor
1351 void mBarRange :: setGuideLineColour(wxColour theNwGuideLineColor)
1353 guideLineColor = theNwGuideLineColor;
1357 * Gets the guide line color
1358 * return guideLineColor The color of the guideLine
1360 wxColour mBarRange :: getGuideLineColour()
1362 return guideLineColor;
1365 void mBarRange ::onLeftClicDown(wxMouseEvent& event )
1367 acceptedClick = true;
1371 void mBarRange::onLeftClickUp(wxMouseEvent& event )
1373 acceptedClick = false;
1376 //EED 20 Juillet 2011
1377 void mBarRange::onKey(wxKeyEvent& event)
1380 if ((event.GetKeyCode()==314) || (event.GetKeyCode()==317))
1385 if ((event.GetKeyCode()==315) || (event.GetKeyCode()==316))
1392 if (_selectionMoveId == 1) // start
1394 SetStart(GetStart()+step);
1395 createAndSendEvent( wxEVT_TSBAR_START );
1398 if (_selectionMoveId == 2) // end
1400 SetEnd(GetEnd()+step);
1401 createAndSendEvent( wxEVT_TSBAR_END );
1404 if (_selectionMoveId == 3) // actual
1406 SetActual(GetActual()+step);
1407 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1410 if (_selectionMoveId == 4) // bar
1412 if (( GetStart()+step>=_min ) && ( GetEnd()+step<=_max ))
1414 SetStart(GetStart()+step);
1415 SetEnd(GetEnd()+step);
1416 if (_moveActualWithBar)
1418 SetActual(GetActual()+step);
1420 createAndSendEvent( wxEVT_TSBAR_START );
1421 createAndSendEvent( wxEVT_TSBAR_END );
1422 createAndSendEvent( wxEVT_TSBAR_ACTUAL );
1423 createAndSendEvent( wxEVT_TSBAR_MOVED );
1424 } // Start>_min && End<_max
1425 }// _selectionMoveId == 4