Example #1
0
void WTemplate::clear()
{
  setIgnoreChildRemoves(true);
  /*
   * We need to copy them first so that removeChild() will not be confused
   * by it.
   */
  WidgetMap toDelete = widgets_;
  widgets_ = WidgetMap();
  for (WidgetMap::iterator i = toDelete.begin(); i != toDelete.end(); ++i)
    delete i->second;
  setIgnoreChildRemoves(false);

  strings_.clear();
  conditions_.clear();

  changed_ = true;
  repaint(RepaintSizeAffected);  
}
Example #2
0
void Network::handleObjectLineMessage(const osc::ReceivedMessage& m,
                                      const IpEndpointName& remoteEndpoint)
{
  // Utility data structures
  char buffer[1024];
  osc::OutboundPacketStream ps(buffer, 1024);

  // Parse OSC message
  osc::Symbol uuid, padUuid;
  float startX, startY, endX, endY;
  m.ArgumentStream() >> uuid >> padUuid >> startX >> startY
                                        >> endX >> endY >> osc::EndMessage;
  std::cerr << uuid << ", " << padUuid << ", "
            << startX << ", " << startY << ", "
            << endX << ", " << endY << std::endl;

  // Check for known arc, add & broadcast if unknown
  WidgetMap* widgets = Widget::getAll();
  WidgetMap::iterator wit = widgets->find(std::string(uuid));
  if (wit == widgets->end()) {
    wit = m_orphans.find(std::string(uuid));
    if (wit == m_orphans.end()) {
      LineTrack* newLine = NULL;

      // Search for pad
      wit = widgets->find(std::string(padUuid));
      if (wit != widgets->end()) {
        Joint *endJoint = NULL, *startJoint = NULL;
        for (WidgetMap::iterator ptr = widgets->begin(); ptr != widgets->end(); ptr++) {
          Track *track = dynamic_cast<Track *>(ptr->second);
          if (track) {
            Joint *joint = track->getJoint1();
            if (!startJoint && joint && joint->hitTest(startX, startY))
              startJoint = joint;
            else if (!endJoint && joint && joint->hitTest(endX, endY))
              endJoint = joint;

            joint = track->getJoint2();
            if (!startJoint && joint && joint->hitTest(startX, startY))
              startJoint = joint;
            else if (!endJoint && joint && joint->hitTest(endX, endY))
              endJoint = joint;
          }
        }

        LineTrack* newLine = new LineTrack(Point2D(startX, startY), Point2D(endX, endY), startJoint, endJoint);
        newLine->setUuid(uuid);
        newLine->getLine()->setLineWidth(3);

        wit->second->addChild(newLine);
        widgets->insert(WidgetData(std::string(uuid), newLine));

        // Tell the world
        newLine->toOutboundPacketStream(ps);
        broadcast(ps);
      } else {// orphan if we don't know about its pad yet
        newLine = new LineTrack(Point2D(startX, startY), Point2D(endX, endY), NULL, NULL);
        newLine->setUuid(uuid);
        m_orphans.insert(WidgetData(std::string(padUuid), newLine));
      }
    }
  }
}