16
Window / Windows .. Cursor-Changes .. only for a Moment visibly ..
« on: June 03, 2012, 09:47:56 am »
deleted
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
#include "stdafx.h"
#ifdef _WIN32
int APIENTRY _tWinMain
(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow
)
#else
int main(void)
#endif
{
#ifdef _DEBUG
sf::RenderWindow window(sf::VideoMode(950, 150), "SFML works!");
#else
//sf::RenderWindow window(sf::VideoMode::getDesktopMode(), "SFML works!", sf::Style::Fullscreen);
sf::RenderWindow window(sf::VideoMode(950, 150), "SFML works!");
#endif
sf::Text txtS("Hello SFML");
#ifdef _WIN32
std::string sFnt = std::getenv("WINDIR"); //> Warnung unterdrücken: 4996;:
sFnt += "\\Fonts\\COUR.TTF";
sf::Font k_Font;
if (!k_Font.loadFromFile(sFnt))
{
txtS.setString("FontFehler");
}
#else
std::string sFnt = "/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf" ;
//std::string sFnt = "/usr/share/fonts/truetype/ttf-liberation/LiberationMono-Bold.ttf" ;
sf::Font k_Font;
if (!k_Font.loadFromFile(sFnt))
{
txtS.setString("FontFehler");
}
#endif
sf::Text txtK(""); //> Zeig TastaturStatus:
txtK.move(20.0, 50.0);
txtK.setScale(0.5, 0.5);
txtK.setFont(k_Font);
sf::Text txtM(""); //> Markiere einige Tasten:
txtM.move(20.0, 70.0);
txtM.setScale(0.5, 0.5);
txtM.setFont(k_Font);
sf::Text txtZ(""); //> Markiere Zusatzinfo:
txtZ.move(20.0, 90.0);
txtZ.setScale(0.5, 0.5);
txtZ.setFont(k_Font);
sf::Text txtC(""); //> Codeinfo:
txtC.move(20.0, 110.0);
txtC.setScale(0.5, 0.5);
txtC.setFont(k_Font);
sf::Event k_Event;
window.setKeyRepeatEnabled(true);
const long k_lKc = sf::Keyboard::KeyCount;
long k_KeyTst[k_lKc];
long i = 0;
//> TastaturStatus=0:
for (i = 0; (i < k_lKc); i++)
{
k_KeyTst[i] = 0;
}
while (window.isOpen())
{
//> EVENTS:
while (window.pollEvent(k_Event))
{
if
(
(k_Event.type == sf::Event::LostFocus)
||
(k_Event.type == sf::Event::GainedFocus)
||
(k_Event.type == sf::Event::Resized)
)
{
//> TastaturStatus=0:
for (i = 0; (i < k_lKc); i++)
{
k_KeyTst[i] = 0;
}
}
//> Eine oder mehrere Tasten gedrückt:
if (k_Event.type == sf::Event::KeyPressed)
{
long lKyC = k_Event.key.code;
if
(
(lKyC > -1)
&&
(lKyC < k_lKc)
)
{
if (k_KeyTst[lKyC] < LONG_MAX)
{
k_KeyTst[lKyC]++;
} else
{
k_KeyTst[lKyC] = 1;
}
}
}
//> Eine oder mehrere Tasten losgelassen:
if (k_Event.type == sf::Event::KeyReleased)
{
long lKyC = k_Event.key.code;
if
(
(lKyC > -1)
&&
(lKyC < k_lKc)
)
{
k_KeyTst[lKyC] = 0;
}
}
if (k_Event.type == sf::Event::Closed)
{
window.close(); //> Und raus ..:
}
}
std::string sTxtK; //> TastaturZustand: "_" | "1" .. "9", "X":
sTxtK = "";
std::string sTxtM; //> Markierung einiger Tasten:
sTxtM = "";
std::string sTxtZ; //> Zusatzbemerkung zu einigen Tasten:
sTxtZ = "";
std::string sTxtC; //> TastenKeyCode:
sTxtC = "KeyCode =";
for (i = 0; (i < k_lKc); i++)
{
if (k_KeyTst[i] > 0)
{
//> Taste ist gedrückt:
char cX[256];
if (k_KeyTst[i] < 10)
{
#ifdef _WIN32
_itoa_s(k_KeyTst[i], cX, 256, 10);
#else
sprintf(cX, "%ld", k_KeyTst[i]);
#endif
sTxtK += cX; //> "1" .. "9":
} else
{
sTxtK += "X";
}
sprintf(cX, " %ld", i);
sTxtC += cX;
} else
{
//> Taste ist nicht gedrückt:
sTxtK += "_";
}
//> Markierungen:
switch (i)
{
case sf::Keyboard::A:
{
sTxtM += "A";
sTxtZ += " ";
break;
}
case sf::Keyboard::B:
{
sTxtM += "B";
sTxtZ += " ";
break;
}
case sf::Keyboard::K:
{
sTxtM += "K";
sTxtZ += " ";
break;
}
case sf::Keyboard::L:
{
sTxtM += "L";
sTxtZ += " ";
break;
}
case sf::Keyboard::LAlt:
{
sTxtM += "a";
sTxtZ += "L";
break;
}
case sf::Keyboard::RAlt:
{
sTxtM += "a";
sTxtZ += "R";
break;
}
case sf::Keyboard::LControl:
{
sTxtM += "c";
sTxtZ += "L";
break;
}
case sf::Keyboard::RControl:
{
sTxtM += "c";
sTxtZ += "R";
break;
}
case sf::Keyboard::LBracket:
{
sTxtM += "[";
sTxtZ += " ";
break;
}
case sf::Keyboard::RBracket:
{
sTxtM += "]";
sTxtZ += " ";
break;
}
default:
{
sTxtM += " ";
sTxtZ += " ";
break;
}
}
}
txtK.setString(sTxtK);
txtM.setString(sTxtM);
txtZ.setString(sTxtZ);
txtC.setString(sTxtC);
window.clear();
window.draw(txtS);
window.draw(txtK);
window.draw(txtM);
window.draw(txtZ);
window.draw(txtC);
window.display();
#ifdef _WIN32
Sleep(33);
#else
usleep(33);
#endif
}
return 0;
}
Download the *.exx: http://www.zwianer.de/Download/SFML_Win32_ZwiAner.exx and rename to *.exe. std::string sFnt = std::getenv("WINDIR");
sFnt += "\\Fonts\\COUR.TTF";
sf::Font k_Font;
//if (!k_Font.loadFromFile("COUR.TTF"))
if (!k_Font.loadFromFile(sFnt))
{
txtS.setString("FontFehler");
}
In this case, it works. (I thought that Fonts always are loaded there without path statement )
sf::Font MyFont;
// Load from a font file on disk
if (!MyFont.LoadFromFile("arial.ttf"))
{
// Error...
}
If I go right in the assumption that the full path always must be used? (Win7/64, VS2010)