Struct pixel_engine::Engine
source · Expand description
Bone of the Engine, join everything;
Fields§
§title: String
Main title of the window, Window’s full title will be “Title - fps”
elapsed: f64
Time between current frame and last frame, usefull for movement’s calculations
Implementations§
source§impl Engine
impl Engine
sourcepub fn size(&self) -> Vu2d
pub fn size(&self) -> Vu2d
Return the current Target size in pixel
Examples found in repository?
More examples
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961
fn draw_explicit_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
uv: [P; 4],
decal: &Decal,
tint: Color,
) {
let pos: [Vf2d; 4] = [pos[0].into(), pos[1].into(), pos[2].into(), pos[3].into()];
let uv: [Vf2d; 4] = [uv[0].into(), uv[1].into(), uv[2].into(), uv[3].into()];
let mut di = px_backend::decals::DecalInstances {
id: decal.0.id(),
pos: [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0)],
uv: [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)],
w: [1.0; 4],
tint: tint.into(),
};
for i in 0..4 {
di.pos[i] = (
(pos[i].x / (self.size().x) as f32) * 2.0 - 1.0,
((pos[i].y / (self.size().y) as f32) * 2.0 - 1.0) * -1.0,
);
di.uv[i] = (uv[i].x, uv[i].y);
}
self.handler.draw_decal_instance(di);
}
fn draw_decal<P: Into<Vf2d> + Copy>(&mut self, pos: P, decal: &Decal) {
self.draw_decal_tinted(pos, decal, Color::WHITE);
}
fn draw_decal_scaled<P: Into<Vf2d> + Copy>(&mut self, pos: P, decal: &Decal, scale: P) {
self.draw_decal_scaled_tinted(pos, decal, scale, Color::WHITE);
}
fn draw_partial_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
) {
self.draw_partial_decal_tinted(pos, decal, source_pos, source_size, Color::WHITE);
}
fn draw_partial_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
scale: P,
) {
self.draw_partial_decal_scaled_tinted(
pos,
decal,
source_pos,
source_size,
scale,
Color::WHITE,
);
}
fn draw_warped_decal<P: Into<Vf2d> + Copy>(&mut self, pos: [P; 4], decal: &Decal) {
self.draw_warped_decal_tinted(pos, decal, Color::WHITE);
}
fn draw_warped_partial_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
source_pos: P,
source_size: P,
decal: &Decal,
) {
self.draw_warped_partial_decal_tinted(pos, source_pos, source_size, decal, Color::WHITE);
}
fn draw_rotated_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
) {
self.draw_rotated_decal_tinted(pos, decal, center, angle, Color::WHITE);
}
fn draw_rotated_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
scale: P,
) {
self.draw_rotated_decal_scaled_tinted(pos, decal, center, angle, scale, Color::WHITE);
}
fn draw_partial_rotated_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
source_pos: P,
source_size: P,
) {
self.draw_partial_rotated_decal_tinted(
pos,
decal,
angle,
center,
source_pos,
source_size,
Color::WHITE,
);
}
fn draw_partial_rotated_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
source_pos: P,
source_size: P,
scaled: P,
) {
self.draw_partial_rotated_decal_scaled_tinted(
pos,
decal,
angle,
center,
source_pos,
source_size,
scaled,
Color::WHITE,
);
}
#[inline]
fn draw_decal_tinted<P: Into<Vf2d> + Copy>(&mut self, pos: P, decal: &Decal, tint: Color) {
into!(pos);
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
let topleft = normalize!(pos, screen_size);
let bottomright = normalize!(
{
pos + Vf2d {
x: decal.0.size.0 as f32,
y: decal.0.size.1 as f32,
}
},
screen_size
);
self.handler
.draw_decal_instance(px_backend::decals::DecalInstances {
id: decal.0.id(),
pos: [
(topleft.x, topleft.y), // A
(topleft.x, bottomright.y), // B
(bottomright.x, bottomright.y), // C
(bottomright.x, topleft.y), // D
],
uv: [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)],
w: [1.0; 4],
tint: tint.into(),
});
}
fn draw_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
scale: P,
tint: Color,
) {
into!(scale, pos);
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
let topleft = normalize!(pos, screen_size);
let bottomright = normalize!(
{
pos + Vf2d {
x: decal.0.size.0 as f32,
y: decal.0.size.1 as f32,
} * scale
},
screen_size
);
self.handler
.draw_decal_instance(px_backend::decals::DecalInstances {
id: decal.0.id(),
pos: [
(topleft.x, topleft.y), // A
(topleft.x, bottomright.y), // B
(bottomright.x, bottomright.y), // C
(bottomright.x, topleft.y), // D
],
uv: [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)],
w: [1.0; 4],
tint: tint.into(),
});
}
#[inline]
fn draw_partial_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
tint: Color,
) {
into!(pos, source_pos, source_size);
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
let topleft = normalize!(pos, screen_size);
let bottomright = normalize!(
{
pos + Vf2d {
x: source_size.x,
y: source_size.x,
}
},
screen_size
);
let mut uv = [(0f32, 0f32); 4];
let uv_scale: Vf2d = decal.0.uv_scale.into();
let uv_topleft = source_pos * uv_scale;
let uv_bottomright = uv_topleft + (source_size * uv_scale);
uv[0] = (uv_topleft.x, uv_topleft.y);
uv[1] = (uv_topleft.x, uv_bottomright.y);
uv[2] = (uv_bottomright.x, uv_bottomright.y);
uv[3] = (uv_bottomright.x, uv_topleft.y);
self.handler
.draw_decal_instance(px_backend::decals::DecalInstances {
id: decal.0.id(),
pos: [
(topleft.x, topleft.y), // A
(topleft.x, bottomright.y), // B
(bottomright.x, bottomright.y), // C
(bottomright.x, topleft.y), // D
],
uv,
w: [1.0; 4],
tint: tint.into(),
});
}
#[inline]
fn draw_partial_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
scale: P,
tint: Color,
) {
into!(pos, source_pos, source_size, scale);
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
let topleft = normalize!(pos, screen_size);
let bottomright = normalize!(
{
pos + Vf2d {
x: source_size.x,
y: source_size.x,
} * scale
},
screen_size
);
let mut uv = [(0f32, 0f32); 4];
let uv_scale: Vf2d = decal.0.uv_scale.into();
let uv_topleft = source_pos * uv_scale;
let uv_bottomright = uv_topleft + (source_size * uv_scale);
uv[0] = (uv_topleft.x, uv_topleft.y);
uv[1] = (uv_topleft.x, uv_bottomright.y);
uv[2] = (uv_bottomright.x, uv_bottomright.y);
uv[3] = (uv_bottomright.x, uv_topleft.y);
self.handler
.draw_decal_instance(px_backend::decals::DecalInstances {
id: decal.0.id(),
pos: [
(topleft.x, topleft.y), // A
(topleft.x, bottomright.y), // B
(bottomright.x, bottomright.y), // C
(bottomright.x, topleft.y), // D
],
uv,
w: [1.0; 4],
tint: tint.into(),
});
}
#[inline]
fn draw_warped_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
decal: &Decal,
tint: Color,
) {
const POINT_ONE: usize = 3;
const POINT_TWO: usize = 0;
const POINT_THREE: usize = 1;
const POINT_FOUR: usize = 2;
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
let pos: [Vf2d; 4] = [pos[0].into(), pos[1].into(), pos[2].into(), pos[3].into()];
let pos: [Vf2d; 4] = [
normalize!({ pos[0] }, screen_size),
normalize!({ pos[1] }, screen_size),
normalize!({ pos[2] }, screen_size),
normalize!({ pos[3] }, screen_size),
];
let mut center: Vf2d = (0.0, 0.0).into();
let mut di = px_backend::decals::DecalInstances {
id: decal.0.id(),
pos: [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0)],
uv: [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)],
w: [1.0; 4],
tint: tint.into(),
};
let rd = (pos[POINT_THREE].x - pos[POINT_ONE].x) * (pos[POINT_FOUR].y - pos[POINT_TWO].y)
- (pos[POINT_FOUR].x - pos[POINT_TWO].x) * (pos[POINT_THREE].y - pos[POINT_ONE].y);
if rd != 0.0 {
let rd = 1.0 / rd;
let rn = ((pos[POINT_FOUR].x - pos[POINT_TWO].x)
* (pos[POINT_ONE].y - pos[POINT_TWO].y)
- (pos[POINT_FOUR].y - pos[POINT_TWO].y) * (pos[POINT_ONE].x - pos[POINT_TWO].x))
* rd;
let sn = ((pos[POINT_THREE].x - pos[POINT_ONE].x)
* (pos[POINT_ONE].y - pos[POINT_TWO].y)
- (pos[POINT_THREE].y - pos[POINT_ONE].y) * (pos[POINT_ONE].x - pos[POINT_TWO].x))
* rd;
if !(!(0.0..=1.0).contains(&rn) || !(0.0..=1.0).contains(&sn)) {
center = pos[POINT_ONE] + (pos[POINT_THREE] - pos[POINT_ONE]) * rn;
};
let mut d = [0.0; 4];
for i in 0..4 {
d[i] = (pos[i] - center).mag();
}
for i in 0..4 {
let q = if d[i] == 0.0 {
1.0
} else {
(d[i] + d[(i + 2) & 3]) / d[(i + 2) & 3]
};
di.uv[i].0 *= q;
di.uv[i].1 *= q;
di.w[i] *= q;
di.pos[i] = (pos[i].x, pos[i].y);
}
self.handler.draw_decal_instance(di);
}
}
#[inline]
fn draw_warped_partial_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
source_pos: P,
source_size: P,
decal: &Decal,
tint: Color,
) {
const POINT_ONE: usize = 3;
const POINT_TWO: usize = 0;
const POINT_THREE: usize = 1;
const POINT_FOUR: usize = 2;
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
into!(source_pos, source_size);
let pos: [Vf2d; 4] = [pos[0].into(), pos[1].into(), pos[2].into(), pos[3].into()];
let pos: [Vf2d; 4] = [
normalize!({ pos[0] }, screen_size),
normalize!({ pos[1] }, screen_size),
normalize!({ pos[2] }, screen_size),
normalize!({ pos[3] }, screen_size),
];
let mut center: Vf2d = (0.0, 0.0).into();
let mut di = px_backend::decals::DecalInstances {
id: decal.0.id(),
pos: [(0.0, 0.0), (0.0, 0.0), (0.0, 0.0), (0.0, 0.0)],
uv: [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)],
w: [1.0; 4],
tint: tint.into(),
};
let rd = (pos[POINT_THREE].x - pos[POINT_ONE].x) * (pos[POINT_FOUR].y - pos[POINT_TWO].y)
- (pos[POINT_FOUR].x - pos[POINT_TWO].x) * (pos[POINT_THREE].y - pos[POINT_ONE].y);
if rd != 0.0 {
let uv_scale: Vf2d = decal.0.uv_scale.into();
let uv_topleft = source_pos * uv_scale;
let uv_bottomright = uv_topleft + (source_size * uv_scale);
di.uv[0] = (uv_topleft.x, uv_topleft.y);
di.uv[1] = (uv_topleft.x, uv_bottomright.y);
di.uv[2] = (uv_bottomright.x, uv_bottomright.y);
di.uv[3] = (uv_bottomright.x, uv_topleft.y);
let rd = 1.0 / rd;
let rn = ((pos[POINT_FOUR].x - pos[POINT_TWO].x)
* (pos[POINT_ONE].y - pos[POINT_TWO].y)
- (pos[POINT_FOUR].y - pos[POINT_TWO].y) * (pos[POINT_ONE].x - pos[POINT_TWO].x))
* rd;
let sn = ((pos[POINT_THREE].x - pos[POINT_ONE].x)
* (pos[POINT_ONE].y - pos[POINT_TWO].y)
- (pos[POINT_THREE].y - pos[POINT_ONE].y) * (pos[POINT_ONE].x - pos[POINT_TWO].x))
* rd;
if !(!(0.0..=1.0).contains(&rn) || !(0.0..=1.0).contains(&sn)) {
center = pos[POINT_ONE] + (pos[POINT_THREE] - pos[POINT_ONE]) * rn;
};
let mut d = [0.0; 4];
for i in 0..4 {
d[i] = (pos[i] - center).mag();
}
for i in 0..4 {
let q = if d[i] == 0.0 {
1.0
} else {
(d[i] + d[(i + 2) & 3]) / d[(i + 2) & 3]
};
di.uv[i].0 *= q;
di.uv[i].1 *= q;
di.w[i] *= q;
di.pos[i] = (pos[i].x, pos[i].y);
}
self.handler.draw_decal_instance(di);
}
}
#[inline]
fn draw_rotated_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
center: P,
angle: f32,
tint: Color,
) {
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
into!(pos, center);
let mut pos_arr = [Vf2d { x: 0.0, y: 0.0 }; 4];
pos_arr[0] = Vf2d {x:0.0,y:0.0} - center /* * scale*/;
pos_arr[1] = Vf2d {x: 0.0, y: decal.size().y as f32} - center /* * scale*/;
pos_arr[2] = Vf2d {x:decal.size().x as f32, y:decal.size().y as f32} - center/* * scale*/;
pos_arr[3] = Vf2d {x:decal.size().x as f32, y: 0.0} - center /* * scale*/;
let (s, c) = angle.sin_cos();
for pos_index in &mut pos_arr {
*pos_index = normalize!(
{
pos + Vf2d {
x: pos_index.x * c - pos_index.y * s,
y: pos_index.x * s + pos_index.y * c,
}
},
screen_size
);
// *pos_index = pos
// + Vf2d {
// x: pos_index.x * c - pos_index.y * s,
// y: pos_index.x * s + pos_index.y * c,
// };
// *pos_index = *pos_index * screen_size * 2.0 - Vf2d { x: 1.0, y: 1.0 };
// pos_index.y *= -1.0;
/*
di.pos[i] = pos + olc::vf2d(di.pos[i].x * c - di.pos[i].y * s, di.pos[i].x * s + di.pos[i].y * c);
di.pos[i] = di.pos[i] * vInvScreenSize * 2.0f - olc::vf2d(1.0f, 1.0f);
di.pos[i].y *= -1.0f;
di.w[i] = 1;
*/
}
self.handler.draw_decal_instance(decals::DecalInstances {
id: decal.0.id(),
pos: [
(pos_arr[0].x, pos_arr[0].y),
(pos_arr[1].x, pos_arr[1].y),
(pos_arr[2].x, pos_arr[2].y),
(pos_arr[3].x, pos_arr[3].y),
],
w: [1.0; 4],
uv: [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)],
tint: tint.into(),
});
}
#[inline]
fn draw_rotated_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
center: P,
angle: f32,
scale: P,
tint: Color,
) {
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
into!(pos, center, scale);
let mut pos_arr = [Vf2d { x: 0.0, y: 0.0 }; 4];
pos_arr[0] = Vf2d {x:0.0,y:0.0} - center /* * scale*/;
pos_arr[1] = Vf2d {x: 0.0, y: decal.size().y as f32} - center /* * scale*/;
pos_arr[2] = Vf2d {x:decal.size().x as f32, y:decal.size().y as f32} - center/* * scale*/;
pos_arr[3] = Vf2d {x:decal.size().x as f32, y: 0.0} - center /* * scale*/;
for p in &mut pos_arr {
*p = *p * scale;
}
let (c, s) = angle.sin_cos();
for pos_index in &mut pos_arr {
*pos_index = normalize!(
{
pos + Vf2d {
x: pos_index.x * c - pos_index.y * s,
y: pos_index.x * s + pos_index.y * c,
}
},
screen_size
);
}
self.handler.draw_decal_instance(decals::DecalInstances {
id: decal.0.id(),
pos: [
(pos_arr[0].x, pos_arr[0].y),
(pos_arr[1].x, pos_arr[1].y),
(pos_arr[2].x, pos_arr[2].y),
(pos_arr[3].x, pos_arr[3].y),
],
w: [1.0; 4],
uv: [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)],
tint: tint.into(),
});
}
#[inline]
fn draw_partial_rotated_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
source_pos: P,
source_size: P,
tint: Color,
) {
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
let uv_scale: Vf2d = decal.0.uv_scale.into();
into!(pos, center, source_pos, source_size);
let uv_topleft = source_pos * uv_scale;
let uv_bottomright = uv_topleft + (source_size * uv_scale);
let mut uv = [(0f32, 0f32); 4];
uv[0] = (uv_topleft.x, uv_topleft.y);
uv[1] = (uv_topleft.x, uv_bottomright.y);
uv[2] = (uv_bottomright.x, uv_bottomright.y);
uv[3] = (uv_bottomright.x, uv_topleft.y);
let mut pos_arr = [Vf2d { x: 0.0, y: 0.0 }; 4];
pos_arr[0] = Vf2d {x:0.0,y:0.0} - center /* * scale*/;
pos_arr[1] = Vf2d {x: 0.0, y: source_size.y} - center /* * scale*/;
pos_arr[2] = Vf2d {x:source_size.x, y: source_size.y } - center/* * scale*/;
pos_arr[3] = Vf2d {x:source_size.x, y: 0.0} - center /* * scale*/;
let (c, s) = angle.sin_cos();
for pos_index in &mut pos_arr {
*pos_index = normalize!(
{
pos + Vf2d {
x: pos_index.x * c - pos_index.y * s,
y: pos_index.x * s + pos_index.y * c,
}
},
screen_size
);
}
self.handler.draw_decal_instance(decals::DecalInstances {
id: decal.0.id(),
pos: [
(pos_arr[0].x, pos_arr[0].y),
(pos_arr[1].x, pos_arr[1].y),
(pos_arr[2].x, pos_arr[2].y),
(pos_arr[3].x, pos_arr[3].y),
],
uv,
w: [1.0; 4],
tint: tint.into(),
});
}
#[inline]
fn draw_partial_rotated_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
source_pos: P,
source_size: P,
scaled: P,
tint: Color,
) {
into!(pos, center, source_pos, source_size, scaled);
let screen_size: Vf2d = (self.size().x as f32, self.size().y as f32).into();
let uv_scale: Vf2d = decal.0.uv_scale.into();
let uv_topleft = source_pos * uv_scale;
let uv_bottomright = uv_topleft + (source_size * uv_scale);
let mut uv = [(0f32, 0f32); 4];
uv[0] = (uv_topleft.x, uv_topleft.y);
uv[1] = (uv_topleft.x, uv_bottomright.y);
uv[2] = (uv_bottomright.x, uv_bottomright.y);
uv[3] = (uv_bottomright.x, uv_topleft.y);
let mut pos_arr = [Vf2d { x: 0.0, y: 0.0 }; 4];
pos_arr[0] = Vf2d {x:0.0,y:0.0} - center /* * scale*/;
pos_arr[1] = Vf2d {x: 0.0, y: source_size.y} - center /* * scale*/;
pos_arr[2] = Vf2d {x:source_size.x, y: source_size.y } - center/* * scale*/;
pos_arr[3] = Vf2d {x:source_size.x, y: 0.0} - center /* * scale*/;
for p in &mut pos_arr {
*p = *p * scaled;
}
let (c, s) = angle.sin_cos();
for pos_index in &mut pos_arr {
*pos_index = normalize!(
{
pos + Vf2d {
x: pos_index.x * c - pos_index.y * s,
y: pos_index.x * s + pos_index.y * c,
}
},
screen_size
);
}
self.handler.draw_decal_instance(decals::DecalInstances {
id: decal.0.id(),
pos: [
(pos_arr[0].x, pos_arr[0].y),
(pos_arr[1].x, pos_arr[1].y),
(pos_arr[2].x, pos_arr[2].y),
(pos_arr[3].x, pos_arr[3].y),
],
w: [1.0; 4],
uv,
tint: tint.into(),
});
}
sourcepub fn get_mouse_btn(&self, btn: MouseBtn) -> Input
pub fn get_mouse_btn(&self, btn: MouseBtn) -> Input
Get the status of a Mouse Button
sourcepub fn get_mouse_location(&self) -> (u32, u32)
pub fn get_mouse_location(&self) -> (u32, u32)
Get the mouse location (in pixel) on the screen Will be defaulted to (0,0) at the start of the program
sourcepub fn get_mouse_wheel(&self) -> MouseWheel
pub fn get_mouse_wheel(&self) -> MouseWheel
Get the scroll wheel direction (If Any) during the frame
sourcepub fn get_pressed(&self) -> HashSet<Keycodes>
pub fn get_pressed(&self) -> HashSet<Keycodes>
Get all Keys pressed during the last frame
sourcepub fn get_held(&self) -> HashSet<Keycodes>
pub fn get_held(&self) -> HashSet<Keycodes>
Get all the keys that were held during the last frame
sourcepub fn get_released(&self) -> HashSet<Keycodes>
pub fn get_released(&self) -> HashSet<Keycodes>
Get all the keys that were released during the last frame
sourcepub fn create_decal(&mut self, sprite: &Sprite) -> Decal
pub fn create_decal(&mut self, sprite: &Sprite) -> Decal
Create a GPU version of Sprite
sourcepub fn start_input(&mut self)
pub fn start_input(&mut self)
Switch to text input mode, return true if it wasn’t in this mode before
sourcepub fn force_stop_input_mode(&mut self)
pub fn force_stop_input_mode(&mut self)
This will clear the input buffer, reset the input cursor and stop the input mode
sourcepub fn is_in_input_mode(&self) -> bool
pub fn is_in_input_mode(&self) -> bool
Is the engine in input mode
sourcepub fn end_input_mode(&mut self) -> &str
pub fn end_input_mode(&mut self) -> &str
Stop the input mode right there, and return a &str to the current buffer. This is if you need to leave the mode but retain the input buffer for a later re-entry
sourcepub fn try_get_finished_input(&mut self) -> Option<String>
pub fn try_get_finished_input(&mut self) -> Option<String>
Return the string when input mode ends (when the key Enter
has been pressed)
This is different than end_input_mode
as it will return the
buffer (and create a new empty one).
This is used when you want to wait until the user has finished typing
sourcepub fn get_input_buffer(&self) -> &str
pub fn get_input_buffer(&self) -> &str
Return the current input buffer as a string slice
sourcepub fn get_input_cursor(&self) -> usize
pub fn get_input_cursor(&self) -> usize
Return the current input cursor position
Trait Implementations§
source§impl DecalDraw for Engine
impl DecalDraw for Engine
source§fn draw_explicit_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
uv: [P; 4],
decal: &Decal,
tint: Color
)
fn draw_explicit_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
uv: [P; 4],
decal: &Decal,
tint: Color
)
source§fn draw_decal<P: Into<Vf2d> + Copy>(&mut self, pos: P, decal: &Decal)
fn draw_decal<P: Into<Vf2d> + Copy>(&mut self, pos: P, decal: &Decal)
source§fn draw_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
scale: P
)
fn draw_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
scale: P
)
source§fn draw_partial_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P
)
fn draw_partial_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P
)
source§fn draw_partial_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
scale: P
)
fn draw_partial_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
scale: P
)
source§fn draw_warped_decal<P: Into<Vf2d> + Copy>(&mut self, pos: [P; 4], decal: &Decal)
fn draw_warped_decal<P: Into<Vf2d> + Copy>(&mut self, pos: [P; 4], decal: &Decal)
source§fn draw_warped_partial_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
source_pos: P,
source_size: P,
decal: &Decal
)
fn draw_warped_partial_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
source_pos: P,
source_size: P,
decal: &Decal
)
source§fn draw_rotated_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P
)
fn draw_rotated_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P
)
angle
radians around center
center is an offset in pixel from the top left corner of the decalsource§fn draw_rotated_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
scale: P
)
fn draw_rotated_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
scale: P
)
draw_rotated_decal
but with scalingsource§fn draw_partial_rotated_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
source_pos: P,
source_size: P
)
fn draw_partial_rotated_decal<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
source_pos: P,
source_size: P
)
source§fn draw_partial_rotated_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
source_pos: P,
source_size: P,
scaled: P
)
fn draw_partial_rotated_decal_scaled<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
angle: f32,
center: P,
source_pos: P,
source_size: P,
scaled: P
)
source§fn draw_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
tint: Color
)
fn draw_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
tint: Color
)
source§fn draw_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
scale: P,
tint: Color
)
fn draw_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
scale: P,
tint: Color
)
source§fn draw_partial_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
tint: Color
)
fn draw_partial_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
tint: Color
)
source§fn draw_partial_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
scale: P,
tint: Color
)
fn draw_partial_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
source_pos: P,
source_size: P,
scale: P,
tint: Color
)
source§fn draw_warped_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
decal: &Decal,
tint: Color
)
fn draw_warped_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
decal: &Decal,
tint: Color
)
source§fn draw_warped_partial_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
source_pos: P,
source_size: P,
decal: &Decal,
tint: Color
)
fn draw_warped_partial_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: [P; 4],
source_pos: P,
source_size: P,
decal: &Decal,
tint: Color
)
source§fn draw_rotated_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
center: P,
angle: f32,
tint: Color
)
fn draw_rotated_decal_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
center: P,
angle: f32,
tint: Color
)
source§fn draw_rotated_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
center: P,
angle: f32,
scale: P,
tint: Color
)
fn draw_rotated_decal_scaled_tinted<P: Into<Vf2d> + Copy>(
&mut self,
pos: P,
decal: &Decal,
center: P,
angle: f32,
scale: P,
tint: Color
)
source§impl DrawSpriteTrait for Engine
impl DrawSpriteTrait for Engine
source§impl SmartDrawingTrait for Engine
impl SmartDrawingTrait for Engine
source§fn draw<P: Into<Vi2d>>(&mut self, pos: P, col: Color)
fn draw<P: Into<Vi2d>>(&mut self, pos: P, col: Color)
PixelMode
source§fn set_pixel_mode(&mut self, mode: PixelMode)
fn set_pixel_mode(&mut self, mode: PixelMode)
PixelMode
source§fn get_pixel<P: Into<Vi2d>>(&self, pos: P) -> Option<Color>
fn get_pixel<P: Into<Vi2d>>(&self, pos: P) -> Option<Color>
source§fn set_blend_factor(&mut self, f: f32)
fn set_blend_factor(&mut self, f: f32)
source§fn get_textsheet(&self) -> &'static Sprite
fn get_textsheet(&self) -> &'static Sprite
Sprite
)source§fn get_pixel_mode(&self) -> PixelMode
fn get_pixel_mode(&self) -> PixelMode
PixelMode
source§fn get_blend_factor(&self) -> f32
fn get_blend_factor(&self) -> f32
Auto Trait Implementations§
impl !RefUnwindSafe for Engine
impl !Send for Engine
impl !Sync for Engine
impl Unpin for Engine
impl !UnwindSafe for Engine
Blanket Implementations§
source§impl<T> DottedShapeTrait for Twhere
T: SmartDrawingTrait,
impl<T> DottedShapeTrait for Twhere
T: SmartDrawingTrait,
source§fn draw_line_dotted<P>(&mut self, p1: P, p2: P, col: Color, pattern: u32)where
P: Into<Vec2d<i32>>,
fn draw_line_dotted<P>(&mut self, p1: P, p2: P, col: Color, pattern: u32)where
P: Into<Vec2d<i32>>,
§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> ShapesTrait for Twhere
T: SmartDrawingTrait,
impl<T> ShapesTrait for Twhere
T: SmartDrawingTrait,
source§fn draw_text<P>(&mut self, pos: P, scale: u32, col: Color, text: &str)where
P: Into<Vec2d<i32>>,
fn draw_text<P>(&mut self, pos: P, scale: u32, col: Color, text: &str)where
P: Into<Vec2d<i32>>,
scale
must be >= 1
The textsize will be equal to scale * 8
for the height and scale * 8 * text.len()
for
the width
This will handle \n
treating it as a new line, but wont do any newline stuff if it is
drawing out of the screensource§fn draw_line<P>(&mut self, p1: P, p2: P, col: Color)where
P: Into<Vec2d<i32>>,
fn draw_line<P>(&mut self, p1: P, p2: P, col: Color)where
P: Into<Vec2d<i32>>,
source§fn draw_rect<P>(&mut self, pos: P, size: P, col: Color)where
P: Into<Vec2d<i32>>,
fn draw_rect<P>(&mut self, pos: P, size: P, col: Color)where
P: Into<Vec2d<i32>>,
(x, y)
and the bottom right corner at (x + w, y + h)
(both inclusive)source§fn fill_rect<P>(&mut self, pos: P, size: P, col: Color)where
P: Into<Vec2d<i32>>,
fn fill_rect<P>(&mut self, pos: P, size: P, col: Color)where
P: Into<Vec2d<i32>>,
(x, y)
and the bottom right corner at (x + w, y + h)
(both inclusive)source§fn draw_circle<P>(&mut self, pos: P, r: u32, col: Color)where
P: Into<Vec2d<i32>>,
fn draw_circle<P>(&mut self, pos: P, r: u32, col: Color)where
P: Into<Vec2d<i32>>,
(x, y)
and raduis r
source§fn fill_circle<P>(&mut self, pos: P, r: u32, col: Color)where
P: Into<Vec2d<i32>>,
fn fill_circle<P>(&mut self, pos: P, r: u32, col: Color)where
P: Into<Vec2d<i32>>,
(x, y)
and raduis r
source§impl<T> SpriteTrait for Twhere
T: SmartDrawingTrait,
impl<T> SpriteTrait for Twhere
T: SmartDrawingTrait,
source§fn draw_sprite<P>(
&mut self,
pos: P,
scale: u32,
sprite: &Sprite,
flip: (bool, bool)
)where
P: Into<Vec2d<i32>>,
fn draw_sprite<P>(
&mut self,
pos: P,
scale: u32,
sprite: &Sprite,
flip: (bool, bool)
)where
P: Into<Vec2d<i32>>,
(x, y)
the flip arguement will allow fliping of the axis
flip: (horizontal, vertical)
scale is the scale of the result (must be >= 1)source§fn draw_partial_sprite<P>(
&mut self,
coords: P,
sprite: &Sprite,
o: P,
size: P,
scale: u32,
flip: (bool, bool)
)where
P: Into<Vec2d<i32>>,
fn draw_partial_sprite<P>(
&mut self,
coords: P,
sprite: &Sprite,
o: P,
size: P,
scale: u32,
flip: (bool, bool)
)where
P: Into<Vec2d<i32>>,
Sprite
onto the Target
coords
is the top left corner of the Target
o
is the Top left corner of the Sprite Chunk
and size
is the (width, height)
of the chunk
flip
and scale
is the same as SpriteTrait::draw_sprite()