MCPcopy Create free account
hub / github.com/NetHack/NetHack / mswin_render_text

Function mswin_render_text

outdated/sys/wince/mhtxtbuf.c:151–268  ·  view source on GitHub ↗

----------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

149}
150/*----------------------------------------------------------------*/
151void
152mswin_render_text(PNHTextBuffer pb, HWND edit_control)
153{
154 RECT rt_client; /* boundaries of the client area of the edit control */
155 SIZE size_text; /* size of the edit control */
156 RECT rt_text; /* calculated text rectangle for the visible line */
157 char buf[BUFSZ]; /* buffer for the visible line */
158 TCHAR tbuf[BUFSZ]; /* temp buffer for DrawText */
159 TCHAR *pText = NULL; /* resulting text (formatted) */
160 int pTextSize = 0; /* resulting text size */
161 char *p_cur = NULL; /* current position in the
162 NHTextBuffer->text_buffer_line->text */
163 char *p_buf_cur = NULL; /* current position in the visible line buffer */
164 int i;
165 HDC hdcEdit; /* device context for the edit control */
166 HFONT hFont, hOldFont; /* edit control font */
167
168 GetClientRect(edit_control, &rt_client);
169 size_text.cx = rt_client.right - rt_client.left;
170 size_text.cy = rt_client.bottom - rt_client.top;
171 size_text.cx -=
172 GetSystemMetrics(SM_CXVSCROLL); /* add a slight right margin - the
173 text looks better that way */
174 hdcEdit = GetDC(edit_control);
175 hFont = (HFONT) SendMessage(edit_control, WM_GETFONT, 0, 0);
176 if (hFont)
177 hOldFont = SelectObject(hdcEdit, hFont);
178
179 /* loop through each line (outer loop) and wrap it around (inner loop) */
180 ZeroMemory(buf, sizeof(buf));
181 p_buf_cur = buf;
182 for (i = 0; i < pb->n_used; i++) {
183 if (pb->b_wrap_text) {
184 p_cur = NHTextLine(pb, i).text;
185
186 /* insert an line break for the empty string */
187 if (!NHTextLine(pb, i).text[0]) {
188 pText = nh_append(pText, &pTextSize, "\r\n");
189 continue;
190 }
191
192 /* add margin to the "formatted" line of text */
193 if (NHTextLine(pb, i).formatted) {
194 strcpy(buf, " ");
195 p_buf_cur += 3;
196 }
197
198 /* scroll thourgh the current line of text and wrap it
199 so it fits to width of the edit control */
200 while (*p_cur) {
201 char *p_word_pos = p_buf_cur;
202
203 /* copy one word into the buffer */
204 while (*p_cur && isspace(*p_cur))
205 if (p_buf_cur != buf)
206 *p_buf_cur++ = *p_cur++;
207 else
208 p_cur++;

Callers 3

ToggleWrapStatusFunction · 0.85
onMSNHCommandFunction · 0.85
LayoutMenuFunction · 0.85

Calls 2

nh_appendFunction · 0.85
isspaceFunction · 0.85

Tested by

no test coverage detected