void Display(void) { glClear(GL_COLOR_BUFFER_BIT); GLfloat colorGray[4] = { 0.5f, 0.5f, 0.5f, 1.0f }; GLfloat colorRed[4] = { 1.0f, 0.0f, 0.0f, 1.0f }; /* Display frame */ char timer_buf[80]; sprintf(timer_buf, "FRAME: %llu", frame_count); RenderString(0.0f, 20.0f, timer_buf, colorGray); /* Display score */ char score_buf[80]; sprintf(score_buf, "SCORE: %llu", score); RenderString(0.0f, 40.0f, score_buf, colorGray); /* Display square */ glColor4fv(colorRed); glBegin(GL_QUADS); for (int i = 0; i < 4; ++i) { glVertex2d(area4p[i][0], area4p[i][1]); } glEnd(); glFlush(); }
void PhysicsLoop( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); RenderString( 1, 2, "Left click to spawn a polygon" ); RenderString( 1, 4, "Right click to spawn a circle" ); static float accumulator = 0; accumulator += clock.Elapsed( ); clock.Start( ); accumulator = Clamp( 0.0f, 0.1f, accumulator ); while(accumulator >= dt) { if(!frameStepping) scene.Step( ); else { if(canStep) { scene.Step( ); canStep = false; } } accumulator -= dt; } clock.Stop( ); scene.Render( ); glutSwapBuffers( ); }
// キー入力情報を表示する void displayKeys(struct engine* engine) { int i, y = 0; char buf[1024]; // 音量上ボタンの状態を表示 sprintf(buf, "VOLUMEUP = %s", engine->volumeup_keydown ? "DOWN" : "UP"); RenderString(engine->width / 2 + 64, engine->height - 32 - y, buf); y += 32; // 音量下ボタンの状態を表示 sprintf(buf, "VOLUMEDOWN = %s", engine->volumedown_keydown ? "DOWN" : "UP"); RenderString(engine->width / 2 + 64, engine->height - 32 - y, buf); }
/** Render the dialog to the pixmap. */ void DrawDialog(void) { int yoffset; int x; Assert(dialog); /* Clear the dialog. */ JXSetForeground(display, rootGC, colors[COLOR_MENU_BG]); JXFillRectangle(display, dialog->pmap, rootGC, 0, 0, dialog->width, dialog->height); /* Draw the message. */ yoffset = 4; for(x = 0; x < dialog->lineCount; x++) { RenderString(dialog->pmap, FONT_MENU, COLOR_MENU_FG, 4, yoffset, dialog->width, dialog->message[x]); yoffset += dialog->lineHeight; } /* Draw the buttons. */ DrawButtons(); }
void Game::update() { m_character->update(); for(int i=0; i<m_gameObjects; i++) m_myGameObjects[i]->collide(m_character); for(int i=0; i<m_gameObjects; i++) m_myGameObjects[i]->update(); glClearColor(1.0, 1.0, 1.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the screen //clear the screen // Display the current score char string[40]; sprintf(string, "Score:%d\n", m_score); sprintf(string, "Press P to Pause\n"); RenderString(0, m_height-20, GLUT_BITMAP_TIMES_ROMAN_24, string); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); m_character->display(); for(int i=0; i<m_gameObjects; i++) m_myGameObjects[i]->display(); glFlush(); if (!isRunning()) return splash(); }
int testAmmCaptcha() { AmmCaptcha_initialize("font.ppm","ourDictionaryCaptcha.txt"); struct Image * captcha = createImage(300,70,3); RenderString(captcha,&fontRAW, 0 , 20, "AmmarServer FTW"); WritePPM(captcha,"captcha.ppm"); coolPHPWave(captcha, 11,12,5,14); WriteJPEGFile(captcha,"captcha.jpg"); /* RenderString(captcha,&fontRAW, 0 , 30, "abcdefghijklmnopqrstuvwxyz"); RenderString(captcha,&fontRAW, 0 , 50, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"); RenderString(captcha,&fontRAW, 0 , 70, "0123456789"); RenderString(captcha,&fontRAW, 0 , 90, "ABCDTest123"); RenderString(captcha,&fontRAW, 0 , 120, "012345Test123");*/ //warpImage(captcha, 40, 120 , 60 , 150); AmmCaptcha_destroy(); return 0; }
//************************************************************************************************ // cMenuItem::Draw() //************************************************************************************************ void cMenuItem::Draw(int ItemLeft , int ItemTop, int ItemWidth) { if (ItemLeft > -1) m_ItemLeft = ItemLeft; if (ItemTop > -1) m_ItemTop = ItemTop; if (ItemWidth > -1) m_ItemWidth = ItemWidth; if (m_Selected) { RenderBox(m_ItemLeft, m_ItemTop, m_ItemLeft + m_ItemWidth, m_ItemTop + ITEM_HEIGHT, FILL, SKIN3); RenderString(m_pText, m_ItemLeft + ITEM_TEXT_LEFT, m_ItemTop + ITEM_TEXT_TOP, m_ItemLeft + m_ItemWidth - ITEM_TEXT_RIGHT, LEFT, WHITE, SKIN3); } else { if (ItemLeft == -1) { RenderBox(m_ItemLeft, m_ItemTop, m_ItemLeft + m_ItemWidth, m_ItemTop + ITEM_HEIGHT, FILL, SKIN2); } RenderString(m_pText, m_ItemLeft + ITEM_TEXT_LEFT, m_ItemTop + ITEM_TEXT_TOP, m_ItemLeft + m_ItemWidth - ITEM_TEXT_RIGHT, LEFT, WHITE, SKIN2); } }
void RenderChatText() { // View transformation gGraphicsDevice->SetTransform(D3DTS_VIEW, &gOrthoViewMatrix); // Perspective transformation gGraphicsDevice->SetTransform(D3DTS_PROJECTION, &gScreenProjectionMatrix); // Render the texture gGraphicsDevice->BeginScene(); { // render the user list size_t index = 0; int y = kFontSize / 4; for (auto iter=gChatUsers.rbegin(); iter != gChatUsers.rend() && index < gMaxChatLines; ++iter) { std::shared_ptr<ChatUser> user = *iter; RenderString(gWindowWidth-kUserListWidth, y, user->nameColorARGB, *user->font, user->username); y += user->font->pixelHeight + kLineSpacing; index++; } y = kFontSize / 4; // render the input text if showing if (gInputText != nullptr) { int x = RenderChatLine(kMessagesLeft, y, gInputText, KWhiteColor) + 2; RenderString(x, y, KWhiteColor, gNormalFont, "_"); y += gInputText->font->pixelHeight + kLineSpacing; } // render the history for (auto iter=gChatLines.rbegin(); iter != gChatLines.rend(); ++iter) { std::shared_ptr<ChatLine> line = *iter; RenderChatLine(kMessagesLeft, y, line, KBlackColor); y += line->font->pixelHeight + kLineSpacing; } gGraphicsDevice->SetTexture(0, nullptr); } gGraphicsDevice->EndScene(); }
int RenderChatLine(int left, int bottom, std::shared_ptr<ChatLine> line, unsigned int color) { const TTV_ChatTokenizedMessage& msg = line->list->messageList[line->index]; // render the badges if (msg.modes & TTV_CHAT_USERMODE_BROADCASTER) left = RenderEmoticon(left, bottom, *line->font, &gBadgeData.broadcasterIcon); else if (msg.modes & TTV_CHAT_USERMODE_MODERATOR) left = RenderEmoticon(left, bottom, *line->font, &gBadgeData.moderatorIcon); if (msg.modes & TTV_CHAT_USERMODE_ADMINSTRATOR) left = RenderEmoticon(left, bottom, *line->font, &gBadgeData.adminIcon); if (msg.modes & TTV_CHAT_USERMODE_STAFF) left = RenderEmoticon(left, bottom, *line->font, &gBadgeData.staffIcon); if (msg.subscriptions & TTV_CHAT_USERSUB_SUBSCRIBER) left = RenderEmoticon(left, bottom, *line->font, &gBadgeData.channelSubscriberIcon); if (msg.subscriptions & TTV_CHAT_USERSUB_TURBO) left = RenderEmoticon(left, bottom, *line->font, &gBadgeData.turboIcon); // render the username utf8char username[kMaxChatUserNameLength + 8]; sprintf_s(username, sizeof(username), line == gInputText ? "%s " : "%s: ", msg.displayName); left = RenderString(left, bottom, msg.nameColorARGB, *line->font, username); for (size_t t=0; t<msg.tokenCount; ++t) { const TTV_ChatMessageToken* token = &msg.tokenList[t]; switch (token->type) { case TTV_CHAT_MSGTOKEN_TEXT: { left = RenderString(left, bottom, color, *line->font, token->data.text.buffer); break; } case TTV_CHAT_MSGTOKEN_TEXTURE_IMAGE: { left = RenderEmoticon(left, bottom, *line->font, token); break; } case TTV_CHAT_MSGTOKEN_URL_IMAGE: { left = RenderString(left, bottom, color, *line->font, "["); left = RenderString(left, bottom, color, *line->font, token->data.urlImage.url); left = RenderString(left, bottom, color, *line->font, "]"); break; } } } return left; }
void OnDrawFrame() { char Txt[1024]; for ( size_t i = 0 ; i < Adapters.size() ; i++ ) { sprintf( Txt, "%s, Name == %s", Adapters[i].FIP, Adapters[i].FName ); RenderString( Txt, 10, ( int )i * 20, 0xFFFFFF ); } if ( g_ServerStarted ) { RenderString( "Started server", 10, 200, 0xFFFFFF ); } if ( g_StartedThread ) { RenderString( "Started thread", 10, 220, 0xFFFFFF ); } if ( g_GotSocket ) { RenderString( "Got socket", 10, 240, 0xFFFFFF ); } if ( g_RunningThread ) { RenderString( "Running thread", 10, 260, 0xFFFFFF ); } }
//************************************************************************************************ // DrawMsgBox() //************************************************************************************************ void cMenu::DrawMsgBox(char* header, char* question, bool okBtn, bool homeBtn, bool drawAll) { IMPORT_FRAMEBUFFER_VARS; if (drawAll) { STORE_PALETTE(&colormap); RenderBox(0, 0, p_xsize, p_ysize, FILL, TRANSP); } int Width = 530; int Height = 142; int Left = p_xsize / 2 - Width / 2; int Top = p_ysize / 2 - Height / 2; if (drawAll) { RenderBox(Left, Top, Left+Width, Top+Height, FILL, SKIN3); RenderBox(Left, Top+42, Left+Width, Top+Height, FILL, SKIN3); RenderBox(Left+2, Top+2, Left+Width-2, Top+42-1, FILL, SKIN1); RenderBox(Left+2, Top+42+1, Left+Width-2, Top+Height-2, FILL, SKIN2); RenderString(header, Left+2, Top+6, Width-2, CENTER, YELLOW, SKIN1); } RenderString(question, Left+2, Top+42+6, Width-2, CENTER, WHITE, SKIN2); if (drawAll) { if (okBtn) { RenderBox(Left+70, Top+Height-42, Left+70+70, Top+Height-12, FILL, SKIN3); RenderString("OK", Left+70, Top+Height-42, 70, CENTER, WHITE, SKIN3); } if (homeBtn) { RenderBox(Left+Width-70-70, Top+Height-42, Left+Width-70, Top+Height-12, FILL, SKIN3); RenderString("HOME", Left+Width-70-70, Top+Height-42, 70, CENTER, WHITE, SKIN3); } } }
void CConsole::Render() { glMatrixMode( GL_PROJECTION); glLoadIdentity(); int theWidth = m_Game->GetScreenWidth(); int theHeight = m_Game->GetScreenHeight(); glOrtho( -theWidth/2, theWidth/2, -theHeight/2, theHeight/2, 0.5, 100 ); glMatrixMode( GL_MODELVIEW); glLoadIdentity(); glBegin( GL_TRIANGLES ); glColor4f( 0.3f, 0.3f, 0.3f, 0.5f ); glVertex3f( -theWidth/2.f, m_CurrentY-2.f, -10.0f ); glVertex3f( -theWidth/2.f, theHeight/2.f, -10.0f ); glVertex3f( theWidth/2.f, m_CurrentY-2.f, -10.0f ); glVertex3f( theWidth/2.f, m_CurrentY-2.f, -10.0f ); glVertex3f( -theWidth/2.f, theHeight/2.f, -10.0f ); glVertex3f( theWidth/2.f, theHeight/2.f, -10.0f ); glEnd(); glLineWidth( 3.0f ); glBegin( GL_LINE_STRIP ); glColor3f( 0.2f, 0.2f, 0.2f ); glVertex3f( -theWidth/2.f, m_CurrentY-2.f, -10.0f ); glVertex3f( theWidth/2.f, m_CurrentY-2.f, -10.0f ); glEnd(); glLineWidth( 2.0f ); for( int i=0; i<8; i++ ) { int theIndex = m_LineCursorIndex-i-1; if( theIndex < 0 ) theIndex += 8; RenderString( theWidth, (int)m_CurrentY+(i+1)*11, m_Lines[ theIndex ] ); } char theBuffer[256]; sprintf( theBuffer, "> %s", m_InputBuffer ); RenderString( theWidth, (int)m_CurrentY, theBuffer ); }
//TODO Pool allocator? unsigned int TextRenderer::AddString(std::string* _text, glm::vec3 _color, float _scale, float _x, float _y) { m_RenderStrings.push_back(RenderString(_text,_color,_scale,_x,_y, m_currentStringID)); //To upper for (int i = 0; (*m_RenderStrings.back().Text)[i] != 0; i++) { if ((*m_RenderStrings.back().Text)[i] <= 122 && (*m_RenderStrings.back().Text)[i] >= 97) (*m_RenderStrings.back().Text)[i] -= 32; } return m_currentStringID++; }
// タッチ位置情報を表示する void displayTouchPoint(struct engine* engine) { int i, y = 0; char buf[1024]; for (i = 0; i < engine->point_count; i++) { sprintf(buf, "TOUCH POINT(%d)=(%d,%d)", i, engine->point[i].x, engine->point[i].y); RenderString(0, engine->height - 32 - y, buf); y += 32; drawCircle(engine->point[i].x, engine->height - engine->point[i].y); } }
static void ShowInfo(int index) { int loop, tind; char tstr[512]; int ixw=160, iyw=300, dy, my, offs=10, soffs=3; dy=iyw/12; my=2*dy; startx = sx + (((ex-sx) - ixw)/2); starty = sy + (((ey-sy) - iyw)/2); tind=index; //frame layout RenderBox(0, 0, ixw, iyw, radius, CMC); // RenderBox(0, 0, ixw, iyw, GRID, CMCS, radius); // titlebar RenderBox(2, 2, ixw-2, dy+2*soffs, radius, CMH); //selectbar RenderBox(2, offs+soffs+(index+1)*dy, ixw, offs+soffs+(index+2)*dy, radius, CMCS); RenderString("Rezap-Zeit", 0, dy, ixw, CENTER, MED, CMHT); for(loop = 0; loop < 10; ++loop) { sprintf(tstr,"%1d =",(loop<9)?(loop+1):0); RenderString(tstr, 10, offs+my, 40, CENTER, MED, (loop == tind)?CMCST:CMCT); sprintf(tstr,"%2d min",wtime[loop]); RenderString(tstr, 40, offs+my, ixw-60, RIGHT, MED, (loop == tind)?CMCST:CMCT); my += dy; } //copy backbuffer to framebuffer memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres); }
/** Display the message on the dialog window. */ void DrawMessage(DialogType *dp) { int yoffset; int x; Assert(dp); yoffset = 4; for(x = 0; x < dp->lineCount; x++) { RenderString(dp->node->window, FONT_MENU, COLOR_TRAY_FG, 4, yoffset, dp->width, NULL, dp->message[x]); yoffset += dp->lineHeight; } }
int AmmCaptcha_getCaptchaFrame(unsigned int captchaID, char *mem,unsigned long * mem_size) { struct Image * captcha = createImage(300,70,3); RenderString(captcha,&fontRAW, 0 + rand()%200 , rand()%40, hashMap_GetKeyAtIndex(captchaStrings,convertExternalIDToInternal(captchaID))); //Apply Swirling effect! coolPHPWave(captcha, 11,12,5,14); //WriteJPEGFile(captcha,"captcha.jpg"); WriteJPEGMemory(captcha,mem,mem_size); fprintf(stderr,"Survived WriteJPEG"); destroyImage(captcha); fprintf(stderr,"Survived destroyImage"); return 1; }
/** Draw a clock tray component. */ void DrawClock(ClockType *clk, const TimeType *now) { TrayComponentType *cp; const char *timeString; int width; int rwidth; /* Only draw if the time changed. */ if(now->seconds == clk->lastTime.seconds) { return; } /* Clear the area. */ cp = clk->cp; if(colors[COLOR_CLOCK_BG1] == colors[COLOR_CLOCK_BG2]) { JXSetForeground(display, rootGC, colors[COLOR_CLOCK_BG1]); JXFillRectangle(display, cp->pixmap, rootGC, 0, 0, cp->width, cp->height); } else { DrawHorizontalGradient(cp->pixmap, rootGC, colors[COLOR_CLOCK_BG1], colors[COLOR_CLOCK_BG2], 0, 0, cp->width, cp->height); } /* Determine if the clock is the right size. */ timeString = GetTimeString(clk->format, clk->zone); width = GetStringWidth(FONT_CLOCK, timeString); rwidth = width + 4; if(rwidth == clk->cp->requestedWidth || clk->userWidth) { /* Draw the clock. */ RenderString(cp->pixmap, FONT_CLOCK, COLOR_CLOCK_FG, (cp->width - width) / 2, (cp->height - GetStringHeight(FONT_CLOCK)) / 2, cp->width, timeString); UpdateSpecificTray(clk->cp->tray, clk->cp); } else { /* Wrong size. Resize. */ clk->cp->requestedWidth = rwidth; ResizeTray(clk->cp->tray); } }
/* void xor_pixmaps(Pixel *dest, Pixel *a, Pixel *b, int w, int h) { int i; for (i=0; i<w*h; i++) { *dest++ = (*a++) ^ (*b++); } } */ void print_keyboard(fbvnc_overlay_t *ov, Pixel* dest,int mode) { int i,j, sx; for (i=0; i<480*160; i++) dest[i] = ICO_TRANS; for (i = 0; i < KEYBOARD_ROWS; i++) { sx = 0; for (j = 0; j < KEYBOARD_KEYCOLS; j++) { RenderString(ov->w,dest,keyboardlayout[(mode == MOD_SHIFT ? 1 : 0)*KEYBOARD_ROWS+i][j], sx, (i+1)*ROW_HEIGHT, keytable[i][j].width*COL_WIDTH, CENTER, ICO_WHITE, (i==posy && j==posx ? ICO_BORDER : ICO_BG)); sx +=keytable[i][j].width*COL_WIDTH; } } }
//************************************************************************************************ // Draw() //************************************************************************************************ void cMenu::Draw() { IMPORT_FRAMEBUFFER_VARS; int MaxMenuHeight = p_ysize - MENU_TOP_MARGIN - MENU_BOTTOM_MARGIN; int MenuHeight = MENU_HEADER_HEIGHT; m_VisibleItemEnd = m_VisibleItemBegin; for (unsigned int i = 0; (MenuHeight + (*m_VisibleItemEnd)->GetItemHeight() <= MaxMenuHeight) && (i < m_ItemList.size()); i++) { MenuHeight += ITEM_HEIGHT; m_VisibleItemEnd++; } if ((m_VisibleItemBegin != m_ItemList.begin()) || (m_VisibleItemEnd != m_ItemList.end())) MenuHeight = MENU_HEADER_HEIGHT + m_ItemList.size() * ITEM_HEIGHT; int MenuTop = (p_ysize - MenuHeight) / 2; int MenuLeft = (p_xsize - m_ItemWidth) / 2; RenderBox(MenuLeft, MenuTop, MenuLeft+m_ItemWidth, MenuTop+MENU_HEADER_HEIGHT, FILL, SKIN1); RenderBox(MenuLeft, MenuTop+MENU_HEADER_HEIGHT, MenuLeft+m_ItemWidth, MenuTop+MenuHeight, FILL, SKIN2); RenderString(m_pName, MenuLeft+ITEM_TEXT_LEFT, MenuTop, m_ItemWidth-ITEM_TEXT_LEFT-ITEM_TEXT_RIGHT, LEFT, YELLOW, SKIN1); TItemList::iterator it; int Top = MenuTop + MENU_HEADER_HEIGHT; for (it = m_VisibleItemBegin; it != m_VisibleItemEnd; it++) { (*it)->Draw(MenuLeft, Top, m_ItemWidth); Top += (*it)->GetItemHeight(); if (it == m_SelectedItem) (*it)->SetSelected(true); } }
// センサー情報を表示する void displaySensors(struct engine* engine) { int i, y = 0; char buf[1024]; char message[][50] = { "", "SENSOR ACCEL:(%+2.3f,%+2.3f,%+2.3f)", "SENSOR MAGNETICFIELD:(%+2.3f,%+2.3f,%+2.3f)", "", "SENSOR GYROSCOPE:(%+2.3f,%+2.3f,%+2.3f)", "SENSOR LIGHT:(%2.3f)", "", "", "SENSOR PROXIMITY:(%2.3f)", }; for (i = 0; i < SENSOR_MAX; i++) { if (engine->sensors[i].sensor != NULL) { // 加速度センサーの状態を表示 sprintf(buf, message[engine->sensors[i].type], engine->sensors[i].value.x, engine->sensors[i].value.y, engine->sensors[i].value.z); RenderString(0, engine->height - 32 - 200 + y, buf); y -= 32; } } }
bool TR::RenderString(FontSlot slot, std::string textToRender) { //Find the slot to use. SlotCollection* slots = TryFindSlotCollection(slot.FontID); if (slots == 0) { return false; } Slot* slotP = TryFindSlot(slot.SlotID, slots); if (slotP == 0) { return false; } //Render into the slot. if (RenderString(textToRender, slot.FontID, RTManager[slotP->RenderTargetID], slotP->TextWidth, slotP->TextHeight)) { slotP->String = textToRender; return true; } return false; }
int main (int argc, char **argv) { int tv,index,i,j,cmct=CMCT,cmc=CMC,trnspi=TRANSP,trnsp=0,found,loop=1,first=1,x0,x1,x2,x3,x4,x5,x6,x7; int xdir=1, ydir=1; double xstep=1, ystep=1; double csx, cex, csy, cey; time_t atim; struct tm *ltim; char *aptr,*rptr; char dstr[2]={0,0}; printf("SSaver Version %s\n",CL_VERSION); ReadConf(); for(i=1; i<argc; i++) { aptr=argv[i]; if((rptr=strchr(aptr,'='))!=NULL) { rptr++; if(strstr(aptr,"DATE=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { sdat=j; } } if(strstr(aptr,"BIG=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { big=(j)?1:0; } } if(strstr(aptr,"SEC=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { secs=j; } } if(strstr(aptr,"SLOW=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { if(!j) { j=1; } slow=j; } } if(strstr(aptr,"FCOL=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { fcol=j; } } if(strstr(aptr,"BCOL=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { bcol=j; } } } } if((sx=Read_Neutrino_Cfg("screen_StartX"))<0) sx=80; if((ex=Read_Neutrino_Cfg("screen_EndX"))<0) ex=620; if((sy=Read_Neutrino_Cfg("screen_StartY"))<0) sy=80; if((ey=Read_Neutrino_Cfg("screen_EndY"))<0) ey=505; if(!slow) { slow=1; } if(slow>10) { slow=10; } xpos=ex/2; ypos=ey/2; for(index=CMCST; index<=CMH; index++) { sprintf(tstr,"menu_%s_alpha",menucoltxt[index-1]); if((tv=Read_Neutrino_Cfg(tstr))>=0) tr[index-1]=(tv<<8); sprintf(tstr,"menu_%s_blue",menucoltxt[index-1]); if((tv=Read_Neutrino_Cfg(tstr))>=0) bl[index-1]=(tv+(tv<<8)); sprintf(tstr,"menu_%s_green",menucoltxt[index-1]); if((tv=Read_Neutrino_Cfg(tstr))>=0) gn[index-1]=(tv+(tv<<8)); sprintf(tstr,"menu_%s_red",menucoltxt[index-1]); if((tv=Read_Neutrino_Cfg(tstr))>=0) rd[index-1]=(tv+(tv<<8)); } fb = open(FB_DEVICE, O_RDWR); if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) { printf("Clock <FBIOGET_FSCREENINFO failed>\n"); return -1; } if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { printf("Clock <FBIOGET_VSCREENINFO failed>\n"); return -1; } if(ioctl(fb, FBIOGETCMAP, &colormap) == -1) { printf("Clock <FBIOGETCMAP failed>\n"); return -1; } if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) { printf("Clock <mapping of Framebuffer failed>\n"); return -1; } //init fontlibrary if((error = FT_Init_FreeType(&library))) { printf("Clock <FT_Init_FreeType failed with Errorcode 0x%.2X>", error); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager))) { printf("Clock <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_SBitCache_New(manager, &cache))) { printf("Clock <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_Lookup_Face(manager, FONT, &face))) { printf("Clock <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } use_kerning = FT_HAS_KERNING(face); #ifdef FT_NEW_CACHE_API desc.face_id = FONT; desc.flags = FT_LOAD_MONOCHROME; #else desc.font.face_id = FONT; desc.image_type = ftc_image_mono; #endif if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres))) { printf("Clock <allocating of Backbuffer failed>\n"); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres); startx = sx; starty = sy; xstep/=(double)slow; ystep/=(double)slow; InitRC(); while(loop) { usleep(15000L); ioctl(fb, FBIOGETCMAP, &colormap); found=0; trnsp=0; for(i=colormap.start;i<colormap.len && found!=7;i++) { if(!colormap.red[i] && !colormap.green[i] && !colormap.blue[i] && !colormap.transp[i]) { cmc=i; found|=1; } if(colormap.red[i]>=0xF000 && colormap.green[i]>=0xF000 && colormap.blue[i]>=0xF000 && !colormap.transp[i]) { cmct=i; found|=2; } if(colormap.transp[i]>trnsp) { trnspi=i; trnsp=colormap.transp[i]; found|=4; } } if(first) { first=0; memset(lbb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres); memset(lfb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres); } if(big) { x0=3; x1=14; x2=26; x3=BIG; x4=30; x5=60; } else { x0=7; x1=12; x2=18; x3=MED; x4=18; x5=40; } x6=0; x7=0; time(&atim); ltim=localtime(&atim); if(secs) { sprintf(tstr,"%02d:%02d:%02d",ltim->tm_hour,ltim->tm_min,ltim->tm_sec); } else { sprintf(tstr," %02d%c%02d",ltim->tm_hour,(ltim->tm_sec & 1)?':':' ',ltim->tm_min); if(!sdat) { x6=3; x7=36+4*big; } } xpos+=xstep*(double)xdir; ypos+=ystep*(double)ydir; csx=xpos+x7; csy=ypos; cex=xpos+x7+100+20*big; cey=ypos+x2+2*(1+big)+sdat*x4; if(csx<0 || (sx+cex)>=ex) { xdir*=-1; xpos+=xstep*(double)xdir; csx=xpos+x7; cex=xpos+x7+100+20*big; xstep=rand()&3; if(!xstep) { xstep=1; } xstep/=(double)slow; } if(csy<0 || (sy+cey)>=ey) { ydir*=-1; ypos+=ystep*(double)ydir; csy=ypos; cey=ypos+x2+2*(1+big)+sdat*x4; ystep=rand()&3; if(!ystep || (ystep==3 && ydir==1)) { ystep=1; } ystep/=(double)slow; } for(i=x6; i<strlen(tstr); i++) { *dstr=tstr[i]; RenderString(dstr, xpos-x0+(i*x1), ypos+x2, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc)); } if(sdat) { sprintf(tstr,"%02d.%02d.%02d",ltim->tm_mday,ltim->tm_mon+1,ltim->tm_year-100); for(i=0; i<strlen(tstr); i++) { *dstr=tstr[i]; RenderString(dstr, xpos-x0+(i*x1), ypos+x5-2-2*big, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc)); } } for(i=0;i<=((sdat)?40:20)*(1+big);i++) { j=(starty+ypos+i)*var_screeninfo.xres+xpos+startx; if((j+100+20*big)<var_screeninfo.xres*var_screeninfo.yres) { memcpy(lfb+j, lbb+j, 100+20*big); } } RenderBox(csx, csy, cex, cey, FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct)); if(++loop>10) { if(RCKeyPressed()||ExistFile("/tmp/.ssaver_kill")) { loop=0; } } } cmct=0; cmc=0; for(i=colormap.start;i<colormap.len;i++) { if(colormap.transp[i]>cmct) { cmc=i; cmct=colormap.transp[i]; } } memset(lfb, cmc, var_screeninfo.xres*var_screeninfo.yres); FTC_Manager_Done(manager); FT_Done_FreeType(library); free(lbb); munmap(lfb, fix_screeninfo.smem_len); close(fb); CloseRC(); remove("/tmp/.ssaver_kill"); return 0; }
void RenderMenuScreen() { unsigned char color; for (int i = 0; i < 3; i++) { if (i == highlight) { color = 255; } else { color = 0; } RenderRectangle(MENUBUTTONOFFSET, MENUBUTTONTOP + MENUBUTTONSPACING * i, MENUBUTTONWIDTH, MENUBUTTONHEIGHT, color, color, color); } RenderString("Conway's game of life", 3, 170, 150, 255, 255, 255); RenderString("Use arrow keys to switch modes, enter to start", 1, 240, 260, 255, 255, 255); RenderString("Controls:", 1, 70, TOPCONTROLS - 30, 255, 255, 255); RenderString("Space: Start and stop", 1, 10, TOPCONTROLS, 255, 255, 255); RenderString("C: Clear grid", 1, 10, TOPCONTROLS + CONTROLSPACING, 255, 255, 255); RenderString("G: Toggle grid", 1, 10, TOPCONTROLS + CONTROLSPACING * 2, 255, 255, 255); RenderString("L: Load .cells preset", 1, 10, TOPCONTROLS + CONTROLSPACING * 3, 255, 255, 255); RenderString("R: Randomize", 1, 10, TOPCONTROLS + CONTROLSPACING * 4, 255, 255, 255); RenderString("Esc: Exit to menu screen", 1, 10, TOPCONTROLS + CONTROLSPACING * 5, 255, 255, 255); RenderString("Up/down arrow keys: Change speed", 1, 10, TOPCONTROLS + CONTROLSPACING * 6, 255, 255, 255); RenderString("Left mouse button: Toggle cell life", 1, 10, TOPCONTROLS + CONTROLSPACING * 7, 255, 255, 255); RenderString("Right mouse button: Toggle cell color", 1, 10, TOPCONTROLS + CONTROLSPACING * 8, 255, 255, 255); if (highlight == 0) { color = 0; } else { color = 255; } RenderString("Original", 2, MENUBUTTONOFFSET + 30, MENUBUTTONTOP + 10, color, color, color); if (highlight == 1) { color = 0; } else { color = 255; } RenderString("Immigration", 2, MENUBUTTONOFFSET + 2, MENUBUTTONTOP + MENUBUTTONSPACING + 10, color, color, color); if (highlight == 2) { color = 0; } else { color = 255; } RenderString("Rainbow", 2, MENUBUTTONOFFSET + 40, MENUBUTTONTOP + MENUBUTTONSPACING * 2 + 10, color, color, color); };
void RenderLoadScreen() { int yPos = 1; unsigned char color; for (int i = 0; i < MAXFILES; i++) { strcpy(str, fileList[i]); unsigned char *pathPointer = str; if (*pathPointer == NULL) { if (highlight > i - 1) { highlight = i - 1; } break; } pathPointer += strlen(fileList[i]) - 6; *pathPointer = 254; while (*(pathPointer - 1) != '\\') { pathPointer--; } if (highlight == i) { color = 255; } else { color = 0; } RenderRectangle(8, yPos, (strlen(pathPointer) - 6) * 10, 16, color, color, color); switch (color) { case 0: color = 255; break; case 255: color = 0; break; } RenderString(pathPointer, 1, 10, yPos, color, color, color); yPos += 20; if (highlight == i) { FILE *fp; fp = fopen(fileList[highlight], "r"); unsigned char *strStart; unsigned char character; int yPos = 10; while ((character = fgetc(fp)) == '!') { strStart = str; while ((character = fgetc(fp)) != '\n') { *(strStart++) = character; } *strStart = 254; RenderString(str, 1, 200, yPos, 255, 255, 255); yPos += 20; } fclose(fp); } } };
int main (int argc, char **argv) { unsigned int margin_left_F, digit_width, margin_top_t, font_size, margin_top_box, margin_top_d, digits, secs_width, adj_height; int i = 0; int j = 0; int w = 0; int ms = 0; int mw = 0; int loop = 1; unsigned int newmail = 0; unsigned int mailgfx = 0; int xdir = 1, ydir = 1; double xstep = 1, ystep = 1; double csx, cex, csy, cey; time_t atim; struct tm *ltim; char *aptr,*rptr; char dstr[2] = {0,0}; FILE *tfh; printf("Clock / SSaver Version %s\n",CL_VERSION); for (i = 1; i < argc; i++) { if (!strncmp(argv[i], "-ss", 3)) { ssaver = 1; continue; } } if (ssaver) { time(&atim); srand((unsigned int)atim); ReadConf(SCFG_FILE); } else { ReadConf(CCFG_FILE); } for (i = 1; i < argc; i++) { aptr=argv[i]; if((rptr=strchr(aptr,'='))!=NULL) { rptr++; if (!ssaver) { if(strstr(aptr,"X=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { xpos=j; } } if(strstr(aptr,"Y=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { ypos=j; } } if(strstr(aptr,"MAIL=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { mail=j; } } } if(strstr(aptr,"DATE=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { show_date=j; } } if(strstr(aptr,"BIG=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { big=(j)?1:0; } } if(strstr(aptr,"SEC=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { show_sec=j; } } if(strstr(aptr,"BLINK=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { blink=j; } } if(strstr(aptr,"SLOW=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { if(!j) { j=1; } slow=j; } } if(strstr(aptr,"FCOL=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { fcol=j; } } if(strstr(aptr,"BCOL=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { bcol=j; } } } } if((sx=Read_Neutrino_Cfg("screen_StartX"))<0) sx=80; if((ex=Read_Neutrino_Cfg("screen_EndX"))<0) ex=620; if((sy=Read_Neutrino_Cfg("screen_StartY"))<0) sy=80; if((ey=Read_Neutrino_Cfg("screen_EndY"))<0) ey=505; fb = open(FB_DEVICE, O_RDWR); if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) { printf("Clock / SSaver <FBIOGET_FSCREENINFO failed>\n"); return -1; } if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { printf("Clock / SSaver <FBIOGET_VSCREENINFO failed>\n"); return -1; } if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) { printf("Clock / SSaver <mapping of Framebuffer failed>\n"); return -1; } //init fontlibrary if((error = FT_Init_FreeType(&library))) { printf("Clock / SSaver <FT_Init_FreeType failed with Errorcode 0x%.2X>", error); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager))) { printf("Clock / SSaver <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_SBitCache_New(manager, &cache))) { printf("Clock / SSaver <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_Lookup_Face(manager, FONT, &face))) { printf("Clock / SSaver <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } use_kerning = FT_HAS_KERNING(face); #ifdef FT_NEW_CACHE_API desc.face_id = FONT; #else desc.font.face_id = FONT; #endif #if FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 0 desc.image_type = ftc_image_mono; #else desc.flags = FT_LOAD_MONOCHROME; #endif //init backbuffer if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres))) { printf("Clock / SSaver <allocating of Backbuffer failed>\n"); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if (!slow) slow=1; if (slow>10) slow=10; if (fcol > MAXCOL && !(ssaver == 1 && fcol == 99)) fcol = 2; if (bcol > 3 && !(bcol == 10)) bcol = 1; if (ssaver) { memset(lbb, col[bcol], var_screeninfo.xres*var_screeninfo.yres); memset(lfb, col[bcol], var_screeninfo.xres*var_screeninfo.yres); } else memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres); if (big) //grosse Schrift (time/date) { margin_left_F = 3; // 3 digit_width = 14; // 14 margin_top_t = 26; // 26 font_size = BIG; // 40 margin_top_box = 30; // 30 margin_top_d = 60; // 60 } else { margin_left_F = 7; //7 Abstand links digit_width = 12; //12 Ziffernblockbreite margin_top_t = 19; //19 Abstand "TimeString"-Unterkante von oben font_size = MED; //30 Schriftgroesse margin_top_box = 20; //20 Abstand Renderbox von oben margin_top_d = 40; //40 Abstand "DateString" von oben } digits = 0; secs_width = 0; startx = sx; starty = sy; mw = (big) ? 42 : 36; //mailwidth adj_height = 1 * (!big && !show_date); //max steprange == 3, so we need always a top/bottom margin of >=3 if (!show_sec && !show_date) { digits = 3; //3 Platzhalter ':ss' secs_width = digits * digit_width; } if (ssaver) { xpos = rand() %480 + 10; ypos = rand() %460 + 10; xdir *= (rand() &1) == 0 ? -1 : 1; ydir *= (rand() &1) == 0 ? -1 : 1; xstep/=(double)slow; ystep/=(double)slow; if (fcol == 99) { cCol = 1; Change_Col(&fcol, &bcol); } InitRC(); } while (loop) { if (ssaver) usleep(15000L); else { usleep(150000L); newmail = 0; if(mail && ExistFile(MAIL_FILE)) { if((tfh = fopen(MAIL_FILE,"r")) != NULL) { if(fgets(tstr, 511, tfh)) { if(sscanf(tstr, "%d", &i)) { newmail = i; } } fclose(tfh); } } } time(&atim); ltim=localtime(&atim); if (show_sec) { sprintf(tstr,"%02d:%02d:%02d", ltim->tm_hour, ltim->tm_min, ltim->tm_sec); } else { if (blink) sprintf(tstr," %02d%c%02d", ltim->tm_hour, (ltim->tm_sec & 1)? ' ' : ':', ltim->tm_min); else sprintf(tstr," %02d:%02d", ltim->tm_hour, ltim->tm_min); } if (!ssaver) { if (((int)xpos >= mw) || (!show_sec)) { ms = (int)xpos + ((show_sec) ? 0 : mw) - mw; //mail left } else { ms = (int)xpos + 100 + 20 * big; //mail right } //paint Backgroundcolor to clear digit RenderBox(xpos+secs_width, ypos, xpos+secs_width+100+20*big, ypos+margin_top_box + adj_height, FILL, col[bcol]); } if (ssaver) { xpos += xstep * (double)xdir; ypos += ystep * (double)ydir; csx = xpos + secs_width; csy = ypos; cex = xpos + secs_width + 100 + 20 * big; cey = ypos + margin_top_t + 2 * (1 + big) + (margin_top_box * show_date) + adj_height; if ((int)csx < 0 || (sx + (int)cex) > ex) { if (cCol) Change_Col(&fcol, &bcol); xdir *= -1; xpos += xstep * (double)xdir; csx = xpos + secs_width; cex = xpos + secs_width + 100 + 20 * big; xstep = rand() &3; if (!xstep) { xstep = 1; } xstep /= (double)slow; } if ((int)csy < 0 || (sy + (int)cey) > ey) { if (cCol) Change_Col(&fcol, &bcol); ydir *= -1; ypos += ystep * (double)ydir; csy = ypos; cey = ypos + margin_top_t + 2 * (1 + big) + (margin_top_box * show_date) + adj_height; ystep = rand() &3; if (!ystep) { ystep = 1; } ystep /= (double)slow; } RenderBox(csx, csy, cex, cey, FILL, col[bcol]); } for (i = digits; i < strlen(tstr); i++) { *dstr = tstr[i]; RenderString(dstr, xpos - margin_left_F + (i * digit_width), ypos + margin_top_t, 30, CENTER, font_size, col[fcol]); } if (show_date) { sprintf(tstr, "%02d.%02d.%02d", ltim->tm_mday, ltim->tm_mon + 1, ltim->tm_year - 100); if (!ssaver) { //Backgroundbox color Date RenderBox(xpos, ypos + margin_top_box, xpos + 100 + 20 * big, ypos + margin_top_d, FILL, col[bcol]); } for(i = 0; i < strlen(tstr); i++) { *dstr = tstr[i]; RenderString(dstr, xpos - margin_left_F + (i * digit_width), ypos + margin_top_d - 2 - (2 * big), 30, CENTER, font_size, col[fcol]); } } if (ssaver) { w = 100 + 20 * big + ((show_sec) ? 0 : - secs_width); for (i = 0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++) { j = (starty + (int)ypos + i) * var_screeninfo.xres + (int)xpos + ((show_sec) ? 0 : secs_width) + startx; if ((j + w) < var_screeninfo.xres * var_screeninfo.yres) { memcpy(lfb+j, lbb+j, w); } } } else { if (newmail > 0) { mailgfx = 1; //Background mail, left site from clock RenderBox(ms, ypos, ms+mw, ypos+margin_top_box + adj_height, FILL, col[bcol]); //bcol if(!(ltim->tm_sec & 1)) { RenderBox (ms+8, ypos+5+(1+big), ms+mw-8, ypos+margin_top_box+adj_height-2-(3*big), GRID, col[fcol]); DrawLine (ms+8, ypos+5+(1+big), ms+mw-8, ypos+margin_top_box+adj_height-2-(3*big), col[fcol]); DrawLine (ms+8, ypos+margin_top_box+adj_height-2-(3*big), ms+mw-8, ypos+5+(1+big), col[fcol]); DrawLine (ms+(9+1*big), ypos+4+(1+big), ms+(mw/2), ypos+1, col[fcol]); DrawLine (ms+(9+1*big), ypos+5+(1+big), ms+(mw/2), ypos+2, col[fcol]); DrawLine (ms+(mw/2), ypos+1, ms+mw-(9+1*big), ypos+4+(1+big), col[fcol]); DrawLine (ms+(mw/2), ypos+2, ms+mw-(9+1*big), ypos+5+(1+big), col[fcol]); } else { sprintf(tstr,"%d",newmail); RenderString(tstr, ms, ypos+margin_top_t, mw, CENTER, font_size, col[fcol]); } } else { if (mailgfx > 0) RenderBox(ms, ypos, ms+mw, ypos + margin_top_box + adj_height, FILL, (!show_date || show_sec) ? TRANSP : col[bcol]); else ms=(int)xpos; } w = 100 + 20 * big + ((mailgfx) ? ((show_sec) ? mw : 0) : - secs_width); for (i=0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++) { j = (starty + (int)ypos + i) * var_screeninfo.xres + ( ((ms < (int)xpos) ? ms : (int)xpos) + ((show_sec) ? 0 : ((mailgfx) ? 0 : secs_width)) ) + startx; if ((j + w) < var_screeninfo.xres * var_screeninfo.yres) { memcpy(lfb+j, lbb+j, w); } } if (newmail == 0 && mailgfx > 0) mailgfx = 0; } if (++loop > 10) { if ( (ssaver && (RCKeyPressed() || ExistFile("/tmp/.ssaver_kill"))) || (!ssaver && ExistFile("/tmp/.clock_kill")) ) loop = 0; } } /**************************** * close down Clock / SSaver ****************************/ if (ssaver) { memset(lfb, 0, var_screeninfo.xres*var_screeninfo.yres); remove("/tmp/.ssaver_kill"); CloseRC(); } else { memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres); remove("/tmp/.clock_kill"); for (i=0; i <= ((show_date) ? 20 : 10) * (2 + big) + adj_height; i++) { j=(starty+(int)ypos+i)*var_screeninfo.xres+((ms<(int)xpos)?ms:(int)xpos)+((show_sec)?0:((mailgfx)?0:secs_width))+startx; if((j+100+20*big+((mail)?mw:0))<var_screeninfo.xres*var_screeninfo.yres) { memcpy(lfb+j, lbb+j, w); } } } FTC_Manager_Done(manager); FT_Done_FreeType(library); free(lbb); munmap(lfb, fix_screeninfo.smem_len); close(fb); return 0; }
void TexFont::RenderString( const wxString &string, int x, int y ) { RenderString((const char*)string.ToUTF8(), x, y); }
void CglFont::glPrint(float x, float y, float s, const int options, const std::string& text) { // s := scale or absolute size? if (options & FONT_SCALE) { s *= fontSize; } float sizeX = s, sizeY = s; // render in normalized coords (0..1) instead of screencoords (0..~1024) if (options & FONT_NORM) { sizeX *= globalRendering->pixelX; sizeY *= globalRendering->pixelY; } // horizontal alignment (FONT_LEFT is default) if (options & FONT_CENTER) { x -= sizeX * 0.5f * GetTextWidth(text); } else if (options & FONT_RIGHT) { x -= sizeX * GetTextWidth(text); } // vertical alignment y += sizeY * GetDescender(); // move to baseline (note: descender is negative) if (options & FONT_BASELINE) { // nothing } else if (options & FONT_DESCENDER) { y -= sizeY * GetDescender(); } else if (options & FONT_VCENTER) { float textDescender; y -= sizeY * 0.5f * GetTextHeight(text,&textDescender); y -= sizeY * 0.5f * textDescender; } else if (options & FONT_TOP) { y -= sizeY * GetTextHeight(text); } else if (options & FONT_ASCENDER) { y -= sizeY * GetDescender(); y -= sizeY; } else if (options & FONT_BOTTOM) { float textDescender; GetTextHeight(text,&textDescender); y -= sizeY * textDescender; } if (options & FONT_NEAREST) { x = (int)x; y = (int)y; } // backup text & outline colors (also ::ColorResetIndicator will reset to those) baseTextColor = textColor; baseOutlineColor = outlineColor; // immediate mode? const bool immediate = !inBeginEnd; if (immediate) { Begin(!(options & (FONT_OUTLINE | FONT_SHADOW))); } // select correct decoration RenderString function if (options & FONT_OUTLINE) { RenderStringOutlined(x, y, sizeX, sizeY, text); } else if (options & FONT_SHADOW) { RenderStringShadow(x, y, sizeX, sizeY, text); } else { RenderString(x, y, sizeX, sizeY, text); } // immediate mode? if (immediate) { End(); } // reset text & outline colors (if changed via in text colorcodes) SetColors(&baseTextColor,&baseOutlineColor); }
/** Draw a button. */ void DrawButton(ButtonNode *bp) { ColorType fg; long bg1, bg2; long up, down; DecorationsType decorations; Drawable drawable; GC gc; int x, y; int width, height; int xoffset, yoffset; int iconWidth, iconHeight; int textWidth, textHeight; Assert(bp); drawable = bp->drawable; x = bp->x; y = bp->y; width = bp->width; height = bp->height; gc = JXCreateGC(display, drawable, 0, NULL); /* Determine the colors to use. */ switch(bp->type) { case BUTTON_LABEL: fg = COLOR_MENU_FG; bg1 = colors[COLOR_MENU_BG]; bg2 = colors[COLOR_MENU_BG]; up = colors[COLOR_MENU_UP]; down = colors[COLOR_MENU_DOWN]; decorations = settings.menuDecorations; break; case BUTTON_MENU_ACTIVE: fg = COLOR_MENU_ACTIVE_FG; bg1 = colors[COLOR_MENU_ACTIVE_BG1]; bg2 = colors[COLOR_MENU_ACTIVE_BG2]; down = colors[COLOR_MENU_ACTIVE_UP]; up = colors[COLOR_MENU_ACTIVE_DOWN]; decorations = settings.menuDecorations; break; case BUTTON_TRAY: fg = COLOR_TRAYBUTTON_FG; bg1 = colors[COLOR_TRAYBUTTON_BG1]; bg2 = colors[COLOR_TRAYBUTTON_BG2]; up = colors[COLOR_TRAYBUTTON_UP]; down = colors[COLOR_TRAYBUTTON_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_TRAY_ACTIVE: fg = COLOR_TRAYBUTTON_ACTIVE_FG; bg1 = colors[COLOR_TRAYBUTTON_ACTIVE_BG1]; bg2 = colors[COLOR_TRAYBUTTON_ACTIVE_BG2]; down = colors[COLOR_TRAYBUTTON_ACTIVE_UP]; up = colors[COLOR_TRAYBUTTON_ACTIVE_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_TASK: fg = COLOR_TASKLIST_FG; bg1 = colors[COLOR_TASKLIST_BG1]; bg2 = colors[COLOR_TASKLIST_BG2]; up = colors[COLOR_TASKLIST_UP]; down = colors[COLOR_TASKLIST_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_TASK_ACTIVE: fg = COLOR_TASKLIST_ACTIVE_FG; bg1 = colors[COLOR_TASKLIST_ACTIVE_BG1]; bg2 = colors[COLOR_TASKLIST_ACTIVE_BG2]; down = colors[COLOR_TASKLIST_ACTIVE_UP]; up = colors[COLOR_TASKLIST_ACTIVE_DOWN]; decorations = settings.trayDecorations; break; case BUTTON_MENU: default: fg = COLOR_MENU_FG; bg1 = colors[COLOR_MENU_BG]; bg2 = colors[COLOR_MENU_BG]; up = colors[COLOR_MENU_UP]; down = colors[COLOR_MENU_DOWN]; decorations = settings.menuDecorations; break; } /* Draw the background. */ if(bp->fill) { /* Draw the button background. */ JXSetForeground(display, gc, bg1); if(bg1 == bg2) { /* single color */ JXFillRectangle(display, drawable, gc, x, y, width, height); } else { /* gradient */ DrawHorizontalGradient(drawable, gc, bg1, bg2, x, y, width, height); } } /* Draw the border. */ if(bp->border) { if(decorations == DECO_MOTIF) { JXSetForeground(display, gc, up); JXDrawLine(display, drawable, gc, x, y, x + width - 1, y); JXDrawLine(display, drawable, gc, x, y, x, y + height - 1); JXSetForeground(display, gc, down); JXDrawLine(display, drawable, gc, x, y + height - 1, x + width - 1, y + height - 1); JXDrawLine(display, drawable, gc, x + width - 1, y, x + width - 1, y + height - 1); } else { JXSetForeground(display, gc, down); JXDrawRectangle(display, drawable, gc, x, y, width - 1, height - 1); } } /* Determine the size of the icon (if any) to display. */ iconWidth = 0; iconHeight = 0; if(bp->icon) { if(bp->icon == &emptyIcon) { iconWidth = Min(width - 4, height - 4); iconHeight = iconWidth; } else { const int ratio = (bp->icon->width << 16) / bp->icon->height; iconHeight = height - 4; iconWidth = (iconHeight * ratio) >> 16; if(iconWidth > width - 4) { iconWidth = width - 4; iconHeight = (iconWidth << 16) / ratio; } } } /* Determine how much room is left for text. */ textWidth = 0; textHeight = 0; if(bp->text && (width > height || !bp->icon)) { textWidth = GetStringWidth(bp->font, bp->text); textHeight = GetStringHeight(bp->font); if(iconWidth > 0 && textWidth + iconWidth + 7 > width) { textWidth = width - iconWidth - 7; } else if(iconWidth == 0 && textWidth + 5 > width) { textWidth = width - 5; } textWidth = textWidth < 0 ? 0 : textWidth; } /* Determine the offset of the text in the button. */ if(bp->alignment == ALIGN_CENTER || width <= height) { xoffset = (width - iconWidth - textWidth + 1) / 2; if(xoffset < 0) { xoffset = 0; } } else { xoffset = 2; } /* Display the icon. */ if(bp->icon) { yoffset = (height - iconHeight + 1) / 2; PutIcon(bp->icon, drawable, colors[fg], x + xoffset, y + yoffset, iconWidth, iconHeight); xoffset += iconWidth + 2; } /* Display the label. */ if(textWidth > 0) { yoffset = (height - textHeight + 1) / 2; RenderString(drawable, bp->font, fg, x + xoffset, y + yoffset, textWidth, bp->text); } JXFreeGC(display, gc); }
int main(int argc, char *args[]) { #if _WIN32 // NOTE(nathan): Set the windows schedular granularity to 1ms // so that our SDL_Delay() and be more granular // SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); // NOTE(nathan): This seems to give a more consistant result than above timeBeginPeriod(1); #if _DEBUG HWND console = GetConsoleWindow(); if(console != 0) MoveWindow(console, -900, 100, 700, 800, TRUE); #endif #endif SDL_Init(SDL_INIT_EVERYTHING); // NOTE(nathan): This also initializes the window_with and window_height WindowData window_data = { }; window_data.target_width = 1920; window_data.target_height = 1080; FixViewport(1280, 720, &window_data); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4); SDL_Window *window = SDL_CreateWindow( "Banana", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, window_data.width, window_data.height, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); // ToggleFullScreen(window); SDL_ShowCursor(SDL_DISABLE); // OutputSystemInfo(); SDL_GLContext glContext = SDL_GL_CreateContext(window); glewExperimental = GL_TRUE; if (glewInit() != GLEW_OK) Error("glewInit"); // Goes stuttery if we turn on vsync SDL_GL_SetSwapInterval((int)window_data.vsync); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); bool running = true; SDL_Event e; uint32 gameUpdateHz = 60; float32 targetSecondsPerFrame = 1.0f / (float32)gameUpdateHz; perfCountFreq = SDL_GetPerformanceFrequency(); uint64 lastCounter = GetWallClock(); GameMemory game_memory = { 0 }; game_memory.size = Megabytes(64); game_memory.memory = SDL_malloc(game_memory.size); EditorMemory editor_memory = { 0 }; editor_memory.size = Megabytes(64); editor_memory.memory = SDL_malloc(editor_memory.size); RenderContext render_context = {}; render_context.diffuse = CreateShader("assets/shaders/diffuse.vert", "assets/shaders/diffuse.frag"); InitializeContext(&render_context); VoxelRenderContext voxel_render_context = {}; voxel_render_context.diffuse = CreateShader("assets/shaders/voxels.vert", "assets/shaders/voxels.frag"); InitializeVoxelContext(&voxel_render_context); InputData input = { }; input.window = window; UIContext ui_context = { 0 }; ui_context.input = &input; ui_context.render_context = &render_context; Mode mode = MODE_GAME; bool game_paused = false; while (running) { while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) running = false; if (e.type == SDL_WINDOWEVENT) { if (e.window.event == SDL_WINDOWEVENT_RESIZED) { FixViewport((int)e.window.data1, (int)e.window.data2, &window_data); } } if (e.type == SDL_KEYDOWN) { SDL_Scancode key = e.key.keysym.scancode; input.keyboard_state[key] = true; if (key == SDL_SCANCODE_ESCAPE) running = false; if (key == SDL_SCANCODE_F12) window_data.vsync = !window_data.vsync; if (key == SDL_SCANCODE_F11) ToggleFullScreen(window, &window_data); if (key == SDL_SCANCODE_F10) { if (mode == MODE_GAME) { game_paused = true; mode = MODE_EDITOR; } else { mode = MODE_GAME; game_paused = false; } } } if (e.type == SDL_KEYUP) { SDL_Scancode key = e.key.keysym.scancode; input.keyboard_state[key] = false; } if (e.type == SDL_MOUSEMOTION) { input.mouse_pos.x = (((float)window_data.target_width / (float)window_data.vp_width) * ((float)e.motion.x - window_data.vp_x)); input.mouse_pos.y = (((float)window_data.target_height / (float)window_data.vp_height) * ((float)e.motion.y - window_data.vp_y)); } if (e.type == SDL_MOUSEBUTTONDOWN) { if (e.button.button == SDL_BUTTON_LEFT) input.mb_left = true; if (e.button.button == SDL_BUTTON_RIGHT) input.mb_right = true; if (e.button.button == SDL_BUTTON_MIDDLE) input.mb_middle = true; } if (e.type == SDL_MOUSEBUTTONUP) { if (e.button.button == SDL_BUTTON_LEFT) input.mb_left = false; if (e.button.button == SDL_BUTTON_RIGHT) input.mb_right = false; if (e.button.button == SDL_BUTTON_MIDDLE) input.mb_middle = false; } } float32 delta = 1.0f / (float32)gameUpdateHz; GameUpdateAndRender(&game_memory, &input, &render_context, &voxel_render_context, &window_data, game_paused, delta); uint64 workCounter = GetWallClock(); float32 workSecondsElapsed = GetSecondsElapsed(lastCounter, workCounter); // Dont include this in frametime if (mode == MODE_EDITOR) EditorUpdateAndRender(&editor_memory, &input, &render_context, &ui_context, delta); float32 secondsElapsedForFrame = workSecondsElapsed; if (secondsElapsedForFrame < targetSecondsPerFrame) { uint32 sleepMS = (uint32)((1000.0f * (targetSecondsPerFrame - secondsElapsedForFrame)) - 1); if (sleepMS > 0) SDL_Delay(sleepMS); while (secondsElapsedForFrame < targetSecondsPerFrame) { secondsElapsedForFrame = GetSecondsElapsed(lastCounter, GetWallClock()); } } else { // Error("Missed Frame Rate"); } uint64 endCounter = GetWallClock(); float64 msPerFrame = 1000.0f * GetSecondsElapsed(lastCounter, endCounter); lastCounter = endCounter; // Debug Render BeginRenderer(&render_context); std::string s = "FRAMETIME " + std::to_string(msPerFrame) + " VSYNC " + std::to_string(window_data.vsync); RenderString(&render_context, 40.0f, 40.0f, s.c_str(), 0.0f); EndRenderer(); SDL_GL_SwapWindow(window); input.prev_keyboard_state = input.keyboard_state; input.mb_left_prev = input.mb_left; input.mb_right_prev = input.mb_right; input.mb_middle_prev = input.mb_middle; } UnloadContext(&render_context); UnloadVoxelContext(&voxel_render_context); SDL_free(game_memory.memory); SDL_GL_DeleteContext(glContext); SDL_DestroyWindow(window); SDL_Quit(); return(0); }