Ejemplo n.º 1
0
//------------------------------------------------------------------
void urFont::loadFont(string filename, int fontsize){
	// load anti-aliased, non-full character set:
	loadFont(filename, fontsize, true, false, false);
}
Ejemplo n.º 2
0
void initMenuGraphics(){
	clearMenuTextures();
	char font1[] = "font/Champagne.ttf";
	char font2[] = "font/lighthouse.ttf";

	TTF_Font* police = NULL;
	char bienvenue[34]="Bienvenue dans Imac Tower Defense";

	SDL_Surface* bienvenue_surface=loadFont(police,bienvenue,font2,100);
	MENU_TEXTURES_ID.BIENVENUE = makeTextureFromSurface (bienvenue_surface);
	SDL_FreeSurface(bienvenue_surface);

	char choix[18]="Choisir une carte";
	SDL_Surface* choix_surface=loadFont(police,choix,font1,100);
	MENU_TEXTURES_ID.MAP_CHOICE_LEGEND =  makeTextureFromSurface (choix_surface);
	SDL_FreeSurface(choix_surface);
	
	char aide[16]="Lire les regles";
	SDL_Surface* aide_surface=loadFont(police,aide,font1,100);
	MENU_TEXTURES_ID.AIDE_LEGEND=makeTextureFromSurface (aide_surface);
	SDL_FreeSurface(aide_surface);
	
	char playLegend[7]="Play !";
	SDL_Surface* play_surface=loadFont(police,playLegend,font1,100);
	MENU_TEXTURES_ID.PLAY_LEGEND = makeTextureFromSurface (play_surface);
	SDL_FreeSurface(play_surface);

	char pushEnter[31]="Appuyer sur ENTER pour valider";
	SDL_Surface* PushEnter_surface=loadFont(police,pushEnter,font1,100);
	MENU_TEXTURES_ID.PUSH_ENTER = makeTextureFromSurface (PushEnter_surface);
	SDL_FreeSurface(PushEnter_surface);

	MENU_TEXTURES_ID.FLECHES = makeTextureFromFile("images/fleches.png");
	MENU_TEXTURES_ID.AIDE_BUTTON = makeTextureFromFile("images/monstrehelp.png");
	MENU_TEXTURES_ID.MAP_CHOICE_BUTTON = makeTextureFromFile("images/monstrecarte.png");
	MENU_TEXTURES_ID.PLAY_BUTTON = makeTextureFromFile("images/monstreplay.png");
	MENU_TEXTURES_ID.RULES = makeTextureFromFile("images/regles.png");
	MENU_TEXTURES_ID.RULES_CLOSE = makeTextureFromFile("images/close.png");
	MENU_TEXTURES_ID.BULLE = makeTextureFromFile("images/bulle.png");


	//Création du menu de choix de carte
	if(BUTTON_OF_MENU.lstMapName != NULL) freeListComplete(BUTTON_OF_MENU.lstMapName);
	if(BUTTON_OF_MENU.lstMapButton != NULL) freeListComplete(BUTTON_OF_MENU.lstMapButton);
	if(BUTTON_OF_MENU.lstMapTextureIndex != NULL) freeListComplete(BUTTON_OF_MENU.lstMapTextureIndex);
	
	BUTTON_OF_MENU.lstMapName = createEmptyList();
	BUTTON_OF_MENU.lstMapButton = createEmptyList();
	BUTTON_OF_MENU.lstMapTextureIndex = createEmptyList();
	BUTTON_OF_MENU.indexButtonClicked = -1;
	BUTTON_OF_MENU.indexFirstButtonDisplayed = 1;
	
	readDirectory(BUTTON_OF_MENU.lstMapName);
	char* ptrMapName;
	char displayedName[MAX_LENGHT];
	int i = 0;
	float xText=0.;
	float yTextInit=140.;
	float yTextCurrent = yTextInit;
	float zText = 0.0;
	goToHeadList(BUTTON_OF_MENU.lstMapName);
	while( (ptrMapName = (char*) nextData(BUTTON_OF_MENU.lstMapName)) != NULL){
		strcpy(displayedName, ptrMapName);
		int j = 0;
		for(j = 0; displayedName[j] != '.';j++);
		displayedName[j] = 0;
		
		SDL_Surface* text=loadFont(police,displayedName,font1,100);
		GLuint* texId = (GLuint*) malloc(sizeof(GLuint));
		if(texId == NULL){
			fprintf(stderr, "Erreur fatale : impossible d'allouer la mémoire nécessaire.\n");
			exit(EXIT_FAILURE);
		}
		*texId = makeTextureFromSurface (text);
		insertBottomCell(BUTTON_OF_MENU.lstMapTextureIndex, texId);
		
		//Création du bouton associé
		yTextCurrent = yTextInit - (70.* (i % NB_MAP_DISPLAYED));
		if(i > NB_MAP_DISPLAYED -1) zText = -2.0;
		Point3D mapPosition = PointXYZ(xText,yTextCurrent, zText);
		int width = text->w;
		if( width > 600){
			width = 600;
		}
		insertBottomCell(BUTTON_OF_MENU.lstMapButton, createButton(MAP_MENU,mapPosition,width,text->h));
		SDL_FreeSurface(text);
		i++;
	}
	
	Point3D aidePosition = PointXYZ(-150.,100.,0.);
	Button* aideButton = createButton(AIDE_MENU,aidePosition,120,120);
	free(BUTTON_OF_MENU.regles);
	BUTTON_OF_MENU.regles = aideButton;
	
	Point3D choixPosition = PointXYZ(140.,100.,0.);
	Button* choixButton = createButton(CHOIX_MENU,choixPosition,120,120);
	free(BUTTON_OF_MENU.choix_carte);
	BUTTON_OF_MENU.choix_carte = choixButton;
	
	Point3D playPosition = PointXYZ(0.,-100.,0.);
	Button* playButton = createButton(PLAY_MENU,playPosition,120,120);
	free(BUTTON_OF_MENU.jouer);
	BUTTON_OF_MENU.jouer=playButton;
		
	Point3D closePosition = PointXYZ(223.,225.,0.);
	Button* closeButton = createButton(CLOSE_RULES_MENU,closePosition,30,30);
	free(BUTTON_OF_MENU.close_rules);
	BUTTON_OF_MENU.close_rules=closeButton;
	
	TTF_CloseFont(police);

}
Ejemplo n.º 3
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    preferencesDialog = new PreferencesDialog();
    fontDialog = new FontDialog();

    //----File----
    connect(ui->actionConvert_to_Handwritten, SIGNAL(triggered()),
            this, SLOT(renderFirstSheet()));
    connect(ui->actionLoad_Text_from_File, SIGNAL(triggered()),
            this, SLOT(loadTextFromFile()));
    connect(ui->actionLoad_Font, SIGNAL(triggered()),
            this, SLOT(loadFont()));
    connect(ui->actionFont_Editor, SIGNAL(triggered()),
            fontDialog, SLOT(exec()));
    connect(ui->actionSave_Current_Sheet_as, SIGNAL(triggered()),
            this, SLOT(saveSheet()));
    connect(ui->actionSave_All_Sheets, SIGNAL(triggered()),
            this, SLOT(saveAllSheets()));
    connect(ui->actionPrint_Current_Sheet, SIGNAL(triggered()),
            this, SLOT(printSheet()));
    connect(ui->actionPrint_All, SIGNAL(triggered()),
            this, SLOT(printAllSheets()));

    //----Edit----
    //connect menu action "Show Toolbar"
    connect(ui->actionShow_ToolBar, SIGNAL(triggered(bool)),
            ui->toolBar, SLOT(setVisible(bool)));
    connect(ui->toolBar, SIGNAL(visibilityChanged(bool)),
            ui->actionShow_ToolBar, SLOT(setChecked(bool)));

    //preferencesDialog connections
    connect(ui->actionPreferences, SIGNAL(triggered()),
            preferencesDialog, SLOT(exec()));
    connect(preferencesDialog, SIGNAL(settingsChanged()),
            ui->svgView, SLOT(loadSettingsFromFile()));

    //----Help----
    connect(ui->actionAbout_Scribbler, SIGNAL(triggered()),
            this, SLOT(showAboutBox()));
    connect(ui->actionLicenses_and_Credits, SIGNAL(triggered()),
            this, SLOT(showLicensesBox()));

    //----ToolBar----
    //add actions to tool bar and connect them to slots
    connect(ui->toolBar->addAction(QPixmap("://render.png"), tr("Convert to Handwritten")), SIGNAL(triggered(bool)),
            this, SLOT(renderFirstSheet()));
    connect(ui->toolBar->addAction(QPixmap("://printer.png"), tr("Print Current Sheet")), SIGNAL(triggered(bool)),
            this, SLOT(printSheet()));
    connect(ui->toolBar->addAction(QPixmap("://save.png"), tr("Save Current Sheet as Image")), SIGNAL(triggered(bool)),
            this, SLOT(saveSheet()));

    ui->toolBar->addSeparator();

    connect(ui->toolBar->addAction(QPixmap("://right.png"), tr("Next Sheet")), SIGNAL(triggered(bool)),
            this, SLOT(renderNextSheet()));
    connect(ui->toolBar->addAction(QPixmap("://left.png"), tr("Previous Sheet")), SIGNAL(triggered(bool)),
            this, SLOT(renderPreviousSheet()));

    connect(fontDialog, SIGNAL(fontReady()),
            ui->svgView, SLOT(loadFont()));

    ui->toolBar->actions()[4]->setDisabled(true);
    ui->toolBar->actions()[5]->setDisabled(true);

    //initialize some class members
    sheetPointers.push_back(0);
    currentSheetNumber = 0;
    version = "0.4 alpha";

    preferencesDialog->loadSettingsFromFile();

    /* This is a hack to avoid a bug. When program starts, it needs some time
     * (at least 1 ms on my configuration, but I set delay to 100 ms just to be sure
     * that it will work on weaker machines) before it can write settings to file,
     * otherwise ui->colorButton->palette().background().color() will return
     * default buttons background color, which will be written to settings
     * file at once program launches.
     */

    QTime dieTime = QTime::currentTime().addMSecs(100);
    while (QTime::currentTime() < dieTime)
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

    preferencesDialog->loadSettingsToFile();
}
Ejemplo n.º 4
0
int multiplayer(SDL_Window *win, SDL_Renderer *ren){
	/*
		langue
		musique
		Done
	*/

	SDL_Surface *img_srf;
    SDL_Texture *img_txtu;
    SDL_Rect tapisPos;
    SDL_Rect but, butClick[3];

    ServSetting serv;

    FILE *server_settings = NULL;

    strcpy(serv.ip, "127.0.0.1");
    serv.port = 23;

    server_settings = fopen("server_settings.conf", "r");
    if(server_settings != NULL){
    	while(fread(&serv, sizeof(ServSetting), 1, server_settings) && !feof(server_settings));
    	printf("serv ip: %s port: %d", serv.ip, serv.port);
    	fclose(server_settings);
    }
    else{
    	perror("Open server_settings.conf");
    }
    

	int loop = 1;
	int i, j;
	int lastclick = -1;
	int onIP = 1;

	char ip[32] = {0};
	char port[16] = {0};
	char _ip[33] = {0};
	char _port[17] = {0};
	//char filename[45] = {0};

	strcpy(ip, serv.ip);
    sprintf(port, "%d", serv.port);


	TTF_Font *f;
	TTF_Font *fBig;
	SDL_Event event;

	f = loadFont("minecraft.ttf", 15);
	fBig = loadFont("minecraft.ttf", 25);  

	img_srf = SDL_LoadBMP("grey_wool.bmp");
	img_txtu = SDL_CreateTextureFromSurface(ren, img_srf);
    SDL_FreeSurface(img_srf);

	while(loop){
	    for(i = 0; i <= 14; i++){
				for(j = 0; j <= 9; j++){
					tapisPos.x = i*80;
	    			tapisPos.y = j*80;
	    			tapisPos.w = 80;
	        		tapisPos.h = 80;
					SDL_RenderCopy(ren, img_txtu, NULL, &tapisPos);
				}
			}
		text(ren, fBig, "Roku Kotore", 450, 50, -1, -1, 255, 255, 255, 255);

		color(ren, 50, 50, 70);

		but = text(ren, f, "Continuer", 500, 600, -1, -1, 255, 255, 255, 255);       //-----
		butClick[0] = rect(ren, but.x - 100, but.y - 10, but.w + 200, but.h + 20, 1);  //  bouton
		text(ren, f, "Continuer", 500, 600, -1, -1, 255, 255, 255, 255);

		text(ren, f, "IP", 300, 300, -1, -1, 255, 255, 255, 255);
		text(ren, f, "PORT", 300, 400, -1, -1, 255, 255, 255, 255);

		color(ren, 10, 10, 10);
		but = text(ren, f, "#################################", 500, 300, -1, -1, 255, 255, 255, 255);       //-----
		butClick[1] = rect(ren, but.x - 10, but.y - 10, but.w + 20, but.h + 20, 1);  //  bouton
		sprintf(_ip, " %s", ip);
		text(ren, f, _ip, 500, 300, -1, -1, 255, 255, 255, 255);
		if(onIP){
			color(ren, 255, 255, 255);
			rect(ren, but.x - 10, but.y - 10, but.w + 20, but.h + 20, 0);
		}	

		color(ren, 10, 10, 10);
		but = text(ren, f, "#################", 500, 400, -1, -1, 255, 255, 255, 255);       //-----
		butClick[2] = rect(ren, but.x - 10, but.y - 10, but.w + 20, but.h + 20, 1);  //  bouton
		sprintf(_port, " %s", port);
		text(ren, f, _port, 500, 400, -1, -1, 255, 255, 255, 255);
		if(!onIP){
			color(ren, 255, 255, 255);
			rect(ren, but.x - 10, but.y - 10, but.w + 20, but.h + 20, 0);
		}

		switch(lastclick){
			case 0:
				strcpy(serv.ip, ip);
				sscanf(port, "%d", &serv.port);
				//printf("IP : %s PORT : %d\n", serv.ip, serv.port);
				server_settings = fopen("server_settings.conf", "w");
			    if(server_settings != NULL){
			    	printf("savingIP : %s PORT : %d\n", serv.ip, serv.port);
			    	fwrite(&serv, sizeof(ServSetting), 1, server_settings);
			    	fclose(server_settings);
			    }
			    else{
			    	perror("Open server_settings.conf (save)");
			    }
				loop = 0;
				break;

			case 1:
				onIP = 1;
				break;

			case 2:
				onIP = 0;
				break;
		}


		while(SDL_PollEvent(&event)){
			switch(event.type){
				case SDL_QUIT:
					loop = 0;
					break;
				case SDL_KEYDOWN:
					switch(event.key.keysym.sym){
						case SDLK_BACKSPACE:
							if(onIP){
								if(strlen(ip) > 0){
									ip[strlen(ip)-1] = 0;
								}
							}
							else{
								if(strlen(port) > 0){
									port[strlen(port)-1] = 0;
								}
							}
							break;
						case SDLK_RETURN:
							break;
							
						case SDLK_ESCAPE:
							loop = 0;
							break;
					}
					break;
				case SDL_TEXTINPUT:
					if(onIP){
						if(strlen(ip) < 32){
							strcat(ip, event.text.text);
						}
					}
					else{
						if(strlen(port) < 15){
							strcat(port, event.text.text);
						}
					}
					break;
				
				case SDL_MOUSEBUTTONUP:
					switch(event.button.button){
						case SDL_BUTTON_LEFT:
							for (i = 0; i < 3; i++)
							{
								if(mouseX() >= butClick[i].x && mouseX() <= butClick[i].x + butClick[i].w && mouseY() >= butClick[i].y && mouseY() <= butClick[i].y + butClick[i].h ){
									lastclick = i;
								}
							}
						break;
					}
					break;
			}
		}		
		drawScene(ren);
	}
	closeFont(f);
	closeFont(fBig);
	SDL_DestroyTexture(img_txtu);
}
Ejemplo n.º 5
0
void Grafix::loadFont(const ByteArrayPtr &memory, const String &fontname)
{
	MemFile ff(memory);
	loadFont(ff,fontname);
}
Ejemplo n.º 6
0
void MusicSelection::generateClickableButtons()
{
	MusicSelectionClickableButton button;
	//Note: Don't destroy generated textures that are created here! They are removed during uninit

	//Generate number of keys buttons
	{
		button.x = (int)(initVariables.musicSelection_gameKeys_button_x * ((float)initVariables.screen_width));
		button.y = (int)(initVariables.musicSelection_gameKeys_button_y * ((float)initVariables.screen_height));
		button.width = (int)(initVariables.musicSelection_gameKeys_button_width * ((float)initVariables.screen_width));
		button.height = (int)(initVariables.musicSelection_gameKeys_button_height * ((float)initVariables.screen_height));
		button.backgroundTexture.texture = NULL;
		button.text = "4 Key";
		SDL_Color color = { 255,255,255 };
		button.fontTexture = loadFont(Renderer, initVariables.musicSelection_font, 48, button.text, color);
		clickableButtons.push_back(button);

		button.x += button.width + ((int)(initVariables.musicSelection_gameKeys_button_separation * ((float)initVariables.screen_width)));
		button.text = "6 Key";
		button.fontTexture = loadFont(Renderer, initVariables.musicSelection_font, 48, button.text, color);
		clickableButtons.push_back(button);
	}

	//Generate difficulty buttons
	{
		int availableSpace = (int)(initVariables.musicSelection_albumArt_width_and_height * ((float)initVariables.screen_width));
		int totalSeparationSpace = availableSpace - ((int)(((float)initVariables.screen_height) * ((float)enums::TOTAL_DIFFICULTIES) * initVariables.musicSelection_difficulty_button_height));
		int separation = totalSeparationSpace / (enums::TOTAL_DIFFICULTIES - 1);

		button.y = (int)(initVariables.musicSelection_albumArt_y * ((float)initVariables.screen_height));
		button.x = (int)(((float)initVariables.screen_width) * initVariables.musicSelection_difficulty_button_x);
		button.width = (int)(((float)initVariables.screen_width) * initVariables.musicSelection_difficulty_button_width);
		button.height = (int)(((float)initVariables.screen_height) * initVariables.musicSelection_difficulty_button_height);
		button.backgroundTexture = loadTexture("round rectangle.png", Renderer);
		button.text = "EASY";
		SDL_Color color = { 0,0,0 };
		button.fontTexture = loadFont(Renderer, initVariables.musicSelection_font, 48, button.text, color);
		clickableButtons.push_back(button);

		button.y += (separation + button.height);
		button.text = "NORMAL";
		button.fontTexture = loadFont(Renderer, initVariables.musicSelection_font, 48, button.text, color);
		clickableButtons.push_back(button);

		button.y += (separation + button.height);
		button.text = "HARD";
		button.fontTexture = loadFont(Renderer, initVariables.musicSelection_font, 48, button.text, color);
		clickableButtons.push_back(button);

		button.y += (separation + button.height);
		button.text = "EXTREME";
		button.fontTexture = loadFont(Renderer, initVariables.musicSelection_font, 48, button.text, color);
		clickableButtons.push_back(button);
	}


	//Generate start game button
	{
		button.x = (int)(((float)initVariables.screen_width) * initVariables.musicSelection_startGame_button_x);
		button.y = (int)(((float)initVariables.screen_height) * initVariables.musicSelection_startGame_button_y);
		button.width = (int)(((float)initVariables.screen_width) * initVariables.musicSelection_startGame_button_width);
		button.height = (int)(((float)initVariables.screen_height) * initVariables.musicSelection_startGame_button_height);
		button.backgroundTexture.texture = NULL;
		button.text = "START";
		SDL_Color color = { 255,255,255 };
		button.fontTexture = loadFont(Renderer, initVariables.musicSelection_font, 48, button.text, color);
		clickableButtons.push_back(button);
	}
}
Ejemplo n.º 7
0
TextRendererTTF::TextRendererTTF(std::string fontFile)
{
    ScreenWidth = 600;
    ScreenHeight = 600;
    color[0] = 1;
    color[1] = 1;
    color[2] = 1;
    color[3] = 1;
    TextVBO = -1;
    TextVAO = -1;
    fontSize = 16;

    fontLoadError = GL_FALSE;
    shaderError = GL_FALSE;
    freetypeError = GL_FALSE;
    glewError = GL_FALSE;

    if (FT_Init_FreeType(&ft))
    {
        std::cerr << "Could not initialize freetype library." << std::endl;
        freetypeError = GL_TRUE;
    }

    // Turn on GLEW
    if (glewInit())
    {
        std::cerr << "Unable to initialize GLEW." << std::endl;
        glewError = GL_TRUE;
    }

    std::string vertShade =
    "#version 330\n"
    "attribute vec4 coord;\n"
    "varying vec2 texpos;\n"
    "uniform mat4 rotMat;\n"
    "void main(void) {\n"
    "  gl_Position = rotMat * vec4(coord.xy, 0, 1);\n"
    "  texpos = coord.zw;\n"
    "}\n";

    std::string fragShade =
    "#version 330\n"
    "varying vec2 texpos;\n"
    "uniform sampler2D tex;\n"
    "uniform vec4 color;\n"
    "void main(void) {\n"
    "  gl_FragColor = vec4(1, 1, 1, texture2D(tex, texpos).a) * color;\n"
    "}\n";

    shader.load(vertShade.c_str(), fragShade.c_str());

    if(shader.program == 0)
    {
        std::cerr << "Unable to create text shader." << std::endl;
        shaderError = GL_TRUE;
    }

    attribute_coord = glGetAttribLocation(shader.program, "coord");
    uniform_tex = glGetUniformLocation(shader.program, "tex");
    uniform_color = glGetUniformLocation(shader.program, "color");
    rotmat = glGetUniformLocation(shader.program, "rotMat");

    if(attribute_coord == -1 || uniform_tex == -1 || uniform_color == -1 || rotmat == -1)
    {
        std::cerr << "Unable to link attributes." << std::endl;
        shaderError = GL_TRUE;
    }

    // Create the vertex buffer object
    glGenBuffers(1, &TextVBO);
    glGenVertexArrays(1, &TextVAO);

    if (fontFile.compare("") != 0)
        loadFont(fontFile);
}
Ejemplo n.º 8
0
void Macro::draw(QGraphicsScene* scene, QColor background, QColor font) {
    //size 241, 281
    //QBrush Ybrush(Qt::blue);
    //scene->setBackgroundBrush(Ybrush);

    QFont titleFont("Times", 10, QFont::Bold);
    QGraphicsTextItem * titleItem = new QGraphicsTextItem;
    titleItem->setPos(70,10);
    titleItem->setDefaultTextColor(font);
    titleItem->setFont(titleFont);
    titleItem->setPlainText("Macro Recorder");
    scene->addItem(titleItem);

    QFont actFont("Times", 9, QFont::Bold);
    QGraphicsTextItem * actItem = new QGraphicsTextItem;
    actItem->setPos(30,40);
    actItem->setDefaultTextColor(font);
    actItem->setFont(actFont);
    if (activationKeyRec == false) {
        QChar key = static_cast<char>(activationKey);
        QString sKey = key;
        actItem->setPlainText("Activation Key: (" + sKey + ")");
    }
    else {
        actItem->setPlainText("Activation Key: RECORDING");
    }
    scene->addItem(actItem);

    QBrush onB(font);
    QPen onP(font);
    scene->addRect(160,150,40,40, onP, onB);
    scene->addRect(160,200,40,40, onP, onB);

    QFont onFont("Times", 11, QFont::Bold);
    QGraphicsTextItem * onItem = new QGraphicsTextItem;
    onItem->setPos(166,158);
    if (on) {
        onItem->setDefaultTextColor(Qt::yellow);
    }
    else {
       onItem->setDefaultTextColor(Qt::black);
    }
    onItem->setFont(onFont);
    onItem->setPlainText("On");
    scene->addItem(onItem);

    QFont offFont("Times", 11, QFont::Bold);
    QGraphicsTextItem * offItem = new QGraphicsTextItem;
    offItem->setPos(166,208);
    if (on) {
        offItem->setDefaultTextColor(Qt::black);
    }
    else {
       offItem->setDefaultTextColor(Qt::yellow);
    }
    offItem->setFont(offFont);
    offItem->setPlainText("Off");
    scene->addItem(offItem);

    if (recording) {
        QBrush recB(Qt::red);
        QPen recP(Qt::red);
        scene->addRect(60,80,30,30, recP, recB);
    }
    else {
        QBrush recB(font);
        QPen recP(font);
        scene->addRect(60,80,30,30, recP, recB);
    }

    QBrush loadB(font);
    QPen loadP(font);
    scene->addRect(140,80,30,30, loadP, loadB);

    QFont loadFont("Times", 7, QFont::Bold);
    QGraphicsTextItem * loadItem = new QGraphicsTextItem;
    loadItem->setPos(140,85);
    loadItem->setDefaultTextColor(Qt::black);
    loadItem->setFont(loadFont);
    loadItem->setPlainText("Load");
    scene->addItem(loadItem);

    QFont recFont("Times", 8, QFont::Bold);
    QGraphicsTextItem * recItem = new QGraphicsTextItem;
    recItem->setPos(61,83);
    recItem->setDefaultTextColor(Qt::black);
    recItem->setFont(recFont);
    recItem->setPlainText("Rec");
    scene->addItem(recItem);

}
Ejemplo n.º 9
0
bool StyledTTFont::loadFont(const Common::String &fontName, int32 point, uint style) {
	_style = style;
	return loadFont(fontName, point);
}
Ejemplo n.º 10
0
void ofxBaseGui::setUseTTF(bool bUseTTF){
	if(bUseTTF && !fontLoaded){
		loadFont(OF_TTF_MONO,10,true,true);
	}
	useTTF = bUseTTF;
}
Ejemplo n.º 11
0
//--------------------------------------------------------------
void ofxFreeType2::loadFont(string filepath, int size) {
	loadFont(filepath, size, true, false,false);
}
Ejemplo n.º 12
0
void ofTrueTypeFont::reloadTextures(){
	loadFont(filename, fontSize, bAntiAliased, bFullCharacterSet, bMakeContours, simplifyAmt, dpi);
}
Ejemplo n.º 13
0
//--------------------------------------------------------	
ADMVideoSubtitle::ADMVideoSubtitle(AVDMGenericVideoStream *in,CONFcouple *couples)
{

  uint32_t frame;
//  char c;

  _uncompressed=NULL;
  _font=NULL;


  _in=in;
  memcpy(&_info,_in->getInfo(),sizeof(_info));

	frame=3*_in->getInfo()->width*_in->getInfo()->height;

	_subs=NULL;
	_fd=NULL;
 	_line=0;
	_oldframe=0;
	_oldline=0;
	_font = new ADMfont();	
	if(couples)
	{
                int32_t b;
			SUBCONF *_param;
			_conf=NEW( SUBCONF);


			_param=_conf; // keep macro happy

			GET(_fontsize);
			GET(_subname);
			GET(_fontname);
			GET(_charset);
			GET(_baseLine);
			GET(_Y_percent);
			GET(_U_percent);
			GET(_V_percent);
			GET(_selfAdjustable);
			GET(_delay);
			GET(_useBackgroundColor);
			GET(_bg_Y_percent);
      			GET(_bg_U_percent);
      			GET(_bg_V_percent);
//                        GET(_blend);
                        couples->getCouple("_blend",&b);
                        _param->_blend=(BlendMode)b;
			if(_conf->_baseLine>_info.height-_conf->_fontsize*SRT_MAX_LINE)
                        {
                                printf("Base exceeded : base :%lu height :%lu bottom:%lu\n",
                                        _conf->_baseLine,_info.height,_info.height-_conf->_fontsize*SRT_MAX_LINE);
                                _conf->_baseLine=_conf->_fontsize*SRT_MAX_LINE;
                        }

                    char *ft,*sub;
                        ft=(char *)ADM_alloc(500);
                        sub=(char *)ADM_alloc(500);
                        strcpy(ft,(char *)_conf->_subname); 
                        _conf->_subname=(ADM_filename *)ft;
                        strcpy(sub,(char *)_conf->_fontname); 
                        _conf->_fontname=(ADM_filename *)sub;

                        sub=(char *)ADM_alloc(500);
                        strcpy(sub,_conf->_charset);
                        _conf->_charset=sub;
                        loadSubtitle();
                        loadFont();

	}
	else
	{
			_conf=NEW( SUBCONF);

			_conf->_fontname=(ADM_filename *)ADM_alloc(500);
			_conf->_subname=(ADM_filename *)ADM_alloc(500);
			_conf->_charset=(char *)ADM_alloc(500);
			_conf->_fontname[0]=0;
			_conf->_subname[0]=0;
			_conf->_charset[0]=0;
			
			
			_conf->_baseLine=_info.height-24*SRT_MAX_LINE;
			_conf->_Y_percent=255;
			_conf->_U_percent=0;
			_conf->_V_percent=0;
                        _conf->_fontsize=24; 
			_conf->_selfAdjustable=0;
			_conf->_delay=0;
			_conf->_useBackgroundColor=0;
			
			_conf->_bg_Y_percent=0;
			_conf->_bg_U_percent=0;
			_conf->_bg_V_percent=0;
                        _conf->_blend=BLEND_SOLID;

			prefs->get(FILTERS_SUBTITLE_FONTSIZE,&(_conf->_fontsize));
			prefs->get(FILTERS_SUBTITLE_YPERCENT,&(_conf->_Y_percent));
			prefs->get(FILTERS_SUBTITLE_UPERCENT,&(_conf->_U_percent));
			prefs->get(FILTERS_SUBTITLE_VPERCENT,&(_conf->_V_percent));
			prefs->get(FILTERS_SUBTITLE_SELFADJUSTABLE,&(_conf->_selfAdjustable));			
			prefs->get(FILTERS_SUBTITLE_USEBACKGROUNDCOLOR,&(_conf->_useBackgroundColor));
			
			// _conf->_fontname, ... are used as memory for a dialog
			// later. we can't used the length of the current string
			{ char *tmp;
			   prefs->get(FILTERS_SUBTITLE_FONTNAME,&tmp);
			   strcpy((char *)_conf->_fontname,tmp);
			   ADM_dealloc(tmp);
			   
			   prefs->get(FILTERS_SUBTITLE_CHARSET,&tmp);
			   strcpy(_conf->_charset,tmp); 
                           ADM_dealloc(tmp);
			}
			
	}

  
  	_info.encoding=1;


	_bitmap=0xffffffff;
#define BITMAP_SIZE _info.width*_conf->_fontsize*SRT_MAX_LINE
	_bitmapBuffer=new uint8_t[_info.width*_info.height];
	_maskBuffer=new uint8_t[_info.width*_info.height];
  _bgBitmapBuffer=new uint8_t[(_info.width*_info.height)>>1];
	_bgMaskBuffer=new uint8_t[_info.width*_info.height];
        _dirty=new uint8_t[_info.height];
	ADM_assert(_bitmapBuffer);
	ADM_assert(_maskBuffer);
	ADM_assert(_bgBitmapBuffer);
	ADM_assert(_bgMaskBuffer);
        ADM_assert(_dirty);
}
Ejemplo n.º 14
0
struct FontData *
awtJNI_GetFontData(JNIEnv * env, jobject font, char **errmsg)
{
    /* We are going to create at most 4 outstanding local refs in this
     * function. */
    if ((*env)->EnsureLocalCapacity(env, 4) < 0) {
        return NULL;
    }

    if (!JNU_IsNull(env, font) && awtJNI_IsMultiFont(env, font)) {
        JNU_CHECK_EXCEPTION_RETURN(env, NULL);

        struct FontData *fdata = NULL;
        int32_t i, size;
        char *fontsetname = NULL;
        char *nativename = NULL;
        Boolean doFree = FALSE;
        jobjectArray componentFonts = NULL;
        jobject peer = NULL;
        jobject fontDescriptor = NULL;
        jstring fontDescriptorName = NULL;
        jstring charsetName = NULL;

        fdata = (struct FontData *) JNU_GetLongFieldAsPtr(env,font,
                                                         fontIDs.pData);

        if (fdata != NULL && fdata->flist != NULL) {
            return fdata;
        }
        size = (*env)->GetIntField(env, font, fontIDs.size);
        fdata = (struct FontData *) malloc(sizeof(struct FontData));

        peer = (*env)->CallObjectMethod(env, font, fontIDs.getPeer);

        componentFonts =
          (*env)->GetObjectField(env, peer, platformFontIDs.componentFonts);
        /* We no longer need peer */
        (*env)->DeleteLocalRef(env, peer);

        fdata->charset_num = (*env)->GetArrayLength(env, componentFonts);

        fdata->flist = (awtFontList *) malloc(sizeof(awtFontList)
                                              * fdata->charset_num);
        fdata->xfont = NULL;
        for (i = 0; i < fdata->charset_num; i++) {
            /*
             * set xlfd name
             */

            fontDescriptor = (*env)->GetObjectArrayElement(env, componentFonts, i);
            fontDescriptorName =
              (*env)->GetObjectField(env, fontDescriptor,
                                     fontDescriptorIDs.nativeName);

            if (!JNU_IsNull(env, fontDescriptorName)) {
                nativename = (char *) JNU_GetStringPlatformChars(env, fontDescriptorName, NULL);
                if (nativename == NULL) {
                    nativename = "";
                    doFree = FALSE;
                } else {
                    doFree = TRUE;
                }
            } else {
                nativename = "";
                doFree = FALSE;
            }

            fdata->flist[i].xlfd = malloc(strlen(nativename)
                                          + strlen(defaultXLFD));
            jio_snprintf(fdata->flist[i].xlfd, strlen(nativename) + 10,
                         nativename, size * 10);

            if (nativename != NULL && doFree)
                JNU_ReleaseStringPlatformChars(env, fontDescriptorName, (const char *) nativename);

            /*
             * set charset_name
             */

            charsetName =
              (*env)->GetObjectField(env, fontDescriptor,
                                     fontDescriptorIDs.charsetName);

            fdata->flist[i].charset_name = (char *)
                JNU_GetStringPlatformChars(env, charsetName, NULL);
            if (fdata->flist[i].charset_name == NULL) {
                (*env)->ExceptionClear(env);
                JNU_ThrowOutOfMemoryError(env, "Could not create charset name");
                return NULL;
            }

            /* We are done with the objects. */
            (*env)->DeleteLocalRef(env, fontDescriptor);
            (*env)->DeleteLocalRef(env, fontDescriptorName);
            (*env)->DeleteLocalRef(env, charsetName);

            /*
             * set load & XFontStruct
             */
            fdata->flist[i].load = 0;

            /*
             * This appears to be a bogus check.  The actual intent appears
             * to be to find out whether this is the "base" font in a set,
             * rather than iso8859_1 explicitly.  Note that iso8859_15 will
             * and must also pass this test.
             */

            if (fdata->xfont == NULL &&
                strstr(fdata->flist[i].charset_name, "8859_1")) {
                fdata->flist[i].xfont =
                    loadFont(awt_display, fdata->flist[i].xlfd, size * 10);
                if (fdata->flist[i].xfont != NULL) {
                    fdata->flist[i].load = 1;
                    fdata->xfont = fdata->flist[i].xfont;
                    fdata->flist[i].index_length = 1;
                } else {
                    /* Free any already allocated storage and fonts */
                    int j = i;
                    for (j = 0; j <= i; j++) {
                        free((void *)fdata->flist[j].xlfd);
                        JNU_ReleaseStringPlatformChars(env, NULL,
                            fdata->flist[j].charset_name);
                        if (fdata->flist[j].load) {
                            XFreeFont(awt_display, fdata->flist[j].xfont);
                        }
                    }
                    free((void *)fdata->flist);
                    free((void *)fdata);

                    if (errmsg != NULL) {
                        *errmsg = "java/lang" "NullPointerException";
                    }
                    (*env)->DeleteLocalRef(env, componentFonts);
                    return NULL;
                }
            }
        }
        (*env)->DeleteLocalRef(env, componentFonts);
        /*
         * XFontSet will create if the peer of TextField/TextArea
         * are used.
         */
        fdata->xfs = NULL;

        JNU_SetLongFieldFromPtr(env,font,fontIDs.pData,fdata);
        Disposer_AddRecord(env, font, pDataDisposeMethod, ptr_to_jlong(fdata));
        return fdata;
    } else {
        JNU_CHECK_EXCEPTION_RETURN(env, NULL);
        Display *display = NULL;
        struct FontData *fdata = NULL;
        char fontSpec[1024];
        int32_t height;
        int32_t oheight;
        int32_t above = 0;              /* tries above height */
        int32_t below = 0;              /* tries below height */
        char *foundry = NULL;
        char *name = NULL;
        char *encoding = NULL;
        char *style = NULL;
        XFontStruct *xfont = NULL;
        jstring family = NULL;

        if (JNU_IsNull(env, font)) {
            if (errmsg != NULL) {
                *errmsg = "java/lang" "NullPointerException";
            }
            return (struct FontData *) NULL;
        }
        display = XDISPLAY;

        fdata = (struct FontData *) JNU_GetLongFieldAsPtr(env,font,fontIDs.pData);
        if (fdata != NULL && fdata->xfont != NULL) {
            return fdata;
        }

        family = (*env)->CallObjectMethod(env, font, fontIDs.getFamily);

        if (!awtJNI_FontName(env, family, &foundry, &name, &encoding)) {
            if (errmsg != NULL) {
                *errmsg = "java/lang" "NullPointerException";
            }
            (*env)->DeleteLocalRef(env, family);
            return (struct FontData *) NULL;
        }
        style = Style((*env)->GetIntField(env, font, fontIDs.style));
        oheight = height = (*env)->GetIntField(env, font, fontIDs.size);

        while (1) {
            jio_snprintf(fontSpec, sizeof(fontSpec), "-%s-%s-%s-*-*-%d-*-*-*-*-*-%s",
                         foundry,
                         name,
                         style,
                         height,
                         encoding);

            /*fprintf(stderr,"LoadFont: %s\n", fontSpec); */
            xfont = XLoadQueryFont(display, fontSpec);

            /* XXX: sometimes XLoadQueryFont returns a bogus font structure */
            /* with negative ascent. */
            if (xfont == (Font) NULL || xfont->ascent < 0) {
                if (xfont != NULL) {
                    XFreeFont(display, xfont);
                }
                if (foundry != anyfoundry) {  /* Use ptr comparison here, not strcmp */
                    /* Try any other foundry before messing with the sizes */
                    foundry = anyfoundry;
                    continue;
                }
                /* We couldn't find the font. We'll try to find an */
                /* alternate by searching for heights above and below our */
                /* preferred height. We try for 4 heights above and below. */
                /* If we still can't find a font we repeat the algorithm */
                /* using misc-fixed as the font. If we then fail, then we */
                /* give up and signal an error. */
                if (above == below) {
                    above++;
                    height = oheight + above;
                } else {
                    below++;
                    if (below > 4) {
                        if (name != defaultfontname || style != anystyle) {
                            name = defaultfontname;
                            foundry = defaultfoundry;
                            height = oheight;
                            style = anystyle;
                            encoding = isolatin1;
                            above = below = 0;
                            continue;
                        } else {
                            if (errmsg != NULL) {
                                *errmsg = "java/io/" "FileNotFoundException";
                            }
                            (*env)->DeleteLocalRef(env, family);
                            return (struct FontData *) NULL;
                        }
                    }
                    height = oheight - below;
                }
                continue;
            } else {
                fdata = ZALLOC(FontData);

                if (fdata == NULL) {
                    if (errmsg != NULL) {
                        *errmsg = "java/lang" "OutOfMemoryError";
                    }
                } else {
                    fdata->xfont = xfont;
                    JNU_SetLongFieldFromPtr(env,font,fontIDs.pData,fdata);
                    Disposer_AddRecord(env, font, pDataDisposeMethod,
                                       ptr_to_jlong(fdata));
                }
                (*env)->DeleteLocalRef(env, family);
                return fdata;
            }
        }
        /* not reached */
    }
}
Ejemplo n.º 15
0
static void initWithFont(int fontSize)
{
	loadFont(false);
	refreshScreen();
}
Ejemplo n.º 16
0
bool Graphics::loadFonts(const char *font, const char *boldFont) {
  return (!FT_Init_FreeType(&_fontLibrary) &&
          loadFont(font, _fontFace) &&
          loadFont(boldFont, _fontFaceB));
}
Ejemplo n.º 17
0
VolumeListingDialog::VolumeListingDialog(QWidget* parent) 
    : QWidget(parent)
    , reader_(0)
{
    setWindowFlags(Qt::Dialog);
    setWindowModality(Qt::WindowModal);
    setWindowTitle(tr("Volume Selection"));

    // table configuration
    table_ = new QTableWidget();
    table_->setSelectionBehavior(QAbstractItemView::SelectRows);
    table_->setSortingEnabled(true);
    table_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

    // top label
    QVBoxLayout* mainLayout = new QVBoxLayout();
    titleLabel_ = new QLabel(tr("The selected file contains multiple volumes. Please select the volumes to load:"));
    QFont labelFont = titleLabel_->font();
    labelFont.setPointSize(titleLabel_->font().pointSize()+1);
    labelFont.setBold(true);
    titleLabel_->setFont(labelFont);
    mainLayout->addWidget(titleLabel_);
    
    // filter bar
    QHBoxLayout* searchLayout = new QHBoxLayout();
    filterLabel_ = new QLabel(tr("Filter: "));
    searchLayout->addWidget(filterLabel_);
    filterTextBox_ = new QLineEdit();
    searchLayout->addWidget(filterTextBox_);
    comboBoxFilterAttribute_ = new QComboBox();
    comboBoxFilterAttribute_->setMinimumWidth(100);
    searchLayout->addWidget(comboBoxFilterAttribute_);
    mainLayout->addLayout(searchLayout);

    // table
    mainLayout->addWidget(table_);

    // buttons
    QHBoxLayout* buttonLayout = new QHBoxLayout();
    buttonLayout->addStretch();
    cancelButton_ = new QPushButton(tr("Cancel"));
    cancelButton_->setFixedWidth(100);
    buttonLayout->addWidget(cancelButton_);
    selectAllButton_ = new QPushButton(tr("Select All"));
    selectAllButton_->setFixedWidth(100);
    buttonLayout->addWidget(selectAllButton_);
    loadButton_ = new QPushButton(tr("Load"));
    loadButton_->setFixedWidth(100);
    QFont loadFont(loadButton_->font());
    loadFont.setBold(true);
    loadButton_->setFont(loadFont);
    buttonLayout->addWidget(loadButton_);
    mainLayout->addLayout(buttonLayout);

    setLayout(mainLayout);

    connect(table_, SIGNAL(itemSelectionChanged()), this, SLOT(updateGuiState()));
    connect(table_, SIGNAL(cellDoubleClicked(int, int)), this, SLOT(cellDoubleClicked()));

    connect(filterTextBox_, SIGNAL(textChanged(const QString&)), this, SLOT(updateTableRows()));
    connect(filterTextBox_, SIGNAL(editingFinished()), this, SLOT(updateTableRows()));
    connect(comboBoxFilterAttribute_, SIGNAL(currentIndexChanged(int)), this, SLOT(updateTableRows()));

    connect(loadButton_, SIGNAL(clicked()), this, SLOT(loadClicked()));
    connect(selectAllButton_, SIGNAL(clicked()), this, SLOT(selectAllClicked()));
    connect(cancelButton_, SIGNAL(clicked()), this, SLOT(cancelClicked()));

    resize(600, 300);
    updateGuiState();
}
Ejemplo n.º 18
0
int main(int argc, char* args[])
{
	Player player1;
	Player player2;

	struct Ball ball;
	struct Vector vel;

	// Players vars
	int moveP1, moveP2;
	player1.score = player2.score = 0;

	// Keyboard
	const Uint8* keyState;

	char buffer[65];
	int r = 10;

	// Color

	SDL_Color textColor = { 255, 255, 255, 255 };
	
	// Init players positions
	moveP1 = moveP2 = SCREEN_HEIGHT / 2 - PLAYER_HEIGHT / 2;

	// Init ball
	ball.w = ball.h = 10;
	ball.x = SCREEN_WIDTH / 2 - ball.w / 2;
	ball.y = SCREEN_HEIGHT / 2 - ball.w / 2;	
	ball.speed = 4;

	// Init ball velocity
	vel.x = 1;
	vel.y = 1;

	if (initSDL());
	{
		loadFont();

		scorePlayer1 = loadTextTexture(_itoa(player1.score, buffer, r), textColor);
		scorePlayer2 = loadTextTexture(_itoa(player2.score, buffer, r), textColor);
		// Main loop
		while (!quit)
		{
			// Event loop
			while (SDL_PollEvent(&e) != 0)
			{
				// User presses the close button
				if (e.type == SDL_QUIT)
					quit = true;
			}

			keyState = SDL_GetKeyboardState(NULL);
			if (keyState[SDL_SCANCODE_A])
			{
				if ((moveP1 + PLAYER_HEIGHT) < SCREEN_HEIGHT)
				{
					moveP1 += PLAYER_SPEED;
					//printf("Player1: %d\n", moveP1 + PLAYER_HEIGHT);
				}
			}
			if (keyState[SDL_SCANCODE_S])
			{
				if (moveP1 > 10)
				{
					moveP1 -= PLAYER_SPEED;
					//printf("Player1: %d\n", moveP1);
				}
			}
			if (keyState[SDL_SCANCODE_J])
			{
				if ((moveP2 + PLAYER_HEIGHT) < SCREEN_HEIGHT)
				{
					moveP2 += PLAYER_SPEED;
					//printf("Player2: %d\n", moveP2 + PLAYER_HEIGHT);
				}
			}
			if (keyState[SDL_SCANCODE_K])
			{
				if (moveP2 > 10)
				{
					moveP2 -= PLAYER_SPEED;
					//printf("Player2: %d\n", moveP2);
				}
			}

			// Bounce of player1
			if ( (ball.x <= (20 + PLAYER_WIDTH)) && ((ball.y >= moveP1) && (ball.y <= moveP1 + PLAYER_HEIGHT)) )
			{
				vel.x *= -1;
			}

			// Bounce of player2
			else if ( (ball.x + 10 >= (SCREEN_WIDTH - PLAYER_WIDTH - 20)) && ((ball.y >= moveP2) && (ball.y <= moveP2 + PLAYER_HEIGHT)) )
			{
				vel.x *= -1;
			}

			// Bounce from top and bottom edges
			if ( (ball.y + 10 >= SCREEN_HEIGHT) || (ball.y <= 0) )
			{
				vel.y *= -1;
			}

			// Player 1 won
			if (ball.x + ball.w >= SCREEN_WIDTH)
			{
				player1.score += 1;
				scorePlayer1 = loadTextTexture(_itoa(player1.score, buffer, r), textColor);
				resetBall(&ball, "Player 1 won!\n");
			}

			// Player 2 won
			if (ball.x + ball.w <= 0)
			{
				player2.score += 1;
				scorePlayer2 = loadTextTexture(_itoa(player2.score, buffer, r), textColor);
				resetBall(&ball, "Player 2 won!\n");
			}

			ball.x += (int)vel.x * ball.speed;
			ball.y += (int)vel.y * ball.speed;

			// Clear screen
			SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
			SDL_RenderClear(renderer);

			// Draw objects
			drawPlayers(moveP1, moveP2);
			drawBall(ball);

			// Draw text
			renderTextTexture(scorePlayer1, SCREEN_WIDTH / 4 - scorePlayer1.w / 2, 20);
			renderTextTexture(scorePlayer2, SCREEN_WIDTH * 3 / 4 - scorePlayer2.w / 2, 20);

			// Update screen
			SDL_RenderPresent(renderer);
		}

		closeSDL();
	}

	return 0;
}
Ejemplo n.º 19
0
MusicSelectionPanel MusicSelection::generateMusicSelectionPanel(int index)
{
	SDL_Color color = { 0,0,0 };
	MusicSelectionPanel msp = { loadFont(Renderer,initVariables.musicSelection_font,48,beatMaps[index].songName, color), index, 0, 0, (int)(initVariables.musicSelection_panel_width * ((float)initVariables.screen_height)) };
	return msp;
}
Ejemplo n.º 20
0
bool MMSLabelWidget::prepareText(int *width, int *height, bool recalc) {
    // check if we have to (re)load the font
    this->surface->lock();

    loadFont();

    if (!this->font) {
        this->surface->unlock();
        return false;
    }

    // font available, use it for this surface
    this->surface->setFont(this->font);

    this->surface->unlock();

    if (!this->translated) {
        // text changed and have to be translated
        if ((this->rootwindow)&&(this->rootwindow->windowmanager)&&(getTranslate())) {
            // translate text
            string source;
            getText(source);
            this->rootwindow->windowmanager->getTranslator()->translate(source, this->translated_text);
        }
        else {
            // text can not or should not translated
            getText(this->translated_text);
        }

        // reset swap flag
        this->swap_left_right = false;

        // language specific conversions
        MMSLanguage targetlang = this->rootwindow->windowmanager->getTranslator()->getTargetLang();
        if ((targetlang == MMSLANG_IL) || (targetlang == MMSLANG_AR)) {
            if (convBidiString(this->translated_text, this->translated_text), (targetlang == MMSLANG_AR) ? true : false) {
                // bidirectional conversion successful, swap alignment horizontal
                this->swap_left_right = true;
            }
        }

        // mark as translated
        this->translated = true;
    }

    // get width and height of the string to be drawn
    int realWidth, realHeight;
    this->font->getStringWidth(this->translated_text, -1, &realWidth);
    this->font->getHeight(&realHeight);

    if (!this->minmax_set) {
        if (width)  *width = realWidth;
        if (height) *height = realHeight;
    }
    else {
        if (recalc) {
            // calculate dynamic label size

            // get maximum width and height of the label
            int maxWidth = getMaxWidthPix();
            if (maxWidth <= 0) maxWidth = getInnerGeometry().w;
            int maxHeight = getMaxHeightPix();
            if (maxHeight <= 0) maxHeight = getInnerGeometry().h;

            // get minimum width and height of the label
            int minWidth = getMinWidthPix();
            int minHeight = getMinHeightPix();

            if (width)  {
                if (realWidth < minWidth)
                    *width = minWidth;
                else if (realWidth > maxWidth)
                    *width = maxWidth;
                else
                    *width = realWidth;

                if (*width <= 0) *width = 1;
            }

            if (height) {
                if (realHeight < minHeight)
                    *height = minHeight;
                else if (realHeight > maxHeight)
                    *height = maxHeight;
                else
                    *height = realHeight;

                if (*height <= 0) *height = 1;
            }
        }
        else {
            if (width)  *width = realWidth;
            if (height) *height = realHeight;
        }
    }

    return true;
}
Ejemplo n.º 21
0
int
main(int argc, char *argv[])
{

    int index;                  /* index of last key we pushed in the bitmap font */
    SDL_Window *window;
    SDL_Event event;            /* last event received */
    SDL_Keymod mod;             /* key modifiers of last key we pushed */
    SDL_Scancode scancode;      /* scancode of last key we pushed */

    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
        printf("Error initializing SDL: %s", SDL_GetError());
    }
    /* create window */
    window = SDL_CreateWindow("iPhone keyboard test", 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0);
    /* create renderer */
    renderer = SDL_CreateRenderer(window, -1, 0);

    /* load up our font */
    loadFont();

    /* draw the background, we'll just paint over it */
    SDL_SetRenderDrawColor(renderer, bg_color.r, bg_color.g, bg_color.b, bg_color.a);
    SDL_RenderFillRect(renderer, NULL);
    SDL_RenderPresent(renderer);

    int done = 0;
    /* loop till we get SDL_Quit */
    while (SDL_WaitEvent(&event)) {
        switch (event.type) {
        case SDL_QUIT:
            done = 1;
            break;
        case SDL_KEYDOWN:
            index = keyToIndex(event.key.keysym);
            scancode = event.key.keysym.scancode;
            mod = event.key.keysym.mod;
            if (scancode == SDL_SCANCODE_DELETE) {
                /* if user hit delete, delete the last character */
                backspace();
                lastCharWasColon = 0;
            } else if (lastCharWasColon && scancode == SDL_SCANCODE_0
                       && (mod & KMOD_SHIFT)) {
                /* if our last key was a colon and this one is a close paren, the make a hoppy face */
                backspace();
                drawIndex(32);  /* index for happy face */
                numChars++;
                drawCursor();
                lastCharWasColon = 0;
            } else if (index != -1) {
                /* if we aren't doing a happy face, then just draw the normal character */
                drawIndex(index);
                numChars++;
                drawCursor();
                lastCharWasColon =
                    (event.key.keysym.scancode == SDL_SCANCODE_SEMICOLON
                     && (event.key.keysym.mod & KMOD_SHIFT));
            }
            /* check if the key was a colon */
            /* draw our updates to the screen */
            SDL_RenderPresent(renderer);
            break;
        case SDL_MOUSEBUTTONUP:
            /*      mouse up toggles onscreen keyboard visibility */
            if (SDL_IsTextInputActive()) {
                SDL_StopTextInput();
            } else {
                SDL_StartTextInput();
            }
            break;
        }
    }
    cleanup();
    return 0;
}
Ejemplo n.º 22
0
//------------------------------------------------------------------------------
// Halo Font functions
// FtglHaloFont::outputText() -- FtglHaloFont output routines
//------------------------------------------------------------------------------
void FtglHaloFont::outputText(const double x, const double y, const char* txt, const int n, const bool vf, const bool rf)
{
    GLfloat ocolor[4];
    glGetFloatv(GL_CURRENT_COLOR, ocolor);        

    // Make sure we have characters to print
    if (n <= 0) return;

    // Make sure we have a loaded font
    if (isNotLoaded()) {
        loadFont();
        if (isNotLoaded()) throw new ExpInvalidFont();
    }

    // Prepare the output text
    char cbuf[MSG_BUF_LEN];
    int nn = xferChars(cbuf,MSG_BUF_LEN,txt,n);
    if (nn <= 0) return;

    if (haloColor != 0) Graphic::lcColor3(haloColor->red(), haloColor->green(), haloColor->blue()); 
    // default to black if we have no color specified
    else glColor3f(0,0,0);

    // now render the outline font over it! 
    if (!rf) {
        if (outline != 0) {
            glPushMatrix();
            glTranslated(x, y, -0.01f);
            // get our current linewidth
            GLfloat lw = 0;
            glGetFloatv(GL_LINE_WIDTH, &lw);
            glLineWidth(linewidth);
            glScalef(GLfloat(getFontWidth()), GLfloat(getFontHeight()), 1.0f);
            if (vf) {
                // Vertical text
                GLdouble dy = getLineSpacing();
                if (getFontHeight() != 0.0) dy = getLineSpacing() / getFontHeight();
                char cc[2];
                cc[1] = '\0';
                for (int i = 0; i < nn; i++) {
                    cc[0] = cbuf[i];
                    outline->Render(cc);    
                    glTranslated(0.0, -dy, 0.0);
                }
            }
            else {
                // Normal text
                outline->Render(cbuf);    
            }
            glLineWidth(lw);
            glPopMatrix();
        } 
        else {
              if (isMessageEnabled(MSG_ERROR)) {
                  std::cerr << "FtglHaloFont::outputText() - no outline font available" << std::endl;
              }
        }
    }

    glColor4fv(ocolor);

    // output the text
    FTGLPolygonFont* ftgl1 = (FTGLPolygonFont*)FTGL();   
    if (ftgl1 != 0) {
        glPushMatrix();
        glTranslated(x, y, 0.0);
        glScalef(GLfloat(getFontWidth()), GLfloat(getFontHeight()), 1.0f);
        if (vf) {
            // Vertical text
            GLdouble dy = getLineSpacing();
            if (getFontHeight() != 0.0) dy = getLineSpacing() / getFontHeight();
            char cc[2];
            cc[1] = '\0';
            for (int i = 0; i < nn; i++) {
                cc[0] = cbuf[i];
                ftgl1->Render(cc);    
                glTranslated(0.0, -dy, 0.0);
            }
        }
        else {
            // Normal text
            ftgl1->Render(cbuf);    
        }
        glPopMatrix();
    }   
    else {
          if (isMessageEnabled(MSG_ERROR)) {
              std::cerr << "FtglPolygonFont::outputText() - no Polygon font available" << std::endl;
          }
    }
}
Ejemplo n.º 23
0
int XMessageBox::show()
{
   if (mDisplay == NULL)
      return -1;

   int retVal = 0;
   retVal = loadFont();
   if (retVal < 0)
      return retVal;

   // set the maximum window dimensions
   mScreenWidth = DisplayWidth(mDisplay, DefaultScreen(mDisplay));
   mScreenHeight = DisplayHeight(mDisplay, DefaultScreen(mDisplay));
   mMaxWindowWidth = min(mScreenWidth, MessageBox_MaxWinWidth);
   mMaxWindowHeight = min(mScreenHeight, MessageBox_MaxWinHeight);

   // split the message into a vector of lines
   splitMessage();

   // set the dialog dimensions
   setDimensions();

   mWin = XCreateSimpleWindow(
      mDisplay,
      DefaultRootWindow(mDisplay),
      (mScreenWidth - mMBWidth) / 2,  (mScreenHeight - mMBHeight) / 2,
      mMBWidth, mMBHeight,
      1, 
      BlackPixel(mDisplay, DefaultScreen(mDisplay)),
      WhitePixel(mDisplay, DefaultScreen(mDisplay)));

   mGC = XCreateGC(mDisplay, mWin, 0, 0);

   XSetFont(mDisplay, mGC, mFS->fid);

   // set input mask
   XSelectInput(mDisplay, mWin, 
      ExposureMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask);

   // set wm protocols in case they hit X
   Atom wm_delete_window = 
      XInternAtom(mDisplay, "WM_DELETE_WINDOW", False);
   Atom wm_protocols = 
      XInternAtom(mDisplay, "WM_PROTOCOLS", False);
   XSetWMProtocols (mDisplay, mWin, &wm_delete_window, 1);
   // set pop up dialog hint
   XSetTransientForHint(mDisplay, mWin, mWin);
   
   // set title
   XTextProperty wtitle;
   wtitle.value = (unsigned char *)mTitle;
   wtitle.encoding = XA_STRING;
   wtitle.format = 8;
   wtitle.nitems = strlen(mTitle);
   XSetWMName(mDisplay, mWin, &wtitle);

   // show window
   XMapRaised(mDisplay, mWin);
   // move it in case some bozo window manager repositioned it
   XMoveWindow(mDisplay, mWin, 
      (mScreenWidth - mMBWidth) / 2,  (mScreenHeight - mMBHeight) / 2);
   // raise it to top
   XRaiseWindow(mDisplay, mWin);

   XMessageBoxButton* clickedButton = NULL;
   XEvent event;
   Vector<XMessageBoxButton>::iterator iter;
   bool done = false;
   while (!done)
   {
      XNextEvent(mDisplay, &event);
      switch (event.type)
      {
         case Expose:
            repaint();
            break;
         case MotionNotify:
            for (iter = mButtons.begin(); iter != mButtons.end(); ++iter)
               iter->setMouseCoordinates(event.xmotion.x, event.xmotion.y);
            break;
         case ButtonPress:
            for (iter = mButtons.begin(); iter != mButtons.end(); ++iter)
            {
               if (iter->pointInRect(event.xbutton.x, event.xbutton.y))
               {
                  iter->setMouseDown(true);
                  iter->setMouseCoordinates(event.xbutton.x, event.xbutton.y);
                  break;
               }
            }
            break;
         case ButtonRelease:
            for (iter = mButtons.begin(); iter != mButtons.end(); ++iter)
            {
               if (iter->pointInRect(event.xbutton.x, event.xbutton.y) &&
                  iter->isMouseDown())
               {
                  // we got a winner!
                  clickedButton = iter;
                  done = true;
                  break;
               }
            }
            if (clickedButton == NULL)
            {
               // user released outside a button.  clear the button states
               for (iter = mButtons.begin(); iter != mButtons.end(); ++iter)
                  iter->setMouseDown(false);
            }
            break;
         case ClientMessage:
            if (event.xclient.message_type == wm_protocols &&
               event.xclient.data.l[0] == static_cast<long>(wm_delete_window))
               done = true;
            break;
      }
      repaint();
   }

   XUnmapWindow(mDisplay, mWin);
   XDestroyWindow(mDisplay, mWin);
   XFreeGC(mDisplay, mGC);
   XFreeFont(mDisplay, mFS);

   if (clickedButton != NULL)
      return clickedButton->getClickVal();
   else
      return -1;
}
Ejemplo n.º 24
0
void Grafix::loadFont(const String &filename, const String &fontname)
{
	File ff;
	ff.open(filename,File::READ);
	loadFont(ff,fontname);
}