bezctx_quartz.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. ppedit - A pattern plate editor for Spiro splines.
  3. Copyright (C) 2007 Raph Levien
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301, USA.
  16. */
  17. #include <Carbon/Carbon.h>
  18. #include "zmisc.h"
  19. #include "bezctx.h"
  20. #include "bezctx_quartz.h"
  21. typedef struct {
  22. bezctx base;
  23. CGMutablePathRef pathref;
  24. int is_open;
  25. } bezctx_quartz;
  26. static void
  27. bezctx_quartz_moveto(bezctx *z, double x, double y, int is_open) {
  28. bezctx_quartz *bc = (bezctx_quartz *)z;
  29. if (!bc->is_open) CGPathCloseSubpath(bc->pathref);
  30. CGPathMoveToPoint(bc->pathref, NULL, x, y);
  31. bc->is_open = is_open;
  32. }
  33. static void
  34. bezctx_quartz_lineto(bezctx *z, double x, double y) {
  35. bezctx_quartz *bc = (bezctx_quartz *)z;
  36. CGPathAddLineToPoint(bc->pathref, NULL, x, y);
  37. }
  38. static void
  39. bezctx_quartz_quadto(bezctx *z, double x1, double y1, double x2, double y2)
  40. {
  41. bezctx_quartz *bc = (bezctx_quartz *)z;
  42. CGPathAddQuadCurveToPoint(bc->pathref, NULL, x1, y1, x2, y2);
  43. }
  44. bezctx *
  45. new_bezctx_quartz(void) {
  46. bezctx_quartz *result = znew(bezctx_quartz, 1);
  47. result->base.moveto = bezctx_quartz_moveto;
  48. result->base.lineto = bezctx_quartz_lineto;
  49. result->base.quadto = bezctx_quartz_quadto;
  50. result->base.mark_knot = NULL;
  51. result->pathref = CGPathCreateMutable();
  52. result->is_open = 1;
  53. return &result->base;
  54. }
  55. CGMutablePathRef
  56. bezctx_to_quartz(bezctx *z)
  57. {
  58. bezctx_quartz *bc = (bezctx_quartz *)z;
  59. CGMutablePathRef result = bc->pathref;
  60. if (!bc->is_open) CGPathCloseSubpath(result);
  61. zfree(bc);
  62. return result;
  63. }