1 /* 2 * Copyright (c) 1999-2000, Eric Moon. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions, and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions, and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * 3. The name of the author may not be used to endorse or promote products 17 * derived from this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 21 * OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 27 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31 32 // MediaNodePanel.h 33 // c.lenz 9oct99 34 // 35 // HISTORY 36 // c.lenz 9oct99 Begun 37 38 #ifndef __MediaNodePanel_H__ 39 #define __MediaNodePanel_H__ 40 41 // DiagramView 42 #include "DiagramBox.h" 43 // MediaRoutingView 44 #include "MediaJack.h" 45 46 // STL 47 #include <vector> 48 // Support Kit 49 #include <String.h> 50 51 #include "IStateArchivable.h" 52 53 #include "cortex_defs.h" 54 __BEGIN_CORTEX_NAMESPACE 55 56 int compareID(const void *lValue, const void *rValue); 57 58 class MediaIcon; 59 class NodeRef; 60 61 class MediaNodePanel : public DiagramBox, 62 public BHandler, 63 public IStateArchivable 64 { 65 typedef DiagramBox _inherited; 66 67 public: // *** constants 68 69 // [e.moon 26oct99] moved definitions to MediaNodePanel.cpp 70 static float M_DEFAULT_WIDTH; 71 static float M_DEFAULT_HEIGHT; 72 static float M_LABEL_H_MARGIN; 73 static float M_LABEL_V_MARGIN; 74 static float M_BODY_H_MARGIN; 75 static float M_BODY_V_MARGIN; 76 77 public: // *** accessors 78 79 NodeRef* const ref; 80 81 public: // *** ctor/dtor 82 83 MediaNodePanel( 84 BPoint position, 85 NodeRef *nodeRef); 86 87 virtual ~MediaNodePanel(); 88 89 public: // *** derived from DiagramItem 90 91 virtual void attachedToDiagram(); 92 93 virtual void detachedFromDiagram(); 94 95 virtual void DrawBox(); 96 97 virtual void MouseDown( 98 BPoint point, 99 uint32 buttons, 100 uint32 clicks); 101 102 virtual void MouseOver( 103 BPoint point, 104 uint32 transit); 105 106 virtual void MessageDropped( 107 BPoint point, 108 BMessage *message); 109 110 virtual void selected(); 111 112 virtual void deselected(); 113 114 public: // *** derived from BHandler 115 116 virtual void MessageReceived( 117 BMessage *message); 118 119 public: // *** updating 120 121 // is called by the MediaRoutingView when the layout 122 // (i.e. icon size, orientation, default sizes) have 123 // changed 124 void layoutChanged( 125 int32 layout); 126 127 // query the NodeManager for all free inputs & outputs 128 // and add a MediaJack instance for each; (connected 129 // inputs are added when the connection is reported or 130 // queried) 131 void populateInit(); 132 133 // completely update the list of free input/output jacks 134 void updateIOJacks(); 135 136 // arrange the MediaJacks in order of their IDs, resize 137 // the panel if more space is needed 138 void arrangeIOJacks(); 139 140 // display popup-menu at the given point 141 void showContextMenu( 142 BPoint point); 143 144 public: // *** sorting methods 145 146 // used for sorting the panels by media_node_id 147 friend int compareID( 148 const void *lValue, 149 const void *rValue); 150 151 public: // *** IStateArchivable 152 153 status_t importState( 154 const BMessage* archive); //nyi 155 156 status_t exportState( 157 BMessage* archive) const; //nyi 158 159 private: // *** internal operations 160 161 // fetch node name (shortening as necessary to fit) 162 // and update label placement 163 void _prepareLabel(); 164 165 // update the offscreen bitmap 166 void _updateBitmap(); 167 168 void _drawInto( 169 BView *target, 170 BRect targetRect, 171 int32 layout); 172 173 void _updateIcon( 174 int32 layout); 175 176 private: // *** data 177 178 // a pointer to the panel's offscreen bitmap 179 BBitmap *m_bitmap; 180 181 BBitmap *m_icon; 182 183 BString m_label; // truncated 184 185 BString m_fullLabel; // not truncated 186 187 bool m_labelTruncated; 188 189 BPoint m_labelOffset; 190 191 BRect m_labelRect; 192 193 BRect m_bodyRect; 194 195 // cached position in the "other" layout 196 BPoint m_alternatePosition; 197 198 bool m_mouseOverLabel; 199 200 // [e.moon 7dec99] 201 static const BPoint s_invalidPosition; 202 }; 203 204 __END_CORTEX_NAMESPACE 205 #endif /* __MediaNodePanel_H__ */ 206