Changeset 973 for cpp/frams/canvas


Ignore:
Timestamp:
07/03/20 00:37:13 (4 years ago)
Author:
Maciej Komosinski
Message:

Increased SString and std::string compatibility: introduced length(), size(), and capacity(), and removed legacy methods that have std::string equivalents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/canvas/neurodiagram.cpp

    r838 r973  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2017  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2020  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    136136                int *xywh = GetXYWH(el);
    137137                XY[0] = 0;
    138                 XY[1] = ((1 + i)*xywh[3]) / (GetInputs(el) + 1);
     138                XY[1] = ((1 + i) * xywh[3]) / (GetInputs(el) + 1);
    139139                return XY;
    140140        }
     
    230230        if (i >= countNeurons()) return;
    231231        NeuroProbe *probe = new NeuroProbe(getNS(i));
    232         Pixel s=getSize();
    233         s.x=s.y=max(probe->getSize().x,min(s.x/3,s.y/3));
     232        Pixel s = getSize();
     233        s.x = s.y = max(probe->getSize().x, min(s.x / 3, s.y / 3));
    234234        probes += (void*)probe;
    235235        add(probe);
     
    255255        addNeuroDescription(tooltip, n);
    256256        label += n->getClassName();
    257         if (n->getClassParams().len())
     257        if (n->getClassParams().length())
    258258        {
    259259                tooltip += "\n"; tooltip += n->getClassParams();
     
    319319                                */
    320320
    321         // NeuroSymbol is also responsible for drawing connection lines from its inputs to other NeuroSymbols' outputs
     321                                // NeuroSymbol is also responsible for drawing connection lines from its inputs to other NeuroSymbols' outputs
    322322        NeuroSymbol *ns2;
    323323        if (!diagram.isLive())
     
    350350                        {
    351351                                y2 = pos.y - yw / 3;
    352                                 if ((ns2->pos.y<pos.y) && (ns2->pos.y>(pos.y - ns2->size.y))) y2 -= pos.y - ns2->pos.y;
     352                                if ((ns2->pos.y < pos.y) && (ns2->pos.y > (pos.y - ns2->size.y))) y2 -= pos.y - ns2->pos.y;
    353353                        }
    354354                        // note: "diagram" uses global coordinate system, so we add "pos" or "ns2->pos" to get NeuroSymbol's global positions
     
    413413int NeuroSymbol::inputY(int i)
    414414{
    415         return (1 + i)*size.y / ((n->getInputCount()) + 1);
     415        return (1 + i) * size.y / ((n->getInputCount()) + 1);
    416416}
    417417
     
    421421                if (x < size.x / 4)
    422422                { // inputs?
    423                 if (n->getInputCount() > 0)
    424                 {
    425                         int i = (y*n->getInputCount()) / size.y;
    426                         double w;
    427                         Neuro* target = n->getInput(i, w);
    428                         if (target)
     423                        if (n->getInputCount() > 0)
    429424                        {
    430                                 SString t = "connected to #";
    431                                 t += SString::valueOf((int)target->refno);
    432                                 t += " - ";
    433                                 addNeuroDescription(t, target);
    434                                 //              if (w!=1.0)
     425                                int i = (y * n->getInputCount()) / size.y;
     426                                double w;
     427                                Neuro* target = n->getInput(i, w);
     428                                if (target)
    435429                                {
    436                                         t += ", weight=";
    437                                         t += SString::valueOf(w);
     430                                        SString t = "connected to #";
     431                                        t += SString::valueOf((int)target->refno);
     432                                        t += " - ";
     433                                        addNeuroDescription(t, target);
     434                                        //              if (w!=1.0)
     435                                        {
     436                                                t += ", weight=";
     437                                                t += SString::valueOf(w);
     438                                        }
     439                                        return t;
    438440                                }
    439                                 return t;
    440441                        }
    441                 }
    442442                }
    443443        return CanvasWindow::hint(x, y);
     
    448448NeuroProbe::NeuroProbe(NeuroSymbol* ns)
    449449        :DCanvasWindow(DCanvasWindow::Title + DCanvasWindow::Border + DCanvasWindow::Close + DCanvasWindow::Size,
    450         ns->getLabel().c_str(), &neurochart, &neurochart)
     450                ns->getLabel().c_str(), &neurochart, &neurochart)
    451451{
    452452        holdismine = 0;
     
    515515                                        while (*dr != NeuroImpl::ENDDRAWING)
    516516                                        {
    517                                                 int x = ((*(dr++))*scale) / (NeuroImpl::MAXDRAWINGXY + 1) + x0;
    518                                                 int y = ((*(dr++))*scale) / (NeuroImpl::MAXDRAWINGXY + 1) + y0;
     517                                                int x = ((*(dr++)) * scale) / (NeuroImpl::MAXDRAWINGXY + 1) + x0;
     518                                                int y = ((*(dr++)) * scale) / (NeuroImpl::MAXDRAWINGXY + 1) + y0;
    519519                                                if (first) { moveTo(x, y); first = 0; }
    520520                                                else lineTo(x, y);
     
    577577        {
    578578                double st = neurochart.unmapData(unmapClientY(y));
    579                 if (st<-1.0) st = -1.0; else if (st>1.0) st = 1.0;
     579                if (st < -1.0) st = -1.0; else if (st > 1.0) st = 1.0;
    580580                if (chsel == 0)
    581581                        link->n->state = st;
     
    602602                int sy = size.y;
    603603                if (chsel >= 0) sy -= textHeight();
    604                 return ((y<sy) && (y>(sy - textHeight())));
     604                return ((y < sy) && (y > (sy - textHeight())));
    605605        }
    606606        return 0;
     
    635635                {
    636636                        link->n->flags ^= Neuro::HoldState;
    637                         holdismine = ((link->n->flags&Neuro::HoldState) != 0);
     637                        holdismine = ((link->n->flags & Neuro::HoldState) != 0);
    638638                        requestPaint();
    639639                        return LeftButton;
     
    645645SString NeuroProbe::hint(int x, int y)
    646646{
    647         if ((chsel >= 0) && (x<size.x - 16) && (y>size.y - 16))
    648                 return SString((link->n->flags&Neuro::HoldState) ? "Click to release" : "Click to hold");
     647        if ((chsel >= 0) && (x < size.x - 16) && (y > size.y - 16))
     648                return SString((link->n->flags & Neuro::HoldState) ? "Click to release" : "Click to hold");
    649649        else if (insideChSelector(x, y))
    650650                return SString::sprintf("channel %d of %d (click and drag to switch channels)", chsel, chnum);
Note: See TracChangeset for help on using the changeset viewer.