You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovdCCommentProxy.cpp 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #include "ovdCCommentProxy.h"
  2. #include "ovdTAttributeHandler.h"
  3. namespace OpenViBE {
  4. namespace Designer {
  5. CCommentProxy::CCommentProxy(const Kernel::IKernelContext& ctx, const Kernel::IComment& comment)
  6. : m_kernelCtx(ctx), m_constComment(&comment)
  7. {
  8. if (m_constComment)
  9. {
  10. const TAttributeHandler handler(*m_constComment);
  11. m_centerX = handler.getAttributeValue<int>(OV_AttributeId_Comment_XCenterPosition);
  12. m_centerY = handler.getAttributeValue<int>(OV_AttributeId_Comment_YCenterPosition);
  13. }
  14. }
  15. CCommentProxy::CCommentProxy(const Kernel::IKernelContext& ctx, Kernel::IScenario& scenario, const CIdentifier& commentID)
  16. : m_kernelCtx(ctx), m_constComment(scenario.getCommentDetails(commentID)), m_comment(scenario.getCommentDetails(commentID))
  17. {
  18. if (m_constComment)
  19. {
  20. const TAttributeHandler handler(*m_constComment);
  21. m_centerX = handler.getAttributeValue<int>(OV_AttributeId_Comment_XCenterPosition);
  22. m_centerY = handler.getAttributeValue<int>(OV_AttributeId_Comment_YCenterPosition);
  23. }
  24. }
  25. int CCommentProxy::getWidth(GtkWidget* widget) const
  26. {
  27. int x, y;
  28. updateSize(widget, getLabel(), &x, &y);
  29. return x;
  30. }
  31. int CCommentProxy::getHeight(GtkWidget* widget) const
  32. {
  33. int x, y;
  34. updateSize(widget, getLabel(), &x, &y);
  35. return y;
  36. }
  37. void CCommentProxy::setCenter(const int centerX, const int centerY)
  38. {
  39. m_centerX = centerX;
  40. m_centerY = centerY;
  41. m_applied = false;
  42. }
  43. void CCommentProxy::apply()
  44. {
  45. if (m_comment)
  46. {
  47. TAttributeHandler handler(*m_comment);
  48. if (handler.hasAttribute(OV_AttributeId_Comment_XCenterPosition)) { handler.setAttributeValue<int>(OV_AttributeId_Comment_XCenterPosition, m_centerX); }
  49. else { handler.addAttribute<int>(OV_AttributeId_Comment_XCenterPosition, m_centerX); }
  50. if (handler.hasAttribute(OV_AttributeId_Comment_YCenterPosition)) { handler.setAttributeValue<int>(OV_AttributeId_Comment_YCenterPosition, m_centerY); }
  51. else { handler.addAttribute<int>(OV_AttributeId_Comment_YCenterPosition, m_centerY); }
  52. m_applied = true;
  53. }
  54. }
  55. const char* CCommentProxy::getLabel() const
  56. {
  57. m_label = m_constComment->getText().toASCIIString();
  58. return m_label.c_str();
  59. }
  60. void CCommentProxy::updateSize(GtkWidget* widget, const char* text, int* xSize, int* ySize)
  61. {
  62. PangoRectangle rectangle;
  63. PangoContext* context = gtk_widget_create_pango_context(widget);
  64. PangoLayout* layout = pango_layout_new(context);
  65. pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
  66. if (pango_parse_markup(text, -1, 0, nullptr, nullptr, nullptr, nullptr)) { pango_layout_set_markup(layout, text, -1); }
  67. else { pango_layout_set_text(layout, text, -1); }
  68. pango_layout_get_pixel_extents(layout, nullptr, &rectangle);
  69. *xSize = rectangle.width;
  70. *ySize = rectangle.height;
  71. g_object_unref(layout);
  72. g_object_unref(context);
  73. }
  74. } // namespace Designer
  75. } // namespace OpenViBE