Sprint 4 Drag and drop

pull/1/head
asb2m10 10 years ago
parent 50828bcc70
commit 847ba1635e
  1. BIN
      Builds/MacOSX/Dexed.xcodeproj/project.xcworkspace/xcuserdata/asb2m10.xcuserdatad/UserInterfaceState.xcuserstate
  2. 3
      README.md
  3. 38
      Source/CartManager.cpp
  4. 1
      Source/CartManager.h
  5. 4
      Source/Dexed.h
  6. 2
      Source/OperatorEditor.cpp
  7. 82
      Source/ProgramListBox.cpp
  8. 15
      Source/ProgramListBox.h

@ -18,11 +18,12 @@ in the source folder) stays on the Apache 2.0 license to able to collaborate bet
Changelog Changelog
--------- ---------
#### Version 0.8.1 #### Version 0.8.2
* Cartridge Manager * Cartridge Manager
* Apple AU support * Apple AU support
* Basic theming * Basic theming
* Fixed the UI corruption when more than one Dexed instance was loaded * Fixed the UI corruption when more than one Dexed instance was loaded
* Fixed wrong display value issues
#### Version 0.8.0 #### Version 0.8.0
* New UI by [AZur Studio](http://bji.yukihotaru.com/) * New UI by [AZur Studio](http://bji.yukihotaru.com/)

@ -212,6 +212,9 @@ void CartManager::resetActiveSysex() {
void CartManager::selectionChanged() { void CartManager::selectionChanged() {
File file = cartBrowser->getSelectedFile(); File file = cartBrowser->getSelectedFile();
if ( ! file.exists() )
return;
if ( file.isDirectory() ) if ( file.isDirectory() )
return; return;
@ -233,6 +236,9 @@ void CartManager::selectionChanged() {
message << ((int)checksum) << " != " << ((int)syx_data[4102]); message << ((int)checksum) << " != " << ((int)syx_data[4102]);
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Warning", message); AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon, "Warning", message);
browserCart->readOnly = true;
} else {
browserCart->readOnly = false;
} }
browserCart->setSelected(-1); browserCart->setSelected(-1);
browserCart->setCartridge(browserSysex); browserCart->setCartridge(browserSysex);
@ -270,6 +276,38 @@ void CartManager::programRightClicked(ProgramListBox *source, int pos) {
} }
void CartManager::programDragged(ProgramListBox *destListBox, int dest, char *packedPgm) {
if ( destListBox == activeCart ) {
char *sysex = mainWindow->processor->sysex;
memcpy(sysex+(dest*128), packedPgm, 128);
mainWindow->updateUI();
} else {
File file = cartBrowser->getSelectedFile();
if ( ! file.exists() )
return;
if ( file.isDirectory() )
return;
if ( file.getSize() > 5000 )
return;
MemoryBlock block;
file.loadFileAsData(block);
if ( block.getSize() < 4104 )
return;
char *sysex = ((char *) block.getData()) + 6;
memcpy(sysex+(dest*128), packedPgm, 128);
char exported[4104];
exportSysexCart(exported, sysex, 0);
file.replaceWithData(exported, 4104);
browserCart->setCartridge(sysex);
}
}
void CartManager::initialFocus() { void CartManager::initialFocus() {
cartBrowser->grabKeyboardFocus(); cartBrowser->grabKeyboardFocus();
} }

@ -65,6 +65,7 @@ public:
virtual void programSelected(ProgramListBox *source, int pos) override; virtual void programSelected(ProgramListBox *source, int pos) override;
virtual void programRightClicked(ProgramListBox *source, int pos) override; virtual void programRightClicked(ProgramListBox *source, int pos) override;
virtual void programDragged(ProgramListBox *destListBox, int dest, char *packedPgm) override;
void initialFocus(); void initialFocus();
}; };

@ -24,14 +24,14 @@
void dexed_trace(const char *source, const char *fmt, ...); void dexed_trace(const char *source, const char *fmt, ...);
#ifdef DEBUG #ifdef DEBUG
#define DEXED_VERSION "0.8.1 DEBUG" #define DEXED_VERSION "0.8.2 DEBUG"
#ifdef _MSC_VER #ifdef _MSC_VER
#define TRACE(fmt, ...) dexed_trace(__FUNCTION__,fmt,##__VA_ARGS__) #define TRACE(fmt, ...) dexed_trace(__FUNCTION__,fmt,##__VA_ARGS__)
#else #else
#define TRACE(fmt, ...) dexed_trace(__PRETTY_FUNCTION__,fmt,##__VA_ARGS__) #define TRACE(fmt, ...) dexed_trace(__PRETTY_FUNCTION__,fmt,##__VA_ARGS__)
#endif #endif
#else #else
#define DEXED_VERSION "0.8.1" #define DEXED_VERSION "0.8.2"
#define TRACE(fmt, ...) #define TRACE(fmt, ...)
#endif #endif

@ -458,7 +458,7 @@ void OperatorEditor::updateDisplay() {
if (opMode->getToggleState() == 0) { if (opMode->getToggleState() == 0) {
if ( freq == 0 ) if ( freq == 0 )
freq = 0.5; freq = 0.5;
txtFreq << "f = " << (freq + ((freq*2) * (fine/100))); txtFreq << "f = " << (freq + (freq * (fine/100)));
} else { } else {
freq = pow(10,((int)freq)&3); freq = pow(10,((int)freq)&3);
freq = freq + ((freq*10) * (fine/100)); freq = freq + ((freq*10) * (fine/100));

@ -28,6 +28,8 @@ ProgramListBox::ProgramListBox(const String name, int numCols) : Component(name)
rows = 32 / numCols; rows = 32 / numCols;
selectedPgm = -1; selectedPgm = -1;
hasContent = false; hasContent = false;
dragCandidate = -1;
readOnly = false;
} }
void ProgramListBox::paint(Graphics &g) { void ProgramListBox::paint(Graphics &g) {
@ -44,7 +46,6 @@ void ProgramListBox::paint(Graphics &g) {
g.setColour(Colour(75,73,73)); g.setColour(Colour(75,73,73));
g.drawLine(0,getHeight(),getWidth(),getHeight(), 2); g.drawLine(0,getHeight(),getWidth(),getHeight(), 2);
const float dashLength[] = { 4, 4 }; const float dashLength[] = { 4, 4 };
g.setColour(Colour(83,76,69)); g.setColour(Colour(83,76,69));
@ -59,14 +60,20 @@ void ProgramListBox::paint(Graphics &g) {
for(int i=0;i<cols;i++) { for(int i=0;i<cols;i++) {
for(int j=0;j<rows;j++) { for(int j=0;j<rows;j++) {
if ( selectedPgm == pgm ) { if ( selectedPgm == pgm && dragCandidate == -1 ) {
g.setColour(DXLookNFeel::fillColour); g.setColour(DXLookNFeel::fillColour);
g.fillRoundedRectangle(cellWidth*i+2, cellHeight*j + 2, cellWidth - 4, cellHeight - 4, 0); g.fillRoundedRectangle(cellWidth*i+2, cellHeight*j + 2, cellWidth - 4, cellHeight - 4, 0);
} }
if ( hasContent == true ) { if ( hasContent == true ) {
if ( dragCandidate != pgm ) {
g.setColour(Colours::white); g.setColour(Colours::white);
g.drawFittedText(programNames[pgm], cellWidth * i , cellHeight * j, cellWidth, cellHeight, Justification::centred, true); g.drawFittedText(programNames[pgm], cellWidth * i , cellHeight * j, cellWidth, cellHeight, Justification::centred, true);
} else {
g.setColour(DXLookNFeel::fillColour);
g.fillRoundedRectangle(cellWidth*i+2, cellHeight*j + 2, cellWidth - 4, cellHeight - 4, 0);
}
} }
pgm++; pgm++;
} }
@ -89,8 +96,8 @@ void ProgramListBox::addListener(ProgramListBoxListener *listener) {
this->listener = listener; this->listener = listener;
} }
int ProgramListBox::programPosition(const MouseEvent &event) { int ProgramListBox::programPosition(int x, int y) {
return (event.getMouseDownY() / cellHeight) + ((event.getMouseDownX() / cellWidth) * rows); return (y / cellHeight) + ((x / cellWidth) * rows);
} }
void ProgramListBox::mouseDoubleClick(const MouseEvent &event) { void ProgramListBox::mouseDoubleClick(const MouseEvent &event) {
@ -99,7 +106,7 @@ void ProgramListBox::mouseDoubleClick(const MouseEvent &event) {
if ( ! event.mods.isLeftButtonDown() ) if ( ! event.mods.isLeftButtonDown() )
return; return;
int pos = programPosition(event); int pos = programPosition(event.getMouseDownX(), event.getMouseDownY());
if ( listener != nullptr ) if ( listener != nullptr )
listener->programSelected(this, pos); listener->programSelected(this, pos);
} }
@ -110,11 +117,33 @@ void ProgramListBox::mouseDown(const MouseEvent &event) {
if ( ! event.mods.isRightButtonDown() ) if ( ! event.mods.isRightButtonDown() )
return; return;
int pos = programPosition(event); int pos = programPosition(event.getMouseDownX(), event.getMouseDownY());
if ( listener != nullptr ) if ( listener != nullptr )
listener->programRightClicked(this, pos); listener->programRightClicked(this, pos);
} }
void ProgramListBox::mouseDrag(const MouseEvent &event) {
if ( ! hasContent )
return;
if ( dragCandidate != -1 )
return;
if ( event.getDistanceFromDragStart() < 7 )
return;
if (DragAndDropContainer* const dragContainer = DragAndDropContainer::findParentDragContainerFor(this)) {
Image snapshot (Image::ARGB, cellWidth, cellHeight, true);
int position = programPosition(event.getMouseDownX(), event.getMouseDownY());
Graphics g(snapshot);
g.setColour(DXLookNFeel::lightBackground);
g.fillRect(0,0,cellWidth, cellHeight);
g.setColour(Colours::white);
g.drawFittedText(programNames[position], 0, 0, cellWidth, cellHeight, Justification::centred, true);
void *src = cartContent + (position*128);
var description = var(src, 128);
dragContainer->startDragging(description, this, snapshot, false);
}
}
void ProgramListBox::setSelected(int idx) { void ProgramListBox::setSelected(int idx) {
selectedPgm = idx; selectedPgm = idx;
} }
@ -124,3 +153,44 @@ char* ProgramListBox::getCurrentCart() {
return nullptr; return nullptr;
return cartContent; return cartContent;
} }
bool ProgramListBox::isInterestedInDragSource (const SourceDetails& dragSourceDetail) {
if ( readOnly )
return false;
if ( ! hasContent )
return false;
Component *comp = dragSourceDetail.sourceComponent.get();
if ( comp == nullptr )
return false;
if ( dynamic_cast<ProgramListBox*>(comp) == nullptr )
return false;
return true;
}
void ProgramListBox::itemDropped(const SourceDetails& dragSourceDetails) {
dragCandidate = programPosition(dragSourceDetails.localPosition.x, dragSourceDetails.localPosition.y);
MemoryBlock* block = dragSourceDetails.description.getBinaryData();
if ( listener != nullptr )
listener->programDragged(this, dragCandidate, (char *)block->getData());
dragCandidate = -1;
repaint();
}
void ProgramListBox::itemDragEnter(const SourceDetails &dragSourceDetails) {
dragCandidate = programPosition(dragSourceDetails.localPosition.x, dragSourceDetails.localPosition.y);
repaint();
}
void ProgramListBox::itemDragMove(const SourceDetails &dragSourceDetails) {
dragCandidate = programPosition(dragSourceDetails.localPosition.x, dragSourceDetails.localPosition.y);
repaint();
}
void ProgramListBox::itemDragExit(const SourceDetails &dragSourceDetails) {
dragCandidate = -1;
repaint();
}

@ -29,23 +29,27 @@ public:
virtual ~ProgramListBoxListener() {} virtual ~ProgramListBoxListener() {}
virtual void programSelected(ProgramListBox *source, int pos) = 0; virtual void programSelected(ProgramListBox *source, int pos) = 0;
virtual void programRightClicked(ProgramListBox *source, int pos) = 0; virtual void programRightClicked(ProgramListBox *source, int pos) = 0;
virtual void programDragged(ProgramListBox *destListBox, int dest, char *packedPgm) = 0;
}; };
class ProgramListBox : public Component { class ProgramListBox : public Component, public DragAndDropTarget {
ProgramListBoxListener *listener; ProgramListBoxListener *listener;
bool hasContent; bool hasContent;
bool showPgmNumber; bool showPgmNumber;
int cols, rows; int cols, rows;
int cellWidth, cellHeight; int cellWidth, cellHeight;
int programPosition(const MouseEvent &event); int programPosition(int x, int y);
int selectedPgm; int selectedPgm;
// TODO: this should be a pointer // TODO: this should be a pointer
char cartContent[4104]; char cartContent[4104];
int dragCandidate;
public: public:
StringArray programNames; StringArray programNames;
bool readOnly;
ProgramListBox(const String name, int numCols); ProgramListBox(const String name, int numCols);
void addListener(ProgramListBoxListener *listener); void addListener(ProgramListBoxListener *listener);
void paint(Graphics &g); void paint(Graphics &g);
@ -53,8 +57,15 @@ public:
void resized(); void resized();
void mouseDoubleClick(const MouseEvent &event); void mouseDoubleClick(const MouseEvent &event);
void mouseDown(const MouseEvent &event); void mouseDown(const MouseEvent &event);
void mouseDrag(const MouseEvent &event);
void setSelected(int idx); void setSelected(int idx);
char* getCurrentCart(); char* getCurrentCart();
bool isInterestedInDragSource(const SourceDetails& dragSourceDetails) override;
void itemDragEnter(const SourceDetails &dragSourceDetails) override;
void itemDragMove(const SourceDetails &dragSourceDetails) override;
void itemDragExit(const SourceDetails &dragSourceDetails) override;
void itemDropped(const SourceDetails& dragSourceDetails) override;
}; };

Loading…
Cancel
Save