Example #1
0
LRESULT CALLBACK Proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
    Window* window = (Window*)GetWindowLong(hwnd, GWL_USERDATA);
    switch (message) {
    case  WM_ERASEBKGND:
        return true;
    case WM_PAINT:
        {
            RECT rect;
            GetUpdateRect(hwnd, &rect, FALSE);
            SkRect clip_rect = SkRect::MakeXYWH(
                SkIntToScalar(rect.left), 
                SkIntToScalar(rect.top), 
                SkIntToScalar(rect.right - rect.left),
                SkIntToScalar(rect.bottom - rect.top));
            window->Draw(clip_rect);
            TexturePool::GetInstance()->CanvasToScreen(clip_rect);
        }
        break;
    case WM_SIZE:
        {
            if(wParam != SIZE_MINIMIZED) {
                RECT rect;
                GetClientRect(hwnd, &rect);
                window->SetGeometry(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
                window->Dolayout();
            }
        }
        break;
    case WM_GETMINMAXINFO:
        {
            LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
            if(window->LimitMaxWidth() < (int)(INT32_MAX - GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYBORDER))) {
                lpMMI->ptMaxTrackSize.x = window->LimitMaxWidth() + GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYBORDER);
            }
            if(window->LimitMaxHeight() < (int)(INT32_MAX - GetSystemMetrics(SM_CYBORDER) + GetSystemMetrics(SM_CYBORDER))) {
                lpMMI->ptMaxTrackSize.y = window->LimitMaxHeight() + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYBORDER);
            }
            RECT inner_rect, window_rect;
            GetClientRect(hwnd, &inner_rect);
            GetWindowRect(hwnd, &window_rect);

            lpMMI->ptMinTrackSize.x = window->LimitMinWidth() + 
                ((window_rect.right - window_rect.left) - (inner_rect.right - inner_rect.left));

            lpMMI->ptMinTrackSize.y = window->LimitMinHeight() +
                ((window_rect.bottom - window_rect.top) - (inner_rect.bottom - inner_rect.top));
        }
    default:
        auto events = EventFactory::GetInstance()->CreateEvent(message, wParam, lParam);
        for (auto event:events) {
            if(event && event->Target()) {
                event->Target()->DoEvent(event.get());
            }
        }
    }
    return CallWindowProc(window->oldProc_, hwnd, message, wParam, lParam);
}
Example #2
0
void Actor::draw(Window &window)
{
	int frame = mAnimFrame;

	if (frame3)
		frame = 1;


	SDL_Rect animClip = { getSpriteClip()->x + (frame * getWorld()->getCharSprites()->tileW), getSpriteClip()->y + (mAnimState * getWorld()->getCharSprites()->tileH), 
		getWorld()->getCharSprites()->tileW, getWorld()->getCharSprites()->tileH };

	window.Draw(getSprite(), getPosx() - getWorld()->getCamera()->view.x, getPosy() - getWorld()->getCamera()->view.y, &animClip);
}
Example #3
0
void Actor::drawRect(Window &window)
{
	SDL_Rect colBox = mCollisionBox;
	colBox.x -= getWorld()->getCamera()->view.x;
	colBox.y -= getWorld()->getCamera()->view.y;

	colBox.x *= SIZE_FACTOR;
	colBox.y *= SIZE_FACTOR;
	colBox.w *= SIZE_FACTOR;
	colBox.h *= SIZE_FACTOR;

	window.Draw(window.getGreen(), colBox);
}
Example #4
0
int main(int argc, char **argv)
{
    PoleaxeManager = Manager(new manager());
    Alleg::Init();
    Mouse m = Mouse(new mouse());
    Keyboard k = Keyboard(new keyboard());
	Display disp = Display(new display());
	Timer t = Timer(new timer());
	disp->SetDisplayMode(840, 525, 32);
	Window w = Window(new window("test window", 10, 10, 300, 200, 0));
	PoleaxeManager->AddWindow(w);
	disp->SetBackground("background.bmp");
	w->Draw();
	PoleaxeManager->MessageLoop();
	return 0;
}
Example #5
0
int main(int argv, char** argc)
{
	Window win;
	win.Init("MyWindow");
	
	SDL_Texture *texBackground = win.LoadImage("../res/background.png");
	win.Clear();
	win.Draw(texBackground,win.Box());
	win.Present();

	Event evt;
	evt.AddCallback(SDL_KEYDOWN,funKeyDown);
	evt.StartEvent();

	return 0;
}
Example #6
0
/**
 *  zeichnet die Steuerelemente.
 *
 *  @author OLiver
 */
void Window::DrawControls(void)
{
	for(std::map<unsigned int,Window*>::iterator it = idmap.begin(); it != idmap.end(); ++it)
	{
		Window *control = it->second;
		assert(control);

		control->Msg_PaintBefore();
		control->Draw();
	}

	for(std::map<unsigned int,Window*>::iterator it = idmap.begin(); it != idmap.end(); ++it)
	{
		Window *control = it->second;
		assert(control);

		control->Msg_PaintAfter();
	}
}
Example #7
0
/**
 *  zeichnet die Steuerelemente.
 */
void Window::DrawControls()
{
    for(std::map<unsigned int, Window*>::iterator it = childIdToWnd_.begin(); it != childIdToWnd_.end(); ++it)
    {
        Window* control = it->second;
        RTTR_Assert(control);

        control->Msg_PaintBefore();
        control->Draw();
    }

    for(std::map<unsigned int, Window*>::iterator it = childIdToWnd_.begin(); it != childIdToWnd_.end(); ++it)
    {
        Window* control = it->second;
        RTTR_Assert(control);

        control->Msg_PaintAfter();
    }
}
Example #8
0
void Tile::drawAnimate(Window &window)
{
	//use window to draw objects
	//sprites will be drawn relative to the camera view
	window.Draw(mSprite, mPosx - mWorld->getCamera()->view.x, mPosy - mWorld->getCamera()->view.y, &mSpriteClip);
}
Example #9
0
int main(int argc, char **argv)
{
	InitAllegro();

	ALLEGRO_KEYBOARD_STATE klawiatura;
	ALLEGRO_MOUSE_STATE mysz;
	ALLEGRO_EVENT_QUEUE* event_queue = al_create_event_queue();
	ALLEGRO_EVENT_QUEUE* key_queue = al_create_event_queue();
	ALLEGRO_DISPLAY* okno = al_create_display(WINDOW_WIDTH, WINDOW_HEIGHT);
	ALLEGRO_FONT* defaultFont = al_create_builtin_font();
	ALLEGRO_TIMER* timer = al_create_timer(1.0 / 60.0);

	al_register_event_source(key_queue, al_get_display_event_source(okno));
	al_register_event_source(event_queue, al_get_display_event_source(okno));
	al_register_event_source(key_queue, al_get_keyboard_event_source());
	al_register_event_source(event_queue, al_get_timer_event_source(timer));

	al_set_window_title(okno, "Fraktale");
	al_set_target_bitmap(al_get_backbuffer(okno));
	
	Menu* menu = new Menu(WINDOW_WIDTH, WINDOW_HEIGHT);
	Mandelbrot* mandelbrot = new Mandelbrot(WINDOW_WIDTH, WINDOW_HEIGHT, defaultFont);
	Julia* julia = new Julia(WINDOW_WIDTH, WINDOW_HEIGHT, defaultFont);
	Window* window = new Window(menu, mandelbrot, julia);
	menu->SetWindow(window);
	mandelbrot->SetWindow(window);
	julia->SetWindow(window);

	const ALLEGRO_COLOR backgroundColor = al_map_rgb(255, 255, 255);
	const ALLEGRO_COLOR frameColor = al_map_rgb(255, 255, 255);
	const int frameThickness = 2;

	ALLEGRO_USTR* str = al_ustr_new("");
	int pos = (int)al_ustr_size(str);

	ALLEGRO_EVENT ev;

	double blokadaKlikniecia = al_get_time();
	
	int poczX = -1, poczY = -1, poprzedniStan = window->stanOkna;
	bool petla = true, klikniecieMyszy = false, klawiszWcisniety = false, wpisywanieIteracji = false;

	double screenRatio = static_cast<double>(WINDOW_HEIGHT) / static_cast<double>(WINDOW_WIDTH);

	while (petla)
	{
		if (poprzedniStan != window->stanOkna)
		{
			blokadaKlikniecia = al_get_time();
		}

		poprzedniStan = window->stanOkna;

		al_get_next_event(event_queue, &ev);
		al_get_mouse_state(&mysz);

		int mx = mysz.x;
		int my = mysz.y;

		bool koniecKlikniecia = false;

		if (mysz.buttons & 1 && klikniecieMyszy == false && al_get_time() > blokadaKlikniecia + 0.3)
		{
			klikniecieMyszy = true;

			if (window->CzyFraktal())
			{
				poczX = mx;
				poczY = my;
			}
		}
		else if (!(mysz.buttons & 1) && klikniecieMyszy == true && al_get_time() > blokadaKlikniecia + 0.3)
		{
			klikniecieMyszy = false;

			int pp = window->stanOkna;

			int respond = window->Click(mx, my);
			if (respond == Responds_t::RESPOND_CLOSE_WINDOW)
				petla = false;

			if (window->CzyFraktal() && (pp == WINDOWSTATE_MANDELBROT || pp == WINDOWSTATE_JULIA))
			{
				koniecKlikniecia = true;
			}

			if (pp == WINDOWSTATE_MENU && window->CzyFraktal())
			{
				window->ZaladujFraktal();
			}
		}

		if (koniecKlikniecia)
		{
			if (window->CzyFraktal())
			{
				Fraktal* fraktal = window->AktualnyFraktal();
				fraktal->Powieksz(poczX, mx, poczY, SkalujY(poczY, screenRatio, poczX, mx));
			}
			poczX = -1, poczY = -1;
		}

		al_get_next_event(key_queue, &ev);

		if (ev.type == ALLEGRO_EVENT_KEY_DOWN && klawiszWcisniety == false && window->CzyFraktal())
		{
			int kod = ev.keyboard.keycode;
			klawiszWcisniety = true;

			if (kod == 9)
			{
				wpisywanieIteracji = true;
			}
			else if (kod == 10)
			{
				Fraktal* fraktal = window->AktualnyFraktal();
				fraktal->Resetuj();
			}
			else if (kod >= 27 && kod <= 36 && wpisywanieIteracji)
			{
				pos += al_ustr_append_chr(str, kod + 21);
			}
			else if (kod == ALLEGRO_KEY_ENTER)
			{
				if (wpisywanieIteracji == true)
					wpisywanieIteracji = false;
				unsigned char* tmp = str->data;
				int t = atoi((const char*)tmp);
				window->SetIteracje(t);
			}
			else if (kod == ALLEGRO_KEY_BACKSPACE)
			{
				if (al_ustr_prev(str, &pos))
					al_ustr_truncate(str, pos);
			}
			else if (kod == ALLEGRO_KEY_ESCAPE)
			{
				window->stanOkna = WINDOWSTATE_MENU;
			}
		}
		else if (ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			klawiszWcisniety = false;
		}

		al_clear_to_color(backgroundColor);

		if (wpisywanieIteracji)
			window->Draw(str);
		else
			window->Draw(NULL);

		if(poczX != -1)
			al_draw_rectangle(poczX, poczY, mx, SkalujY(poczY, screenRatio, poczX, mx), frameColor, frameThickness);
		al_flip_display();
	}
	al_destroy_display(okno);
	return 0;
}