Ticket #2508: MediaPlayer - Playlist Icons.diff
File MediaPlayer - Playlist Icons.diff, 4.4 KB (added by , 16 years ago) |
---|
-
src/apps/mediaplayer/playlist/PlaylistListView.cpp
15 15 #include <ScrollBar.h> 16 16 #include <ScrollView.h> 17 17 #include <Window.h> 18 #include <NodeInfo.h> 19 #include <Mime.h> 20 #include <Bitmap.h> 18 21 19 22 #include "CommandStack.h" 20 23 #include "Controller.h" … … 51 54 return ceilf(fh.ascent * 0.8); 52 55 } 53 56 57 static BString 58 get_mime_string(const entry_ref* ref) 59 { 60 BFile file(ref, B_READ_ONLY); 61 BNodeInfo nodeInfo(&file); 62 char mimeString[B_MIME_TYPE_LENGTH]; 63 if (nodeInfo.GetType(mimeString) != B_OK) { 64 BMimeType type; 65 if (BMimeType::GuessMimeType(ref, &type) != B_OK) 66 return BString(); 54 67 68 strlcpy(mimeString, type.Type(), B_MIME_TYPE_LENGTH); 69 nodeInfo.SetType(type.Type()); 70 } 71 return BString(mimeString); 72 } 73 55 74 class PlaylistItem : public SimpleItem { 56 75 public: 57 58 virtual~PlaylistItem();76 PlaylistItem(const entry_ref& ref); 77 virtual ~PlaylistItem(); 59 78 60 void Draw(BView* owner, BRect frame, 61 const font_height& fh, 62 bool tintedLine, uint32 mode, 63 bool active, 64 uint32 playbackState); 79 void Draw(BView* owner, BRect frame, const font_height& fh, bool tintedLine, 80 uint32 mode, bool active, uint32 playbackState); 65 81 66 67 entry_reffRef;68 82 private: 83 entry_ref fRef; 84 BBitmap * fBitmap; 69 85 }; 70 86 71 87 72 88 PlaylistItem::PlaylistItem(const entry_ref& ref) 73 89 : SimpleItem(ref.name), 74 fRef(ref) 90 fRef(ref), 91 fBitmap(NULL) 75 92 { 93 BRect rect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1); 94 95 #ifdef HAIKU_TARGET_PLATFORM_HAIKU 96 fBitmap = new BBitmap(rect, B_RGBA32); 97 #else 98 fBitmap = new BBitmap(rect, B_CMAP8); 99 #endif 100 101 BString mimeString = get_mime_string(&ref); 102 BMimeType mimeType(mimeString.String()); 103 status_t status = mimeType.GetIcon(fBitmap, B_MINI_ICON); 104 105 // get supertype icon 106 if (status != B_OK) { 107 BMimeType superType; 108 status = mimeType.GetSupertype(&superType); 109 if (status == B_OK) 110 status = superType.GetIcon(fBitmap, B_MINI_ICON); 111 } 112 113 // get default icon 114 if (status != B_OK) { 115 BMimeType genericType(B_FILE_MIME_TYPE); 116 status = genericType.GetIcon(fBitmap, B_MINI_ICON); 117 } 118 119 if (status != B_OK) { 120 delete fBitmap; 121 fBitmap = NULL; 122 } 76 123 } 77 124 78 125 79 126 PlaylistItem::~PlaylistItem() 80 127 { 128 delete fBitmap; 81 129 } 82 130 83 131 … … 88 136 rgb_color color = (rgb_color){ 255, 255, 255, 255 }; 89 137 if (tintedLine) 90 138 color = tint_color(color, 1.04); 139 91 140 // background 92 141 if (IsSelected()) 93 142 color = tint_color(color, B_DARKEN_2_TINT); 94 143 owner->SetLowColor(color); 95 144 owner->FillRect(frame, B_SOLID_LOW); 145 96 146 // label 97 147 rgb_color black = (rgb_color){ 0, 0, 0, 255 }; 98 148 owner->SetHighColor(black); 99 const char* text = Text();100 149 switch (mode) { 101 150 case DISPLAY_NAME: 102 151 // TODO … … 108 157 break; 109 158 } 110 159 111 float playbackMarkSize = playback_mark_size(fh); 112 float textOffset = text_offset(fh); 160 float iconOffset = frame.left + 4; 161 float textOffset = iconOffset + B_MINI_ICON + 4; 162 float playbackSize = playback_mark_size(fh); 163 float playbackOffset = frame.Width() - playbackSize - 4; 113 164 114 BString truncatedString(text); 165 BString truncatedString(Text()); 166 115 167 owner->TruncateString(&truncatedString, B_TRUNCATE_MIDDLE, 116 frame.Width() - playbackMarkSize - textOffset); 117 owner->DrawString(truncatedString.String(), 118 BPoint(frame.left + playbackMarkSize + textOffset, 168 playbackOffset - textOffset - text_offset(fh) - 4); 169 owner->DrawString(truncatedString.String(), BPoint(textOffset, 119 170 floorf(frame.top + frame.bottom + fh.ascent) / 2 - 1)); 120 171 172 if (fBitmap) { 173 BPoint point(iconOffset, 174 frame.top + (frame.Height() - B_MINI_ICON) / 2.0f); 175 owner->SetDrawingMode(B_OP_ALPHA); 176 owner->DrawBitmap(fBitmap, point); 177 } 178 179 owner->SetDrawingMode(B_OP_COPY); 180 121 181 // playmark 122 182 if (active) { 123 183 rgb_color green = (rgb_color){ 0, 255, 0, 255 }; 124 184 if (playbackState != PLAYBACK_STATE_PLAYING) 125 185 green = tint_color(color, B_DARKEN_1_TINT); 126 186 127 BRect r(0, 0, playbackMarkSize, playbackMarkSize); 128 r.OffsetTo(frame.left + 4, 129 ceilf((frame.top + frame.bottom) / 2) - 5); 187 BRect r(0, 0, playbackSize, playbackSize); 188 r.OffsetTo(playbackOffset, ceilf((frame.top + frame.bottom) / 2) - 4); 130 189 131 190 BPoint arrow[3]; 132 191 arrow[0] = r.LeftTop();