Text [email protected] 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /******************************************************************************/
  2. #include "stdafx.h"
  3. /******************************************************************************/
  4. TextStyleEditor TextStyleEdit;
  5. /******************************************************************************/
  6. /******************************************************************************/
  7. void TextStyleEditor::Change::create(ptr user)
  8. {
  9. data=TextStyleEdit.edit;
  10. TextStyleEdit.undoVis();
  11. }
  12. void TextStyleEditor::Change::apply(ptr user)
  13. {
  14. TextStyleEdit.edit.undo(data);
  15. TextStyleEdit.setChanged();
  16. TextStyleEdit.toGui();
  17. TextStyleEdit.undoVis();
  18. }
  19. void TextStyleEditor::TextClip::draw(C GuiPC &gpc)
  20. {
  21. if(visible() && gpc.visible)
  22. {
  23. D.clip(gpc.clip);
  24. Rect r=rect()+gpc.offset;
  25. TextStyleEdit.panel.draw(r);
  26. text_style=TextStyleEdit.game;
  27. GuiPC gpc2=gpc; gpc2.clip&=r; ::EE::Text::draw(gpc2);
  28. }
  29. }
  30. void TextStyleEditor::undoVis() {SetUndo(undos, undo, redo);}
  31. void TextStyleEditor::PreChanged(C Property &prop) {TextStyleEdit.undos.set(&prop);}
  32. void TextStyleEditor::Changed(C Property &prop) {TextStyleEdit.setChanged();}
  33. void TextStyleEditor::ParamsShadow(EditTextStyle &e, C Str &t) {e.shadow =TextInt (t); e. shadow_time.getUTC();}
  34. void TextStyleEditor::ParamsShade(EditTextStyle &e, C Str &t) {e.shade =TextInt (t); e. shade_time.getUTC();}
  35. void TextStyleEditor::ParamsColor(EditTextStyle &e, C Str &t) {e.color =TextVec4(t); e. color_time.getUTC();}
  36. void TextStyleEditor::ParamsSelect(EditTextStyle &e, C Str &t) {e.selection=TextVec4(t); e.selection_time.getUTC();}
  37. void TextStyleEditor::ParamsAlign(EditTextStyle &e, C Str &t) {e.align =TextVec2(t); e. align_time.getUTC();}
  38. void TextStyleEditor::ParamsSize(EditTextStyle &e, C Str &t) {e.size =TextVec2(t); e. size_time.getUTC();}
  39. void TextStyleEditor::ParamsSpace(EditTextStyle &e, C Str &t) {e.space =TextVec2(t); e. space_time.getUTC();}
  40. void TextStyleEditor::ParamsFont(EditTextStyle &e, C Str &t)
  41. {
  42. e.font.zero(); int i=TextInt(t); if(InRange(i, Proj.font_node.children))
  43. {
  44. C Str &name=Proj.font_node.children[i].name;
  45. REPA(Proj.publish_fonts)if(Elm *elm=Proj.findElm(Proj.publish_fonts[i]))if(Equal(elm->name, name, true))
  46. {
  47. e.font=elm->id;
  48. break;
  49. }
  50. }
  51. e.font_time.getUTC();
  52. }
  53. Str TextStyleEditor::ParamsFont(C EditTextStyle &e)
  54. {
  55. if(Elm *elm=Proj.findElm(e.font))REPA(Proj.font_node.children)if(Equal(elm->name, Proj.font_node.children[i].name, true))return i;
  56. return S;
  57. }
  58. void TextStyleEditor::Undo(TextStyleEditor &editor) {editor.undos.undo();}
  59. void TextStyleEditor::Redo(TextStyleEditor &editor) {editor.undos.redo();}
  60. void TextStyleEditor::Locate(TextStyleEditor &editor) {Proj.elmLocate(editor.elm_id);}
  61. void TextStyleEditor::create()
  62. {
  63. add("Shadow" , MemberDesc(MEMBER(EditTextStyle, shadow )).setTextToDataFunc(ParamsShadow)).desc("Shadow Intensity");
  64. add("Shade" , MemberDesc(MEMBER(EditTextStyle, shade )).setTextToDataFunc(ParamsShade )).desc("Shading");
  65. add("Color" , MemberDesc(MEMBER(EditTextStyle, color )).setTextToDataFunc(ParamsColor )).setColor();
  66. add("Selection", MemberDesc(MEMBER(EditTextStyle, selection)).setTextToDataFunc(ParamsSelect)).setColor();
  67. add("Align" , MemberDesc(MEMBER(EditTextStyle, align )).setTextToDataFunc(ParamsAlign )).range(-1, 1);
  68. add("Size" , MemberDesc(MEMBER(EditTextStyle, size )).setTextToDataFunc(ParamsSize )).min(0).mouseEditSpeed(0.3f);
  69. add("Space" , MemberDesc(MEMBER(EditTextStyle, space )).setTextToDataFunc(ParamsSpace )).min(0);
  70. font_prop=&add("Font" , MemberDesc().setFunc(ParamsFont, ParamsFont)).setEnum(); font_prop->combobox.setData(Proj.font_node);
  71. autoData(&edit);
  72. ::PropWin::create("Text Style Editor", Vec2(0.02f, -0.07f), 0.036f, 0.043f, 0.3f); ::PropWin::changed(Changed, PreChanged); button[1].show(); button[2].func(HideProjAct, SCAST(GuiObj, T)).show(); flag|=WIN_RESIZABLE;
  73. T+=undo .create(Rect_LU(0.02f, -0.01f , 0.05f, 0.05f)).func(Undo, T).focusable(false).desc("Undo"); undo.image="Gui/Misc/undo.img";
  74. T+=redo .create(Rect_LU(undo.rect().ru(), 0.05f, 0.05f)).func(Redo, T).focusable(false).desc("Redo"); redo.image="Gui/Misc/redo.img";
  75. T+=locate.create(Rect_LU(redo.rect().ru()+Vec2(0.01f, 0), 0.14f, 0.05f), "Locate").func(Locate, T).focusable(false).desc("Locate this element in the Project");
  76. T+=text .create("Sample Text\nNew Line");
  77. panel.border_color.a=0;
  78. rect(Rect_C(0, 0, Min(1.7f, D.w()*2), Min(1.07f, D.h()*2)));
  79. }
  80. void TextStyleEditor::toGame() {if(game)edit.copyTo(*game, Proj);}
  81. void TextStyleEditor::toGui()
  82. {
  83. ::PropWin::toGui(); toGame();
  84. if(font_prop && font_prop->combobox()<=0 && edit.font.valid()) // if there is a font specified but not in combobox selection (for example if combobox selection lists only certain fonts)
  85. {
  86. Elm *font=Proj.findElm(edit.font); font_prop->combobox.setText(font ? font->name : UnknownName, true, QUIET);
  87. }
  88. }
  89. TextStyleEditor& TextStyleEditor::hide( ) {set(null); ::PropWin::hide(); return T;}
  90. Rect TextStyleEditor::sizeLimit( )C {Rect r=::EE::Window::sizeLimit(); r.min.set(1.0f, 0.49f); return r;}
  91. TextStyleEditor& TextStyleEditor::rect(C Rect &rect)
  92. {
  93. ::EE::Window::rect(rect);
  94. flt x=0; if(props.elms())x=props[0].button.rect().max.x;
  95. Rect r(x, -clientHeight(), clientWidth(), 0); r.extend(-0.05f); //r.setC(r.center(), Min(r.w(), 0.8), Min(r.h(), 0.7));
  96. text.rect(r);
  97. return T;
  98. }
  99. void TextStyleEditor::flush()
  100. {
  101. if(elm && changed && game)
  102. {
  103. if(ElmTextStyle *data=elm->textStyleData()){data->newVer(); data->from(edit);} // modify just before saving/sending in case we've received data from server after edit
  104. Save( edit, Proj.editPath(*elm)); // edit
  105. Save(*game, Proj.gamePath(*elm)); Proj.savedGame(*elm); // game
  106. Server.setElmLong(elm->id);
  107. }
  108. changed=false;
  109. }
  110. void TextStyleEditor::setChanged()
  111. {
  112. if(elm)
  113. {
  114. changed=true;
  115. if(ElmTextStyle *data=elm->textStyleData()){data->newVer(); data->from(edit);}
  116. toGame();
  117. }
  118. }
  119. void TextStyleEditor::set(Elm *elm)
  120. {
  121. if(elm && elm->type!=ELM_TEXT_STYLE)elm=null;
  122. if(T.elm!=elm)
  123. {
  124. flush();
  125. undos.del(); undoVis();
  126. T.elm =elm;
  127. T.elm_id=(elm ? elm->id : UIDZero);
  128. if(elm){edit.load(Proj.editPath(*elm)); game=Proj.gamePath(elm_id);}else{edit.reset(); game.clear();}
  129. toGui();
  130. Proj.refresh(false, false);
  131. visible(T.elm!=null).moveToTop();
  132. }
  133. }
  134. void TextStyleEditor::activate(Elm *elm) {set(elm); if(T.elm)::EE::GuiObj::activate();}
  135. void TextStyleEditor::toggle(Elm *elm) {if(elm==T.elm)elm=null; set(elm);}
  136. void TextStyleEditor::elmChanged(C UID &elm_id)
  137. {
  138. if(elm && elm->id==elm_id)
  139. {
  140. undos.set(null, true);
  141. EditTextStyle temp; if(temp.load(Proj.editPath(*elm)))if(edit.sync(temp))toGui();
  142. }
  143. }
  144. void TextStyleEditor::erasing(C UID &elm_id) {if(elm && elm->id==elm_id)set(null);}
  145. void TextStyleEditor::fontChanged()
  146. {
  147. if(font_prop)font_prop->combobox.setData(Proj.font_node);
  148. }
  149. void TextStyleEditor::drag(Memc<UID> &elms, GuiObj *obj, C Vec2 &screen_pos)
  150. {
  151. if(contains(obj))REPA(elms)if(Elm *elm=Proj.findElm(elms[i], ELM_FONT))
  152. {
  153. undos.set("font");
  154. edit.font=elm->id; edit.font_time.getUTC(); setChanged(); toGui();
  155. elms.remove(i, true); // remove at the end
  156. break;
  157. }
  158. }
  159. TextStyleEditor::TextStyleEditor() : elm_id(UIDZero), elm(null), changed(false), font_prop(null), undos(true) {}
  160. /******************************************************************************/