summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index c0dbcded..7fe30f1e 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -25,6 +25,7 @@ struct Impl_DocumentWidget {
25 iString *newSource; 25 iString *newSource;
26 iGmDocument *doc; 26 iGmDocument *doc;
27 int pageMargin; 27 int pageMargin;
28 int scrollY;
28}; 29};
29 30
30iDeclareType(Url) 31iDeclareType(Url)
@@ -71,6 +72,7 @@ void init_DocumentWidget(iDocumentWidget *d) {
71 d->newSource = new_String(); 72 d->newSource = new_String();
72 d->doc = new_GmDocument(); 73 d->doc = new_GmDocument();
73 d->pageMargin = 5; 74 d->pageMargin = 5;
75 d->scrollY = 0;
74 setUrl_DocumentWidget(d, collectNewCStr_String("file:///home/jaakko/test.gmi")); 76 setUrl_DocumentWidget(d, collectNewCStr_String("file:///home/jaakko/test.gmi"));
75} 77}
76 78
@@ -173,13 +175,18 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
173 return iTrue; 175 return iTrue;
174 } 176 }
175 } 177 }
178 else if (ev->type == SDL_MOUSEWHEEL) {
179 d->scrollY -= 3 * ev->wheel.y * lineHeight_Text(default_FontId);
180 postRefresh_App();
181 return iTrue;
182 }
176 return processEvent_Widget(w, ev); 183 return processEvent_Widget(w, ev);
177} 184}
178 185
179iDeclareType(DrawContext) 186iDeclareType(DrawContext)
180 187
181struct Impl_DrawContext { 188struct Impl_DrawContext {
182 const iDocumentWidget *d; 189 const iDocumentWidget *widget;
183 iRect bounds; 190 iRect bounds;
184 iPaint paint; 191 iPaint paint;
185}; 192};
@@ -189,8 +196,9 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) {
189 iString text; 196 iString text;
190 /* TODO: making a copy is unnecessary; the text routines should accept Rangecc */ 197 /* TODO: making a copy is unnecessary; the text routines should accept Rangecc */
191 initRange_String(&text, run->text); 198 initRange_String(&text, run->text);
192 drawString_Text(run->font, add_I2(d->bounds.pos, run->bounds.pos), run->color, &text); 199 iInt2 origin = addY_I2(d->bounds.pos, -d->widget->scrollY);
193 drawRect_Paint(&d->paint, moved_Rect(run->bounds, d->bounds.pos), red_ColorId); 200 drawString_Text(run->font, add_I2(run->bounds.pos, origin), run->color, &text);
201// drawRect_Paint(&d->paint, moved_Rect(run->bounds, origin), red_ColorId);
194 deinit_String(&text); 202 deinit_String(&text);
195} 203}
196 204
@@ -206,11 +214,14 @@ static void draw_DocumentWidget_(const iDocumentWidget *d) {
206 iConstCast(iDocumentWidget *, d)->state = ready_DocumentState; 214 iConstCast(iDocumentWidget *, d)->state = ready_DocumentState;
207 } 215 }
208 if (d->state != ready_DocumentState) return; 216 if (d->state != ready_DocumentState) return;
209 iDrawContext ctx = {.d = d, .bounds = bounds_Widget(w) }; 217 iDrawContext ctx = {.widget = d, .bounds = bounds_Widget(w) };
210 shrink_Rect(&ctx.bounds, init1_I2(gap_UI * d->pageMargin)); 218 shrink_Rect(&ctx.bounds, init1_I2(gap_UI * d->pageMargin));
211 init_Paint(&ctx.paint); 219 init_Paint(&ctx.paint);
212 drawRect_Paint(&ctx.paint, ctx.bounds, teal_ColorId); 220 drawRect_Paint(&ctx.paint, ctx.bounds, teal_ColorId);
213 render_GmDocument(d->doc, (iRangei){ 0, height_Rect(ctx.bounds) }, drawRun_DrawContext_, &ctx); 221 render_GmDocument(d->doc,
222 (iRangei){ d->scrollY, d->scrollY + height_Rect(ctx.bounds) },
223 drawRun_DrawContext_,
224 &ctx);
214} 225}
215 226
216iBeginDefineSubclass(DocumentWidget, Widget) 227iBeginDefineSubclass(DocumentWidget, Widget)