Exemplo n.º 1
0
int main(int argc, char **argv) {
    try {
        int port = 3902;
        if (argc > 1) {
            std::string firstArg(argv[1]);
            port = ::cukebins::internal::fromString<int>(firstArg);
        }
        std::clog << "Listening on port " << port << std::endl;
        ::cukebins::acceptWireProtocol(port);
    } catch (std::exception &e) {
        std::cerr << e.what() << std::endl;
        exit(1);
    }
    return 0;
}
static int RadialGradient_init(radialGradientObject* self,
  PyObject* args,
  PyObject*)
{
  auto numArgs = PySequence_Length(args);
  if (numArgs == 0){
    PyErr_SetString(PyExc_ValueError, "Atleast one color stop required");
    return init_fail;
  }

  // Possibly unwrapped sequence
  PyObject* unwrapped = nullptr;

  // The center point is an optional argument (although the first!)
  Point center(0,0);

  // If the first argument is an point, the color stop parsing should be offset
  int firstColorStop = 0;

  if (numArgs == 1){
    // Check if this is a single color stop
    PyObject* pyStop = PySequence_GetItem(args, 0);
    ColorStop stop;
    if (parse_color_stop(pyStop, stop)){
      py_xdecref(pyStop);
      self->gradient = new RadialGradient(Point(0,0), Radii(1.0,1.0), {stop});
      return init_ok;
    }
    else if (!PySequence_Check(pyStop)){
      PyErr_SetString(PyExc_ValueError, "Atleast one color stop required");
      py_xdecref(pyStop);
      return init_fail;
    }
    numArgs = PySequence_Length(pyStop);
    if (numArgs == 0){
      PyErr_SetString(PyExc_ValueError, "Atleast one color stop required");
      return init_fail;
    }
    args = pyStop;
    unwrapped = pyStop;
  }
  else if (numArgs > 1){
    // Try to parse the first argument as a center point
    scoped_ref firstArg(PySequence_GetItem(args,0));
    if (PySequence_Check(firstArg.get()) &&
      PySequence_Length(firstArg.get()) == 2)
    {
      if (point_from_sequence_noerr(firstArg.get(), center)){
        firstColorStop += 1;
      }
    }
  }

  std::vector<ColorStop> v;
  for (int i = firstColorStop; i != numArgs; i++){
    PyObject* pyStop = PySequence_GetItem(args, i);
    ColorStop stop;
    bool ok = parse_color_stop(pyStop, stop);
    py_xdecref(pyStop);
    if (!ok){
      py_xdecref(unwrapped);
      return init_fail;
    }
    v.push_back(stop);
  }

  self->gradient = new RadialGradient(center, Radii(1.0,1.0), v);
  py_xdecref(unwrapped);
  return init_ok;
}