void ofxArcText::drawString(string text, float x, float y, float radius, bool asShapes) { ofPushMatrix(); ofTranslate(x,y); float angles[text.length()]; float widths[text.length()]; float totalAngle = 0; for (int i=0; i < text.length(); i++) { widths[i] = getCharacterWidth( text.at(i) ) * letterSpacing; angles[i] = atan(widths[i]/radius); totalAngle += angles[i]; } switch (align) { case LEFT: break; case CENTER: ofRotateZ(ofRadToDeg(totalAngle/2)); break; case RIGHT: ofRotateZ(ofRadToDeg(totalAngle)); break; } if (showDebug) { ofNoFill(); ofCircle(0,0,radius); ofLine(0,0,0,radius); ofPushMatrix(); for (int i=0; i<text.length(); i++) { ofRotateZ(-ofRadToDeg(angles[i])); ofLine(0,0,0,radius); } ofPopMatrix(); } for (int i=0; i<text.length(); i++) { ofPushMatrix(); ofTranslate(0, radius); ofRotateZ(-ofRadToDeg(angles[i])/2); //local rotation, use this or center letter before rotating string str = ofToString((unsigned char)text.at(i)); if (asShapes) ofTrueTypeFont::drawStringAsShapes(str,0,0); else ofTrueTypeFont::drawString(str,0,0); ofPopMatrix(); ofRotateZ(-ofRadToDeg(angles[i])); } ofPopMatrix(); //for (int i=0; i<text.length(); i++) { // float opposite = getCharacterWidth(text.at(i)) * letterSpacing; // float angle = atan(opposite/radius) / 2; // ofRotateZ(-ofRadToDeg(angle)); // string s = ofToString((char)text.at(i)); // ofTrueTypeFont::drawString(s,-widths[i]/2,radius); // ofRotateZ(-ofRadToDeg(angle)); //} }
static void redrawText() { int x, y; XSetForeground(display, gcInvers, cmap24[C_blue]); for (y = 0; y < selected_model->text_height; y++) { for (x = 0; x < selected_model->text_width; x++) { XCopyArea(display, font[scale - 1], win, gc, bws[y * selected_model->text_width + x] * getCharacterWidth(), 0, getCharacterWidth(), getCharacterHeight(), start_x + x * getCharacterWidth(), start_y + y * getCharacterHeight()); if (selectText && x >= cx1 && y >= cy1 && x <= cx2 && y <= cy2) { XFillRectangle(display, win, gcInvers, start_x + x * getCharacterWidth(), start_y + y * getCharacterHeight(), getCharacterWidth(), getCharacterHeight()); } } } }
void DisplayManager::printCharacter(char c, int8_t dx, int8_t dy, uint8_t brightness){ uint8_t data[8]; getCharacterData(c, data); for(uint8_t y=0; y<getCharacterHeight(); ++y){ for(uint8_t x=0; x<getCharacterWidth(); ++x){ // font data is 8 bits left adjusted if((data[y] & _BV(7-x)) && x+dx<10) blipbox.leds.setLed(x+dx, 7-y+dy, brightness); else if(x+dx<10) blipbox.leds.setLed(x+dx, 7-y+dy, 0x00); } } }
static void handle_event() { XEvent event; KeySym key; /* a dealie-bob to handle KeyPress Events */ char text[255]; /* a char buffer for KeyPress Events */ while (1) { while (!XPending(display)) { if (update) { update = 0; //XClearArea(display, win, 0, 0, emu_window_width, emu_window_height, 1); generateKrtImage(); redraw(); usleep(0x20000); } } XNextEvent(display, &event); #if DEBUG_MSG dbg_print_event(&event); #endif if (event.type == Expose && event.xexpose.count == 0) { redraw(); } if (event.type == KeyRelease) { lastKeyStroke = 0; } if (event.type == KeyPress) { int len = XLookupString(&event.xkey, text, 255, &key, 0); if (len > 0) { lastKeyStroke = text[0]; } else { /*TODO use mapping table*/ switch (key) { case XK_Left: lastKeyStroke = 0x08; break; case XK_Right: lastKeyStroke = 0x09; break; case XK_Up: lastKeyStroke = 0x0b; break; case XK_Down: lastKeyStroke = 0x0a; break; default: printf("umpapped key %lx->0x%x\n", key, lastKeyStroke); lastKeyStroke = 0; break; } } /*if (text[0] == 'q' || text[0] == 0x3) { break;*/ } if (event.type == ConfigureNotify) { int scaleX = event.xconfigurerequest.width / selected_model->pixel_width; int scaleY = event.xconfigurerequest.height / selected_model->pixel_height; int tmpScale = scaleX > scaleY ? scaleY : scaleX; scale = tmpScale ? tmpScale : 1; scale = scale > ZOOM_MAX ? ZOOM_MAX : scale; emu_window_width = selected_model->pixel_width * scale; emu_window_height = selected_model->pixel_height * scale; start_x = (event.xconfigurerequest.width - emu_window_width) / 2; start_y = (event.xconfigurerequest.height - emu_window_height) / 2; } if (event.type == ClientMessage) { /* TODO erledigen wir später, test ob auch wirklich das Fester geschlossen werden soll * if (event.xclient.data.l[0] == wmDeleteWindow) { global.done = 1; } */ break; } if (event.type == ButtonPress) { cursorFromX = (event.xbutton.x - start_x) / getCharacterWidth(); cursorFromY = (event.xbutton.y - start_y) / getCharacterHeight(); selectText = 1; } if (event.type == ButtonRelease) { selectText = 0; XSetSelectionOwner(display, XA_PRIMARY, win, CurrentTime); redraw(); } if (event.type == MotionNotify) { cursorToX = (event.xmotion.x - start_x) / getCharacterWidth(); cursorToY = (event.xmotion.y - start_y) / getCharacterHeight(); cursorToX = cursorToX < 0 ? 0 : cursorToX; cursorToY = cursorToY < 0 ? 0 : cursorToY; cursorToX = cursorToX >= selected_model->text_width ? selected_model->text_width : cursorToX; cursorToY = cursorToY >= selected_model->text_height ? selected_model->text_height - 1 : cursorToY; printf("mark (%d,%d) (%d,%d)\n", cursorFromX, cursorFromY, cursorToX, cursorToY); redraw(); } if (event.type == SelectionRequest) { handleSelectionRequest(event.xselectionrequest); } } }