⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wg__editbox_8cpp-source.html

📁 一个小巧的嵌入式图形系统wGUI, 可以用VC编译
💻 HTML
📖 第 1 页 / 共 4 页
字号:
00140                SelStartNorm  = <a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a>;00141           }00142 00143           <span class="comment">// Handle scrolling</span>00144           <span class="comment">// Patch  for "Scrolling while selecting to left in editbox" by Oldrich Dlouhy</span>00145           <span class="keywordflow">if</span> (! <a class="code" href="classwGui_1_1CEditBox.html#n8">m_bMouseDown</a>)00146           {00147                <span class="keywordtype">int</span> RightBorder = CharRects[SelStartNorm + SelLenNorm - 1].Right() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a>;00148                <span class="keywordtype">int</span> LeftBorder = CharRects[SelStartNorm].Left() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a>;00149 00150                <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a> &lt; 0)00151                {00152                     <span class="keywordflow">if</span> (LeftBorder &lt;= 0)00153                     {00154                          <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> = -(CharRects[SelStartNorm].Left() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>());00155                     }00156                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (RightBorder &gt; SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>())00157                     {00158                          <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> = SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - (CharRects[SelStartNorm + SelLenNorm].Right() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>());00159                     }00160                }00161                <span class="keywordflow">else</span>00162                {00163                     <span class="keywordflow">if</span> (RightBorder &gt;= SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>())00164                     {00165                          <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> = SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - (CharRects[SelStartNorm + SelLenNorm].Right() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>());00166                     }00167                     <span class="keywordflow">else</span> <span class="keywordflow">if</span> (LeftBorder &lt; 0)00168                     {00169                          <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> = -(CharRects[SelStartNorm].Left() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>());00170                     }00171                }00172 00173                <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> != 0 &amp;&amp;00174                     (CharRects[<a class="code" href="classwGui_1_1CWindow.html#n0">m_sWindowText</a>.length()].Right() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> &lt; SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>()))00175                {00176                     <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> = SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>() - (CharRects[<a class="code" href="classwGui_1_1CWindow.html#n0">m_sWindowText</a>.length()].Right() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>());00177                     <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> &gt; 0)00178                     {00179                          <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a> = 0;00180                     }00181                }00182           }00183 00184           <span class="comment">// Selection</span>00185           <span class="keywordflow">if</span> (<a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a> != 0)00186           {00187                <a class="code" href="classwGui_1_1CRect.html">CRect</a> SelRect;00188                SelRect.<a class="code" href="classwGui_1_1CRect.html#a8">SetBottom</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>());00189                SelRect.<a class="code" href="classwGui_1_1CRect.html#a5">SetTop</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>());00190                SelRect.<a class="code" href="classwGui_1_1CRect.html#a6">SetLeft</a>(CharRects[SelStartNorm].Left() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a>);00191                SelRect.<a class="code" href="classwGui_1_1CRect.html#a7">SetRight</a>(CharRects[SelLenNorm + SelStartNorm - 1].Right() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a>);00192                SelRect.<a class="code" href="classwGui_1_1CRect.html#a31">ClipTo</a>(SubRect);00193                Painter.<a class="code" href="classwGui_1_1CPainter.html#a5">DrawRect</a>(SelRect, <span class="keyword">true</span>, <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a>(102, 128, 151), <a class="code" href="classwGui_1_1CRGBColor.html">CRGBColor</a>(102, 128, 151));00194           }00195 00196           <span class="comment">//TODO:</span>00197           <span class="comment">//We should do this regardless of wether there's text selected or not.</span>00198           <span class="comment">// This means we'll have to calculate the CursorPos all the time.  Including when we're selecting.</span>00199           <span class="keywordflow">else</span>00200           {00201                <span class="comment">//RenderStringWithCursor</span>00202                <span class="keywordtype">int</span> CursorPos;00203                CursorPos = CharRects[<a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a>].Left() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a>;00204                <span class="keywordflow">if</span> (CursorPos &gt;= SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() &amp;&amp; CursorPos &lt;= SubRect.<a class="code" href="classwGui_1_1CRect.html#a11">Right</a>())00205                {00206                     Painter.<a class="code" href="classwGui_1_1CPainter.html#a4">DrawVLine</a>(SubRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>(), SubRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>(), CursorPos, COLOR_BLACK);00207                }00208           }00209      }00210 00211      DrawRect.<a class="code" href="classwGui_1_1CRect.html#a6">SetLeft</a>(DrawRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a>);00212      <span class="keywordtype">int</span> HeightDiff=<a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a>-&gt;GetMaxFontHeight()/4;00213      DrawRect.<a class="code" href="classwGui_1_1CRect.html#a5">SetTop</a>(DrawRect.<a class="code" href="classwGui_1_1CRect.html#a9">Top</a>() - HeightDiff);00214      DrawRect.<a class="code" href="classwGui_1_1CRect.html#a8">SetBottom</a>(DrawRect.<a class="code" href="classwGui_1_1CRect.html#a12">Bottom</a>() - HeightDiff);00215      <a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a>-&gt;Draw(<a class="code" href="classwGui_1_1CWindow.html#n6">m_pSDLSurface</a>, SubRect, DrawRect.<a class="code" href="classwGui_1_1CRect.html#a15">BottomLeft</a>(), FontColor);00216 }00217 00218 <a name="l00219"></a><a class="code" href="classwGui_1_1CEditBox.html#a8">00219</a> <span class="keywordtype">void</span> CEditBox::SetWindowText(<span class="keyword">const</span> std::string&amp; sText)00220 {00221      <a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a> = 0;00222      <a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a> = 0;00223      CWindow::SetWindowText(sText);00224      std::auto_ptr&lt;CRenderedString&gt; pRenderedString(<span class="keyword">new</span> <a class="code" href="classwGui_1_1CRenderedString.html">CRenderedString</a>(00225           <a class="code" href="classwGui_1_1CEditBox.html#n0">m_pFontEngine</a>, sText, CRenderedString::VALIGN_NORMAL, CRenderedString::HALIGN_LEFT));00226      <a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a> = pRenderedString;00227      <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00228 }00229 00230 <a name="l00231"></a><a class="code" href="classwGui_1_1CEditBox.html#a9">00231</a> <span class="keywordtype">bool</span> CEditBox::OnMouseButtonDown(<a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Point, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> Button)00232 {00233      <span class="keywordtype">bool</span> bResult = <span class="keyword">false</span>;00234 00235      <span class="keywordflow">if</span> (! CWindow::OnMouseButtonDown(Point, Button) &amp;&amp; <a class="code" href="classwGui_1_1CWindow.html#n7">m_bVisible</a> &amp;&amp; (<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>.<a class="code" href="classwGui_1_1CRect.html#a32">HitTest</a>(Point) == CRect::RELPOS_INSIDE) &amp;&amp;00236           (Button == CMouseMessage::LEFT) &amp;&amp; !<a class="code" href="classwGui_1_1CEditBox.html#n7">m_bReadOnly</a>)00237      {00238           <span class="keywordflow">if</span> (CApplication::Instance()-&gt;GetKeyFocus() != <span class="keyword">this</span>)00239           {00240                CApplication::Instance()-&gt;SetKeyFocus(<span class="keyword">this</span>);00241           }00242 00243           <a class="code" href="classwGui_1_1CPoint.html">CPoint</a> Offset;00244           std::vector&lt;CRect&gt; CharRects;00245           <a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a>-&gt;GetMetrics(0, &amp;Offset, &amp;CharRects);00246           <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00247           SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-3);00248 00249           <span class="keywordtype">int</span> xDelta = abs(Point.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() - (CharRects[0].Left() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>()));00250           <a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a> = 0;00251           <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; <a class="code" href="classwGui_1_1CEditBox.html#n1">m_pRenderedString</a>-&gt;GetLength(); ++i)00252           {00253                <span class="keywordflow">if</span> (abs(Point.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() - (CharRects[i].Right() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a>)) &lt; xDelta)00254                {00255                     xDelta = abs(Point.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() - (CharRects[i].Right() + Offset.<a class="code" href="classwGui_1_1CPoint.html#a6">XPos</a>() + SubRect.<a class="code" href="classwGui_1_1CRect.html#a10">Left</a>() + <a class="code" href="classwGui_1_1CEditBox.html#n6">m_ScrollOffset</a>));00256                     <a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a> = i + 1;00257                }00258           }00259 00260           <a class="code" href="classwGui_1_1CEditBox.html#n5">m_DragStart</a> = <a class="code" href="classwGui_1_1CEditBox.html#n3">m_SelStart</a>;00261           <a class="code" href="classwGui_1_1CEditBox.html#n4">m_SelLength</a> = 0;00262           <a class="code" href="classwGui_1_1CEditBox.html#n8">m_bMouseDown</a> = <span class="keyword">true</span>;00263           <a class="code" href="classwGui_1_1CWindow.html#a23">StartDrawProc</a>();00264           bResult = <span class="keyword">true</span>;00265      }00266 00267      <span class="keywordflow">return</span> bResult;00268 }00269 00270 <a name="l00271"></a><a class="code" href="classwGui_1_1CEditBox.html#a10">00271</a> <span class="keywordtype">bool</span> CEditBox::HandleMessage(<a class="code" href="classwGui_1_1CMessage.html">CMessage</a>* pMessage)00272 {00273      <span class="keywordtype">bool</span> bHandled = <span class="keyword">false</span>;00274      <a class="code" href="classwGui_1_1CRect.html">CRect</a> SubRect(<a class="code" href="classwGui_1_1CWindow.html#n1">m_WindowRect</a>);00275      SubRect.<a class="code" href="classwGui_1_1CRect.html#a28">Grow</a>(-3);00276 00277      <span class="keywordflow">if</span> (pMessage)00278      {00279           <span class="keywordflow">switch</span>(pMessage-&gt;<a class="code" href="classwGui_1_1CMessage.html#a2">MessageType</a>())00280           {00281           <span class="keywordflow">case</span> CMessage::MOUSE_BUTTONUP:00282                <a class="code" href="classwGui_1_1CEditBox.html#n8">m_bMouseDown</a> = <span class="keyword">false</span>;00283                <span class="keywordflow">break</span>;00284           <span class="keywordflow">case</span> CMessage::MOUSE_MOVE:00285           {00286                <a class="code" href="classwGui_1_1CMouseMessage.html">CMouseMessage</a>* pMouseMessage = dynamic_cast&lt;CMouseMessage*&gt;(pMessage);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -