1+ #include < JuceHeader.h>
2+ #include " ListBoxObjectItem.h"
3+ #include " ObjectBrowserDialog.h"
4+
5+ ListBoxObjectItem::ListBoxObjectItem (ObjectsListBox* parent, int rowNumber, bool isSelected, std::function<void (bool shouldFade)> dismissDialog)
6+ : row(rowNumber)
7+ , rowIsSelected(isSelected)
8+ , objectsListBox(parent)
9+ , dismissMenu(dismissDialog)
10+ {
11+ objectName = parent->objects [rowNumber];
12+ objectDescription = parent->descriptions [objectName];
13+ }
14+
15+ void ListBoxObjectItem::paint (juce::Graphics& g)
16+ {
17+ if (rowIsSelected || mouseHover) {
18+ auto colour = findColour (PlugDataColour::panelActiveBackgroundColourId);
19+ if (mouseHover && !rowIsSelected)
20+ colour = colour.withAlpha (0 .5f );
21+
22+ g.setColour (colour);
23+ g.fillRoundedRectangle (getLocalBounds ().reduced (4 , 2 ).toFloat (), Corners::defaultCornerRadius);
24+ // g.fillRoundedRectangle({ 4.0f, 1.0f, getWidth() - 8.0f, getHeight() - 2.0f }, Corners::defaultCornerRadius);
25+ }
26+
27+ auto colour = rowIsSelected ? findColour (PlugDataColour::panelActiveTextColourId) : findColour (PlugDataColour::panelTextColourId);
28+
29+ auto textBounds = Rectangle<int >(0 , 0 , getWidth (), getHeight ()).reduced (18 , 6 );
30+
31+ Fonts::drawStyledText (g, objectName, textBounds.removeFromTop (textBounds.proportionOfHeight (0 .5f )), colour, Bold, 14 );
32+
33+ Fonts::drawText (g, objectDescription, textBounds, colour, 14 );
34+ }
35+
36+ bool ListBoxObjectItem::hitTest (int x, int y)
37+ {
38+ auto bounds = getLocalBounds ().reduced (4 , 2 );
39+ return bounds.contains (x, y);
40+ }
41+
42+ void ListBoxObjectItem::mouseEnter (MouseEvent const & e)
43+ {
44+ mouseHover = true ;
45+ repaint ();
46+ }
47+
48+ void ListBoxObjectItem::mouseExit (MouseEvent const & e)
49+ {
50+ mouseHover = false ;
51+ repaint ();
52+ }
53+
54+ void ListBoxObjectItem::mouseDown (MouseEvent const & e)
55+ {
56+ objectsListBox->selectRow (row, true , true );
57+ }
58+
59+ void ListBoxObjectItem::mouseUp (MouseEvent const & e)
60+ {
61+ if (e.mouseWasDraggedSinceMouseDown ())
62+ dismissMenu (false );
63+ }
64+
65+ void ListBoxObjectItem::dismiss (bool withAnimation)
66+ {
67+ dismissMenu (withAnimation);
68+ }
69+
70+ String ListBoxObjectItem::getObjectString ()
71+ {
72+ return " #X obj 0 0 " + objectName;
73+ }
74+
75+ String ListBoxObjectItem::getItemName () const
76+ {
77+ return objectName;
78+ }
79+
80+ void ListBoxObjectItem::refresh (String name, String description, int rowNumber, bool isSelected)
81+ {
82+ objectName = name;
83+ objectDescription = description;
84+ row = rowNumber;
85+ rowIsSelected = isSelected;
86+ repaint ();
87+ }
0 commit comments