2 * Acess2 Window Manager v3
3 * - By John Hodge (thePowersGang)
6 * - Formatted Line Editor
9 #include <wm_renderer.h>
10 #include <richtext_messages.h>
11 #include <stdio.h> // sscanf
13 #define LINES_PER_BLOCK 30
16 typedef struct sRichText_LineBlock
18 struct sRichText_LineBlock *Next;
20 char *Lines[LINES_PER_BLOCK];
21 } tRichText_LineBlock;
22 typedef struct sRichText_Window
24 int DispLines, DispCols;
25 int FirstVisRow, FirstVisCol;
27 int CursorRow, CursorCol;
28 tRichText_LineBlock FirstBlock;
37 int Renderer_RichText_Init(void);
38 tWindow *Renderer_RichText_Create(int Flags);
39 void Renderer_RichText_Redraw(tWindow *Window);
40 int Renderer_RichText_HandleMessage(tWindow *Target, int Msg, int Len, const void *Data);
43 tWMRenderer gRenderer_RichText = {
45 .CreateWindow = Renderer_RichText_Create,
46 .Redraw = Renderer_RichText_Redraw,
47 .HandleMessage = Renderer_RichText_HandleMessage
51 int Renderer_RichText_Init(void)
53 WM_RegisterRenderer(&gRenderer_RichText);
57 tWindow *Renderer_RichText_Create(int Flags)
59 tRichText_Window *info;
60 tWindow *ret = WM_CreateWindowStruct( sizeof(*info) );
62 info = ret->RendererInfo;
63 // Everything starts at zero?
67 static inline int Renderer_RichText_RenderText_Act(tWindow *Window, tRichText_Window *info, int X, int Row, const char *Text, int Bytes, tColour FG, tColour BG)
70 // TODO: Fill only what is needed
71 WM_Render_DrawRect(Window, X, Row*info->LineHeight,
72 Window->W - X, info->LineHeight,
75 rwidth = WM_Render_DrawText(Window,
76 X, Row*info->LineHeight,
77 Window->W - X, info->LineHeight,
84 void Renderer_RichText_RenderText(tWindow *Window, int Line, const char *Text)
86 tRichText_Window *info = Window->RendererInfo;
87 tColour fg = info->DefaultFG;
88 tColour bg = info->DefaultBG;
94 const char *oldtext = Text;
96 for( int i = 0; i < info->FirstVisCol + info->DispCols; i ++ )
101 if( i == info->FirstVisCol )
106 if( ch <=3 && bRender ) {
107 // Render previous characters
108 curx += Renderer_RichText_RenderText_Act(Window, info, curx, Line,
109 oldtext, Text - oldtext, fg, bg);
114 case 1: // FG Select (\1 RRGGBB)
115 len = sscanf(Text, "%6x", &fg);
121 case 2: // BG Select (\2 RRGGBB)
122 len = sscanf(Text, "%6x", &bg);
128 case 3: // Flagset (0,it,uline,bold)
129 len = sscanf(Text, "%1x", &flags);
134 bItalic = !!(flags & (1 << 2));
135 bULine = !!(flags & (1 << 1));
136 bBold = !!(flags & (1 << 0));
138 default: // Any char, nop
142 curx += Renderer_RichText_RenderText_Act(Window, info, curx, Line, oldtext, Text - oldtext, fg, bg);
143 WM_Render_DrawRect(Window, curx, Line * info->LineHeight, Window->W - curx, info->LineHeight, info->DefaultBG);
146 void Renderer_RichText_Redraw(tWindow *Window)
148 tRichText_Window *info = Window->RendererInfo;
150 tRichText_LineBlock *lines = &info->FirstBlock;
152 // Locate the first line block
153 for( i = info->FirstVisRow; i > LINES_PER_BLOCK && lines; i -= LINES_PER_BLOCK )
156 for( i = 0; i < info->DispLines && lines; i ++ )
158 if( i >= info->nLines - info->FirstVisRow )
160 // TODO: Dirty rectangles?
161 WM_Render_DrawRect(Window,
162 0, i*info->LineHeight,
163 Window->W, info->LineHeight,
166 // TODO: Horizontal scrolling?
168 //Renderer_RichText_RenderText(Window, i, lines->Lines[i % LINES_PER_BLOCK]);
169 WM_Render_DrawText(Window,
170 0, i*info->LineHeight,
171 Window->W, info->LineHeight,
172 info->Font, info->DefaultFG,
173 lines->Lines[i % LINES_PER_BLOCK],
176 if( (i + 1) % LINES_PER_BLOCK == 0 )
179 // Clear out i -- info->DispLines
180 WM_Render_DrawRect(Window,
181 0, i*info->LineHeight,
182 Window->W, (info->DispLines-i)*info->LineHeight,
187 int Renderer_RichText_HandleMessage(tWindow *Target, int Msg, int Len, const void *Data)
191 case MSG_RICHTEXT_SETATTR: