1 // DiagramItem.cpp 2 3 #include "DiagramItem.h" 4 #include "DiagramView.h" 5 6 __USE_CORTEX_NAMESPACE 7 8 #include <Debug.h> 9 #define D_METHOD(x) //PRINT(x) 10 11 // -------------------------------------------------------- // 12 // *** static member initialization 13 // -------------------------------------------------------- // 14 15 bigtime_t DiagramItem::m_lastSelectionTime = 0; 16 int32 DiagramItem::m_countSelected = 0; 17 18 // -------------------------------------------------------- // 19 // *** ctor/dtor (public) 20 // -------------------------------------------------------- // 21 22 DiagramItem::DiagramItem( 23 uint32 itemType) 24 : m_type(itemType), 25 m_view(0), 26 m_group(0), 27 m_draggable(false), 28 m_selectable(true), 29 m_selected(false), 30 m_selectionTime(system_time()) 31 { 32 D_METHOD(("DiagramItem::DiagramItem()\n")); 33 } 34 35 DiagramItem::~DiagramItem() 36 { 37 D_METHOD(("DiagramItem::~DiagramItem()\n")); 38 } 39 40 // -------------------------------------------------------- // 41 // *** operations (public) 42 // -------------------------------------------------------- // 43 44 void DiagramItem::select() 45 { 46 D_METHOD(("DiagramItem::select()\n")); 47 if (!m_selected) 48 { 49 m_selected = true; 50 m_lastSelectionTime = m_selectionTime = system_time(); 51 m_countSelected = 1; 52 selected(); 53 view()->Invalidate(frame()); 54 } 55 } 56 57 void DiagramItem::selectAdding() 58 { 59 D_METHOD(("DiagramItem::selectAdding()\n")); 60 if (!m_selected) 61 { 62 m_selected = true; 63 m_selectionTime = m_lastSelectionTime - m_countSelected++; 64 selected(); 65 view()->Invalidate(frame()); 66 } 67 } 68 69 void DiagramItem::deselect() 70 { 71 D_METHOD(("DiagramItem::deselect()\n")); 72 if (m_selected) 73 { 74 m_selected = false; 75 deselected(); 76 view()->Invalidate(frame()); 77 } 78 } 79 80 // -------------------------------------------------------- // 81 // *** hook functions (public) 82 // -------------------------------------------------------- // 83 84 float DiagramItem::howCloseTo( 85 BPoint point) const 86 { 87 D_METHOD(("DiagramItem::howCloseTo()\n")); 88 if (frame().Contains(point)) 89 { 90 return 1.0; 91 } 92 return 0.0; 93 } 94 95 // -------------------------------------------------------- // 96 // *** compare functions (friend) 97 // -------------------------------------------------------- // 98 99 int __CORTEX_NAMESPACE__ compareSelectionTime( 100 const void *lValue, 101 const void *rValue) 102 { 103 D_METHOD(("compareSelectionTime()\n")); 104 int returnValue = 0; 105 const DiagramItem *lItem = *(reinterpret_cast<const DiagramItem* const*>(reinterpret_cast<const void* const*>(lValue))); 106 const DiagramItem *rItem = *(reinterpret_cast<const DiagramItem* const*>(reinterpret_cast<const void* const*>(rValue))); 107 if (lItem->m_selectionTime < rItem->m_selectionTime) 108 { 109 returnValue = 1; 110 } 111 else if (lItem->m_selectionTime > rItem->m_selectionTime) 112 { 113 returnValue = -1; 114 } 115 return returnValue; 116 } 117 118 // END -- DiagramItem.cpp -- 119