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, oldtext, Text - oldtext, fg, bg);
113 case 1: // FG Select (\1 RRGGBB)
114 len = sscanf(Text, "%6x", &fg);
120 case 2: // BG Select (\2 RRGGBB)
121 len = sscanf(Text, "%6x", &bg);
127 case 3: // Flagset (0,it,uline,bold)
128 len = sscanf(Text, "%1x", &flags);
133 bItalic = !!(flags & (1 << 2));
134 bULine = !!(flags & (1 << 1));
135 bBold = !!(flags & (1 << 0));
137 default: // Any char, nop
141 curx += Renderer_RichText_RenderText_Act(Window, info, curx, Line, oldtext, Text - oldtext, fg, bg);
142 WM_Render_DrawRect(Window, curx, Line * info->LineHeight, Window->W - curx, info->LineHeight, info->DefaultBG);
145 void Renderer_RichText_Redraw(tWindow *Window)
147 tRichText_Window *info = Window->RendererInfo;
149 tRichText_LineBlock *lines = &info->FirstBlock;
151 // Locate the first line block
152 for( i = info->FirstVisRow; i > LINES_PER_BLOCK && lines; i -= LINES_PER_BLOCK )
155 for( i = 0; i < info->DispLines && lines; i ++ )
157 if( i >= info->nLines - info->FirstVisRow )
159 // TODO: Dirty rectangles?
160 WM_Render_DrawRect(Window,
161 0, i*info->LineHeight,
162 Window->W, info->LineHeight,
165 // TODO: Horizontal scrolling?
167 //Renderer_RichText_RenderText(Window, i, lines->Lines[i % LINES_PER_BLOCK]);
168 WM_Render_DrawText(Window,
169 0, i*info->LineHeight,
170 Window->W, info->LineHeight,
171 info->Font, info->DefaultFG,
172 lines->Lines[i % LINES_PER_BLOCK],
175 if( (i + 1) % LINES_PER_BLOCK == 0 )
178 // Clear out i -- info->DispLines
179 WM_Render_DrawRect(Window,
180 0, i*info->LineHeight,
181 Window->W, (info->DispLines-i)*info->LineHeight,
186 int Renderer_RichText_HandleMessage(tWindow *Target, int Msg, int Len, const void *Data)
190 case MSG_RICHTEXT_SETATTR: