GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — newt/label.c at master · mlichvar/newt Expand file tree/ Copy pathlabel.cMore file actions 98 lines (77 loc) · 1.84 KB / Copy pathlabel.cFile metadata and controls98 lines (77 loc) · 1.84 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 #include <slang.h> #include <stdlib.h> #include <string.h> #include "newt.h" #include "newt_pr.h" struct label { char * text; int length; int cs; }; static void labelDraw(newtComponent co); static void labelDestroy(newtComponent co); static struct componentOps labelOps = { labelDraw, newtDefaultEventHandler, labelDestroy, newtDefaultPlaceHandler, newtDefaultMappedHandler, } ; newtComponent newtLabel(int left, int top, const char * text) { newtComponent co; struct label * la; co = malloc(sizeof(*co)); if (co == NULL) return NULL; la = malloc(sizeof(struct label)); if (la == NULL) { free(co); return NULL; } co->data = la; co->destroyCallback = NULL; co->ops = &labelOps; co->height = 1; co->width = wstrlen(text, -1); co->top = top; co->left = left; co->takesFocus = 0; co->isMapped = 0; la->length = strlen(text); la->text = strdup(text); la->cs = COLORSET_LABEL; return co; } void newtLabelSetText(newtComponent co, const char * text) { int newLength; struct label * la = co->data; co->width = wstrlen(text,-1); newLength = strlen(text); if (newLength <= la->length) { memset(la->text, ' ', la->length); memcpy(la->text, text, newLength); } else { free(la->text); la->text = strdup(text); la->length = newLength; } labelDraw(co); } void newtLabelSetColors(newtComponent co, int colorset) { struct label * la = co->data; la->cs = colorset; labelDraw(co); } static void labelDraw(newtComponent co) { struct label * la = co->data; if (!co->isMapped) return; SLsmg_set_color(la->cs); newtGotorc(co->top, co->left); SLsmg_write_string(la->text); } static void labelDestroy(newtComponent co) { struct label * la = co->data; free(la->text); free(la); free(co); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |