Struct pixel_engine::Engine

source ·
pub struct Engine {
    pub title: String,
    pub elapsed: f64,
    /* private fields */
}
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§

Return the current Target size in pixel

Examples found in repository?
src/engine/logic.rs (line 311)
308
309
310
311
312
313
314
315
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Engine")
            .field("title", &self.title)
            .field("size", &self.size())
            .field("scale", &self.size.2)
            .field("elapsed", &self.elapsed)
            .finish()
    }
More examples
Hide additional examples
src/engine/decals.rs (line 350)
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(),
            });
        }

Return the pixel scale factor

Get The status of a key

Get the status of a Mouse Button

Get the mouse location (in pixel) on the screen Will be defaulted to (0,0) at the start of the program

Get the scroll wheel direction (If Any) during the frame

Get all Keys pressed during the last frame

Get all the keys that were held during the last frame

Get all the keys that were released during the last frame

Create a GPU version of Sprite

Switch to text input mode, return true if it wasn’t in this mode before

This will clear the input buffer, reset the input cursor and stop the input mode

Is the engine in input mode

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

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

Return the current input buffer as a string slice

Return the current input cursor position

Trait Implementations§

Formats the value using the given formatter. Read more
Draw A decal with given position and uv (You probably don’t want to use this)
Draw a decal from the given position
Draw a decal with a given scale
Draw a partial decal from the given position
Draw a partial decal with a given scale
Draw a decal where all Corner are given, this will set the uv correctly to allow texture warping The points are in order: Read more
Draw a decal where all Corner are given, this will set the uv correctly to allow texture warping The points are in order: Read more
Draw a decal rotated angle radians around center center is an offset in pixel from the top left corner of the decal
Same as draw_rotated_decal but with scaling
Draw a zone of a decal and rotate it
Draw a zone of a decal, rotate it and scaled it
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Same as the non tinted variant, but with an tint color parameter
Draw the given string starting at the position given and scaled
Get the pixel at the given location, but bypassing any bounds check Read more
Set the pixel at the given location, but bypassing any bounds check Read more
Set the pixel data at the given coordinates to the given Color Will use the current PixelMode
Clear the Sprite With the given Color
Get the size of the target
Set the PixelMode
Get the Pixel Data at the given coordinates
Set the Blend Factor Used for alpha calculations
Get The textsheet (A Sprite)
Return the PixelMode
Get the Blend Factor Used for alpha calculations

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Draw a dotted line
Draw a rectangle with the top left corner at (x, y) and the bottom right corner at (x + w, y + h) (both inclusive) This is the dotted form
Draw the edges of a triangle between the three points This is the dotted form

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
Draw text to the screen 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 screen
Draw a line between two points, You don’t need to do anything with the points for it to work, it will swap them it needed.
Draw a rectangle with the top left corner at (x, y) and the bottom right corner at (x + w, y + h) (both inclusive)
Fill a rectangle with the top left corner at (x, y) and the bottom right corner at (x + w, y + h) (both inclusive)
Draw a circle with center (x, y) and raduis r
Fill a circle with center (x, y) and raduis r
Draw the edges of a triangle between the three points
Fill the given triangle
Draw a Sprite with the top left corner at (x, y) the flip arguement will allow fliping of the axis flip: (horizontal, vertical) scale is the scale of the result (must be >= 1)
Draw a chunk of the given 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()
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.