2 * Acess2 Window Manager v3
3 * - By John Hodge (thePowersGang)
6 * - Formatted Line Editor
9 #include <wm_renderer.h>
10 #include <richtext_messages.h>
12 #define LINES_PER_BLOCK 30
15 typedef struct sRichText_LineBlock
17 struct sRichText_LineBlock *Next;
19 char *Lines[LINES_PER_BLOCK];
20 } tRichText_LineBlock;
21 typedef struct sRichText_Window
23 int DispLines, DispCols;
24 int FirstVisRow, FirstVisCol;
26 int CursorRow, CursorCol;
27 tRichText_LineBlock FirstBlock;
36 int Renderer_RichText_Init(void);
37 tWindow *Renderer_RichText_Create(int Flags);
38 void Renderer_RichText_Redraw(tWindow *Window);
39 int Renderer_RichText_HandleMessage(tWindow *Target, int Msg, int Len, const void *Data);
42 tWMRenderer gRenderer_RichText = {
44 .CreateWindow = Renderer_RichText_Create,
45 .Redraw = Renderer_RichText_Redraw,
46 .HandleMessage = Renderer_RichText_HandleMessage
50 int Renderer_RichText_Init(void)
52 WM_RegisterRenderer(&gRenderer_RichText);
56 tWindow *Renderer_RichText_Create(int Flags)
58 tRichText_Window *info;
59 tWindow *ret = WM_CreateWindowStruct( sizeof(*info) );
61 info = ret->RendererInfo;
62 // Everything starts at zero?
66 inline int Renderer_RichText_RenderText_Act(tWindow *Window, tRichText_Window *info, int X, int Row, const char *Text, int Bytes, tColour FG, tColour BG)
69 // TODO: Fill only what is needed
70 WM_Render_DrawRect(Window, X, Row*info->LineHeight,
71 Window->W - X, info->LineHeight,
74 rwidth = WM_Render_DrawText(Window,
75 X, Row*info->LineHeight,
76 Window->W - X, info->LineHeight,
83 void Renderer_RichText_RenderText(tWindow *Window, int Line, const char *Text)
85 tRichText_Window *info = Window->RendererInfo;
86 tColour fg = info->DefaultFG;
87 tColour bg = info->DefaultBG;
93 const char *oldtext = Text;
95 for( int i = 0; i < info->FirstVisCol + info->DispCols; i ++ )
100 if( i == info->FirstVisCol )
105 if( ch <=3 && bRender ) {
106 // Render previous characters
107 curx += Renderer_RichText_RenderText_Act(Window, info, curx, Line, oldtext, Text - oldtext, fg, bg);
112 case 1: // FG Select (\1 RRGGBB)
113 len = sscanf(Text, "%6x", &fg);
119 case 2: // BG Select (\2 RRGGBB)
120 len = sscanf(Text, "%6x", &bg);
126 case 3: // Flagset (0,it,uline,bold)
127 len = sscanf(Text, "%1x", &flags);
132 bItalic = !!(flags & (1 << 2));
133 bULine = !!(flags & (1 << 1));
134 bBold = !!(flags & (1 << 0));
136 default: // Any char, nop
140 curx += Renderer_RichText_RenderText_Act(Window, info, curx, Line, oldtext, Text - oldtext, fg, bg);
141 WM_Render_DrawRect(Window, curx, Line * info->LineHeight, Window->W - curx, info->LineHeight, info->DefaultBG);
144 void Renderer_RichText_Redraw(tWindow *Window)
146 tRichText_Window *info = Window->RendererInfo;
148 tRichText_LineBlock *lines = &info->FirstBlock;
150 // Locate the first line block
151 for( i = info->FirstVisRow; i > LINES_PER_BLOCK && lines; i -= LINES_PER_BLOCK )
154 for( i = 0; i < info->DispLines && lines; i ++ )
156 if( i >= info->nLines - info->FirstVisRow )
158 // TODO: Dirty rectangles?
159 WM_Render_DrawRect(Window,
160 0, i*info->LineHeight,
161 Window->W, info->LineHeight,
164 // TODO: Horizontal scrolling?
166 //Renderer_RichText_RenderText(Window, i, lines->Lines[i % LINES_PER_BLOCK]);
167 WM_Render_DrawText(Window,
168 0, i*info->LineHeight,
169 Window->W, info->LineHeight,
170 info->Font, info->DefaultFG,
171 lines->Lines[i % LINES_PER_BLOCK],
174 if( (i + 1) % LINES_PER_BLOCK == 0 )
177 // Clear out i -- info->DispLines
178 WM_Render_DrawRect(Window,
179 0, i*info->LineHeight,
180 Window->W, (info->DispLines-i)*info->LineHeight,
185 int Renderer_RichText_HandleMessage(tWindow *Target, int Msg, int Len, const void *Data)
189 case MSG_RICHTEXT_SETATTR: