Skip to content

Commit

Permalink
Faster dragging by only drawing visible bits during the drag operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
travisgoodspeed committed Aug 17, 2024
1 parent e1c81fb commit 04c88d9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ the `V` key. Rows and columns are now stored as sorted lists intead
of sets. Rows and columns are now in a consistent order in the file
export. Performance boosts in bit marking, background bit marking and
alignment. Universal binary for macOS. RomAlignerTilting works
better for designs with a gap between banks.
better for designs with a gap between banks. Out-of-view bits are no
longer drawn during dragging, speeding up adjusting groups of long
lines.

2024-07-14 -- Fixes crash when deleting a double-selected item. Delete
and backspace now delete objects like `D`. Multiple disassemblers.
Expand Down
23 changes: 23 additions & 0 deletions maskromtool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,11 @@ void MaskRomTool::markBit(RomLineItem* row, RomLineItem* col){

//This rectangle will be a small box around the pixel.
QPointF point=bitLocation(row, col);
//When dragging, skip anything that's not immediately visible.
if(dragging && !isPointVisible(point))
return;


RomBitItem *bit=new RomBitItem(point, bitSize, row, col);
scene->addItem(bit);
bit->setVisible(bitsVisible);
Expand Down Expand Up @@ -1534,6 +1539,24 @@ static bool colthroughrect(QLineF line, QRectF rect){
return false;
}

//Is a point visible? Handy when dragging.
bool MaskRomTool::isPointVisible(QPointF p){
//Primary view.
QRectF rect=view->mapToScene(view->viewport()->rect()).boundingRect();
if(p.x()<rect.right() && p.x()>rect.left()
&& p.y()>rect.top() && p.y()<rect.bottom())
return true;

//Secondary view, only if visible.
if(!second.isVisible()) return false;
rect=second.view->mapToScene(second.view->viewport()->rect()).boundingRect();
if(p.x()<rect.right() && p.x()>rect.left()
&& p.y()>rect.top() && p.y()<rect.bottom())
return true;

return false;
}

//Mark up all of the bits where rows and columns collide.
bool MaskRomTool::markBits(bool full){
bool bitswerevisible=bitsVisible;
Expand Down
3 changes: 3 additions & 0 deletions maskromtool.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class MaskRomTool : public QMainWindow{
* hogging the rendering thread.
*/
enum {STATE_IDLE, STATE_CLEARING, STATE_MARKING} state=STATE_IDLE;
bool dragging=false; //Only mark visible bits when true.

//Marks all of the bit positions, but not their connections.
bool markBits(bool full=true);
Expand All @@ -121,6 +122,8 @@ class MaskRomTool : public QMainWindow{
void moveList(QList<QGraphicsItem*> list, QPointF offset);
//Inserts a new line, either row or column.
bool insertLine(RomLineItem* line);
//Is a point visible? Handy when dragging.
bool isPointVisible(QPointF p);

//Get a bit at a point.
RomBitItem* getBit(QPointF point);
Expand Down
3 changes: 2 additions & 1 deletion romscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ void RomScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent){

//Right mouse can drag a line, so we mark an undo point before moving.
if(mouseEvent->buttons()==Qt::RightButton){
maskRomTool->dragging=true;
maskRomTool->markUndoPoint();
maskRomTool->clearBits(false);
}
Expand Down Expand Up @@ -222,7 +223,6 @@ void RomScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent){
//qDebug()<<"Selection: "<<x<<y<<w<<h;

auto newselection=items(x, y, w, h,

//Qt::ItemSelectionMode::ContainsItemBoundingRect, //Useful for bits.
//Qt::ItemSelectionMode::ContainsItemShape, // Only when fully covered.
//Qt::ItemSelectionMode::IntersectsItemBoundingRect, //Useful for a near miss, sometimes too wide.
Expand Down Expand Up @@ -278,6 +278,7 @@ void RomScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent){
* arrangement. As a workaround, we remark the bits after releasing the
* button from a moving drag.
*/
maskRomTool->dragging=false;
if(maskRomTool->bitsVisible){
//Clear the old bits in the background.
//This will continue until redrawing them.
Expand Down

0 comments on commit 04c88d9

Please sign in to comment.