Skip to content

Commit

Permalink
Merge pull request #6 from KwDrama/feature-chat
Browse files Browse the repository at this point in the history
Feature chat
  • Loading branch information
elfaka authored May 30, 2021
2 parents 33fc81f + 02ba9b2 commit 1c25d5f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 85 deletions.
4 changes: 2 additions & 2 deletions Client/Forms/ControlChat.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 20 additions & 83 deletions Client/Forms/ControlChat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public ControlChat(Chat chat, bool continuous)

// ์ด์ „ ์ฑ„ํŒ…์— ์—ฐ์†์ ์ผ ๊ฒฝ์šฐ ์š”์†Œ ์ œ๊ฑฐ

PictureBox pic = null;
Control dataControl = null;
// ๋ฐ์ดํ„ฐ ํ‘œ์‹œ
if (chat.type == ChatType.Image)
{
pic = new PictureBox();
PictureBox pic = new PictureBox();

// ์ด๋ฏธ์ง€
pic.Image = chat.image;
Expand All @@ -59,13 +59,12 @@ public ControlChat(Chat chat, bool continuous)
Height = pic.Height + verticalSpace;

// ์‹œ๊ฐ„ ๋ผ๋ฒจ ์œ„์น˜
lblTime.Location = new Point(Math.Max(
pic.Location.X, pic.Location.X + pic.Width - lblTime.Width),
lblTime.Location.Y);
lblTime.Left = Math.Max(pic.Location.X, pic.Location.X + pic.Width - lblTime.Width);

// ์ปจํŠธ๋กค ์ถ”๊ฐ€ ๋ฐ ์ œ๊ฑฐ
Controls.Remove(lblText);
Controls.Add(pic);
dataControl = pic;
}
else
{
Expand All @@ -85,97 +84,35 @@ public ControlChat(Chat chat, bool continuous)
sizef = g.MeasureString(lblText.Text, Font);
lblText.Width = (int)sizef.Width + 3;

lblTime.Location = new Point(Math.Max(
lblText.Location.X, lblText.Location.X + lblText.Width - lblTime.Width),
lblTime.Location.Y);
lblTime.Left = Math.Max(lblText.Location.X, lblText.Location.X + lblText.Width - lblTime.Width);
}
dataControl = lblText;
}

// ๋‚ด๊ฐ€ ๋ณด๋‚ธ ๊ฒƒ์ผ ๊ฒฝ์šฐ
if (chat.empId == Program.employee.id)
// ์—ฐ์†์ ์ผ ๊ฒฝ์šฐ ํ”„๋กœํ•„, ์ด๋ฆ„์„ ์ œ๊ฑฐ
// ์‹œ๊ณ„๋Š” ๋‹ค์Œ ์ฑ„ํŒ…์ด ๋“ค์–ด์™”์„ ๋•Œ SetContinuous() ํ˜ธ์ถœ ๋˜์„œ ์ œ๊ฑฐ ๋จ
if (continuous || chat.empId == Program.employee.id)
{
// ์ „์ฒด ๋†’์ด์— ๋Œ€ํ•œ Offset ๋‹ค์‹œ ์ง€์ •
int needSubstractheight = lblName.Height + lblName.Margin.Bottom;
verticalSpace -= needSubstractheight;

// ๋ฐ์ดํ„ฐ ์œ„์น˜
if (chat.type == ChatType.Image)
{
// ์šฐ์ธก ์ •๋ ฌ ํ›„ lblName ๋†’์ด๋งŒํผ ์œ„๋กœ ์˜ฌ๋ฆฌ๊ธฐ
pic.Location = new Point(Width - Padding.Right - pic.Width, pic.Location.Y - needSubstractheight);
pic.Anchor = AnchorStyles.Top | AnchorStyles.Right;

// ์ „์ฒด ๋†’์ด ์ง€์ •
Height = pic.Height + verticalSpace;
}
else
{
// ์šฐ์ธก ์ •๋ ฌ ํ›„ lblName ๋†’์ด๋งŒํผ ์œ„๋กœ ์˜ฌ๋ฆฌ๊ธฐ
lblText.Location = new Point(Width - Padding.Right - lblText.Width, lblText.Location.Y - needSubstractheight);
lblText.Anchor = AnchorStyles.Top | AnchorStyles.Right;
lblText.BackColor = Color.LemonChiffon;

// ์ „์ฒด ๋†’์ด ์ง€์ •
Height = lblText.Height + verticalSpace;
}

// ์‹œ๊ณ„ ์œ„์น˜
lblTime.TextAlign = ContentAlignment.TopLeft;
lblTime.Anchor = AnchorStyles.Top | AnchorStyles.Right;
lblTime.Location = new Point(Math.Min(
chat.type == ChatType.Image ? pic.Location.X : lblText.Location.X,
Width - Padding.Right - lblTime.Width),
lblTime.Location.Y);
dataControl.Top = 4;
Height = dataControl.Top + dataControl.Height + lblTime.Height;

// ๋ถˆํ•„์š” ์ปจํŠธ๋กค ์ง€์šฐ๊ธฐ
Controls.Remove(picProfile);
Controls.Remove(lblName);
}
else
{
// ๋‹ค๋ฅธ ์‚ฌ๋žŒ์ด ๋ณด๋‚ธ ๊ฒƒ์ด ์—ฐ์†์ ์ผ ๊ฒฝ์šฐ
if (continuous)
{
// ์ „์ฒด ๋†’์ด์— ๋Œ€ํ•œ Offset ๋‹ค์‹œ ์ง€์ •
int needSubstractheight = lblName.Height + lblName.Margin.Bottom;
verticalSpace -= needSubstractheight;

// ๋ฐ์ดํ„ฐ ์œ„์น˜
if (chat.type == ChatType.Image)
{
// ์šฐ์ธก ์ •๋ ฌ ํ›„ lblName ๋†’์ด๋งŒํผ ์œ„๋กœ ์˜ฌ๋ฆฌ๊ธฐ
pic.Location = new Point(pic.Location.X, pic.Location.Y - needSubstractheight);

// ์ „์ฒด ๋†’์ด ์ง€์ •
Height = pic.Height + verticalSpace;
}
else
{
// ์šฐ์ธก ์ •๋ ฌ ํ›„ lblName ๋†’์ด๋งŒํผ ์œ„๋กœ ์˜ฌ๋ฆฌ๊ธฐ
lblText.Location = new Point(lblText.Location.X, lblText.Location.Y - needSubstractheight);

// ์ „์ฒด ๋†’์ด ์ง€์ •
Height = lblText.Height + verticalSpace;
}



// ๋ถˆํ•„์š” ์ปจํŠธ๋กค ์ง€์šฐ๊ธฐ
Controls.Remove(picProfile);
Controls.Remove(lblName);
}
}

// ์—ฐ์†๋  ๊ฒฝ์šฐ ํŒจ๋”ฉ ์ œ๊ฑฐ
if (continuous)
// ๋‚ด๊ฐ€ ๋ณด๋‚ธ ๊ฒƒ์ผ ๊ฒฝ์šฐ
if (chat.empId == Program.employee.id)
{
int needSubstractHeight = Padding.Top - 4;
// ๋ฐ์ดํ„ฐ ์œ„์น˜
dataControl.Left = Width - dataControl.Width - Padding.Right;
dataControl.Anchor = AnchorStyles.Top | AnchorStyles.Right;
dataControl.BackColor = Color.LemonChiffon;

Height -= needSubstractHeight;
Padding = new Padding(Padding.Left, 4, Padding.Right, Padding.Bottom);
// ์‹œ๊ณ„ ์œ„์น˜
lblTime.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
lblTime.Left = Math.Min(dataControl.Left, Width - Padding.Right - lblTime.Width);
}

BackColor = Color.FromArgb(new Random(DateTime.Now.Millisecond).Next());
}

public void SetContinuous()
Expand Down

0 comments on commit 1c25d5f

Please sign in to comment.