1
Graphics / Scaled Tiles
« on: January 01, 2010, 05:26:44 pm »
I want get scaled tile on my screen.
Edit. I forgot Imag.Copy. Sorry for making problems.
Edit. I forgot Imag.Copy. Sorry for making problems.
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.
float Scale = Tileset.GetHeight() * 1.0f /Field_Size ;
sf::IntRect Rect((Element_Type*Tileset.GetHeight()) * Scale, 0, (Tileset.GetHeight()) * Scale, (Tileset.GetHeight())*Scale);
Tileset_Sprite.SetScale(Scale,Scale);Tileset_Sprite.SetSubRect(Rect);Tileset_Sprite.SetPosition(Field_Pos_X, Field_Pos_Y);
Render->Draw(Tileset_Sprite);
int Number_Of_Blurs = 0;
for(int i = 0; i < Number_Of_Blurs; i++)
{
sf::Image Temp_Image = Image_Render.GetImage();
sf::Sprite Blur_Image(Temp_Image);
Image_Render.Clear();
Image_Render.Draw(Blur_Image, Effect);
Image_Render.Display();
}
sf::Sound Button_Click;
void Menu::Create_Buttons((...), sf::SoundBuffer &Snd_Over, sf::SoundBuffer &Snd_Click)
{
for(unsigned int i = 0; i < Number buttons(); i++)
{
sf_gui::Button New_Window;
[...]
New_Window.Button_Over.SetBuffer(Snd_Over);
New_Window.Button_Click.SetBuffer(Snd_Click);
Windows.insert(Windows.end(), New_Window);
}
}
if clicked on button
{
if(Clicked == true)
{
if(Is_Click_Played == false)
{
Button_Click.Play();
Is_Click_Played = true;
}
State = 2;
Result = true;
}
}
else Is_Click_Played = false;
int Mouse_X = Render->GetInput().GetMouseX(), Mouse_Y = Render->GetInput().GetMouseY();
#ifndef Main_H
#define Main_H
#include <vector>
#include <windows.h>
//SFML graphics
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
//main values
extern sf::RenderWindow *Render;
#endif
#include "Main.h"
#define WIN32_LEAN_AND_MEAN
#pragma warning (disable : 4996)
int mouse_x, mouse_y;
sf::RenderWindow *Render;
//FPS and Delta Time
int FPS_Frames;
float DeltaTime;
sf::Clock FPS_Timer;
float FPS_Number, FPS_Time;
int FPS;
//zmienne okienka
HWND hWindow, Render_Window;
MSG Msg;
// nazwa klasy okna
std::string WindowClass = "Window";
std::string WindowCaption = "Caption";
void Display_FPS();
LRESULT CALLBACK WindowEventProc(HWND hWindow, UINT uMsg,WPARAM wParam, LPARAM lParam);
//----------------------- funkcja WinMain()----------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
WNDCLASSEX KlasaOkna;
ZeroMemory (&KlasaOkna, sizeof(WNDCLASSEX));
KlasaOkna.cbSize = sizeof(WNDCLASSEX);
KlasaOkna.hInstance = hInstance;
KlasaOkna.lpfnWndProc = WindowEventProc;
KlasaOkna.lpszClassName = WindowClass.c_str();
KlasaOkna.hCursor = LoadCursor(NULL, IDC_ARROW);
KlasaOkna.hIcon = LoadIcon(NULL, IDI_APPLICATION);
KlasaOkna.hbrBackground = (HBRUSH) COLOR_WINDOW;
RegisterClassEx (&KlasaOkna);
// tworzymy okno funkcją CreateWindowEx
hWindow = CreateWindowEx(NULL, // rozszerzony styl
WindowClass.c_str(), // klasa okna
WindowCaption.c_str(), // tekst na p. tytułu
WS_SYSMENU, // styl okna
CW_USEDEFAULT, // współrzędna X
CW_USEDEFAULT, // współrzędna Y
800, // szerokość
600, // wysokość
NULL, // okno nadrzędne
NULL, // menu
hInstance, // instancjs aplikacji
NULL); // dodatkowe dane
// pokazujemy nasze okno
DWORD Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
HWND Render_Window = CreateWindow("STATIC", NULL, Style, 0, 0, 800, 600, hWindow, NULL, hInstance, NULL);
sf::RenderWindow View01(Render_Window);
Render = &View01;
ShowWindow (hWindow, SW_SHOW);
while (Msg.message != WM_QUIT)
{
if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (&Msg);
DispatchMessage (&Msg);
}
else
{
sf::Event Event;
while (Render->GetEvent(Event))
{
// Process event
}
Display_FPS();
Render->Clear(sf::Color(255, 255, 255));
Render->Display();
}
}
return static_cast<int>(Msg.wParam);// zwracamy kod wyjścia
}
LRESULT CALLBACK WindowEventProc(HWND hWindow, UINT uMsg,WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
break;
case WM_DESTROY: // kończymy program
PostQuitMessage (0);
return 0;
break;
case WM_MOUSEMOVE:
{
mouse_x = LOWORD(lParam);
mouse_y = HIWORD(lParam);
}
break;
}
return DefWindowProc(hWindow, uMsg, wParam, lParam);
}
void Display_FPS()
{
//delta time calculate
DeltaTime = FPS_Timer.GetElapsedTime();
FPS_Timer.Reset();
//FPS calculate
++FPS_Frames;//add frame
FPS_Time += DeltaTime;//time of generating one frame
if (FPS_Time >= 1.0f) // czy minęła sekunda?
{
FPS_Number = FPS_Frames / FPS_Time;//calculate fps
FPS_Frames = 0;//reset frame number
FPS_Time = 0.0f;//reset time
}
std::string tmp, tmp2, tmp3; // brzydkie rozwiązanie
itoa((int)FPS_Number, (char*)tmp.c_str(), 10);
std::string Caption = "Caption ";
Caption += tmp.c_str();
char Buffer[255];
int Mouse_X = Render->GetInput().GetMouseX(), Mouse_Y = Render->GetInput().GetMouseY();
//sprintf( Buffer, " MouseX: %d MouseY: %d", Mouse_X, Mouse_Y);
sprintf( Buffer, " MouseX: %d MouseY: %d", mouse_x, mouse_y);
Caption += Buffer;
SetWindowText(hWindow, Caption.c_str());
}
sfml-system-s-d.lib sfml-main-d.lib sfml-window-s-d.lib sfml-graphics-s-d.lib
#include "Main.h"
#define WIN32_LEAN_AND_MEAN
sf::RenderWindow *Render;
int mouse_x, mouse_y;
//FPS and Delta Time
int FPS_Frames;
float DeltaTime;
sf::Clock FPS_Timer;
float FPS_Number, FPS_Time;
int FPS;
//zmienne okienka
HWND hWindow, Render_Window;
MSG Msg;
// nazwa klasy okna
std::string WindowClass = "Window";
std::string WindowCaption = " ";
b2AABB WorldSize;
b2Vec2 gravity(0.0f, 0.0f);
bool doSleep = true;
//zasoby
//obrazki
sf::Image Img_Button[2];
//fonty
sf::Font Fnt_Arial, Fnt_Times_New_Roman;
void Display_FPS();
LRESULT CALLBACK WindowEventProc(HWND hWindow, UINT uMsg,WPARAM wParam, LPARAM lParam);
//----------------------- funkcja WinMain()----------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int nCmdShow)
{
WNDCLASSEX KlasaOkna;
ZeroMemory (&KlasaOkna, sizeof(WNDCLASSEX));
KlasaOkna.cbSize = sizeof(WNDCLASSEX);
KlasaOkna.hInstance = hInstance;
KlasaOkna.lpfnWndProc = WindowEventProc;
KlasaOkna.lpszClassName = WindowClass.c_str();
KlasaOkna.hCursor = LoadCursor(NULL, IDC_ARROW);
KlasaOkna.hIcon = LoadIcon(NULL, IDI_APPLICATION);
KlasaOkna.hbrBackground = (HBRUSH) COLOR_WINDOW;
RegisterClassEx (&KlasaOkna);
// tworzymy okno funkcją CreateWindowEx
hWindow = CreateWindowEx(NULL, // rozszerzony styl
WindowClass.c_str(), // klasa okna
WindowCaption.c_str(), // tekst na p. tytułu
WS_SYSMENU, // styl okna
CW_USEDEFAULT, // współrzędna X
CW_USEDEFAULT, // współrzędna Y
800, // szerokość
600, // wysokość
NULL, // okno nadrzędne
NULL, // menu
hInstance, // instancjs aplikacji
NULL); // dodatkowe dane
// pokazujemy nasze okno
DWORD Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS;
HWND Render_Window = CreateWindow("STATIC", NULL, Style, 0, 0, 800, 600, hWindow, NULL, hInstance, NULL);
sf::RenderWindow View01(Render_Window);
Render = &View01;
ShowWindow (hWindow, SW_SHOW);
while (Msg.message != WM_QUIT)
{
if (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE))
{
TranslateMessage (&Msg);
DispatchMessage (&Msg);
}
else
{
sf::Event Event;
while (Render->GetEvent(Event))
{
// Process event
}
Display_FPS();
Render->Clear(sf::Color(255, 255, 255));
//some display functions
Button.Display(Render, DeltaTime);
Render->Display();
}
}
return static_cast<int>(Msg.wParam);// zwracamy kod wyjścia
}
LRESULT CALLBACK WindowEventProc(HWND hWindow, UINT uMsg,WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_CREATE:
break;
case WM_DESTROY: // kończymy program
PostQuitMessage (0);
return 0;
break;
//mouse move by winapi
case WM_MOUSEMOVE:
{
mouse_x = LOWORD(lParam);
mouse_y = HIWORD(lParam);
}
break;
}
return DefWindowProc(hWindow, uMsg, wParam, lParam);
}
void Display_FPS()
{
//delta time calculate
DeltaTime = FPS_Timer.GetElapsedTime();
FPS_Timer.Reset();
//FPS calculate
++FPS_Frames;//add frame
FPS_Time += DeltaTime;//time of generating one frame
if (FPS_Time >= 1.0f) // czy minęła sekunda?
{
FPS_Number = FPS_Frames / FPS_Time;//calculate fps
FPS_Frames = 0;//reset frame number
FPS_Time = 0.0f;//reset time
}
std::string tmp, tmp2, tmp3; // brzydkie rozwiązanie
itoa((int)FPS_Number, (char*)tmp.c_str(), 10);
std::string Caption;
Caption += tmp.c_str();
char Buffer[255];
int Mouse_X = Render->GetInput().GetMouseX(), Mouse_Y = Render->GetInput().GetMouseY();
//sprintf( Buffer, " MouseX: %d MouseY: %d", Mouse_X, Mouse_Y); - currently using Winapi input
sprintf( Buffer, " MouseX: %d MouseY: %d Button %d", mouse_x, mouse_y, Button.State);
Caption += Buffer;
SetWindowText(hWindow, Caption.c_str());
}