static void replayview_drawitem(void *n, int item, int cnt) { MenuEntry *e = (MenuEntry*)n; Replay *rpy = (Replay*)e->arg; float sizes[] = {1.2, 1.45, 0.8, 0.8, 0.65}; int columns = 5, i, j; for(i = 0; i < columns; ++i) { char tmp[128]; int csize = sizes[i] * (SCREEN_W - 210)/columns; int o = 0; for(j = 0; j < i; ++j) o += sizes[j] * (SCREEN_W - 210)/columns; Alignment a = AL_Center; // hell yeah, another loop-switch sequence switch(i) { case 0: a = AL_Left; time_t t = rpy->stages[0].seed; struct tm* timeinfo = localtime(&t); strftime(tmp, 128, "%Y-%m-%d %H:%M", timeinfo); break; case 1: a = AL_Center; strncpy(tmp, rpy->playername, 128); break; case 2: plrmode_repr(tmp, 128, rpy->stages[0].plr_char, rpy->stages[0].plr_shot); tmp[0] = tmp[0] - 'a' + 'A'; break; case 3: snprintf(tmp, 128, difficulty_name(rpy->stages[0].diff)); break; case 4: a = AL_Right; if(rpy->stgcount == 1) snprintf(tmp, 128, "Stage %i", rpy->stages[0].stage); else snprintf(tmp, 128, "%i stages", rpy->stgcount); break; } shorten(tmp, csize); switch(a) { case AL_Center: o += csize * 0.5 - stringwidth(tmp, _fonts.standard) * 0.5; break; case AL_Right: o += csize - stringwidth(tmp, _fonts.standard); break; default: break; } draw_text(AL_Left, o + 10, 20*item, tmp, _fonts.standard); } }
void draw_stage_menu(MenuData *m) { draw_options_menu_bg(m); draw_text(AL_Right, (stringwidth(m->title, _fonts.mainmenu) + 10) * (1-m->fade), 30, m->title, _fonts.mainmenu); glPushMatrix(); glTranslatef(100, 100 + (((m->ecount * 20 + 290) > SCREEN_W)? min(0, SCREEN_H * 0.7 - 100 - m->drawdata[2]) : 0), 0); /* glPushMatrix(); glTranslatef(SCREEN_W/2 - 100, m->drawdata[2], 0); glScalef(SCREEN_W - 200, 20, 1); glColor4f(0,0,0,0.5); draw_quad(); glPopMatrix(); */ Texture *bg = get_tex("part/smoke"); glPushMatrix(); glTranslatef(m->drawdata[0], m->drawdata[2], 0); glScalef(m->drawdata[1]/100.0, 0.2, 1); glRotatef(m->frames*2,0,0,1); glColor4f(0,0,0,0.5); draw_texture_p(0,0,bg); glPopMatrix(); MenuEntry *s = &(m->entries[m->cursor]); m->drawdata[0] += ((s->draw? SCREEN_W/2 - 100 : (stringwidth(s->name, _fonts.mainmenu)/2 - s->drawdata*1.5)) - m->drawdata[0])/10.0; m->drawdata[1] += ((s->draw? (SCREEN_W - 200)*0.85 : stringwidth(s->name, _fonts.mainmenu)) - m->drawdata[1])/10.0; m->drawdata[2] += (20*m->cursor - m->drawdata[2])/10.0; int i; for(i = 0; i < m->ecount; i++) { MenuEntry *e = &(m->entries[i]); e->drawdata += 0.2 * (10*(i == m->cursor) - e->drawdata); float a = e->drawdata * 0.1; if(e->action == NULL) glColor4f(0.5, 0.5, 0.5, 0.5); else { //glColor4f(0.7 + 0.3 * (1-a), 1, 1, 0.7 + 0.3 * a); float ia = 1-a; glColor4f(0.9 + ia * 0.1, 0.6 + ia * 0.4, 0.2 + ia * 0.8, 0.7 + 0.3 * a); } if(e->draw) e->draw(e, i, m->ecount); else if(e->name) draw_text(AL_Left, 20 - e->drawdata, 20*i, e->name, _fonts.standard); } glPopMatrix(); fade_out(m->fade); }
void textredraw(Text *t, Rectangle r, Font *f, Image *b, int odx) { int maxt; Rectangle rr; frinit(t, r, f, b, t->Frame.cols); rr = t->r; rr.min.x -= Scrollwid+Scrollgap; /* back fill to scroll bar */ draw(t->b, rr, t->cols[BACK], nil, ZP); /* use no wider than 3-space tabs in a directory */ maxt = maxtab; if(t->what == Body){ if(t->w->isdir) maxt = min(TABDIR, maxtab); else maxt = t->tabstop; } t->maxtab = maxt*stringwidth(f, "0"); if(t->what==Body && t->w->isdir && odx!=Dx(t->all)){ if(t->maxlines > 0){ textreset(t); textcolumnate(t, t->w->dlp, t->w->ndl); textshow(t, 0, 0, 1); } }else{ textfill(t); textsetselect(t, t->q0, t->q1); } }
void drawplanet(Image *scr, Planetrec *p, Point pt) { if(strcmp(p->name, "sun") == 0){ drawdisc(scr, p->semidiam, 0, suncolor, pt, nil); return; } if(strcmp(p->name, "moon") == 0){ drawdisc(scr, p->semidiam, 0, mooncolor, pt, nil); return; } if(strcmp(p->name, "shadow") == 0){ drawdisc(scr, p->semidiam, 2, shadowcolor, pt, nil); return; } if(strcmp(p->name, "mercury") == 0){ drawdisc(scr, p->semidiam, 0, mercurycolor, pt, "m"); return; } if(strcmp(p->name, "venus") == 0){ drawdisc(scr, p->semidiam, 0, venuscolor, pt, "v"); return; } if(strcmp(p->name, "mars") == 0){ drawdisc(scr, p->semidiam, 0, marscolor, pt, "M"); return; } if(strcmp(p->name, "jupiter") == 0){ drawdisc(scr, p->semidiam, 0, jupitercolor, pt, "J"); return; } if(strcmp(p->name, "saturn") == 0){ drawdisc(scr, p->semidiam, 1, saturncolor, pt, "S"); return; } if(strcmp(p->name, "uranus") == 0){ drawdisc(scr, p->semidiam, 0, uranuscolor, pt, "U"); return; } if(strcmp(p->name, "neptune") == 0){ drawdisc(scr, p->semidiam, 0, neptunecolor, pt, "N"); return; } if(strcmp(p->name, "pluto") == 0){ drawdisc(scr, p->semidiam, 0, plutocolor, pt, "P"); return; } if(strcmp(p->name, "comet") == 0){ drawdisc(scr, p->semidiam, 0, cometcolor, pt, "C"); return; } pt.x -= stringwidth(font, p->name)/2; pt.y -= font->height/2; string(scr, pt, grey, ZP, font, p->name); }
void textcolumnate(Text *t, Dirlist **dlp, int ndl) { int i, j, w, colw, mint, maxt, ncol, nrow; Dirlist *dl; uint q1; static Rune Lnl[] = { '\n', 0 }; static Rune Ltab[] = { '\t', 0 }; if(t->file->ntext > 1) return; mint = stringwidth(t->fr.font, "0"); /* go for narrower tabs if set more than 3 wide */ t->fr.maxtab = min(maxtab, TABDIR)*mint; maxt = t->fr.maxtab; colw = 0; for(i=0; i<ndl; i++){ dl = dlp[i]; w = dl->wid; if(maxt-w%maxt < mint || w%maxt==0) w += mint; if(w % maxt) w += maxt-(w%maxt); if(w > colw) colw = w; } if(colw == 0) ncol = 1; else ncol = max(1, Dx(t->fr.r)/colw); nrow = (ndl+ncol-1)/ncol; q1 = 0; for(i=0; i<nrow; i++){ for(j=i; j<ndl; j+=nrow){ dl = dlp[j]; fileinsert(t->file, q1, dl->r, dl->nr); q1 += dl->nr; if(j+nrow >= ndl) break; w = dl->wid; if(maxt-w%maxt < mint){ fileinsert(t->file, q1, Ltab, 1); q1++; w += mint; } do{ fileinsert(t->file, q1, Ltab, 1); q1++; w += maxt-(w%maxt); }while(w < colw); } fileinsert(t->file, q1, Lnl, 1); q1++; } }
void center(Font *f, Point p, char *s, Image *color) { int i, n, dx; Rune rbuf[32]; char sbuf[32*UTFmax+1]; dx = stringwidth(f, s); if(dx > Facesize){ n = torune(rbuf, s, nelem(rbuf)); for(i=0; i<n; i++){ dx = runestringnwidth(f, rbuf, i+1); if(dx > Facesize) break; } sprint(sbuf, "%.*S", i, rbuf); s = sbuf; dx = stringwidth(f, s); } p.x += (Facesize-dx)/2; string(screen, p, color, ZP, f, s); }
void textredraw(Text *t, Rectangle r, Font *f, Image *b) { Rectangle r1; frinit(t, r, f, b, t->Frame.cols); r1 = t->r; r1.min.x -= Scrollsize+Scrollgap; /* back fill to scroll bar */ draw(t->b, r1, t->cols[BACK], nil, ZP); t->maxtab = Maxtab*stringwidth(f, "0"); textfill(t); textsetselect(t, t->q0, t->q1); }
void DrawLat(long latVal, Rect r, WorldRect view, short precision, Boolean label) { short /*x1, x2, y, */ w; Point x_y1, x_y2; WorldPoint wp; Boolean offQuickDrawPlane; char roundLat, roundLong, longString[20], latString[20]; if (latVal > 90000010 || latVal < -90000000) return; //view.loLong = _min(view.loLong, 180000000); view.loLong = _min(view.loLong, 360000000); //view.loLong = _max(view.loLong, -180000000); view.loLong = _max(view.loLong, -360000000); //x1 = SameDifferenceX(view.loLong); x_y1 = GetQuickDrawPt(view.loLong,latVal,&r,&offQuickDrawPlane); //view.hiLong = _min(view.hiLong, 180000000); view.hiLong = _min(view.hiLong, 360000000); //view.hiLong = _max(view.hiLong, -180000000); view.hiLong = _max(view.hiLong, -360000000); //x2 = SameDifferenceX(view.hiLong); x_y2 = GetQuickDrawPt(view.hiLong,latVal,&r,&offQuickDrawPlane); //y = (r.bottom + r.top) - SameDifferenceY(latVal); //if (y > (r.bottom - 30)) return; // don't let low lat line write over long values if (x_y1.v > (r.bottom - 30)) return; // don't let low lat line write over long values wp.pLong = 0; wp.pLat = latVal; WorldPointToStrings2(wp, latString, &roundLat, longString, &roundLong); SimplifyLLString(latString, precision, roundLat); w = label ? stringwidth(latString) : 0; RGBForeColor(&colors[LIGHTGRAY]); // SetPenPat(label ? BLACK : GRAY); //MyMoveTo(x1, y); MyMoveTo(x_y1.h, x_y1.v); // MyMoveTo(x1 + w + 10, y); //MyLineTo(x2, y); MyLineTo(x_y2.h, x_y2.v); if (label) { RGBForeColor(&colors[BLACK]); // MyMoveTo(x1 + 5, y + 3); //MyMoveTo(x1 + 1, y); MyMoveTo(x_y1.h + 1, x_y1.v); drawstring(latString); } }
static void shorten(char *s, int width) { float sw = stringwidth(s, _fonts.standard); float len = strlen(s); float avgw = sw / len; int c = width / avgw, i; if(c > len) return; s[c+1] = 0; for(i = 0; i < 3; ++i) s[c - i] = '.'; }
void drawtime(void) { Rectangle r; r.min = addpt(screen->r.min, datep); if(eqpt(enddate, ZP)){ enddate = r.min; enddate.x += stringwidth(datefont, "Wed May 30 22:54"); /* nice wide string */ enddate.x += Facesep; /* for safety */ } r.max.x = enddate.x; r.max.y = enddate.y+datefont->height; draw(screen, r, bgrnd, nil, ZP); string(screen, r.min, display->black, ZP, datefont, date); }
int labelwidth(void) { int i, j, n, w, maxw; char strs[Nlab][Lablen]; maxw = 0; for(i=0; i<ngraph; i++){ /* choose value for rightmost graph */ labelstrs(&graph[ngraph*(nmach-1)+i], strs, &n); for(j=0; j<n; j++){ w = stringwidth(mediumfont, strs[j]); if(w > maxw) maxw = w; } } return maxw; }
void getimage(Cimage *ci, Rune *altr) { Rectangle r; Memimage *mi; Image *i, *i2; char buf[128]; uchar *bits; int nbits; mi = ci->mi; if(mi == nil) { snprint(buf, sizeof(buf), "[%S]", altr ? altr : L"IMG"); r.min = Pt(0, 0); r.max.x = 2*Space + stringwidth(font, buf); r.max.y = 2*Space + font->height; ci->i = eallocimage(display, r, GREY1, 1, DBlack); r.min.x += Space; r.min.y += Space; string(ci->i, r.min, display->white, ZP, font, buf); return; } nbits = bytesperline(mi->r, mi->depth)*Dy(mi->r); bits = emalloc(nbits); unloadmemimage(mi, mi->r, bits, nbits); /* /* get rid of alpha channel from transparent gif * / if(mi->depth == 16){ for(y=1; y<nbits; y+=2) bits[y>>1] = bits[y]; } */ i = eallocimage(display, mi->r, mi->chan, 0, DNofill); loadimage(i, i->r, bits, nbits); i2 = eallocimage(display, i->r, RGB24, 1, DNofill); draw(i2, i2->r, display->black, nil, ZP); draw(i2, i2->r, i, nil, i->r.min); free(bits); freememimage(mi); freeimage(i); ci->i = i2; ci->mi = nil; }
void DrawLong(long longVal, Rect r, WorldRect view, short precision, Boolean label) { short /*x, y1, y2, */ w; Point x_y1,x_y2; WorldPoint wp; Boolean offQuickDrawPlane; char roundLat, roundLong, longString[20], latString[20]; //if (longVal > 180000010 || longVal < -180000000) return; //if (longVal > 360000010 || longVal < -180000000) return; if (longVal > 360000010 || longVal < -360000000) return; //x = SameDifferenceX(longVal); view.loLat = _min(view.loLat, 90000000); view.loLat = _max(view.loLat, -90000000); //y1 = (r.bottom + r.top) - SameDifferenceY(view.loLat); x_y1 = GetQuickDrawPt(longVal,view.loLat,&r,&offQuickDrawPlane); view.hiLat = _min(view.hiLat, 90000000); view.hiLat = _max(view.hiLat, -90000000); //y2 = (r.bottom + r.top) - SameDifferenceY(view.hiLat); x_y2 = GetQuickDrawPt(longVal,view.hiLat,&r,&offQuickDrawPlane); // RGBForeColor(&colors[label ? BLACK : LIGHTGRAY]); RGBForeColor(&colors[LIGHTGRAY]); // SetPenPat(label ? BLACK : GRAY); // MyMoveTo(x, y1 - 20); //MyMoveTo(x, y1); // bottom edge of view //MyLineTo(x, y2 - 1); // top edge of view MyMoveTo(x_y1.h, x_y1.v); // bottom edge of view MyLineTo(x_y2.h, x_y2.v - 1); // top edge of view if (label) { RGBForeColor(&colors[BLACK]); wp.pLong = longVal; wp.pLat = 0; WorldPointToStrings2(wp, latString, &roundLat, longString, &roundLong); SimplifyLLString(longString, precision, roundLong); w = stringwidth(longString); //MyMoveTo(x - (w / 2), y1 - 1); MyMoveTo(x_y1.h - (w / 2), x_y1.v - 1); drawstring(longString); } }
void frinit(Frame *f, Rectangle r, Font *ft, Image *b, Image *cols[NCOL]) { f->font = ft; f->display = b->display; f->maxtab = 8*stringwidth(ft, "0"); f->nbox = 0; f->nalloc = 0; f->nchars = 0; f->nlines = 0; f->p0 = 0; f->p1 = 0; f->box = 0; f->lastlinefull = 0; if(cols != 0) memmove(f->cols, cols, sizeof f->cols); frsetrects(f, r, b); if(f->tick==nil && f->cols[BACK]!=0) frinittick(f); }
void HiliteObjectsRect(DialogPtr w, RECTPTR r, long n) // limits the horizontal selection based on text string width { char s[256]; short left, right, style = normal; ListItem item = model->GetNthListItem(n, 0, &style, s); if (item.owner == 0) return; TextFontSizeFace(kFontIDGeneva,LISTTEXTSIZE,style); right = DrawBullet(item, r, FALSE, 0); left = right + 3; if (left > r->left) r->left = left; right = r->left + stringwidth(s) + 3; if (right < r->right) r->right = right; // selects only upto right edge of text TextFontSizeFace(kFontIDGeneva,LISTTEXTSIZE,normal); }
void drawdisc(Image *scr, DAngle semidiam, int ring, Image *color, Point pt, char *s) { int d; d = npixels(semidiam*2); if(d < 5) d = 5; fillellipse(scr, pt, d, d, color, ZP); if(ring == 1) ellipse(scr, pt, 5*d/2, d/2, 0, color, ZP); if(ring == 2) ellipse(scr, pt, d, d, 0, grey, ZP); if(s){ d = stringwidth(font, s); pt.x -= d/2; pt.y -= font->height/2 + 1; string(scr, pt, display->black, ZP, font, s); } }
static void paintitem(Image *m, Menu *menu, Rectangle textr, int off, int i, int highlight, Image *save, Image *restore) { char *item; Rectangle r; Point pt; if(i < 0) return; r = menurect(textr, i); if(restore){ draw(m, r, restore, nil, restore->r.min); return; } if(save) draw(save, save->r, m, nil, r.min); item = menu->item? menu->item[i+off] : (*menu->gen)(i+off); pt.x = (textr.min.x+textr.max.x-stringwidth(font, item))/2; pt.y = textr.min.y+i*(font->height+Vspacing); draw(m, r, highlight? high : back, nil, pt); string(m, pt, highlight? htext : text, pt, font, item); }
void resize(void) { int i, j, k, n, startx, starty, x, y, dx, dy, ly, ondata, maxx, wid, nlab; Graph *g; Rectangle machr, r; uint64_t v, vmax; char buf[128], labs[Nlab][Lablen]; draw(screen, screen->r, display->white, nil, ZP); /* label left edge */ x = screen->r.min.x; y = screen->r.min.y + Labspace+mediumfont->height+Labspace; dy = (screen->r.max.y - y)/ngraph; dx = Labspace+stringwidth(mediumfont, "0")+Labspace; startx = x+dx+1; starty = y; for(i=0; i<ngraph; i++,y+=dy){ draw(screen, Rect(x, y-1, screen->r.max.x, y), display->black, nil, ZP); draw(screen, Rect(x, y, x+dx, screen->r.max.y), cols[graph[i].colindex][0], nil, paritypt(x)); label(Pt(x, y), dy, graph[i].label); draw(screen, Rect(x+dx, y, x+dx+1, screen->r.max.y), cols[graph[i].colindex][2], nil, ZP); } /* label top edge */ dx = (screen->r.max.x - startx)/nmach; for(x=startx, i=0; i<nmach; i++,x+=dx){ draw(screen, Rect(x-1, starty-1, x, screen->r.max.y), display->black, nil, ZP); j = dx/stringwidth(mediumfont, "0"); n = mach[i].nproc; if(n>1 && j>=1+3+mach[i].lgproc){ /* first char of name + (n) */ j -= 3+mach[i].lgproc; if(j <= 0) j = 1; snprint(buf, sizeof buf, "%.*s(%d)", j, mach[i].shortname, n); }else snprint(buf, sizeof buf, "%.*s", j, mach[i].shortname); string(screen, Pt(x+Labspace, screen->r.min.y + Labspace), display->black, ZP, mediumfont, buf); } maxx = screen->r.max.x; /* label right, if requested */ if(ylabels && dy>Nlab*(mediumfont->height+1)){ wid = labelwidth(); if(wid < (maxx-startx)-30){ /* else there's not enough room */ maxx -= 1+Lx+wid; draw(screen, Rect(maxx, starty, maxx+1, screen->r.max.y), display->black, nil, ZP); y = starty; for(j=0; j<ngraph; j++, y+=dy){ /* choose value for rightmost graph */ g = &graph[ngraph*(nmach-1)+j]; labelstrs(g, labs, &nlab); r = Rect(maxx+1, y, screen->r.max.x, y+dy-1); if(j == ngraph-1) r.max.y = screen->r.max.y; draw(screen, r, cols[g->colindex][0], nil, paritypt(r.min.x)); for(k=0; k<nlab; k++){ ly = y + (dy*(nlab-k)/(nlab+1)); draw(screen, Rect(maxx+1, ly, maxx+1+Lx, ly+1), display->black, nil, ZP); ly -= mediumfont->height/2; string(screen, Pt(maxx+1+Lx, ly), display->black, ZP, mediumfont, labs[k]); } } } } /* create graphs */ for(i=0; i<nmach; i++){ machr = Rect(startx+i*dx, starty, maxx, screen->r.max.y); if(i < nmach-1) machr.max.x = startx+(i+1)*dx - 1; y = starty; for(j=0; j<ngraph; j++, y+=dy){ g = &graph[i*ngraph+j]; /* allocate data */ ondata = g->ndata; g->ndata = Dx(machr)+1; /* may be too many if label will be drawn here; so what? */ g->data = erealloc(g->data, g->ndata*sizeof(g->data[0])); if(g->ndata > ondata) memset(g->data+ondata, 0, (g->ndata-ondata)*sizeof(g->data[0])); /* set geometry */ g->r = machr; g->r.min.y = y; g->r.max.y = y+dy - 1; if(j == ngraph-1) g->r.max.y = screen->r.max.y; draw(screen, g->r, cols[g->colindex][0], nil, paritypt(g->r.min.x)); g->overflow = 0; r = g->r; r.max.y = r.min.y+mediumfont->height; r.max.x = r.min.x+stringwidth(mediumfont, "999999999999"); freeimage(g->overtmp); g->overtmp = nil; if(r.max.x <= g->r.max.x) g->overtmp = allocimage(display, r, screen->chan, 0, -1); g->newvalue(g->mach, &v, &vmax, 0); redraw(g, vmax); } } flushimage(display, 1); }
void plot(char *flags) { int i, j, k; char *t; int32_t x, y; int ra, dec; int m; Point p, pts[10]; Record *r; Rectangle rect, r1; int dx, dy, nogrid, textlevel, nogrey, zenithup; Image *scr; char *name, buf[32]; double v; if(plotopen() < 0) return; nogrid = 0; nogrey = 0; textlevel = 1; dx = 512; dy = 512; zenithup = 0; for(;;){ if(t = alpha(flags, "nogrid")){ nogrid = 1; flags = t; continue; } if((t = alpha(flags, "zenith")) || (t = alpha(flags, "zenithup")) ){ zenithup = 1; flags = t; continue; } if((t = alpha(flags, "notext")) || (t = alpha(flags, "nolabel")) ){ textlevel = 0; flags = t; continue; } if((t = alpha(flags, "alltext")) || (t = alpha(flags, "alllabel")) ){ textlevel = 2; flags = t; continue; } if(t = alpha(flags, "dx")){ dx = strtol(t, &t, 0); if(dx < 100){ fprint(2, "dx %d too small (min 100) in plot\n", dx); return; } flags = skipbl(t); continue; } if(t = alpha(flags, "dy")){ dy = strtol(t, &t, 0); if(dy < 100){ fprint(2, "dy %d too small (min 100) in plot\n", dy); return; } flags = skipbl(t); continue; } if((t = alpha(flags, "nogrey")) || (t = alpha(flags, "nogray"))){ nogrey = 1; flags = skipbl(t); continue; } if(*flags){ fprint(2, "syntax error in plot\n"); return; } break; } flatten(); folded = 0; if(bbox(0, 0, 1) < 0) return; if(ramax-ramin<100 || decmax-decmin<100){ fprint(2, "plot too small\n"); return; } scr = allocimage(display, Rect(0, 0, dx, dy), RGB24, 0, DBlack); if(scr == nil){ fprint(2, "can't allocate image: %r\n"); return; } rect = scr->r; rect.min.x += 16; rect = insetrect(rect, 40); if(setmap(ramin, ramax, decmin, decmax, rect, zenithup) < 0){ fprint(2, "can't set up map coordinates\n"); return; } if(!nogrid){ for(x=ramin; ; ){ for(j=0; j<nelem(pts); j++){ /* use double to avoid overflow */ v = (double)j / (double)(nelem(pts)-1); v = decmin + v*(decmax-decmin); pts[j] = map(x, v); } bezspline(scr, pts, nelem(pts), Endsquare, Endsquare, 0, GREY, ZP); ra = x; if(folded){ ra -= 180*c; if(ra < 0) ra += 360*c; } p = pts[0]; p.x -= stringwidth(font, hm5(angle(ra)))/2; string(scr, p, GREY, ZP, font, hm5(angle(ra))); p = pts[nelem(pts)-1]; p.x -= stringwidth(font, hm5(angle(ra)))/2; p.y -= font->height; string(scr, p, GREY, ZP, font, hm5(angle(ra))); if(x == ramax) break; x += gridra(mapdec); if(x > ramax) x = ramax; } for(y=decmin; y<=decmax; y+=c){ for(j=0; j<nelem(pts); j++){ /* use double to avoid overflow */ v = (double)j / (double)(nelem(pts)-1); v = ramin + v*(ramax-ramin); pts[j] = map(v, y); } bezspline(scr, pts, nelem(pts), Endsquare, Endsquare, 0, GREY, ZP); p = pts[0]; p.x += 3; p.y -= font->height/2; string(scr, p, GREY, ZP, font, deg(angle(y))); p = pts[nelem(pts)-1]; p.x -= 3+stringwidth(font, deg(angle(y))); p.y -= font->height/2; string(scr, p, GREY, ZP, font, deg(angle(y))); } } /* reorder to get planets in front of stars */ tolast(nil); tolast("moon"); /* moon is in front of everything... */ tolast("shadow"); /* ... except the shadow */ for(i=0,r=rec; i<nrec; i++,r++){ dec = r->ngc.dec; ra = r->ngc.ra; if(folded){ ra -= 180*c; if(ra < 0) ra += 360*c; } if(textlevel){ name = nameof(r); if(name==nil && textlevel>1 && r->type==SAO){ snprint(buf, sizeof buf, "SAO%ld", r->index); name = buf; } if(name) drawname(scr, nogrey? display->white : alphagrey, name, ra, dec); } if(r->type == Planet){ drawplanet(scr, &r->planet, map(ra, dec)); continue; } if(r->type == SAO){ m = r->sao.mag; if(m == UNKNOWNMAG) m = r->sao.mpg; if(m == UNKNOWNMAG) continue; m = dsize(m); if(m < 3) fillellipse(scr, map(ra, dec), m, m, nogrey? display->white : lightgrey, ZP); else{ ellipse(scr, map(ra, dec), m+1, m+1, 0, display->black, ZP); fillellipse(scr, map(ra, dec), m, m, display->white, ZP); } continue; } if(r->type == Abell){ ellipse(scr, addpt(map(ra, dec), Pt(-3, 2)), 2, 1, 0, lightblue, ZP); ellipse(scr, addpt(map(ra, dec), Pt(3, 2)), 2, 1, 0, lightblue, ZP); ellipse(scr, addpt(map(ra, dec), Pt(0, -2)), 1, 2, 0, lightblue, ZP); continue; } switch(r->ngc.type){ case Galaxy: j = npixels(r->ngc.diam); if(j < 4) j = 4; if(j > 10) k = j/3; else k = j/2; ellipse(scr, map(ra, dec), j, k, 0, lightblue, ZP); break; case PlanetaryN: p = map(ra, dec); j = npixels(r->ngc.diam); if(j < 3) j = 3; ellipse(scr, p, j, j, 0, green, ZP); line(scr, Pt(p.x, p.y+j+1), Pt(p.x, p.y+j+4), Endsquare, Endsquare, 0, green, ZP); line(scr, Pt(p.x, p.y-(j+1)), Pt(p.x, p.y-(j+4)), Endsquare, Endsquare, 0, green, ZP); line(scr, Pt(p.x+j+1, p.y), Pt(p.x+j+4, p.y), Endsquare, Endsquare, 0, green, ZP); line(scr, Pt(p.x-(j+1), p.y), Pt(p.x-(j+4), p.y), Endsquare, Endsquare, 0, green, ZP); break; case DiffuseN: case NebularCl: p = map(ra, dec); j = npixels(r->ngc.diam); if(j < 4) j = 4; r1.min = Pt(p.x-j, p.y-j); r1.max = Pt(p.x+j, p.y+j); if(r->ngc.type != DiffuseN) draw(scr, r1, ocstipple, ocstipple, ZP); line(scr, Pt(p.x-j, p.y-j), Pt(p.x+j, p.y-j), Endsquare, Endsquare, 0, green, ZP); line(scr, Pt(p.x-j, p.y+j), Pt(p.x+j, p.y+j), Endsquare, Endsquare, 0, green, ZP); line(scr, Pt(p.x-j, p.y-j), Pt(p.x-j, p.y+j), Endsquare, Endsquare, 0, green, ZP); line(scr, Pt(p.x+j, p.y-j), Pt(p.x+j, p.y+j), Endsquare, Endsquare, 0, green, ZP); break; case OpenCl: p = map(ra, dec); j = npixels(r->ngc.diam); if(j < 4) j = 4; fillellipse(scr, p, j, j, ocstipple, ZP); break; case GlobularCl: j = npixels(r->ngc.diam); if(j < 4) j = 4; p = map(ra, dec); ellipse(scr, p, j, j, 0, lightgrey, ZP); line(scr, Pt(p.x-(j-1), p.y), Pt(p.x+j, p.y), Endsquare, Endsquare, 0, lightgrey, ZP); line(scr, Pt(p.x, p.y-(j-1)), Pt(p.x, p.y+j), Endsquare, Endsquare, 0, lightgrey, ZP); break; } } flushimage(display, 1); displayimage(scr); }
void initialize(int argc, char **argv) { int i, blkbg; char *fontname, *p; rfork(RFNAMEG|RFNOTEG); fontname = nil; term = "vt100"; fk = vt100fk; blkbg = nocolor = 0; ARGBEGIN{ case '2': term = "vt220"; fk = vt220fk; break; case 'a': term = "ansi"; fk = ansifk; break; case 'b': blkbg = 1; /* e.g., for linux colored output */ break; case 'c': nocolor = 1; break; case 'f': fontname = EARGF(usage()); break; case 'l': p = EARGF(usage()); logfd = create(p, OWRITE, 0666); if(logfd < 0) sysfatal("could not create log file: %s: %r", p); break; case 'x': fk = xtermfk; term = "xterm"; break; default: usage(); break; }ARGEND; host_buf = malloc(host_bsize); hostp = host_buf; hostlength = 0; if(initdraw(0, fontname, term) < 0){ fprint(2, "%s: initdraw failed: %r\n", term); exits("initdraw"); } werrstr(""); /* clear spurious error messages */ ebegin(Ehost); histp = hist; menu2.item = menutext2; menu3.item = menutext3; pagemode = 0; blocked = 0; NS = font->height; CW = stringwidth(font, "m"); red = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DRed); bordercol = allocimage(display, Rect(0,0,1,1), screen->chan, 1, 0xCCCCCCCC); cursback = allocimage(display, Rect(0, 0, CW+1, NS+1), screen->chan, 0, DNofill); for(i=0; i<8; i++){ colors[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, rgbacolors[i]); hicolors[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, rgbahicolors[i]); } bgdefault = (blkbg? display->black: display->white); fgdefault = (blkbg? display->white: display->black); bgcolor = bgdefault; fgcolor = fgdefault; resize(); if(argc > 0) { sendnchars(strlen(argv[0]),argv[0]); sendnchars(1,"\n"); } }
int menuhit(int but, Mousectl *mc, Menu *menu, Screen *scr) { int i, nitem, nitemdrawn, maxwid, lasti, off, noff, wid, screenitem; int scrolling; Rectangle r, menur, sc, textr, scrollr; Image *b, *save, *backup; Point pt; char *item; if(back == nil) menucolors(); sc = screen->clipr; replclipr(screen, 0, screen->r); maxwid = 0; for(nitem = 0; item = menu->item? menu->item[nitem] : (*menu->gen)(nitem); nitem++){ i = stringwidth(font, item); if(i > maxwid) maxwid = i; } if(menu->lasthit<0 || menu->lasthit>=nitem) menu->lasthit = 0; screenitem = (Dy(screen->r)-10)/(font->height+Vspacing); if(nitem>Maxunscroll || nitem>screenitem){ scrolling = 1; nitemdrawn = Nscroll; if(nitemdrawn > screenitem) nitemdrawn = screenitem; wid = maxwid + Gap + Scrollwid; off = menu->lasthit - nitemdrawn/2; if(off < 0) off = 0; if(off > nitem-nitemdrawn) off = nitem-nitemdrawn; lasti = menu->lasthit-off; }else{ scrolling = 0; nitemdrawn = nitem; wid = maxwid; off = 0; lasti = menu->lasthit; } r = insetrect(Rect(0, 0, wid, nitemdrawn*(font->height+Vspacing)), -Margin); r = rectsubpt(r, Pt(wid/2, lasti*(font->height+Vspacing)+font->height/2)); r = rectaddpt(r, mc->m.xy); pt = ZP; if(r.max.x>screen->r.max.x) pt.x = screen->r.max.x-r.max.x; if(r.max.y>screen->r.max.y) pt.y = screen->r.max.y-r.max.y; if(r.min.x<screen->r.min.x) pt.x = screen->r.min.x-r.min.x; if(r.min.y<screen->r.min.y) pt.y = screen->r.min.y-r.min.y; menur = rectaddpt(r, pt); textr.max.x = menur.max.x-Margin; textr.min.x = textr.max.x-maxwid; textr.min.y = menur.min.y+Margin; textr.max.y = textr.min.y + nitemdrawn*(font->height+Vspacing); if(scrolling){ scrollr = insetrect(menur, Border); scrollr.max.x = scrollr.min.x+Scrollwid; }else scrollr = Rect(0, 0, 0, 0); if(scr){ b = allocwindow(scr, menur, Refbackup, DWhite); if(b == nil) b = screen; backup = nil; }else{ b = screen; backup = allocimage(display, menur, screen->chan, 0, -1); if(backup) draw(backup, menur, screen, nil, menur.min); } draw(b, menur, back, nil, ZP); border(b, menur, Blackborder, bord, ZP); save = allocimage(display, menurect(textr, 0), screen->chan, 0, -1); r = menurect(textr, lasti); moveto(mc, divpt(addpt(r.min, r.max), 2)); menupaint(b, menu, textr, off, nitemdrawn); if(scrolling) menuscrollpaint(b, scrollr, off, nitem, nitemdrawn); while(mc->m.buttons & (1<<(but-1))){ lasti = menuscan(b, menu, but, mc, textr, off, lasti, save); if(lasti >= 0) break; while(!ptinrect(mc->m.xy, textr) && (mc->m.buttons & (1<<(but-1)))){ if(scrolling && ptinrect(mc->m.xy, scrollr)){ noff = ((mc->m.xy.y-scrollr.min.y)*nitem)/Dy(scrollr); noff -= nitemdrawn/2; if(noff < 0) noff = 0; if(noff > nitem-nitemdrawn) noff = nitem-nitemdrawn; if(noff != off){ off = noff; menupaint(b, menu, textr, off, nitemdrawn); menuscrollpaint(b, scrollr, off, nitem, nitemdrawn); } } readmouse(mc); } } if(b != screen) freeimage(b); if(backup){ draw(screen, menur, backup, nil, menur.min); freeimage(backup); } freeimage(save); replclipr(screen, 0, sc); flushimage(display, 1); if(lasti >= 0){ menu->lasthit = lasti+off; return menu->lasthit; } return -1; }
int eenter(char *ask, char *buf, int len, Mouse *m) { int done, down, tick, n, h, w, l, i; Image *b, *save, *backcol, *bordcol; Point p, o, t; Rectangle r, sc; Event ev; Rune k; o = screen->r.min; backcol = allocimagemix(display, DPurpleblue, DWhite); bordcol = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DPurpleblue); if(backcol == nil || bordcol == nil) return -1; while(ecankbd()) ekbd(); if(m) o = m->xy; if(buf && len > 0) n = strlen(buf); else { buf = nil; len = 0; n = 0; } k = -1; tick = n; save = nil; done = down = 0; p = stringsize(font, " "); h = p.y; w = p.x; b = screen; sc = b->clipr; replclipr(b, 0, b->r); while(!done){ p = stringsize(font, buf ? buf : ""); if(ask && ask[0]){ if(buf) p.x += w; p.x += stringwidth(font, ask); } r = rectaddpt(insetrect(Rpt(ZP, p), -4), o); p.x = 0; r = rectsubpt(r, p); p = ZP; if(r.min.x < screen->r.min.x) p.x = screen->r.min.x - r.min.x; if(r.min.y < screen->r.min.y) p.y = screen->r.min.y - r.min.y; r = rectaddpt(r, p); p = ZP; if(r.max.x > screen->r.max.x) p.x = r.max.x - screen->r.max.x; if(r.max.y > screen->r.max.y) p.y = r.max.y - screen->r.max.y; r = rectsubpt(r, p); r = insetrect(r, -2); if(save == nil){ save = allocimage(display, r, b->chan, 0, DNofill); if(save == nil){ n = -1; break; } draw(save, r, b, nil, r.min); } draw(b, r, backcol, nil, ZP); border(b, r, 2, bordcol, ZP); p = addpt(r.min, Pt(6, 6)); if(ask && ask[0]){ p = string(b, p, bordcol, ZP, font, ask); if(buf) p.x += w; } if(buf){ t = p; p = stringn(b, p, display->black, ZP, font, buf, utfnlen(buf, tick)); draw(b, Rect(p.x-1, p.y, p.x+2, p.y+3), display->black, nil, ZP); draw(b, Rect(p.x, p.y, p.x+1, p.y+h), display->black, nil, ZP); draw(b, Rect(p.x-1, p.y+h-3, p.x+2, p.y+h), display->black, nil, ZP); p = string(b, p, display->black, ZP, font, buf+tick); } flushimage(display, 1); nodraw: i = Ekeyboard; if(m != nil) i |= Emouse; replclipr(b, 0, sc); i = eread(i, &ev); /* screen might have been resized */ if(b != screen || !eqrect(screen->clipr, sc)){ freeimage(save); save = nil; } b = screen; sc = b->clipr; replclipr(b, 0, b->r); switch(i){ default: done = 1; n = -1; break; case Ekeyboard: k = ev.kbdc; if(buf == nil || k == Keof || k == '\n'){ done = 1; break; } if(k == Knack || k == Kesc){ done = !n; buf[n = tick = 0] = 0; break; } if(k == Ksoh || k == Khome){ tick = 0; continue; } if(k == Kenq || k == Kend){ tick = n; continue; } if(k == Kright){ if(tick < n) tick += chartorune(&k, buf+tick); continue; } if(k == Kleft){ for(i = 0; i < n; i += l){ l = chartorune(&k, buf+tick); if(i+l >= tick){ tick = i; break; } } continue; } if(k == Ketb){ while(tick > 0){ tick--; if(tick == 0 || strchr(" !\"#$%&'()*+,-./:;<=>?@`[\\]^{|}~", buf[tick-1])) break; } buf[n = tick] = 0; break; } if(k == Kbs){ if(tick <= 0) continue; for(i = 0; i < n; i += l){ l = chartorune(&k, buf+i); if(i+l >= tick){ memmove(buf+i, buf+i+l, n - (i+l)); buf[n -= l] = 0; tick -= l; break; } } break; } if(k < 0x20 || k == Kdel || (k & 0xFF00) == KF || (k & 0xFF00) == Spec) continue; if((len-n) <= (l = runelen(k))) continue; memmove(buf+tick+l, buf+tick, n - tick); runetochar(buf+tick, &k); buf[n += l] = 0; tick += l; break; case Emouse: *m = ev.mouse; if(!ptinrect(m->xy, r)){ down = 0; goto nodraw; } if(m->buttons & 7){ down = 1; if(buf && m->xy.x >= (t.x - w)){ down = 0; for(i = 0; i < n; i += l){ l = chartorune(&k, buf+i); t.x += stringnwidth(font, buf+i, 1); if(t.x > m->xy.x) break; } tick = i; } continue; } done = down; break; } if(save){ draw(b, save->r, save, nil, save->r.min); freeimage(save); save = nil; } } replclipr(b, 0, sc); freeimage(backcol); freeimage(bordcol); flushimage(display, 1); return n; }
uint textload(Text *t, uint q0, char *file, int setqid) { Rune *rp; Dirlist *dl, **dlp; int fd, i, j, n, ndl, nulls; uint q, q1; Dir *d, *dbuf; char *tmp; Text *u; if(t->ncache!=0 || t->file->nc || t->w==nil || t!=&t->w->body) error("text.load"); if(t->w->isdir && t->file->nname==0){ warning(nil, "empty directory name\n"); return 0; } fd = open(file, OREAD); if(fd < 0){ warning(nil, "can't open %s: %r\n", file); return 0; } d = dirfstat(fd); if(d == nil){ warning(nil, "can't fstat %s: %r\n", file); goto Rescue; } nulls = FALSE; if(d->qid.type & QTDIR){ /* this is checked in get() but it's possible the file changed underfoot */ if(t->file->ntext > 1){ warning(nil, "%s is a directory; can't read with multiple windows on it\n", file); goto Rescue; } t->w->isdir = TRUE; t->w->filemenu = FALSE; if(t->file->name[t->file->nname-1] != '/'){ rp = runemalloc(t->file->nname+1); runemove(rp, t->file->name, t->file->nname); rp[t->file->nname] = '/'; winsetname(t->w, rp, t->file->nname+1); free(rp); } dlp = nil; ndl = 0; dbuf = nil; while((n=dirread(fd, &dbuf)) > 0){ for(i=0; i<n; i++){ dl = emalloc(sizeof(Dirlist)); j = strlen(dbuf[i].name); tmp = emalloc(j+1+1); memmove(tmp, dbuf[i].name, j); if(dbuf[i].qid.type & QTDIR) tmp[j++] = '/'; tmp[j] = '\0'; dl->r = bytetorune(tmp, &dl->nr); dl->wid = stringwidth(t->font, tmp); free(tmp); ndl++; dlp = realloc(dlp, ndl*sizeof(Dirlist*)); dlp[ndl-1] = dl; } free(dbuf); } qsort(dlp, ndl, sizeof(Dirlist*), dircmp); t->w->dlp = dlp; t->w->ndl = ndl; textcolumnate(t, dlp, ndl); q1 = t->file->nc; }else{ t->w->isdir = FALSE; t->w->filemenu = TRUE; q1 = q0 + fileload(t->file, q0, fd, &nulls); } if(setqid){ t->file->dev = d->dev; t->file->mtime = d->mtime; t->file->qidpath = d->qid.path; } close(fd); rp = fbufalloc(); for(q=q0; q<q1; q+=n){ n = q1-q; if(n > RBUFSIZE) n = RBUFSIZE; bufread(t->file, q, rp, n); if(q < t->org) t->org += n; else if(q <= t->org+t->nchars) frinsert(t, rp, rp+n, q-t->org); if(t->lastlinefull) break; } fbuffree(rp); for(i=0; i<t->file->ntext; i++){ u = t->file->text[i]; if(u != t){ if(u->org > u->file->nc) /* will be 0 because of reset(), but safety first */ u->org = 0; textresize(u, u->all); textbacknl(u, u->org, 0); /* go to beginning of line */ } textsetselect(u, q0, q0); } if(nulls) warning(nil, "%s: NUL bytes elided\n", file); free(d); return q1-q0; Rescue: close(fd); return 0; }
int tktdispwidth(Tk *tk, TkTtabstop *tb, TkTitem *i, Font *f, int x, int pos, int nchars) { int w, del, locked; TkTtabstop *tbprev; Display *d; TkText *tkt; TkEnv env; tkt = TKobj(TkText, tk); d = tk->env->top->display; if (tb == nil) tb = tkt->tabs; switch(i->kind) { case TkTrune: pos = tktutfpos(i->istring, pos); /* FALLTHRU */ case TkTascii: if(f == nil) { if(!tktanytags(i)) f = tk->env->font; else { tkttagopts(tk, i, nil, &env, nil, 1); f = env.font; } } locked = 0; if(!(tkt->tflag&TkTdlocked)) locked = lockdisplay(d); if(nchars >= 0) w = stringnwidth(f, i->istring+pos, nchars); else w = stringwidth(f, i->istring+pos); if(locked) unlockdisplay(d); break; case TkTtab: if(tb == nil) w = 0; else { tbprev = nil; while(tb->pos <= x && tb->next != nil) { tbprev = tb; tb = tb->next; } w = tb->pos - x; if(w <= 0) { del = tb->pos; if(tbprev != nil) del -= tbprev->pos; while(w <= 0) w += del; } /* todo: other kinds of justification */ } break; case TkTwin: if(i->iwin->sub == 0) w = 0; else w = i->iwin->sub->act.width + 2*i->iwin->padx + 2*i->iwin->sub->borderwidth; break; default: w = 0; } return w; }
int charwidth(char c, TTF_Font *font) { char s[2]; s[0] = c; s[1] = 0; return stringwidth(s, font); }
void getwidth(void) { CFsys *fs; char buf[500], *p, *q, *f[10]; int fd, n, nf; struct winsize ws; Font *f1; if((p = getenv("winid")) != nil){ fs = nsmount("acme", ""); if(fs == nil) return; snprint(buf, sizeof buf, "acme/%d/ctl", atoi(p)); if((fd = fsopenfd(fs, buf, OREAD)) < 0) return; if((n=readn(fd, buf, sizeof buf-1)) <= 0) return; buf[n] = 0; if((nf=tokenize(buf, f, nelem(f))) < 7) return; tabwid = 0; if(nf >= 8 && (tabwid = atoi(f[7])) == 0) return; if((font = openfont(nil, f[6])) == nil) return; mintab = stringwidth(font, "0"); if(tabwid == 0) tabwid = mintab*4; linewidth = atoi(f[5]); tabflag = 1; return; } if((p = getenv("termprog")) != nil && strcmp(p, "9term") == 0) if((p = getenv("font")) != nil) font = openfont(nil, p); if(windowrect(&ws) < 0) return; if(ws.ws_xpixel == 0) font = nil; if(font){ // 9term leaves "is this a hidpi display" in the low bit of the ypixel height. if(ws.ws_ypixel&1) { // need hidpi font. // loadhifpi creates a font that crashes in stringwidth, // for reasons i don't understand. // do it ourselves p = getenv("font"); q = strchr(p, ','); f1 = nil; if(q != nil) f1 = openfont(nil, q+1); if(f1 != nil) font = f1; else ws.ws_xpixel /= 2; } mintab = stringwidth(font, "0"); if((p = getenv("tabstop")) != nil) tabwid = atoi(p)*mintab; else tabwid = 4*mintab; tabflag = 1; linewidth = ws.ws_xpixel; }else linewidth = ws.ws_col; }
void lockscreen(void) { enum { Nfld = 5, Fldlen = 12, Cursorlen = 2*4 + 2*2*16, }; char *s; char buf[Nfld*Fldlen], *flds[Nfld], newcmd[128], cbuf[Cursorlen]; int fd, dx, dy; Image *i; Point p; Rectangle r; Tm *tm; fd = open("/dev/screen", OREAD); if(fd < 0) error("can't open /dev/screen: %r"); if(read(fd, buf, Nfld*Fldlen) != Nfld*Fldlen) error("can't read /dev/screen: %r"); close(fd); buf[sizeof buf-1] = 0; if(tokenize(buf, flds, Nfld) != Nfld) error("can't tokenize /dev/screen header"); snprint(newcmd, sizeof newcmd, "-r %s %s %d %d", flds[1], flds[2], atoi(flds[3]) - 1, atoi(flds[4]) - 1); newwindow(newcmd); if (initdraw(nil, nil, "screenlock") < 0) sysfatal("initdraw failed"); if(display == nil) error("no display"); /* screen is now open and covered. grab mouse and hold on tight */ procrfork(grabmouse, nil, 4096, RFFDG); procrfork(blanker, nil, 4096, RFFDG); fd = open(pic, OREAD); if(fd > 0){ i = readimage(display, fd, 0); if(i){ r = screen->r; p = Pt(r.max.x / 2, r.max.y * 2 / 3); dx = (Dx(screen->r) - Dx(i->r)) / 2; r.min.x += dx; r.max.x -= dx; dy = (Dy(screen->r) - Dy(i->r)) / 2; r.min.y += dy; r.max.y -= dy; draw(screen, screen->r, display->black, nil, ZP); draw(screen, r, i, nil, i->r.min); flushimage(display, 1); } close(fd); /* identify the user on screen, centered */ tm = localtime(time(0)); s = smprint("user %s at %d:%02.2d", getuser(), tm->hour, tm->min); p = subpt(p, Pt(stringwidth(font, "m") * strlen(s) / 2, 0)); screenstring(p, s); } /* clear the cursor */ fd = open("/dev/cursor", OWRITE); if(fd > 0){ memset(cbuf, 0, sizeof cbuf); write(fd, cbuf, sizeof cbuf); /* leave it open */ } }
static void tkscalehoriz(Tk *tk, Image *i) { TkEnv *e; char sv[32]; TkScale *tks; Image *d, *l; Rectangle r, r2, sr; Point p, q; int fh, sh, gh, sl, v, w, h, len; int fgnd; e = tk->env; tks = TKobj(TkScale, tk); fh = e->font->height; fgnd = TkCforegnd; if (tk->flag & Tkdisabled) fgnd = TkCdisablefgnd; r = Rect(0, 0, tk->act.width, tk->act.height); r = rectaddpt(r, Pt(tk->borderwidth, tk->borderwidth)); r = insetrect(r, tk->highlightwidth); r = insetrect(r, ScalePad); if(tks->label != nil) { string(i, r.min, tkgc(e, fgnd), ZP, e->font, tks->label); r.min.y += fh + ScalePad; } if(tks->sv == BoolT) r.min.y += fh + ScalePad; sr = insetrect(r, ScaleBW); w = Dx(sr); h = Dy(sr); sl = tks->sl + 2*ScaleBW; l = tkgc(e, TkCbackgndlght); d = tkgc(e, TkCbackgnddark); tkbevel(i, r.min, w, h, ScaleBW, d, l); tks->pixmin = sr.min.x; tks->pixmax = sr.max.x; sh = h - 2*ScaleBW; tks->sw = sh/2; w -= sl; if (w <= 0) w = 1; p.x = sr.min.x; p.y = sr.max.y; if(tks->tick > 0){ int j, t, l; t = tks->tick; l = tks->to-tks->from; if (l < 0) l = -l; if (l == 0) l = 1; r2.min.y = p.y; r2.max.y = p.y + ScaleBW + ScalePad; for(j = 0; j <= l; j += t){ r2.min.x = p.x+((vlong)j*w)/l+sl/2; r2.max.x = r2.min.x+1; draw(i, r2, tkgc(e, fgnd), nil, ZP); } } v = tks->value-tks->from; len = tks->to-tks->from; if (len != 0) p.x += ((vlong)v*w)/len; p.y = sr.min.y; q = p; q.x += tks->sl/2 + 1; if(ScaleBW > 1) { gh = sh; q.y++; } else gh = sh-1; if(tk->flag & Tkactivated) { r2.min = p; r2.max.x = p.x+sl; r2.max.y = sr.max.y; draw(i, r2, tkgc(e, TkCactivebgnd), nil, ZP); } switch(tks->relief) { case TKsunken: tkbevel(i, p, tks->sl, sh, ScaleBW, d, l); tkbevel(i, q, 0, gh, 1, l, d); break; case TKraised: tkbevel(i, p, tks->sl, sh, ScaleBW, l, d); tkbevel(i, q, 0, gh, 1, d, l); break; } tks->pixpos = p.x; tks->center = p.y + sh/2 + ScaleBW; if(tks->sv != BoolT) return; tkfprint(sv, tks->value); if(tks->digits > 0 && tks->digits < strlen(sv)) sv[tks->digits] = '\0'; w = stringwidth(e->font, sv); p.x = q.x; p.x -= w/2; p.y = r.min.y - fh - ScalePad; if(p.x < tks->pixmin) p.x = tks->pixmin; if(p.x+w > tks->pixmax) p.x = tks->pixmax - w; string(i, p, tkgc(e, fgnd), ZP, e->font, sv); }
static void tkscalevert(Tk *tk, Image *i) { TkEnv *e; TkScale *tks; char sv[32]; Image *d, *l; Rectangle r, r2, sr; Point p, q; int fh, v, sw, gw, w, h, len, sl; int fgnd; e = tk->env; tks = TKobj(TkScale, tk); fh = e->font->height; fgnd = TkCforegnd; if (tk->flag & Tkdisabled) fgnd = TkCdisablefgnd; r = Rect(0, 0, tk->act.width, tk->act.height); r = rectaddpt(r, Pt(tk->borderwidth, tk->borderwidth)); r = insetrect(r, tk->highlightwidth); r = insetrect(r, ScalePad); if (tks->sv) r.min.x += tks->digwidth + ScalePad; if(tks->label != nil) { p = stringsize(e->font, tks->label); r.max.x -= p.x; string(i, Pt(r.max.x, r.min.y), tkgc(e, fgnd), ZP, e->font, tks->label); r.max.x -= ScalePad; } sr = insetrect(r, ScaleBW); h = Dy(sr); w = Dx(sr); sl = tks->sl + 2*ScaleBW; l = tkgc(e, TkCbackgndlght); d = tkgc(e, TkCbackgnddark); tkbevel(i, r.min, w, h, ScaleBW, d, l); tks->pixmin = sr.min.y; tks->pixmax = sr.max.y; sw = w - 2*ScaleBW; tks->sw = sw/2; h -= sl; if (h <= 0) h = 1; p.x = sr.max.x; p.y = sr.min.y; if(tks->tick > 0){ int j, t, l; t = tks->tick; l = tks->to-tks->from; if (l < 0) l = -l; if (l == 0) l = 1; r2.min = p; r2.max.x = p.x + ScaleBW + ScalePad; for(j = 0; j <= l; j += t){ r2.min.y = p.y+((vlong)j*h)/l+sl/2; r2.max.y = r2.min.y+1; draw(i, r2, tkgc(e, fgnd), nil, ZP); } } v = tks->value-tks->from; len = tks->to-tks->from; if (len != 0) p.y += ((vlong)v*h)/len; p.x = sr.min.x; q = p; if(ScaleBW > 1) { q.x++; gw = sw; } else gw = sw-1; q.y += tks->sl/2 + 1; if(tk->flag & Tkactivated) { r2.min = p; r2.max.x = sr.max.x; r2.max.y = p.y+sl; draw(i, r2, tkgc(e, TkCactivebgnd), nil, ZP); } switch(tks->relief) { case TKsunken: tkbevel(i, p, sw, tks->sl, ScaleBW, d, l); tkbevel(i, q, gw, 0, 1, l, d); break; case TKraised: tkbevel(i, p, sw, tks->sl, ScaleBW, l, d); tkbevel(i, q, gw, 0, 1, d, l); break; } tks->pixpos = p.y; tks->center = p.x + sw/2 + ScaleBW; if(tks->sv != BoolT) return; tkfprint(sv, tks->value); if(tks->digits > 0 && tks->digits < strlen(sv)) sv[tks->digits] = '\0'; p.x = r.min.x - ScalePad - stringwidth(e->font, sv); p.y = q.y; p.y -= fh/2; if (p.y < tks->pixmin) p.y = tks->pixmin; if (p.y + fh > tks->pixmax) p.y = tks->pixmax - fh; string(i, p, tkgc(e, fgnd), ZP, e->font, sv); }
void DrawProfilesList(DialogPtr w, RECTPTR r, long n) { char s[256]; DepthValuesSet dvals; if(n == sgObjects.numItems-1) { strcpy(s,"****"); MyMoveTo(DEPTH_COL-stringwidth(s)/2,r->bottom); drawstring(s); MyMoveTo(U_COL-stringwidth(s)/2,r->bottom); drawstring(s); MyMoveTo(V_COL-stringwidth(s)/2,r->bottom); drawstring(s); MyMoveTo(W_COL-stringwidth(s)/2,r->bottom); drawstring(s); MyMoveTo(TEMP_COL-stringwidth(s)/2,r->bottom); drawstring(s); //MyMoveTo(DIR_COL-20,r->bottom); //JLM MyMoveTo(SAL_COL-stringwidth(s)/2,r->bottom); drawstring(s); return; } sgDepthVals->GetListItem((Ptr)&dvals,n); StringWithoutTrailingZeros(s,dvals.depth,1); MyMoveTo(DEPTH_COL-stringwidth(s)/2,r->bottom); drawstring(s); StringWithoutTrailingZeros(s,dvals.value.u,4); MyMoveTo(U_COL-stringwidth(s)/2,r->bottom); drawstring(s); StringWithoutTrailingZeros(s,dvals.value.v,4); MyMoveTo(V_COL-stringwidth(s)/2,r->bottom); drawstring(s); StringWithoutTrailingZeros(s,dvals.w,1); MyMoveTo(W_COL-stringwidth(s)/2,r->bottom); drawstring(s); StringWithoutTrailingZeros(s,dvals.temp,1); MyMoveTo(TEMP_COL-stringwidth(s)/2,r->bottom); drawstring(s); //MyMoveTo(DIR_COL-20,r->bottom);//JLM StringWithoutTrailingZeros(s,dvals.sal,1); MyMoveTo(SAL_COL-stringwidth(s)/2,r->bottom); drawstring(s); return; }