Annotation of nono/lib/rect.h, revision 1.1.1.2

1.1       root        1: //
                      2: // nono
                      3: // Copyright (C) 2021 nono project
                      4: // Licensed under nono-license.txt
                      5: //
                      6: 
                      7: //
                      8: // 矩形構造体
                      9: //
                     10: 
                     11: #pragma once
                     12: 
                     13: #include "header.h"
                     14: 
                     15: //
                     16: // 自前の Rect 構造体
                     17: //
                     18: struct Rect
                     19: {
                     20:        int x {};
                     21:        int y {};
                     22:        int w {};
                     23:        int h {};
                     24: 
                     25:        Rect() {}
                     26: 
                     27:        Rect(int x_, int y_, int w_, int h_) {
                     28:                x = x_;
                     29:                y = y_;
                     30:                w = w_;
                     31:                h = h_;
                     32:        }
                     33: 
                     34:        void SetLTRB(int left, int top, int right, int bottom) {
                     35:                x = left;
                     36:                y = top;
                     37:                w = right - x + 1;
                     38:                h = bottom - y + 1;
                     39:        }
                     40: 
                     41:        int GetRight() const  { return x + w - 1; }
                     42:        int GetBottom() const { return y + h - 1; }
                     43: 
                     44:        void Offset(int dx, int dy) {
                     45:                x += dx;
                     46:                y += dy;
                     47:        }
                     48: 
                     49:        // 点 (px, py) がこの矩形の内側(境界を含む)にあれば true を返す
                     50:        bool Contains(int px, int py) const {
                     51:                return (x <= px && px < x + w &&
                     52:                        y <= py && py < y + h);
                     53:        }
                     54: };
                     55: 
                     56: //
1.1.1.2 ! root       57: // 自前の Rect<float> 構造体
1.1       root       58: //
1.1.1.2 ! root       59: struct RectF
1.1       root       60: {
1.1.1.2 ! root       61:        float x {};
        !            62:        float y {};
        !            63:        float w {};
        !            64:        float h {};
1.1       root       65: 
1.1.1.2 ! root       66:        RectF() {}
1.1       root       67: 
1.1.1.2 ! root       68:        RectF(float x_, float y_, float w_, float h_) {
1.1       root       69:                x = x_;
                     70:                y = y_;
                     71:                w = w_;
                     72:                h = h_;
                     73:        }
                     74: };

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.