コード例 #1
0
ファイル: Layer.cpp プロジェクト: puckipedia/ArtPaint
void
Layer::Clear(rgb_color color)
{
    // This will copy the color (including alpha) to every pixel in this layer.
    // If the selection is not empty, the color will be copied only to the
    // selected points
    Selection* selection = fImageView->GetSelection();

    // we will copy the color to this in correct order
    uint32 color_bits = RGBColorToBGRA(color);

    uint32* bits = (uint32*)fLayerData->Bits();
    if (selection->IsEmpty()) {
        int32 bitslength = fLayerData->BitsLength() / 4;
        for (int32 i = 0; i < bitslength; ++i)
            *bits++ = color_bits;
    } else {
        BRect bounds = selection->GetBoundingRect();
        int32 left = (int32)bounds.left;
        int32 top = (int32)bounds.top;
        int32 right = (int32)bounds.right;
        int32 bottom = (int32)bounds.bottom;
        int32 bpr = fLayerData->BytesPerRow()/4;
        for (int32 y = top; y <= bottom; ++y) {
            for (int32 x = left; x <= right; ++x) {
                if (selection->ContainsPoint(x,y))
                    *(bits + x + y * bpr) = color_bits;
            }
        }
    }
}
コード例 #2
0
ファイル: stretch.c プロジェクト: jmzaleski/ivtools-1.2
Manipulator* StretchTool::CreateManipulator (
    Viewer* v, Event& e, Transformer* rel
) {
    GraphicView* views = v->GetGraphicView();
    Selection* s = v->GetSelection(), *newSel;
    GraphicView* gv;
    Manipulator* m = nil;
    Iterator i;

    newSel = views->ViewIntersecting(e.x-SLOP, e.y-SLOP, e.x+SLOP, e.y+SLOP);
    if (newSel->IsEmpty()) {
        s->Clear();
    } else {
        newSel->First(i);
        gv = newSel->GetView(i);

        if (s->Includes(gv)) {
            s->Remove(gv);
            s->Prepend(gv);
        } else {
            s->Clear();
            s->Append(gv);
            s->Update();
        }
        if (!s->IsEmpty())
            m = gv->CreateManipulator(v, e, rel, this);
    }
    delete newSel;
    return m;
}
コード例 #3
0
ファイル: struct.cpp プロジェクト: neurodebian/iv-hines
void BackCmd::Execute () {
    Clipboard* cb = GetClipboard();
    Editor* ed = GetEditor();

    if (cb == nil) {
        Selection* s = ed->GetSelection();

        if (s->IsEmpty()) {
            return;
        }

        SetClipboard(cb = new Clipboard);
        GraphicView* views = ed->GetViewer()->GetGraphicView();
        s->Sort(views);
        Iterator i;

        for (s->First(i); !s->Done(i); s->Next(i)) {
            s->GetView(i)->Interpret(this);
        }

    } else {
        Clipboard* oldcb = cb;
        SetClipboard(cb = new Clipboard);

        Iterator i;
        for (oldcb->First(i); !oldcb->Done(i); oldcb->Next(i)) {
            oldcb->GetComp(i)->Interpret(this);
        }
        delete oldcb;
    }

    if (!cb->IsEmpty()) {
        ed->GetComponent()->Interpret(this);
    }
}
コード例 #4
0
ファイル: command.c プロジェクト: LambdaCalculus379/SLS-1.02
boolean Command::Reversible () {
    boolean reversible = true;
    Clipboard* cb = GetClipboard();

    if (cb == nil) {
        Editor* ed = GetEditor();
        Selection* s = (ed == nil) ? nil : ed->GetSelection();
        reversible = (s == nil) || !s->IsEmpty();

    } else {
        reversible = !cb->IsEmpty();
    }
    return reversible;
}
コード例 #5
0
ファイル: command.c プロジェクト: LambdaCalculus379/SLS-1.02
void Command::Execute () {
    Selection* s = _editor->GetSelection();
    Clipboard* cb = GetClipboard();

    if (!s->IsEmpty() || (cb != nil && !cb->IsEmpty())) {
        Iterator i;

        if (cb == nil) {
            SetClipboard(cb = new Clipboard);
            cb->Init(s);
        }

        for (cb->First(i); !cb->Done(i); cb->Next(i)) {
            cb->GetComp(i)->Interpret(this);
        }
        unidraw->Update();
    }
}
コード例 #6
0
ファイル: align.cpp プロジェクト: PNCG/neuron
void AlignToGridCmd::Execute () {
    Selection* s = _editor->GetSelection();

    if (!s->IsEmpty()) {
        Clipboard* cb = GetClipboard();
        Iterator i;

        if (cb == nil) {
            for (s->First(i); !s->Done(i); s->Next(i)) {
                s->GetView(i)->Interpret(this);
            }

            SetClipboard(cb = new Clipboard);
            cb->Init(s);

        } else {
            for (cb->First(i); !cb->Done(i); cb->Next(i)) {
                Move(cb->GetComp(i));
            }
        }
        unidraw->Update();
    }
}
コード例 #7
0
ファイル: graphexport.c プロジェクト: jmzaleski/ivtools-1.2
boolean GraphExportCmd::Export (const char* pathname) {
    Editor* editor = GetEditor();
    Selection* s = editor->GetSelection();
    GraphIdrawComp* real_top = (GraphIdrawComp*)editor->GetComponent();
    boolean ok = false;
    char* old_format = NULL;
    
    boolean empty = s->IsEmpty();

    GraphIdrawComp* false_top = new GraphIdrawComp();
    Iterator i;
    empty ? real_top->First(i) : s->First(i);
    while (empty ? !real_top->Done(i) : !s->Done(i)) {
      if (chooser_->idraw_format() || chooser_->postscript_format()) {
	OverlayComp* oc = empty 
	  ? new OverlayComp(real_top->GetComp(i)->GetGraphic()->Copy())
	  : new OverlayComp(s->GetView(i)->GetGraphicComp()->GetGraphic()->Copy());
	false_top->Append(oc);
      } else {
	OverlayComp* oc = empty 
	  ? (OverlayComp*)real_top->GetComp(i)->Copy()
	  : (OverlayComp*)s->GetView(i)->GetGraphicComp()->Copy();
	false_top->Append(oc);
      }
      empty ? real_top->Next(i) : s->Next(i);
    }
     
    OverlayPS* ovpsv;
    if (chooser_->idraw_format() || chooser_->postscript_format())
      ovpsv = (OverlayPS*) false_top->Create(POSTSCRIPT_VIEW);
    else {
      ovpsv = (OverlayPS*) false_top->Create(SCRIPT_VIEW);
      if(strcmp(chooser_->format(), "dot")==0) {
        old_format = OverlayScript::format() ? strnew(OverlayScript::format()) : NULL;
        OverlayScript::format("dot");
      }
    }
    if (ovpsv != nil) {
      
      filebuf fbuf;
      char* tmpfilename;
      
      if (chooser_->to_printer()) {
	tmpfilename = tmpnam(nil);
	false_top->SetPathName(tmpfilename);
	ok = fbuf.open(tmpfilename, output) != 0;
      } else {
	ok = fbuf.open(pathname, output) != 0;
      }
      
      if (ok) {
	ostream out(&fbuf);
	false_top->Attach(ovpsv);
	ovpsv->SetCommand(this);
	if (!chooser_->idraw_format() && !chooser_->postscript_format())
	  ((GraphIdrawScript*)ovpsv)->SetByPathnameFlag(chooser_->by_pathname_flag());
	ovpsv->Update();
	ok = ovpsv->Emit(out);
	fbuf.close();
	
	if (chooser_->to_printer()) {
	  char cmd[CHARBUFSIZE];
	  if (strstr(pathname, "%s")) {
	    char buf[CHARBUFSIZE];
	    sprintf(buf, pathname, tmpfilename);    
	    sprintf(cmd, "(%s;rm %s)&", buf, tmpfilename);
	  } else
	    sprintf(cmd, "(%s %s;rm %s)&", pathname, tmpfilename, tmpfilename);
	  ok = system(cmd) == 0;
	}
      } 
      delete ovpsv;        
    }
    
    delete false_top;
    if (old_format) {
      OverlayScript::format(old_format);
      delete old_format;
    }
    return ok;
}
コード例 #8
0
ファイル: ovcomps.c プロジェクト: jmzaleski/ivtools-1.2
void OverlaysComp::Interpret (Command* cmd) {
    Editor* ed = cmd->GetEditor();

    if (
        (cmd->IsA(DELETE_CMD) || cmd->IsA(CUT_CMD)) && 
        ed->GetComponent() != this
    ) {
        Iterator i;
        for (First(i); !Done(i); Next(i)) {
            GetComp(i)->Interpret(cmd);
        }

    } else if (cmd->IsA(DELETE_CMD)) {
        Clipboard* cb = cmd->GetClipboard();
        Selection* s = ed->GetSelection();

        if (cb == nil) {
            if (s->IsEmpty()) {
                return;
            }
            cmd->SetClipboard(cb = new Clipboard);
            cb->Init(s);
        }
        s->Clear();
        Iterator i;

        for (cb->First(i); !cb->Done(i); cb->Next(i)) {
            OverlayComp* comp = (OverlayComp*)cb->GetComp(i);
            unidraw->CloseDependents(comp);
            comp->Interpret(cmd);
            StorePosition(comp, cmd);
            Remove(comp);
        }
        Notify();
        unidraw->Update();

    } else if (cmd->IsA(CUT_CMD)) {
        Clipboard* cb = cmd->GetClipboard();
        Selection* s = ed->GetSelection();

        if (cb == nil) {
            if (s->IsEmpty()) {
                return;
            }
            GraphicView* views = ed->GetViewer()->GetGraphicView();
            s->Sort(views);
            cmd->SetClipboard(cb = new Clipboard);
            cb->Init(s);

            Clipboard* globalcb = unidraw->GetCatalog()->GetClipboard();
            globalcb->DeleteComps();
            globalcb->CopyInit(s);
        }
        s->Clear();
        Iterator i;

        for (cb->First(i); !cb->Done(i); cb->Next(i)) {
            OverlayComp* comp = (OverlayComp*)cb->GetComp(i);
            unidraw->CloseDependents(comp);
            comp->Interpret(cmd);
            StorePosition(comp, cmd);
            Remove(comp);
        }
        Notify();
        unidraw->Update();

    } else if (cmd->IsA(PASTE_CMD)) {
        Clipboard* cb = cmd->GetClipboard();
        Iterator i;

        if (cb == nil) {
            Clipboard* globalcb = unidraw->GetCatalog()->GetClipboard();

            if (globalcb->IsEmpty()) {
                return;
            }
            cmd->SetClipboard(cb = globalcb->DeepCopy());
        }

        for (cb->First(i); !cb->Done(i); cb->Next(i)) {
            Append((OverlayComp*)cb->GetComp(i));
        }
        Notify();
        SelectClipboard(cb, ed);
        unidraw->Update();

    } else if (cmd->IsA(DUP_CMD)) {
        GraphicView* views = ed->GetViewer()->GetGraphicView();
        OverlayComp* prev, *dup1;
        Iterator i, pos;
        Clipboard* cb = cmd->GetClipboard();
        const float offset = 8;
        MoveCmd move(ed, offset, offset);

        if (cb == nil) {
            OverlaySelection* s = (OverlaySelection*)ed->GetSelection();

            if (s->IsEmpty()) {
                return; 
            }
            cmd->SetClipboard(cb = new Clipboard);
            s->Sort(views);

            for (s->First(i); !s->Done(i); s->Next(i)) {
	        OverlayComp* orig = s->GetView(i)->GetOverlayComp();
                dup1 = (OverlayComp*) orig->Copy();
		if (!dup1->attrlist() && orig->attrlist()) {
		  AttributeList* al = new AttributeList(orig->attrlist());
		  dup1->SetAttributeList(al);
		}
                dup1->Interpret(&move);
                cb->Append(dup1);
            }
            cb->First(i);
            dup1 = (OverlayComp*) cb->GetComp(i);
            Last(pos);
            prev = (OverlayComp*) GetComp(pos);
            cmd->Store(dup1, new VoidData(prev));

        } else {
            cb->First(i);
            dup1 = (OverlayComp*) cb->GetComp(i);
            VoidData* vd = (VoidData*) cmd->Recall(dup1);
            prev = (OverlayComp*) vd->_void;
            SetComp(prev, pos);
        }

        for (cb->Last(i); !cb->Done(i); cb->Prev(i)) {
            InsertAfter(pos, cb->GetComp(i));
        }

        Notify();
        SelectClipboard(cb, ed);
        unidraw->Update();

    } else if (cmd->IsA(OVGROUP_CMD)) {
        OvGroupCmd* gcmd = (OvGroupCmd*) cmd;
        OverlayComp* group = gcmd->GetGroup();
        Component* edComp = gcmd->GetEditor()->GetComponent();

        if (group == this) {
            edComp->Interpret(gcmd);

        } else if (edComp == (Component*) this) {
            Clipboard* cb = cmd->GetClipboard();
            NullGS(group->GetGraphic());
            Group(cb, group, cmd);
            Notify();
            SelectViewsOf(group, ed);
            unidraw->Update();

        } else {
            OverlayComp::Interpret(gcmd);
        }

    } else if (cmd->IsA(UNGROUP_CMD)) {
        UngroupCmd* ucmd = (UngroupCmd*) cmd;
        Component* edComp = ucmd->GetEditor()->GetComponent();

        if (edComp == (Component*) this) {
            Clipboard* cb = cmd->GetClipboard();
            Clipboard* kids = new Clipboard;
            ucmd->SetKids(kids);
            Iterator i;

            for (cb->First(i); !cb->Done(i); cb->Next(i)) {
                OverlayComp* parent = (OverlayComp*)cb->GetComp(i);
                unidraw->CloseDependents(parent);
                Ungroup(parent, kids, cmd);
            }
            Notify();
            SelectClipboard(kids, ed);
            unidraw->Update();

        } else {
            cmd->GetClipboard()->Append(this);
        }

    } else if (cmd->IsA(PUSH_CMD) || cmd->IsA(PULL_CMD)) {
        Component* edComp = cmd->GetEditor()->GetComponent();

        if (edComp == (Component*) this) {
            Clipboard* cb = cmd->GetClipboard();
            Iterator i;

            if (cmd->IsA(PULL_CMD)) {
                for (cb->First(i); !cb->Done(i); cb->Next(i)) {
                    OverlayComp* comp = (OverlayComp*)cb->GetComp(i);
                  Iterator j;
                  SetComp(comp, j);
                  Next(j);
                    StorePosition(comp, cmd);
                  if (!Done(j)) {
                    Remove(comp);
                    InsertAfter(j, comp);
                  }
                }

            } else {
                for (cb->Last(i); !cb->Done(i); cb->Prev(i)) {
                    OverlayComp* comp = (OverlayComp*) cb->GetComp(i);
                  Iterator j;
                  SetComp(comp, j);
                  Prev(j);
                    StorePosition(comp, cmd);
                  if (!Done(j)) {
                    Remove(comp);
                    InsertBefore(j, comp);
                  }
                }
            }
            Notify();
            unidraw->Update();

        } else {
            OverlayComp::Interpret(cmd);
        }

    } else if (cmd->IsA(FRONT_CMD) || cmd->IsA(BACK_CMD)) {
        Component* edComp = cmd->GetEditor()->GetComponent();

        if (edComp == (Component*) this) {
            Clipboard* cb = cmd->GetClipboard();
            Iterator i;

            if (cmd->IsA(FRONT_CMD)) {
                for (cb->First(i); !cb->Done(i); cb->Next(i)) {
                    OverlayComp* comp = (OverlayComp*)cb->GetComp(i);
                    StorePosition(comp, cmd);
                    Remove(comp);
                    Append(comp);
                }

            } else {
                for (cb->Last(i); !cb->Done(i); cb->Prev(i)) {
                    OverlayComp* comp = (OverlayComp*) cb->GetComp(i);
                    StorePosition(comp, cmd);
                    Remove(comp);
                    Prepend(comp);
                }
            }
            Notify();
            unidraw->Update();

        } else {
            OverlayComp::Interpret(cmd);
        }

    } else {
        OverlayComp::Interpret(cmd);
    }
}
コード例 #9
0
ファイル: ovexport.c プロジェクト: barak/ivtools-cvs
void OvExportCmd::Execute () {
    Editor* ed = GetEditor();

#if 0
    Selection* s = ed->GetSelection();
    if (s->IsEmpty()) {
      GAcknowledgeDialog::post
	(ed->GetWindow(), "Nothing selected for export", nil, "no selection");
      return;
    }
#endif

    Style* style;
    boolean reset_caption = false;
    if (chooser_ == nil) {
	style = new Style(Session::instance()->style());
	style->attribute("subcaption", "Export selected graphics to file:");
	style->attribute("open", "Export");
	const char *formats_svg[] = {"EPS", "idraw EPS", "drawtool", "SVG"};
	const char *formats_nosvg[] = {"EPS", "idraw EPS", "drawtool"};
        const char *svg_arg = unidraw->GetCatalog()->GetAttribute("svgexport");
        const boolean svg_flag = svg_arg && strcmp(svg_arg, "true")==0;
	const char **formats = svg_flag ? formats_svg : formats_nosvg;
	int nformats = (svg_flag ? sizeof(formats_svg) : sizeof(formats_nosvg)) / sizeof(char*);
	const char *commands[] = {"ghostview %s", "idraw %s", "drawtool %s", "netscape %s"};
	chooser_ = new ExportChooser(".", WidgetKit::instance(), style,
				     formats, nformats, commands, nil, true);
	Resource::ref(chooser_);
    } else {
	style = chooser_->style();
    }
    boolean again; 
    while (again = chooser_->post_for(ed->GetWindow())) {
	const String* str = chooser_->selected();
	if (str != nil) {
	    NullTerminatedString ns(*str);
	    const char* name = ns.string();
	    style->attribute("caption", "              " );
	    chooser_->twindow()->repair();
	    chooser_->twindow()->display()->sync();

	    Catalog* catalog = unidraw->GetCatalog();
	    boolean ok = true;

	    if (!chooser_->to_printer() && catalog->Exists(name) && catalog->Writable(name)) {
		char buf[CHARBUFSIZE];
		sprintf(buf, "\"%s\" already exists,", name);
		GConfirmDialog* dialog = new GConfirmDialog(buf, "Overwrite?");
	    	Resource::ref(dialog);
	    	ok = dialog->post_for(ed->GetWindow());
	    	Resource::unref(dialog);
	    }

	    if (ok) { 
		ed->GetWindow()->cursor(hourglass);
		chooser_->twindow()->cursor(hourglass);
		if (Export(ns.string())) {
		    again = false;
		    break;
		}
		style->attribute("caption", "Export failed!" );
		reset_caption = true;
		ed->GetWindow()->cursor(arrow);
		chooser_->twindow()->cursor(arrow);
	    }
	}
    }

    chooser_->unmap();
    if (reset_caption) {
      style->attribute("caption", "              " );
    }
    if (!again)
	ed->GetWindow()->cursor(arrow);
    return;
}